diff --git a/sql-core/src/main/java/com/easy/query/core/api/client/EasyQueryClient.java b/sql-core/src/main/java/com/easy/query/core/api/client/EasyQueryClient.java index 2e130be4d..850cb4cb8 100644 --- a/sql-core/src/main/java/com/easy/query/core/api/client/EasyQueryClient.java +++ b/sql-core/src/main/java/com/easy/query/core/api/client/EasyQueryClient.java @@ -80,17 +80,12 @@ default Transaction beginTransaction() { ClientInsertable insertable(T entity); ClientInsertable insertable(Collection entities); - MapClientInsertable> mapInsertable(Map map); - MapClientInsertable> mapInsertable(Collection> maps); ClientExpressionUpdatable updatable(Class entityClass); ClientEntityUpdatable updatable(T entity); ClientEntityUpdatable updatable(Collection entities); - MapClientUpdatable> mapUpdatable(Map map); - - MapClientUpdatable> mapUpdatable(Collection> maps); ClientEntityDeletable deletable(T entity); @@ -109,4 +104,9 @@ default Transaction beginTransaction() { boolean removeTracking(Object entity); EntityState getTrackEntityStateNotNull(Object entity); + MapClientInsertable> mapInsertable(Map map); + MapClientInsertable> mapInsertable(Collection> maps); + MapClientUpdatable> mapUpdatable(Map map); + + MapClientUpdatable> mapUpdatable(Collection> maps); } diff --git a/sql-core/src/main/java/com/easy/query/core/expression/segment/condition/predicate/MapColumnValuePredicate.java b/sql-core/src/main/java/com/easy/query/core/expression/segment/condition/predicate/MapColumnValuePredicate.java index c774d8de4..f71b52dd6 100644 --- a/sql-core/src/main/java/com/easy/query/core/expression/segment/condition/predicate/MapColumnValuePredicate.java +++ b/sql-core/src/main/java/com/easy/query/core/expression/segment/condition/predicate/MapColumnValuePredicate.java @@ -2,6 +2,7 @@ import com.easy.query.core.basic.jdbc.parameter.ConstLikeSQLParameter; import com.easy.query.core.basic.jdbc.parameter.EasyConstSQLParameter; +import com.easy.query.core.basic.jdbc.parameter.MapSQLParameter; import com.easy.query.core.basic.jdbc.parameter.SQLParameter; import com.easy.query.core.basic.jdbc.parameter.ToSQLContext; import com.easy.query.core.context.QueryRuntimeContext; @@ -63,10 +64,6 @@ public SQLPredicateCompare getOperator() { @Override public SQLParameter getParameter() { - EasyConstSQLParameter constSQLParameter = new EasyConstSQLParameter(table, columnName, val); - if (SQLPredicateCompareEnum.LIKE == compare || SQLPredicateCompareEnum.NOT_LIKE == compare) { - return new ConstLikeSQLParameter(constSQLParameter); - } - return constSQLParameter; + return new MapSQLParameter(columnName); } } diff --git a/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/InsertMapExpressionBuilder.java b/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/InsertMapExpressionBuilder.java index 0e305b218..61dea5b5b 100644 --- a/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/InsertMapExpressionBuilder.java +++ b/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/InsertMapExpressionBuilder.java @@ -117,24 +117,15 @@ public EntityInsertSQLExpression toExpression(Object entity) { SQLBuilderSegment insertCloneColumns = new ProjectSQLBuilderSegmentImpl(); SQLSegmentFactory sqlSegmentFactory = runtimeContext.getSQLSegmentFactory(); //format - for (String columnName : map.keySet()) { - InsertUpdateSetColumnSQLSegment columnInsertSegment = sqlSegmentFactory.createInsertMapColumnSegment(columnName, runtimeContext); - insertCloneColumns.append(columnInsertSegment); - } Set ignorePropertySet = new HashSet<>(map.size()); boolean clearIgnoreProperties = clearIgnoreProperties(ignorePropertySet, getRuntimeContext(), map); - - if (clearIgnoreProperties) { - - insertCloneColumns.getSQLSegments().removeIf(o -> { - if (o instanceof SQLEntitySegment) { - SQLEntitySegment sqlEntitySegment = (SQLEntitySegment) o; - String propertyName = sqlEntitySegment.getPropertyName(); - return ignorePropertySet.contains(propertyName); - } - return false; - }); + for (String columnName : map.keySet()) { + if(clearIgnoreProperties&&ignorePropertySet.contains(columnName)){ + continue; + } + InsertUpdateSetColumnSQLSegment columnInsertSegment = sqlSegmentFactory.createInsertMapColumnSegment(columnName, runtimeContext); + insertCloneColumns.append(columnInsertSegment); } int insertColumns = insertCloneColumns.getSQLSegments().size(); diff --git a/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/UpdateMapExpressionBuilder.java b/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/UpdateMapExpressionBuilder.java index 3e7da1a6e..ce0bad5d8 100644 --- a/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/UpdateMapExpressionBuilder.java +++ b/sql-core/src/main/java/com/easy/query/core/expression/sql/builder/impl/UpdateMapExpressionBuilder.java @@ -12,7 +12,6 @@ import com.easy.query.core.expression.segment.condition.predicate.MapColumnNullAssertPredicate; import com.easy.query.core.expression.segment.condition.predicate.MapColumnValuePredicate; import com.easy.query.core.expression.segment.impl.UpdateMapColumnSegmentImpl; -import com.easy.query.core.expression.segment.index.SegmentIndex; import com.easy.query.core.expression.sql.builder.ColumnConfigurerContext; import com.easy.query.core.expression.sql.builder.EntityTableExpressionBuilder; import com.easy.query.core.expression.sql.builder.ExpressionContext; @@ -158,9 +157,6 @@ protected SQLBuilderSegment buildUpdateSetByWhere(PredicateSegment sqlWhere, Map SQLBuilderSegment updateSetSQLBuilderSegment = new UpdateSetSQLBuilderSegment(); TableAvailable entityTable = tableExpressionBuilder.getEntityTable(); EntityMetadata entityMetadata = entityTable.getEntityMetadata(); - Class entityClass = entityMetadata.getEntityClass(); - //非手动指定的那么需要移除where的那一部分 - SegmentIndex predicateIndex = sqlWhere.buildPredicateIndex(); //查询其他所有列除了在where里面的 Set columns = map.keySet(); @@ -171,7 +167,7 @@ protected SQLBuilderSegment buildUpdateSetByWhere(PredicateSegment sqlWhere, Map if(clearIgnoreProperties&&ignorePropertySet.contains(column)){ continue; } - if (predicateIndex.contains(entityClass, column)) { + if (whereColumns.contains(column)) { continue; } updateSetSQLBuilderSegment.append(new UpdateMapColumnSegmentImpl(entityTable, column, runtimeContext)); diff --git a/sql-core/src/main/java/com/easy/query/core/expression/sql/expression/impl/TableSQLExpressionImpl.java b/sql-core/src/main/java/com/easy/query/core/expression/sql/expression/impl/TableSQLExpressionImpl.java index 3777d4b4b..1bdd915cb 100644 --- a/sql-core/src/main/java/com/easy/query/core/expression/sql/expression/impl/TableSQLExpressionImpl.java +++ b/sql-core/src/main/java/com/easy/query/core/expression/sql/expression/impl/TableSQLExpressionImpl.java @@ -86,9 +86,6 @@ public String getSelectTableSource() { @Override public String getTableName() { String tableName = dialect.getQuoteName(doGetTableName()); - if (tableName == null) { - throw new EasyQueryException("table " + EasyClassUtil.getSimpleName(entityTable.getEntityClass()) + " cant found mapping table name"); - } String schema = doGetSchema(); if (EasyStringUtil.isNotBlank(schema)) { return dialect.getQuoteName(schema) + "." + tableName; @@ -110,7 +107,16 @@ protected String doGetSchema() { protected String doGetTableName() { String tableName = entityTable.getTableName(); if (tableNameAs != null) { - return tableNameAs.apply(tableName); + String applyTableName = tableNameAs.apply(tableName); + return checkTableName(applyTableName); + } + return checkTableName(tableName); + } + + private String checkTableName(String tableName) { + + if (tableName == null) { + throw new EasyQueryException("table " + EasyClassUtil.getSimpleName(entityTable.getEntityClass()) + " cant found mapping table name"); } return tableName; } diff --git a/sql-platform/sql-api-proxy/src/main/java/com/easy/query/api/proxy/client/EasyProxyQuery.java b/sql-platform/sql-api-proxy/src/main/java/com/easy/query/api/proxy/client/EasyProxyQuery.java index 1f1aaec68..10e7eb95e 100644 --- a/sql-platform/sql-api-proxy/src/main/java/com/easy/query/api/proxy/client/EasyProxyQuery.java +++ b/sql-platform/sql-api-proxy/src/main/java/com/easy/query/api/proxy/client/EasyProxyQuery.java @@ -8,6 +8,8 @@ import com.easy.query.api.proxy.update.ProxyExpressionUpdatable; import com.easy.query.api.proxy.update.ProxyOnlyEntityUpdatable; import com.easy.query.core.api.client.EasyQueryClient; +import com.easy.query.core.basic.api.insert.map.MapClientInsertable; +import com.easy.query.core.basic.api.update.map.MapClientUpdatable; import com.easy.query.core.basic.extension.track.EntityState; import com.easy.query.core.basic.jdbc.parameter.SQLParameter; import com.easy.query.core.basic.jdbc.tx.Transaction; @@ -115,4 +117,19 @@ default Transaction beginTransaction() { boolean removeTracking(Object entity); EntityState getTrackEntityStateNotNull(Object entity); + + default MapClientInsertable> mapInsertable(Map map) { + return getEasyQueryClient().mapInsertable(map); + } + + default MapClientInsertable> mapInsertable(Collection> maps) { + return getEasyQueryClient().mapInsertable(maps); + } + default MapClientUpdatable> mapUpdatable(Map map) { + return getEasyQueryClient().mapUpdatable(map); + } + + default MapClientUpdatable> mapUpdatable(Collection> maps) { + return getEasyQueryClient().mapUpdatable(maps); + } } diff --git a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/DefaultEasyQuery.java b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/DefaultEasyQuery.java index d001155b9..7ad4aa883 100644 --- a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/DefaultEasyQuery.java +++ b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/DefaultEasyQuery.java @@ -6,17 +6,15 @@ import com.easy.query.api4j.delete.impl.EasyExpressionDeletable; import com.easy.query.api4j.insert.EasyEntityInsertable; import com.easy.query.api4j.insert.EntityInsertable; -import com.easy.query.api4j.insert.map.EasyMapInsertable; -import com.easy.query.api4j.insert.map.MapInsertable; import com.easy.query.api4j.select.Queryable; import com.easy.query.api4j.select.impl.EasyQueryable; import com.easy.query.api4j.update.EntityUpdatable; import com.easy.query.api4j.update.ExpressionUpdatable; import com.easy.query.api4j.update.impl.EasyEntityUpdatable; import com.easy.query.api4j.update.impl.EasyExpressionUpdatable; -import com.easy.query.api4j.update.map.EasyMapUpdatable; -import com.easy.query.api4j.update.map.MapUpdatable; import com.easy.query.core.api.client.EasyQueryClient; +import com.easy.query.core.basic.api.insert.map.MapClientInsertable; +import com.easy.query.core.basic.api.update.map.MapClientUpdatable; import com.easy.query.core.basic.extension.track.EntityState; import com.easy.query.core.basic.jdbc.tx.Transaction; import com.easy.query.core.context.QueryRuntimeContext; @@ -75,16 +73,6 @@ public EntityInsertable insertable(Collection entities) { return new EasyEntityInsertable<>(easyQueryClient.insertable(entities)); } - @Override - public MapInsertable> mapInsertable(Map map) { - return new EasyMapInsertable(easyQueryClient.mapInsertable(map)); - } - - @Override - public MapInsertable> mapInsertable(Collection> maps) { - return new EasyMapInsertable(easyQueryClient.mapInsertable(maps)); - } - @Override public ExpressionUpdatable updatable(Class entityClass) { return new EasyExpressionUpdatable<>(easyQueryClient.updatable(entityClass)); @@ -100,16 +88,6 @@ public EntityUpdatable updatable(Collection entities) { return new EasyEntityUpdatable<>(easyQueryClient.updatable(entities)); } - @Override - public MapUpdatable> mapUpdatable(Map map) { - return new EasyMapUpdatable(easyQueryClient.mapUpdatable(map)); - } - - @Override - public MapUpdatable> mapUpdatable(Collection> maps) { - return new EasyMapUpdatable(easyQueryClient.mapUpdatable(maps)); - } - @Override public EntityDeletable deletable(T entity) { return new EasyEntityDeletable<>(easyQueryClient.deletable(entity)); diff --git a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/EasyQuery.java b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/EasyQuery.java index 502e019bf..3b3bffc65 100644 --- a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/EasyQuery.java +++ b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/client/EasyQuery.java @@ -3,12 +3,12 @@ import com.easy.query.api4j.delete.EntityDeletable; import com.easy.query.api4j.delete.ExpressionDeletable; import com.easy.query.api4j.insert.EntityInsertable; -import com.easy.query.api4j.insert.map.MapInsertable; import com.easy.query.api4j.select.Queryable; import com.easy.query.api4j.update.EntityUpdatable; import com.easy.query.api4j.update.ExpressionUpdatable; -import com.easy.query.api4j.update.map.MapUpdatable; import com.easy.query.core.api.client.EasyQueryClient; +import com.easy.query.core.basic.api.insert.map.MapClientInsertable; +import com.easy.query.core.basic.api.update.map.MapClientUpdatable; import com.easy.query.core.basic.extension.track.EntityState; import com.easy.query.core.basic.jdbc.parameter.SQLParameter; import com.easy.query.core.basic.jdbc.tx.Transaction; @@ -85,8 +85,6 @@ default Transaction beginTransaction() { EntityInsertable insertable(T entity); EntityInsertable insertable(Collection entities); - MapInsertable> mapInsertable(Map map); - MapInsertable> mapInsertable(Collection> maps); ExpressionUpdatable updatable(Class entityClass); @@ -94,9 +92,6 @@ default Transaction beginTransaction() { EntityUpdatable updatable(Collection entities); - MapUpdatable> mapUpdatable(Map map); - - MapUpdatable> mapUpdatable(Collection> maps); EntityDeletable deletable(T entity); @@ -117,4 +112,19 @@ default Transaction beginTransaction() { boolean removeTracking(Object entity); EntityState getTrackEntityStateNotNull(Object entity); + + default MapClientInsertable> mapInsertable(Map map) { + return getEasyQueryClient().mapInsertable(map); + } + + default MapClientInsertable> mapInsertable(Collection> maps) { + return getEasyQueryClient().mapInsertable(maps); + } + default MapClientUpdatable> mapUpdatable(Map map) { + return getEasyQueryClient().mapUpdatable(map); + } + + default MapClientUpdatable> mapUpdatable(Collection> maps) { + return getEasyQueryClient().mapUpdatable(maps); + } } diff --git a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/AbstractMapInsertable.java b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/AbstractMapInsertable.java deleted file mode 100644 index a945a9e48..000000000 --- a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/AbstractMapInsertable.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.easy.query.api4j.insert.map; - -import com.easy.query.core.basic.api.insert.map.MapClientInsertable; -import com.easy.query.core.basic.jdbc.parameter.ToSQLContext; -import com.easy.query.core.enums.SQLExecuteStrategyEnum; -import com.easy.query.core.expression.sql.builder.EntityInsertExpressionBuilder; - -import java.util.Collection; -import java.util.Map; -import java.util.function.Function; - -/** - * create time 2023/10/3 09:11 - * 文件说明 - * - * @author xuejiaming - */ -public class AbstractMapInsertable implements MapInsertable> { - private final MapClientInsertable> mapClientInsertable; - - public AbstractMapInsertable(MapClientInsertable> mapClientInsertable) { - - this.mapClientInsertable = mapClientInsertable; - } - - @Override - public EntityInsertExpressionBuilder getEntityInsertExpressionBuilder() { - return mapClientInsertable.getEntityInsertExpressionBuilder(); - } - - @Override - public long executeRows(boolean fillAutoIncrement) { - return mapClientInsertable.executeRows(fillAutoIncrement); - } - - @Override - public String toSQL(Map entity) { - return mapClientInsertable.toSQL(entity); - } - - @Override - public String toSQL(Map entity, ToSQLContext toSQLContext) { - return mapClientInsertable.toSQL(entity, toSQLContext); - } - - @Override - public MapInsertable> noInterceptor() { - mapClientInsertable.noInterceptor(); - return this; - } - - @Override - public MapInsertable> useInterceptor(String name) { - mapClientInsertable.useInterceptor(name); - return this; - } - - @Override - public MapInsertable> noInterceptor(String name) { - mapClientInsertable.noInterceptor(name); - return this; - } - - @Override - public MapInsertable> useInterceptor() { - mapClientInsertable.useInterceptor(); - return this; - } - - @Override - public MapInsertable> batch(boolean use) { - mapClientInsertable.batch(use); - return this; - } - - @Override - public MapInsertable> setSQLStrategy(boolean condition, SQLExecuteStrategyEnum sqlStrategy) { - mapClientInsertable.setSQLStrategy(condition,sqlStrategy); - return this; - } - - @Override - public MapInsertable> onDuplicateKeyIgnore() { - mapClientInsertable.onDuplicateKeyIgnore(); - return this; - } - - @Override - public MapInsertable> asTable(Function tableNameAs) { - mapClientInsertable.asTable(tableNameAs); - return this; - } - - @Override - public MapInsertable> asSchema(Function schemaAs) { - mapClientInsertable.asSchema(schemaAs); - return this; - } - - @Override - public MapInsertable> asAlias(String alias) { - mapClientInsertable.asAlias(alias); - return this; - } - - @Override - public MapInsertable> asTableLink(Function linkAs) { - mapClientInsertable.asTableLink(linkAs); - return this; - } - - @Override - public MapInsertable> insert(Map entity) { - mapClientInsertable.insert(entity); - return this; - } - - @Override - public MapInsertable> insert(Collection> entities) { - mapClientInsertable.insert(entities); - return this; - } -} diff --git a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/EasyMapInsertable.java b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/EasyMapInsertable.java deleted file mode 100644 index b7370e65d..000000000 --- a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/EasyMapInsertable.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.easy.query.api4j.insert.map; - -import com.easy.query.core.basic.api.insert.map.MapClientInsertable; - -import java.util.Map; - -/** - * create time 2023/10/3 09:16 - * 文件说明 - * - * @author xuejiaming - */ -public class EasyMapInsertable extends AbstractMapInsertable { - public EasyMapInsertable(MapClientInsertable> mapClientInsertable) { - super(mapClientInsertable); - } -} diff --git a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/MapInsertable.java b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/MapInsertable.java deleted file mode 100644 index f962cd6f2..000000000 --- a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/insert/map/MapInsertable.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.easy.query.api4j.insert.map; - -import com.easy.query.core.basic.api.insert.Insertable; - -import java.util.Collection; - -/** - * create time 2023/6/2 16:14 - * 文件说明 - * - * @author xuejiaming - */ -public interface MapInsertable extends Insertable> { - @Override - MapInsertable insert(T entity); - - @Override - MapInsertable insert(Collection entities); -} diff --git a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/update/map/EasyMapUpdatable.java b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/update/map/EasyMapUpdatable.java deleted file mode 100644 index ab92fe600..000000000 --- a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/update/map/EasyMapUpdatable.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.easy.query.api4j.update.map; - -import com.easy.query.core.basic.api.update.map.MapClientUpdatable; -import com.easy.query.core.enums.SQLExecuteStrategyEnum; -import com.easy.query.core.expression.sql.builder.EntityUpdateExpressionBuilder; - -import java.util.Map; -import java.util.function.Function; - -/** - * create time 2023/10/3 18:18 - * 文件说明 - * - * @author xuejiaming - */ -public class EasyMapUpdatable implements MapUpdatable> { - private final MapClientUpdatable> mapMapClientUpdatable; - - public EasyMapUpdatable(MapClientUpdatable> mapMapClientUpdatable){ - - this.mapMapClientUpdatable = mapMapClientUpdatable; - } - - @Override - public MapUpdatable> noInterceptor() { - mapMapClientUpdatable.noInterceptor(); - return this; - } - - @Override - public MapUpdatable> useInterceptor(String name) { - mapMapClientUpdatable.useInterceptor(name); - return this; - } - - @Override - public MapUpdatable> noInterceptor(String name) { - mapMapClientUpdatable.noInterceptor(name); - return this; - } - - @Override - public MapUpdatable> useInterceptor() { - mapMapClientUpdatable.useInterceptor(); - return this; - } - - @Override - public MapUpdatable> useLogicDelete(boolean enable) { - mapMapClientUpdatable.useLogicDelete(enable); - return this; - } - - @Override - public MapUpdatable> batch(boolean use) { - mapMapClientUpdatable.batch(use); - return this; - } - - @Override - public void executeRows(long expectRows, String msg, String code) { - mapMapClientUpdatable.executeRows(expectRows,msg,code); - } - - @Override - public long executeRows() { - return mapMapClientUpdatable.executeRows(); - } - - @Override - public MapUpdatable> setSQLStrategy(boolean condition, SQLExecuteStrategyEnum sqlStrategy) { - mapMapClientUpdatable.setSQLStrategy(condition,sqlStrategy); - return this; - } - - @Override - public MapUpdatable> asTable(Function tableNameAs) { - mapMapClientUpdatable.asTable(tableNameAs); - return this; - } - - @Override - public MapUpdatable> asSchema(Function schemaAs) { - mapMapClientUpdatable.asSchema(schemaAs); - return this; - } - - @Override - public MapUpdatable> asAlias(String alias) { - mapMapClientUpdatable.asAlias(alias); - return this; - } - - @Override - public MapUpdatable> asTableLink(Function linkAs) { - mapMapClientUpdatable.asTableLink(linkAs); - return this; - } - - @Override - public EntityUpdateExpressionBuilder getUpdateExpressionBuilder() { - return mapMapClientUpdatable.getUpdateExpressionBuilder(); - } - - @Override - public MapClientUpdatable> getMapClientUpdate() { - return mapMapClientUpdatable; - } - - @Override - public MapUpdatable> whereColumns(String... columnNames) { - mapMapClientUpdatable.whereColumns(columnNames); - return this; - } -} diff --git a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/update/map/MapUpdatable.java b/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/update/map/MapUpdatable.java deleted file mode 100644 index d5bb56a68..000000000 --- a/sql-platform/sql-api4j/src/main/java/com/easy/query/api4j/update/map/MapUpdatable.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.easy.query.api4j.update.map; - -import com.easy.query.core.basic.api.internal.SQLExecuteStrategy; -import com.easy.query.core.basic.api.update.Updatable; -import com.easy.query.core.basic.api.update.map.MapClientUpdatable; - -/** - * create time 2023/10/3 18:17 - * 文件说明 - * - * @author xuejiaming - */ -public interface MapUpdatable extends Updatable>, SQLExecuteStrategy> { - MapClientUpdatable getMapClientUpdate(); - MapUpdatable whereColumns(String... columnNames); -} diff --git a/sql-platform/sql-api4kt/src/main/java/com/easy/query/api4kt/client/EasyKtQuery.java b/sql-platform/sql-api4kt/src/main/java/com/easy/query/api4kt/client/EasyKtQuery.java index 066ea9ed0..e8c53627d 100644 --- a/sql-platform/sql-api4kt/src/main/java/com/easy/query/api4kt/client/EasyKtQuery.java +++ b/sql-platform/sql-api4kt/src/main/java/com/easy/query/api4kt/client/EasyKtQuery.java @@ -7,6 +7,8 @@ import com.easy.query.api4kt.update.KtEntityUpdatable; import com.easy.query.api4kt.update.KtExpressionUpdatable; import com.easy.query.core.api.client.EasyQueryClient; +import com.easy.query.core.basic.api.insert.map.MapClientInsertable; +import com.easy.query.core.basic.api.update.map.MapClientUpdatable; import com.easy.query.core.basic.extension.track.EntityState; import com.easy.query.core.basic.jdbc.parameter.SQLParameter; import com.easy.query.core.basic.jdbc.tx.Transaction; @@ -108,4 +110,19 @@ default Transaction beginTransaction() { boolean removeTracking(Object entity); EntityState getTrackEntityStateNotNull(Object entity); + + default MapClientInsertable> mapInsertable(Map map) { + return getEasyQueryClient().mapInsertable(map); + } + + default MapClientInsertable> mapInsertable(Collection> maps) { + return getEasyQueryClient().mapInsertable(maps); + } + default MapClientUpdatable> mapUpdatable(Map map) { + return getEasyQueryClient().mapUpdatable(map); + } + + default MapClientUpdatable> mapUpdatable(Collection> maps) { + return getEasyQueryClient().mapUpdatable(maps); + } } diff --git a/sql-test/src/main/java/com/easy/query/test/UpdateTest.java b/sql-test/src/main/java/com/easy/query/test/UpdateTest.java index 706705cad..ef300ea66 100644 --- a/sql-test/src/main/java/com/easy/query/test/UpdateTest.java +++ b/sql-test/src/main/java/com/easy/query/test/UpdateTest.java @@ -27,6 +27,7 @@ import java.math.BigDecimal; import java.time.LocalDateTime; +import java.util.HashMap; import java.util.Random; import java.util.UUID; @@ -805,11 +806,63 @@ public void updateTest30() { } Assert.assertFalse(trackManager.currentThreadTracking()); } -// -// public void mapUpdate(){ -// easyQuery.updatable(Map.class) -// .set(Topic::getStars, 12) -// .where(o -> o.eq(Topic::getId, "2")) -// .executeRows(); -// } + + @Test + public void mapUpdateTest1(){ + try { + + HashMap stringObjectHashMap = new HashMap<>(); + stringObjectHashMap.put("id","123"); + stringObjectHashMap.put("name","123"); + easyQuery.mapUpdatable(stringObjectHashMap).asTable("aaa") + .whereColumns("id") + .executeRows(); + } catch (Exception ex) { + Throwable cause = ex.getCause(); + Assert.assertTrue(cause instanceof EasyQuerySQLStatementException); + EasyQuerySQLStatementException cause1 = (EasyQuerySQLStatementException) cause; + String sql = cause1.getSQL(); + Assert.assertEquals("UPDATE `aaa` SET `name` = ? WHERE `id` = ?", sql); + } + } + @Test + public void mapUpdateTest2(){ + try { + + HashMap stringObjectHashMap = new HashMap<>(); + stringObjectHashMap.put("id","123"); + stringObjectHashMap.put("name","123"); + stringObjectHashMap.put("name1",null); + easyQuery.mapUpdatable(stringObjectHashMap).asTable("aaa") + .setSQLStrategy(SQLExecuteStrategyEnum.ONLY_NOT_NULL_COLUMNS) + .whereColumns("id") + .executeRows(); + } catch (Exception ex) { + Throwable cause = ex.getCause(); + Assert.assertTrue(cause instanceof EasyQuerySQLStatementException); + EasyQuerySQLStatementException cause1 = (EasyQuerySQLStatementException) cause; + String sql = cause1.getSQL(); + Assert.assertEquals("UPDATE `aaa` SET `name` = ? WHERE `id` = ?", sql); + } + } + @Test + public void mapUpdateTest3(){ + try { + + HashMap stringObjectHashMap = new HashMap<>(); + stringObjectHashMap.put("id","123"); + stringObjectHashMap.put("name","123"); + stringObjectHashMap.put("name1",null); + easyQuery.mapUpdatable(stringObjectHashMap).asTable("aaa") + .setSQLStrategy(SQLExecuteStrategyEnum.ALL_COLUMNS) + .whereColumns("id") + .executeRows(); + } catch (Exception ex) { + Throwable cause = ex.getCause(); + Assert.assertTrue(cause instanceof EasyQuerySQLStatementException); + EasyQuerySQLStatementException cause1 = (EasyQuerySQLStatementException) cause; + String sql = cause1.getSQL(); + Assert.assertEquals("UPDATE `aaa` SET `name` = ?,`name1` = ? WHERE `id` = ?", sql); + } + } }