diff --git a/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/config/MilvusPropertiesConfiguration.java b/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/config/MilvusPropertiesConfiguration.java index da9ef0648a33bdd172ebafa8e4eaa56bf342786c..212c878435c8a3547237cd9a7a24339edb8310f3 100644 --- a/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/config/MilvusPropertiesConfiguration.java +++ b/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/config/MilvusPropertiesConfiguration.java @@ -22,4 +22,5 @@ public class MilvusPropertiesConfiguration { private List packages; private boolean openLog; private String logLevel; + private boolean banner = true; } \ No newline at end of file diff --git a/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/service/MilvusInit.java b/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/service/MilvusInit.java index 48dc9e15cbc935857106e0a84e53e8b197216c88..4364dc548a16e27af909b0aa2384c6082b58bdb1 100644 --- a/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/service/MilvusInit.java +++ b/milvus-plus-boot-starter/src/main/java/org/dromara/milvus/plus/service/MilvusInit.java @@ -31,7 +31,7 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Initializ } public void initialize() { - printBanner(); + maybePrintBanner(); LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus", milvusPropertiesConfiguration.isOpenLog(), milvusPropertiesConfiguration.getLogLevel()); @@ -47,6 +47,12 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Initializ return client; } + public void maybePrintBanner() { + if (milvusPropertiesConfiguration.isBanner()) { + printBanner(); + } + } + public void printBanner() { String banner = " __ __ _ _ ____ _ \n" + diff --git a/milvus-plus-core/pom.xml b/milvus-plus-core/pom.xml index f8e1b23899cc903e2ea7c1fa8a8576c043f57216..acf4224c0031e08a60d4422f234fffd9aa184c53 100644 --- a/milvus-plus-core/pom.xml +++ b/milvus-plus-core/pom.xml @@ -28,7 +28,7 @@ io.milvus milvus-sdk-java - 2.5.1 + 2.5.2 org.apache.logging.log4j diff --git a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/cache/PropertyCache.java b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/cache/PropertyCache.java index 4570f71ea7c744f6c39518a3f494cb8c525a8011..c319d2414350a70fa2584c9f60c888e2c0829123 100644 --- a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/cache/PropertyCache.java +++ b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/cache/PropertyCache.java @@ -9,6 +9,8 @@ public class PropertyCache { public Map functionToPropertyMap = new HashMap<>(); //属性名称->集合属性名称 + public Map nullableToPropertyMap = new HashMap<>(); //属性名称->是否允许为空 + public Map methodToPropertyMap = new HashMap<>(); //属性get方法名称->集合属性名称 diff --git a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/converter/MilvusConverter.java b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/converter/MilvusConverter.java index f6a8159e9dfdf5f9006b3a5f60818082c1f22be4..3eefe84dfd6f624d4c5847148b122abb3a8a4a1a 100644 --- a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/converter/MilvusConverter.java +++ b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/converter/MilvusConverter.java @@ -100,6 +100,7 @@ public class MilvusConverter { String fieldName = fieldAnnotation.name().isEmpty() ? field.getName() : fieldAnnotation.name(); // 缓存属性名与函数名的映射 propertyCache.functionToPropertyMap.put(field.getName(), fieldName); + propertyCache.nullableToPropertyMap.put(field.getName(),fieldAnnotation.nullable()); propertyCache.methodToPropertyMap.put(getGetMethodName(field), fieldName); // 处理主键字段 if (fieldAnnotation.isPrimaryKey()) { diff --git a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaInsertWrapper.java b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaInsertWrapper.java index ad392c63fcada64a2b80867e33e23f49f0c1671c..1fcc2c5227b5c16550bdfe4b0cdebd522c3b9b82 100644 --- a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaInsertWrapper.java +++ b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaInsertWrapper.java @@ -114,7 +114,9 @@ public class LambdaInsertWrapper extends AbstractChainWrapper implements String key = entry.getKey(); Object value = entry.getValue(); String tk = propertyCache.functionToPropertyMap.get(key); - GsonUtil.put(jsonObject,tk,value); + if (StringUtils.isNotEmpty(tk)) { + GsonUtil.put(jsonObject,tk,value); + } } if(conversionCache.isAutoID()){ GsonUtil.put(jsonObject,pk,IdWorkerUtils.nextId()); diff --git a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaUpdateWrapper.java b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaUpdateWrapper.java index d6dea4712ec110d2e62d1e964be38b94f1748a99..f02f9087e2376b8944a26a3b2252afdce3e7ee1d 100644 --- a/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaUpdateWrapper.java +++ b/milvus-plus-core/src/main/java/org/dromara/milvus/plus/core/conditions/LambdaUpdateWrapper.java @@ -676,6 +676,9 @@ public class LambdaUpdateWrapper extends AbstractChainWrapper implements W public MilvusResp update(T entity) throws MilvusException { // 获取主键字段 String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName); + if (StringUtils.isNotEmpty(primaryKeyField)) { + throw new MilvusException("not find primary key", 400); + } // 将实体转换为属性映射 Map propertiesMap = getPropertiesMap(entity); PropertyCache propertyCache = conversionCache.getPropertyCache(); @@ -695,14 +698,18 @@ public class LambdaUpdateWrapper extends AbstractChainWrapper implements W hasPrimaryKey = true; primaryKeyValue = value; } - // 添加到更新对象 - GsonUtil.put(updateObject,tableNameColumn, value); + // 校验是否为空 + if (StringUtils.isNotEmpty(tableNameColumn)) { + // 添加到更新对象 + GsonUtil.put(updateObject,tableNameColumn, value); + } } // 检查是否需要构建查询条件 boolean needBuildQuery = !hasPrimaryKey; if (hasPrimaryKey) { for (Map.Entry property : propertyCache.functionToPropertyMap.entrySet()) { - if (updateObject.get(property.getValue()) == null) { + Boolean nullable = propertyCache.nullableToPropertyMap.get(property.getKey()); + if (updateObject.get(property.getValue()) == null&&!nullable) { needBuildQuery = true; eq(primaryKeyField,primaryKeyValue); break; @@ -783,7 +790,9 @@ public class LambdaUpdateWrapper extends AbstractChainWrapper implements W Object value = entry.getValue(); // 根据PropertyCache转换属性名 String tk = propertyCache.functionToPropertyMap.get(key); - GsonUtil.put(jsonObject,tk, value); + if (StringUtils.isNotEmpty(tk)) { + GsonUtil.put(jsonObject,tk, value); + } } // 检查是否包含主键 if (!jsonObject.has(pk)) { @@ -796,7 +805,8 @@ public class LambdaUpdateWrapper extends AbstractChainWrapper implements W for (JsonObject updateObject : jsonObjects) { boolean isBuild=false; for (Map.Entry property : propertyCache.functionToPropertyMap.entrySet()) { - if (updateObject.get(property.getValue()) == null) { + Boolean nullable = propertyCache.nullableToPropertyMap.get(property.getKey()); + if (updateObject.get(property.getValue()) == null&&!nullable) { //缺少数据需要 isBuild=true; } diff --git a/milvus-plus-parent/pom.xml b/milvus-plus-parent/pom.xml index 36166a519ffdaddf75bb58e20a16d9dd38a45e93..9be102a59925e0f79bb0d1da9fe643b39c271e33 100644 --- a/milvus-plus-parent/pom.xml +++ b/milvus-plus-parent/pom.xml @@ -30,7 +30,7 @@ - 2.2.3 + 2.2.4-M1 ${java.version} ${java.version} 3.11.0 diff --git a/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/entity/MilvusPropertiesConfiguration.java b/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/entity/MilvusPropertiesConfiguration.java index 0c44129a5f93616ca8355b5195b49e246e55a83f..20196f9877ee94dc2fdbc7f95f9fa8d9e3d12fc0 100644 --- a/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/entity/MilvusPropertiesConfiguration.java +++ b/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/entity/MilvusPropertiesConfiguration.java @@ -22,4 +22,5 @@ public class MilvusPropertiesConfiguration { private List packages; private boolean openLog; private String logLevel; + private boolean banner = true; } \ No newline at end of file diff --git a/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/service/MilvusInit.java b/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/service/MilvusInit.java index 4b0bcabb2c75644ecdb6697f87157ffd04ce979c..8e3c1e85306997028f50e386b9ead380a71ad9aa 100644 --- a/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/service/MilvusInit.java +++ b/milvus-plus-solon-plugin/src/main/java/org/dromara/solon/service/MilvusInit.java @@ -16,7 +16,7 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Lifecycle //see https://solon.noear.org/article/324 @Bean public MilvusClientV2 init(MilvusPropertiesConfiguration milvusPropertiesConfiguration) { - printBanner(); + maybePrintBanner(milvusPropertiesConfiguration); LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus", milvusPropertiesConfiguration.isOpenLog(), milvusPropertiesConfiguration.getLogLevel()); @@ -36,6 +36,12 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Lifecycle // super.close(); } + public void maybePrintBanner(MilvusPropertiesConfiguration propertiesConfiguration) { + if (propertiesConfiguration.isBanner()) { + printBanner(); + } + } + public void printBanner() { String banner = " __ __ _ _ ____ _ \n" + diff --git a/milvus-spring-demo/pom.xml b/milvus-spring-demo/pom.xml index e2112506f1e4a1b2b35bddf30b415d6904a7f8a7..c4e033b595dc64394230d227d2df23bca9591e4e 100644 --- a/milvus-spring-demo/pom.xml +++ b/milvus-spring-demo/pom.xml @@ -21,7 +21,7 @@ org.dromara.milvus-plus milvus-plus-boot-starter - 2.2.2 + 2.2.4-M1