Skip to content

Commit

Permalink
模式和属性模式代理模式kotlin下支持map的insert和update
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejmnet committed Oct 3, 2023
1 parent 068cdb6 commit 4f7eabd
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,12 @@ default Transaction beginTransaction() {
<T> ClientInsertable<T> insertable(T entity);

<T> ClientInsertable<T> insertable(Collection<T> entities);
MapClientInsertable<Map<String,Object>> mapInsertable(Map<String,Object> map);
MapClientInsertable<Map<String,Object>> mapInsertable(Collection<Map<String,Object>> maps);

<T> ClientExpressionUpdatable<T> updatable(Class<T> entityClass);

<T> ClientEntityUpdatable<T> updatable(T entity);

<T> ClientEntityUpdatable<T> updatable(Collection<T> entities);
MapClientUpdatable<Map<String,Object>> mapUpdatable(Map<String,Object> map);

MapClientUpdatable<Map<String,Object>> mapUpdatable(Collection<Map<String,Object>> maps);

<T> ClientEntityDeletable<T> deletable(T entity);

Expand All @@ -109,4 +104,9 @@ default Transaction beginTransaction() {
boolean removeTracking(Object entity);

EntityState getTrackEntityStateNotNull(Object entity);
MapClientInsertable<Map<String,Object>> mapInsertable(Map<String,Object> map);
MapClientInsertable<Map<String,Object>> mapInsertable(Collection<Map<String,Object>> maps);
MapClientUpdatable<Map<String,Object>> mapUpdatable(Map<String,Object> map);

MapClientUpdatable<Map<String,Object>> mapUpdatable(Collection<Map<String,Object>> maps);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> columns = map.keySet();

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,4 +117,19 @@ default Transaction beginTransaction() {
boolean removeTracking(Object entity);

EntityState getTrackEntityStateNotNull(Object entity);

default MapClientInsertable<Map<String, Object>> mapInsertable(Map<String, Object> map) {
return getEasyQueryClient().mapInsertable(map);
}

default MapClientInsertable<Map<String, Object>> mapInsertable(Collection<Map<String, Object>> maps) {
return getEasyQueryClient().mapInsertable(maps);
}
default MapClientUpdatable<Map<String, Object>> mapUpdatable(Map<String, Object> map) {
return getEasyQueryClient().mapUpdatable(map);
}

default MapClientUpdatable<Map<String, Object>> mapUpdatable(Collection<Map<String, Object>> maps) {
return getEasyQueryClient().mapUpdatable(maps);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,16 +73,6 @@ public <T> EntityInsertable<T> insertable(Collection<T> entities) {
return new EasyEntityInsertable<>(easyQueryClient.insertable(entities));
}

@Override
public MapInsertable<Map<String, Object>> mapInsertable(Map<String, Object> map) {
return new EasyMapInsertable(easyQueryClient.mapInsertable(map));
}

@Override
public MapInsertable<Map<String, Object>> mapInsertable(Collection<Map<String, Object>> maps) {
return new EasyMapInsertable(easyQueryClient.mapInsertable(maps));
}

@Override
public <T> ExpressionUpdatable<T> updatable(Class<T> entityClass) {
return new EasyExpressionUpdatable<>(easyQueryClient.updatable(entityClass));
Expand All @@ -100,16 +88,6 @@ public <T> EntityUpdatable<T> updatable(Collection<T> entities) {
return new EasyEntityUpdatable<>(easyQueryClient.updatable(entities));
}

@Override
public MapUpdatable<Map<String, Object>> mapUpdatable(Map<String, Object> map) {
return new EasyMapUpdatable(easyQueryClient.mapUpdatable(map));
}

@Override
public MapUpdatable<Map<String, Object>> mapUpdatable(Collection<Map<String, Object>> maps) {
return new EasyMapUpdatable(easyQueryClient.mapUpdatable(maps));
}

@Override
public <T> EntityDeletable<T> deletable(T entity) {
return new EasyEntityDeletable<>(easyQueryClient.deletable(entity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,18 +85,13 @@ default Transaction beginTransaction() {
<T> EntityInsertable<T> insertable(T entity);

<T> EntityInsertable<T> insertable(Collection<T> entities);
MapInsertable<Map<String,Object>> mapInsertable(Map<String,Object> map);
MapInsertable<Map<String,Object>> mapInsertable(Collection<Map<String,Object>> maps);

<T> ExpressionUpdatable<T> updatable(Class<T> entityClass);

<T> EntityUpdatable<T> updatable(T entity);

<T> EntityUpdatable<T> updatable(Collection<T> entities);

MapUpdatable<Map<String,Object>> mapUpdatable(Map<String,Object> map);

MapUpdatable<Map<String,Object>> mapUpdatable(Collection<Map<String,Object>> maps);

<T> EntityDeletable<T> deletable(T entity);

Expand All @@ -117,4 +112,19 @@ default Transaction beginTransaction() {
boolean removeTracking(Object entity);

EntityState getTrackEntityStateNotNull(Object entity);

default MapClientInsertable<Map<String, Object>> mapInsertable(Map<String, Object> map) {
return getEasyQueryClient().mapInsertable(map);
}

default MapClientInsertable<Map<String, Object>> mapInsertable(Collection<Map<String, Object>> maps) {
return getEasyQueryClient().mapInsertable(maps);
}
default MapClientUpdatable<Map<String, Object>> mapUpdatable(Map<String, Object> map) {
return getEasyQueryClient().mapUpdatable(map);
}

default MapClientUpdatable<Map<String, Object>> mapUpdatable(Collection<Map<String, Object>> maps) {
return getEasyQueryClient().mapUpdatable(maps);
}
}

This file was deleted.

Loading

0 comments on commit 4f7eabd

Please sign in to comment.