mirror of
https://gitee.com/dromara/MilvusPlus.git
synced 2025-12-08 01:48:23 +08:00
使用迭代器处理可变参数泛型
This commit is contained in:
parent
6db4e35fb9
commit
90ea7e3388
@ -2,7 +2,27 @@ package org.dromara.milvus.plus.core.conditions;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public abstract class AbstractChainWrapper<T> extends ConditionBuilder<T>{
|
public abstract class AbstractChainWrapper<T> extends ConditionBuilder<T>{
|
||||||
|
protected static class ArrayIterator<T> implements Iterator<T> {
|
||||||
|
private final T[] array;
|
||||||
|
private int index = 0;
|
||||||
|
|
||||||
|
public ArrayIterator(T[] array) {
|
||||||
|
this.array = array;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return index < array.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
if (!hasNext()) throw new NoSuchElementException();
|
||||||
|
return array[index++];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,6 @@ package org.dromara.milvus.plus.core.conditions;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.dromara.milvus.plus.cache.ConversionCache;
|
|
||||||
import org.dromara.milvus.plus.cache.PropertyCache;
|
|
||||||
import org.dromara.milvus.plus.core.FieldFunction;
|
|
||||||
import org.dromara.milvus.plus.model.vo.MilvusResp;
|
|
||||||
import io.milvus.exception.MilvusException;
|
import io.milvus.exception.MilvusException;
|
||||||
import io.milvus.v2.client.MilvusClientV2;
|
import io.milvus.v2.client.MilvusClientV2;
|
||||||
import io.milvus.v2.service.vector.request.InsertReq;
|
import io.milvus.v2.service.vector.request.InsertReq;
|
||||||
@ -13,6 +9,10 @@ import io.milvus.v2.service.vector.response.InsertResp;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.dromara.milvus.plus.cache.ConversionCache;
|
||||||
|
import org.dromara.milvus.plus.cache.PropertyCache;
|
||||||
|
import org.dromara.milvus.plus.core.FieldFunction;
|
||||||
|
import org.dromara.milvus.plus.model.vo.MilvusResp;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -83,7 +83,10 @@ public class LambdaInsertWrapper<T> extends AbstractChainWrapper<T> implements
|
|||||||
resp.setSuccess(true);
|
resp.setSuccess(true);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
public MilvusResp<InsertResp> insert(T ... entity) throws MilvusException {
|
||||||
|
Iterator<T> iterator = new ArrayIterator<>(entity);
|
||||||
|
return insert(iterator);
|
||||||
|
}
|
||||||
public MilvusResp<InsertResp> insert(Iterator<T> iterator) throws MilvusException {
|
public MilvusResp<InsertResp> insert(Iterator<T> iterator) throws MilvusException {
|
||||||
PropertyCache propertyCache = conversionCache.getPropertyCache();
|
PropertyCache propertyCache = conversionCache.getPropertyCache();
|
||||||
List<JSONObject> jsonObjects=new ArrayList<>();
|
List<JSONObject> jsonObjects=new ArrayList<>();
|
||||||
|
|||||||
@ -2,11 +2,6 @@ package org.dromara.milvus.plus.core.conditions;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.dromara.milvus.plus.cache.CollectionToPrimaryCache;
|
|
||||||
import org.dromara.milvus.plus.cache.ConversionCache;
|
|
||||||
import org.dromara.milvus.plus.cache.PropertyCache;
|
|
||||||
import org.dromara.milvus.plus.core.FieldFunction;
|
|
||||||
import org.dromara.milvus.plus.model.vo.MilvusResp;
|
|
||||||
import io.milvus.exception.MilvusException;
|
import io.milvus.exception.MilvusException;
|
||||||
import io.milvus.v2.client.MilvusClientV2;
|
import io.milvus.v2.client.MilvusClientV2;
|
||||||
import io.milvus.v2.service.vector.request.SearchReq;
|
import io.milvus.v2.service.vector.request.SearchReq;
|
||||||
@ -16,6 +11,11 @@ import io.milvus.v2.service.vector.response.UpsertResp;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.dromara.milvus.plus.cache.CollectionToPrimaryCache;
|
||||||
|
import org.dromara.milvus.plus.cache.ConversionCache;
|
||||||
|
import org.dromara.milvus.plus.cache.PropertyCache;
|
||||||
|
import org.dromara.milvus.plus.core.FieldFunction;
|
||||||
|
import org.dromara.milvus.plus.model.vo.MilvusResp;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -404,7 +404,10 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements
|
|||||||
resp.setSuccess(true);
|
resp.setSuccess(true);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
public MilvusResp<UpsertResp> updateById(T... entity) throws MilvusException {
|
||||||
|
Iterator<T> iterator = new ArrayIterator<>(entity);
|
||||||
|
return updateById(iterator);
|
||||||
|
}
|
||||||
public MilvusResp<UpsertResp> updateById(Iterator<T> iterator) throws MilvusException {
|
public MilvusResp<UpsertResp> updateById(Iterator<T> iterator) throws MilvusException {
|
||||||
PropertyCache propertyCache = conversionCache.getPropertyCache();
|
PropertyCache propertyCache = conversionCache.getPropertyCache();
|
||||||
String pk = CollectionToPrimaryCache.collectionToPrimary.get(collectionName);
|
String pk = CollectionToPrimaryCache.collectionToPrimary.get(collectionName);
|
||||||
|
|||||||
@ -16,9 +16,7 @@ import java.io.Serializable;
|
|||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xgc
|
* @author xgc
|
||||||
@ -61,25 +59,6 @@ public abstract class BaseMilvusMapper<T>{
|
|||||||
public LambdaInsertWrapper<T> insertWrapper() {
|
public LambdaInsertWrapper<T> insertWrapper() {
|
||||||
return lambda(new LambdaInsertWrapper<>());
|
return lambda(new LambdaInsertWrapper<>());
|
||||||
}
|
}
|
||||||
private static class ArrayIterator<T> implements Iterator<T> {
|
|
||||||
private final T[] array;
|
|
||||||
private int index = 0;
|
|
||||||
|
|
||||||
public ArrayIterator(T[] array) {
|
|
||||||
this.array = array;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return index < array.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public T next() {
|
|
||||||
if (!hasNext()) throw new NoSuchElementException();
|
|
||||||
return array[index++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public MilvusResp<List<MilvusResult<T>>> getById(Serializable ... ids) {
|
public MilvusResp<List<MilvusResult<T>>> getById(Serializable ... ids) {
|
||||||
@ -92,18 +71,15 @@ public abstract class BaseMilvusMapper<T>{
|
|||||||
}
|
}
|
||||||
public MilvusResp<InsertResp> insert(T ... entity){
|
public MilvusResp<InsertResp> insert(T ... entity){
|
||||||
LambdaInsertWrapper<T> lambda = insertWrapper();
|
LambdaInsertWrapper<T> lambda = insertWrapper();
|
||||||
Iterator<T> iterator = new ArrayIterator<>(entity);
|
return lambda.insert(entity);
|
||||||
return lambda.insert(iterator);
|
|
||||||
}
|
}
|
||||||
public MilvusResp<InsertResp> insert(Collection<T> entity){
|
public MilvusResp<InsertResp> insert(Collection<T> entity){
|
||||||
LambdaInsertWrapper<T> lambda = insertWrapper();
|
LambdaInsertWrapper<T> lambda = insertWrapper();
|
||||||
return lambda.insert(entity.iterator());
|
return lambda.insert(entity.iterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MilvusResp<UpsertResp> updateById(T... entity) {
|
public MilvusResp<UpsertResp> updateById(T... entity) {
|
||||||
LambdaUpdateWrapper<T> lambda = updateWrapper();
|
LambdaUpdateWrapper<T> lambda = updateWrapper();
|
||||||
Iterator<T> iterator = new ArrayIterator<>(entity);
|
return lambda.updateById(entity);
|
||||||
return lambda.updateById(iterator);
|
|
||||||
}
|
}
|
||||||
public MilvusResp<UpsertResp> updateById(Collection<T> entity) {
|
public MilvusResp<UpsertResp> updateById(Collection<T> entity) {
|
||||||
LambdaUpdateWrapper<T> lambda = updateWrapper();
|
LambdaUpdateWrapper<T> lambda = updateWrapper();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user