|
@@ -9,9 +9,10 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.ssssssss.magicapi.config.MagicModule;
|
|
|
import org.ssssssss.magicapi.model.Constants;
|
|
|
-import org.ssssssss.magicapi.utils.Invoker;
|
|
|
+import org.ssssssss.script.reflection.JavaInvoker;
|
|
|
import org.ssssssss.script.reflection.JavaReflection;
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
/**
|
|
@@ -24,18 +25,18 @@ public class MongoModule extends HashMap<String, Object> implements MagicModule
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MongoModule.class);
|
|
|
|
|
|
private final MongoTemplate mongoTemplate;
|
|
|
- private final Invoker mongoDbFactoryInvoker;
|
|
|
- private Invoker invoker;
|
|
|
+ private final JavaInvoker<Method> mongoDbFactoryInvoker;
|
|
|
+ private JavaInvoker<Method> invoker;
|
|
|
|
|
|
public MongoModule(MongoTemplate mongoTemplate) {
|
|
|
this.mongoTemplate = mongoTemplate;
|
|
|
- mongoDbFactoryInvoker = Invoker.from(JavaReflection.getMethod(this.mongoTemplate, "getMongoDbFactory"));
|
|
|
+ mongoDbFactoryInvoker = JavaReflection.getMethod(this.mongoTemplate, "getMongoDbFactory");
|
|
|
if (mongoDbFactoryInvoker != null) {
|
|
|
try {
|
|
|
- Object factory = mongoDbFactoryInvoker.invoke(this.mongoTemplate, null, Constants.EMPTY_OBJECT_ARRAY);
|
|
|
- invoker = Invoker.from(JavaReflection.getMethod(factory, "getDb", StringUtils.EMPTY));
|
|
|
+ Object factory = mongoDbFactoryInvoker.invoke0(this.mongoTemplate, null, Constants.EMPTY_OBJECT_ARRAY);
|
|
|
+ invoker = JavaReflection.getMethod(factory, "getDb", StringUtils.EMPTY);
|
|
|
if (invoker == null) {
|
|
|
- invoker = Invoker.from(JavaReflection.getMethod(factory, "getMongoDatabase", StringUtils.EMPTY));
|
|
|
+ invoker = JavaReflection.getMethod(factory, "getMongoDatabase", StringUtils.EMPTY);
|
|
|
}
|
|
|
} catch (Throwable e) {
|
|
|
logger.error("mongo模块初始化失败", e);
|
|
@@ -54,8 +55,8 @@ public class MongoModule extends HashMap<String, Object> implements MagicModule
|
|
|
return null;
|
|
|
}
|
|
|
try {
|
|
|
- Object factory = mongoDbFactoryInvoker.invoke(mongoTemplate, null, Constants.EMPTY_OBJECT_ARRAY);
|
|
|
- MongoDatabase database = (MongoDatabase) invoker.invoke(factory, null, new Object[]{databaseName.toString()});
|
|
|
+ Object factory = mongoDbFactoryInvoker.invoke0(mongoTemplate, null, Constants.EMPTY_OBJECT_ARRAY);
|
|
|
+ MongoDatabase database = (MongoDatabase) invoker.invoke0(factory, null, new Object[]{databaseName.toString()});
|
|
|
return database.getCollection(collection.toString());
|
|
|
} catch (Throwable throwable) {
|
|
|
throw new RuntimeException(throwable);
|