mirror of
https://gitee.com/dromara/MilvusPlus.git
synced 2025-12-06 08:58:26 +08:00
commit
0099c4fa5e
@ -22,4 +22,5 @@ public class MilvusPropertiesConfiguration {
|
||||
private List<String> packages;
|
||||
private boolean openLog;
|
||||
private String logLevel;
|
||||
private boolean banner = true;
|
||||
}
|
||||
@ -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" +
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
<dependency>
|
||||
<groupId>io.milvus</groupId>
|
||||
<artifactId>milvus-sdk-java</artifactId>
|
||||
<version>2.5.1</version>
|
||||
<version>2.5.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
|
||||
@ -9,6 +9,8 @@ public class PropertyCache {
|
||||
|
||||
public Map<String, String> functionToPropertyMap = new HashMap<>(); //属性名称->集合属性名称
|
||||
|
||||
public Map<String, Boolean> nullableToPropertyMap = new HashMap<>(); //属性名称->是否允许为空
|
||||
|
||||
public Map<String, String> methodToPropertyMap = new HashMap<>(); //属性get方法名称->集合属性名称
|
||||
|
||||
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -114,7 +114,9 @@ public class LambdaInsertWrapper<T> extends AbstractChainWrapper<T> 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());
|
||||
|
||||
@ -676,6 +676,9 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
|
||||
public MilvusResp<UpsertResp> update(T entity) throws MilvusException {
|
||||
// 获取主键字段
|
||||
String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName);
|
||||
if (StringUtils.isNotEmpty(primaryKeyField)) {
|
||||
throw new MilvusException("not find primary key", 400);
|
||||
}
|
||||
// 将实体转换为属性映射
|
||||
Map<String, Object> propertiesMap = getPropertiesMap(entity);
|
||||
PropertyCache propertyCache = conversionCache.getPropertyCache();
|
||||
@ -695,14 +698,18 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> 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<String, String> 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<T> extends AbstractChainWrapper<T> 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<T> extends AbstractChainWrapper<T> implements W
|
||||
for (JsonObject updateObject : jsonObjects) {
|
||||
boolean isBuild=false;
|
||||
for (Map.Entry<String, String> 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;
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
</developer>
|
||||
</developers>
|
||||
<properties>
|
||||
<revision>2.2.3</revision>
|
||||
<revision>2.2.4-M1</revision>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<maven-compiler.version>3.11.0</maven-compiler.version>
|
||||
|
||||
@ -22,4 +22,5 @@ public class MilvusPropertiesConfiguration {
|
||||
private List<String> packages;
|
||||
private boolean openLog;
|
||||
private String logLevel;
|
||||
private boolean banner = true;
|
||||
}
|
||||
@ -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" +
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
<dependency>
|
||||
<groupId>org.dromara.milvus-plus</groupId>
|
||||
<artifactId>milvus-plus-boot-starter</artifactId>
|
||||
<version>2.2.2</version>
|
||||
<version>2.2.4-M1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user