Skip to content

Commit

Permalink
Include schema in SQL generated by LogicalMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
abel533 committed May 14, 2024
1 parent 165424f commit 22e9e2d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions mapper/src/main/java/io/mybatis/mapper/logical/LogicalProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static String select(ProviderContext providerContext) {
@Override
public String getSql(EntityTable entity) {
return "SELECT " + entity.baseColumnAsPropertyList()
+ " FROM " + entity.table()
+ " FROM " + entity.tableName()
+ where(() -> entity.whereColumns().stream()
.map(column -> ifTest(column.notNullTest(), () -> "AND " + column.columnEqualsProperty()))
.collect(Collectors.joining(LF)) + logicalNotEqualCondition(entity))
Expand Down Expand Up @@ -102,7 +102,7 @@ public String getSql(EntityTable entity) {
+ ifTest("distinct", () -> "distinct ")
+ ifTest("selectColumns != null and selectColumns != ''", () -> "${selectColumns}")
+ ifTest("selectColumns == null or selectColumns == ''", entity::baseColumnAsPropertyList)
+ " FROM " + entity.table()
+ " FROM " + entity.tableName()
+ trim("WHERE", "", "WHERE |OR |AND ", "", () -> ifParameterNotNull(() -> EXAMPLE_WHERE_CLAUSE) + logicalNotEqualCondition(entity))
+ ifTest("orderByClause != null", () -> " ORDER BY ${orderByClause}")
+ ifTest("orderByClause == null", () -> entity.orderByColumn().orElse(""))
Expand All @@ -127,7 +127,7 @@ public String getSql(EntityTable entity) {
+ ifTest("simpleSelectColumns != null and simpleSelectColumns != ''", () -> "${simpleSelectColumns}")
+ ifTest("simpleSelectColumns == null or simpleSelectColumns == ''", () -> "*")
+ ") FROM "
+ entity.table()
+ entity.tableName()
+ trim("WHERE", "", "WHERE |OR |AND ", "", () -> ifParameterNotNull(() -> EXAMPLE_WHERE_CLAUSE) + logicalNotEqualCondition(entity))
+ ifTest("endSql != null and endSql != ''", () -> "${endSql}");
}
Expand All @@ -145,7 +145,7 @@ public static String selectByPrimaryKey(ProviderContext providerContext) {
@Override
public String getSql(EntityTable entity) {
return "SELECT " + entity.baseColumnAsPropertyList()
+ " FROM " + entity.table()
+ " FROM " + entity.tableName()
+ where(() -> entity.idColumns().stream().map(EntityColumn::columnEqualsProperty).collect(Collectors.joining(" AND ")))
// 如果将条件拼接where()中,将会依赖idColumns()的实现,要求其必须返回非空值
+ logicalNotEqualCondition(entity);
Expand All @@ -164,7 +164,7 @@ public static String selectCount(ProviderContext providerContext) {
return SqlScript.caching(providerContext, new LogicalSqlScript() {
@Override
public String getSql(EntityTable entity) {
return "SELECT COUNT(*) FROM " + entity.table() + LF
return "SELECT COUNT(*) FROM " + entity.tableName() + LF
+ where(() ->
entity.whereColumns().stream().map(column ->
ifTest(column.notNullTest(), () -> "AND " + column.columnEqualsProperty())
Expand Down Expand Up @@ -213,7 +213,7 @@ public static String updateByExampleSelective(ProviderContext providerContext) {
@Override
public String getSql(EntityTable entity) {
return ifTest("example.startSql != null and example.startSql != ''", () -> "${example.startSql}")
+ "UPDATE " + entity.table()
+ "UPDATE " + entity.tableName()
+ set(() -> entity.updateColumns().stream().map(
column -> ifTest(column.notNullTest("entity."),
() -> column.columnEqualsProperty("entity.") + ",")).collect(Collectors.joining(LF)))
Expand Down Expand Up @@ -241,7 +241,7 @@ public static String updateByExampleSetValues(ProviderContext providerContext) {
public String getSql(EntityTable entity) {
return ifTest("example.startSql != null and example.startSql != ''", () -> "${example.startSql}")
+ variableNotEmpty("example.setValues", "Example setValues cannot be empty")
+ "UPDATE " + entity.table()
+ "UPDATE " + entity.tableName()
+ EXAMPLE_SET_CLAUSE_INNER_WHEN
+ variableNotNull("example", "Example cannot be null")
//是否允许空条件,默认允许,允许时不检查查询条件
Expand All @@ -263,7 +263,7 @@ public static String updateByPrimaryKey(ProviderContext providerContext) {
return SqlScript.caching(providerContext, new LogicalSqlScript() {
@Override
public String getSql(EntityTable entity) {
return "UPDATE " + entity.table()
return "UPDATE " + entity.tableName()
+ " SET " + entity.updateColumns().stream().map(EntityColumn::columnEqualsProperty).collect(Collectors.joining(","))
+ where(() -> entity.idColumns().stream().map(EntityColumn::columnEqualsProperty).collect(Collectors.joining(" AND ")))
+ logicalNotEqualCondition(entity);
Expand All @@ -282,7 +282,7 @@ public static String updateByPrimaryKeySelective(ProviderContext providerContext
return SqlScript.caching(providerContext, new LogicalSqlScript() {
@Override
public String getSql(EntityTable entity) {
return "UPDATE " + entity.table()
return "UPDATE " + entity.tableName()
+ set(() ->
entity.updateColumns().stream().map(column ->
ifTest(column.notNullTest(), () -> column.columnEqualsProperty() + ",")
Expand All @@ -304,7 +304,7 @@ public static String updateByPrimaryKeySelectiveWithForceFields(ProviderContext

@Override
public String getSql(EntityTable entity) {
return "UPDATE " + entity.table()
return "UPDATE " + entity.tableName()
+ set(() ->
entity.updateColumns().stream().map(column ->
choose(() ->
Expand Down Expand Up @@ -332,7 +332,7 @@ public static String delete(ProviderContext providerContext) {
@Override
public String getSql(EntityTable entity) {
EntityColumn logicColumn = getLogicalColumn(entity);
return "UPDATE " + entity.table()
return "UPDATE " + entity.tableName()
+ " SET " + columnEqualsValue(logicColumn, deleteValue(logicColumn))
+ parameterNotNull("Parameter cannot be null")
+ where(() -> entity.columns().stream()
Expand All @@ -353,7 +353,7 @@ public static String deleteByPrimaryKey(ProviderContext providerContext) {
@Override
public String getSql(EntityTable entity) {
EntityColumn logicColumn = getLogicalColumn(entity);
return "UPDATE " + entity.table()
return "UPDATE " + entity.tableName()
+ " SET " + columnEqualsValue(logicColumn, deleteValue(logicColumn))
+ " WHERE " + entity.idColumns().stream().map(EntityColumn::columnEqualsProperty).collect(Collectors.joining(" AND "))
+ logicalNotEqualCondition(entity);
Expand All @@ -372,7 +372,7 @@ public static String deleteByExample(ProviderContext providerContext) {
return SqlScript.caching(providerContext, (entity, util) -> {
EntityColumn logicColumn = getLogicalColumn(entity);
return util.ifTest("startSql != null and startSql != ''", () -> "${startSql}")
+ "UPDATE " + entity.table()
+ "UPDATE " + entity.tableName()
+ " SET " + columnEqualsValue(logicColumn, deleteValue(logicColumn))
+ util.parameterNotNull("Example cannot be null")
//是否允许空条件,默认允许,允许时不检查查询条件
Expand Down

0 comments on commit 22e9e2d

Please sign in to comment.