Skip to content

Commit

Permalink
add keywordsFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Sep 20, 2024
1 parent 7792860 commit 75ad68f
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static <Entity> String insertList(TableMetaData tableMetaData, List<Entit
SQL sql = new SQL();
switch (DBType.toType(databaseId)) {
case MYSQL: {
sql.INSERT_INTO(tableMetaData.getTableName());
sql.INSERT_INTO(keywordsFormat(tableMetaData.getTableName(), DBType.MYSQL));

boolean firstRow = true;
int idx = 0;
Expand All @@ -130,7 +130,7 @@ public static <Entity> String insertList(TableMetaData tableMetaData, List<Entit
if (!ObjectUtils.isEmpty(value)) {
if (firstRow) {
sql.VALUES(
"`" + entry.getValue() + "`",
keywordsFormat(entry.getValue(), DBType.MYSQL),
getTokenParam("arg0[" + idx + "]." + entry.getKey()));
}
values.add(getTokenParam("arg0[" + idx + "]." + entry.getKey()));
Expand All @@ -147,7 +147,7 @@ public static <Entity> String insertList(TableMetaData tableMetaData, List<Entit
break;
}
case POSTGRESQL: {
sql.INSERT_INTO("\"" + tableMetaData.getTableName() + "\"");
sql.INSERT_INTO(keywordsFormat(tableMetaData.getTableName(), DBType.POSTGRESQL));

boolean firstRow = true;
List<String> columns = new ArrayList<>();
Expand All @@ -167,7 +167,7 @@ public static <Entity> String insertList(TableMetaData tableMetaData, List<Entit
if (!ObjectUtils.isEmpty(value)) {
if (firstRow) {
sql.VALUES(
"\"" + entry.getValue() + "\"",
keywordsFormat(entry.getValue(), DBType.POSTGRESQL),
getTokenParam("arg0[" + idx + "]." + entry.getKey()));
}
values.add(getTokenParam("arg0[" + idx + "]." + entry.getKey()));
Expand Down Expand Up @@ -277,19 +277,21 @@ public static <Entity> String updateList(
case MYSQL: {
sqlBuilder
.append("UPDATE ")
.append(tableMetaData.getTableName())
.append(keywordsFormat(tableMetaData.getTableName(), DBType.MYSQL))
.append(" SET ");
Map<String, StringBuilder> setClauses = new LinkedHashMap<>();
String primaryKey = "id";
String primaryKey = keywordsFormat("id", DBType.MYSQL);
for (Map.Entry<String, String> entry : fieldColumnMap.entrySet()) {
// Ignore primary key
if (Objects.equals(entry.getKey(), tableMetaData.getPkProperty())) {
primaryKey = entry.getValue();
primaryKey = keywordsFormat(entry.getValue(), DBType.MYSQL);
continue;
}

StringBuilder caseClause = new StringBuilder();
caseClause.append(entry.getValue()).append(" = CASE ");
caseClause
.append(keywordsFormat(entry.getValue(), DBType.MYSQL))
.append(" = CASE ");
for (Entity entity : entities) {
PropertyDescriptor ps = BeanUtils.getPropertyDescriptor(entityClass, entry.getKey());
if (ps == null || ps.getReadMethod() == null) {
Expand Down Expand Up @@ -329,7 +331,10 @@ public static <Entity> String updateList(
.append("' THEN NULL ");
}
}
caseClause.append("ELSE ").append(entry.getValue()).append(" ");
caseClause
.append("ELSE ")
.append(keywordsFormat(entry.getValue(), DBType.MYSQL))
.append(" ");
caseClause.append("END");
setClauses.put(entry.getValue(), caseClause);
}
Expand All @@ -356,16 +361,18 @@ public static <Entity> String updateList(
.append("\"")
.append(" SET ");
Map<String, StringBuilder> setClauses = new LinkedHashMap<>();
String primaryKey = "\"id\"";
String primaryKey = keywordsFormat("id", DBType.POSTGRESQL);
for (Map.Entry<String, String> entry : fieldColumnMap.entrySet()) {
// Ignore primary key
if (Objects.equals(entry.getKey(), tableMetaData.getPkProperty())) {
primaryKey = "\"" + entry.getValue() + "\"";
primaryKey = keywordsFormat(entry.getValue(), DBType.POSTGRESQL);
continue;
}

StringBuilder caseClause = new StringBuilder();
caseClause.append(entry.getValue()).append(" = CASE ");
caseClause
.append(keywordsFormat(entry.getValue(), DBType.POSTGRESQL))
.append(" = CASE ");

for (Entity entity : entities) {
PropertyDescriptor ps = BeanUtils.getPropertyDescriptor(entityClass, entry.getKey());
Expand Down Expand Up @@ -410,7 +417,9 @@ public static <Entity> String updateList(
} else {
caseClause.append("ELSE ");
}
caseClause.append(entry.getValue()).append(" ");
caseClause
.append(keywordsFormat(entry.getValue(), DBType.POSTGRESQL))
.append(" ");
caseClause.append("END");
setClauses.put(entry.getValue(), caseClause);
}
Expand Down

0 comments on commit 75ad68f

Please sign in to comment.