Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package io.seata.common.util;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Collection;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;

public class LowerCaseLinkHashMap<V> implements Map<String, V> {

Expand Down Expand Up @@ -110,7 +110,7 @@ public void clear() {

@Override
public Set<String> keySet() {
return lowerKeyToOriginMap.values().stream().collect(Collectors.toSet());
return new HashSet<>(lowerKeyToOriginMap.values());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ public TableRecords beforeImage() throws SQLException {
*/
public TableRecords buildTableRecords2(TableMeta tableMeta, String selectSQL, ArrayList<List<Object>> paramAppenderList, List<Object> primaryKeys) throws SQLException {
ResultSet rs = null;
try (PreparedStatement ps = statementProxy.getConnection().prepareStatement(selectSQL + " FOR UPDATE")) {
try (PreparedStatement ps = statementProxy.getConnection()
.prepareStatement(primaryKeys.isEmpty() ? selectSQL + " FOR UPDATE" : selectSQL)) {
int ts = CollectionUtils.isEmpty(paramAppenderList) ? 0 : paramAppenderList.size();
int ds = ts == 0 ? 0 : paramAppenderList.get(0).size();
for (int i = 0; i < ts; i++) {
Expand Down Expand Up @@ -300,12 +301,13 @@ public String buildImageSQL(TableMeta tableMeta) {
List<String> uniqueList = new ArrayList<>();
for (ColumnMeta m : v.getValues()) {
String columnName = m.getColumnName();
if (imageParameterMap.get(columnName) == null && m.getColumnDef() != null) {
List<Object> imageParameters = imageParameterMap.get(columnName);
if (imageParameters == null && m.getColumnDef() != null) {
uniqueList.add(columnName + " = DEFAULT(" + columnName + ") ");
columnIsNull = false;
continue;
}
if ((imageParameterMap.get(columnName) == null && m.getColumnDef() == null) || imageParameterMap.get(columnName).get(finalI) == null || imageParameterMap.get(columnName).get(finalI) instanceof Null) {
if ((imageParameters == null && m.getColumnDef() == null) || imageParameters.get(finalI) == null || imageParameters.get(finalI) instanceof Null) {
if (!"PRIMARY".equalsIgnoreCase(k)) {
columnIsNull = false;
uniqueList.add(columnName + " is ? ");
Expand All @@ -316,7 +318,7 @@ public String buildImageSQL(TableMeta tableMeta) {
}
columnIsNull = false;
uniqueList.add(columnName + " = ? ");
paramAppenderTempList.add(imageParameterMap.get(columnName).get(finalI));
paramAppenderTempList.add(imageParameters.get(finalI));
}
if (!columnIsNull) {
if (isContainWhere[0]) {
Expand Down Expand Up @@ -365,22 +367,20 @@ public Map<String, ArrayList<Object>> buildImageParameters(SQLInsertRecognizer r
for (int i = 0; i < insertColumns.size(); i++) {
String m = insertColumns.get(i);
String params = insertParamsArray[i];
ArrayList<Object> imageListTemp = imageParameterMap.computeIfAbsent(m, k -> new ArrayList<>());
ArrayList<Object> imageListTemp = imageParameterMap.computeIfAbsent(m.toLowerCase(), k -> new ArrayList<>());
if ("?".equals(params.trim())) {
ArrayList<Object> objects = parameters.get(paramsindex);
imageListTemp.addAll(objects);
paramsindex++;
} else if (params instanceof String) {
} else {
// params is character string constant
if ((params.trim().startsWith("'") && params.trim().endsWith("'")) || params.trim().startsWith("\"") && params.trim().endsWith("\"")) {
params = params.trim();
params = params.substring(1, params.length() - 1);
}
imageListTemp.add(params);
} else {
imageListTemp.add(params);
}
imageParameterMap.put(m, imageListTemp);
imageParameterMap.put(m.toLowerCase(), imageListTemp);
}
}
return imageParameterMap;
Expand Down