mirror of
https://gitee.com/dromara/MilvusPlus.git
synced 2025-12-06 17:08:27 +08:00
commit
0099c4fa5e
@ -22,4 +22,5 @@ public class MilvusPropertiesConfiguration {
|
|||||||
private List<String> packages;
|
private List<String> packages;
|
||||||
private boolean openLog;
|
private boolean openLog;
|
||||||
private String logLevel;
|
private String logLevel;
|
||||||
|
private boolean banner = true;
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Initializ
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
printBanner();
|
maybePrintBanner();
|
||||||
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus",
|
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus",
|
||||||
milvusPropertiesConfiguration.isOpenLog(),
|
milvusPropertiesConfiguration.isOpenLog(),
|
||||||
milvusPropertiesConfiguration.getLogLevel());
|
milvusPropertiesConfiguration.getLogLevel());
|
||||||
@ -47,6 +47,12 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Initializ
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void maybePrintBanner() {
|
||||||
|
if (milvusPropertiesConfiguration.isBanner()) {
|
||||||
|
printBanner();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void printBanner() {
|
public void printBanner() {
|
||||||
String banner =
|
String banner =
|
||||||
" __ __ _ _ ____ _ \n" +
|
" __ __ _ _ ____ _ \n" +
|
||||||
|
|||||||
@ -28,7 +28,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.milvus</groupId>
|
<groupId>io.milvus</groupId>
|
||||||
<artifactId>milvus-sdk-java</artifactId>
|
<artifactId>milvus-sdk-java</artifactId>
|
||||||
<version>2.5.1</version>
|
<version>2.5.2</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
|||||||
@ -9,6 +9,8 @@ public class PropertyCache {
|
|||||||
|
|
||||||
public Map<String, String> functionToPropertyMap = new HashMap<>(); //属性名称->集合属性名称
|
public Map<String, String> functionToPropertyMap = new HashMap<>(); //属性名称->集合属性名称
|
||||||
|
|
||||||
|
public Map<String, Boolean> nullableToPropertyMap = new HashMap<>(); //属性名称->是否允许为空
|
||||||
|
|
||||||
public Map<String, String> methodToPropertyMap = new HashMap<>(); //属性get方法名称->集合属性名称
|
public Map<String, String> methodToPropertyMap = new HashMap<>(); //属性get方法名称->集合属性名称
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -100,6 +100,7 @@ public class MilvusConverter {
|
|||||||
String fieldName = fieldAnnotation.name().isEmpty() ? field.getName() : fieldAnnotation.name();
|
String fieldName = fieldAnnotation.name().isEmpty() ? field.getName() : fieldAnnotation.name();
|
||||||
// 缓存属性名与函数名的映射
|
// 缓存属性名与函数名的映射
|
||||||
propertyCache.functionToPropertyMap.put(field.getName(), fieldName);
|
propertyCache.functionToPropertyMap.put(field.getName(), fieldName);
|
||||||
|
propertyCache.nullableToPropertyMap.put(field.getName(),fieldAnnotation.nullable());
|
||||||
propertyCache.methodToPropertyMap.put(getGetMethodName(field), fieldName);
|
propertyCache.methodToPropertyMap.put(getGetMethodName(field), fieldName);
|
||||||
// 处理主键字段
|
// 处理主键字段
|
||||||
if (fieldAnnotation.isPrimaryKey()) {
|
if (fieldAnnotation.isPrimaryKey()) {
|
||||||
|
|||||||
@ -114,7 +114,9 @@ public class LambdaInsertWrapper<T> extends AbstractChainWrapper<T> implements
|
|||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
String tk = propertyCache.functionToPropertyMap.get(key);
|
String tk = propertyCache.functionToPropertyMap.get(key);
|
||||||
GsonUtil.put(jsonObject,tk,value);
|
if (StringUtils.isNotEmpty(tk)) {
|
||||||
|
GsonUtil.put(jsonObject,tk,value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(conversionCache.isAutoID()){
|
if(conversionCache.isAutoID()){
|
||||||
GsonUtil.put(jsonObject,pk,IdWorkerUtils.nextId());
|
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 {
|
public MilvusResp<UpsertResp> update(T entity) throws MilvusException {
|
||||||
// 获取主键字段
|
// 获取主键字段
|
||||||
String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName);
|
String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName);
|
||||||
|
if (StringUtils.isNotEmpty(primaryKeyField)) {
|
||||||
|
throw new MilvusException("not find primary key", 400);
|
||||||
|
}
|
||||||
// 将实体转换为属性映射
|
// 将实体转换为属性映射
|
||||||
Map<String, Object> propertiesMap = getPropertiesMap(entity);
|
Map<String, Object> propertiesMap = getPropertiesMap(entity);
|
||||||
PropertyCache propertyCache = conversionCache.getPropertyCache();
|
PropertyCache propertyCache = conversionCache.getPropertyCache();
|
||||||
@ -695,14 +698,18 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
|
|||||||
hasPrimaryKey = true;
|
hasPrimaryKey = true;
|
||||||
primaryKeyValue = value;
|
primaryKeyValue = value;
|
||||||
}
|
}
|
||||||
// 添加到更新对象
|
// 校验是否为空
|
||||||
GsonUtil.put(updateObject,tableNameColumn, value);
|
if (StringUtils.isNotEmpty(tableNameColumn)) {
|
||||||
|
// 添加到更新对象
|
||||||
|
GsonUtil.put(updateObject,tableNameColumn, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 检查是否需要构建查询条件
|
// 检查是否需要构建查询条件
|
||||||
boolean needBuildQuery = !hasPrimaryKey;
|
boolean needBuildQuery = !hasPrimaryKey;
|
||||||
if (hasPrimaryKey) {
|
if (hasPrimaryKey) {
|
||||||
for (Map.Entry<String, String> property : propertyCache.functionToPropertyMap.entrySet()) {
|
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;
|
needBuildQuery = true;
|
||||||
eq(primaryKeyField,primaryKeyValue);
|
eq(primaryKeyField,primaryKeyValue);
|
||||||
break;
|
break;
|
||||||
@ -783,7 +790,9 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
|
|||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
// 根据PropertyCache转换属性名
|
// 根据PropertyCache转换属性名
|
||||||
String tk = propertyCache.functionToPropertyMap.get(key);
|
String tk = propertyCache.functionToPropertyMap.get(key);
|
||||||
GsonUtil.put(jsonObject,tk, value);
|
if (StringUtils.isNotEmpty(tk)) {
|
||||||
|
GsonUtil.put(jsonObject,tk, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 检查是否包含主键
|
// 检查是否包含主键
|
||||||
if (!jsonObject.has(pk)) {
|
if (!jsonObject.has(pk)) {
|
||||||
@ -796,7 +805,8 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
|
|||||||
for (JsonObject updateObject : jsonObjects) {
|
for (JsonObject updateObject : jsonObjects) {
|
||||||
boolean isBuild=false;
|
boolean isBuild=false;
|
||||||
for (Map.Entry<String, String> property : propertyCache.functionToPropertyMap.entrySet()) {
|
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;
|
isBuild=true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<properties>
|
<properties>
|
||||||
<revision>2.2.3</revision>
|
<revision>2.2.4-M1</revision>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
<maven-compiler.version>3.11.0</maven-compiler.version>
|
<maven-compiler.version>3.11.0</maven-compiler.version>
|
||||||
|
|||||||
@ -22,4 +22,5 @@ public class MilvusPropertiesConfiguration {
|
|||||||
private List<String> packages;
|
private List<String> packages;
|
||||||
private boolean openLog;
|
private boolean openLog;
|
||||||
private String logLevel;
|
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
|
//see https://solon.noear.org/article/324
|
||||||
@Bean
|
@Bean
|
||||||
public MilvusClientV2 init(MilvusPropertiesConfiguration milvusPropertiesConfiguration) {
|
public MilvusClientV2 init(MilvusPropertiesConfiguration milvusPropertiesConfiguration) {
|
||||||
printBanner();
|
maybePrintBanner(milvusPropertiesConfiguration);
|
||||||
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus",
|
LogLevelController.setLoggingEnabledForPackage("org.dromara.milvus.plus",
|
||||||
milvusPropertiesConfiguration.isOpenLog(),
|
milvusPropertiesConfiguration.isOpenLog(),
|
||||||
milvusPropertiesConfiguration.getLogLevel());
|
milvusPropertiesConfiguration.getLogLevel());
|
||||||
@ -36,6 +36,12 @@ public class MilvusInit extends AbstractMilvusClientBuilder implements Lifecycle
|
|||||||
// super.close();
|
// super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void maybePrintBanner(MilvusPropertiesConfiguration propertiesConfiguration) {
|
||||||
|
if (propertiesConfiguration.isBanner()) {
|
||||||
|
printBanner();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void printBanner() {
|
public void printBanner() {
|
||||||
String banner =
|
String banner =
|
||||||
" __ __ _ _ ____ _ \n" +
|
" __ __ _ _ ____ _ \n" +
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.milvus-plus</groupId>
|
<groupId>org.dromara.milvus-plus</groupId>
|
||||||
<artifactId>milvus-plus-boot-starter</artifactId>
|
<artifactId>milvus-plus-boot-starter</artifactId>
|
||||||
<version>2.2.2</version>
|
<version>2.2.4-M1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user