mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-20 06:24:12 +00:00
perf[orm]: orm manager adds an API to get MongoClient
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
|
||||
package com.zfoo.orm.manager;
|
||||
|
||||
import com.mongodb.client.ClientSession;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.zfoo.orm.cache.IEntityCaches;
|
||||
import com.zfoo.orm.model.entity.IEntity;
|
||||
@@ -33,16 +33,16 @@ public interface IOrmManager {
|
||||
|
||||
void initAfter();
|
||||
|
||||
/**
|
||||
* EN:Get Mongo Client, through which you can get other databases or do some other complex operations
|
||||
* CN:获取MongoClient,通过MongoClient可以获取到其它数据库或者做一些其它的复杂操作
|
||||
*/
|
||||
MongoClient mongoClient();
|
||||
|
||||
<E extends IEntity<?>> IEntityCaches<?, E> getEntityCaches(Class<E> clazz);
|
||||
|
||||
Collection<IEntityCaches<?, ?>> getAllEntityCaches();
|
||||
|
||||
/**
|
||||
* 获取一个会话
|
||||
*/
|
||||
ClientSession getClientSession();
|
||||
|
||||
/**
|
||||
* 基于对象的orm操作
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,10 @@ package com.zfoo.orm.manager;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.MongoCredential;
|
||||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.client.*;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.model.IndexOptions;
|
||||
import com.mongodb.client.model.Indexes;
|
||||
import com.zfoo.orm.OrmContext;
|
||||
@@ -220,6 +223,11 @@ public class OrmManager implements IOrmManager {
|
||||
.forEach(it -> entityCachesMap.remove(it));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MongoClient mongoClient() {
|
||||
return mongoClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends IEntity<?>> IEntityCaches<?, E> getEntityCaches(Class<E> clazz) {
|
||||
var usable = allEntityCachesUsableMap.get(clazz);
|
||||
@@ -237,11 +245,6 @@ public class OrmManager implements IOrmManager {
|
||||
return Collections.unmodifiableCollection(entityCachesMap.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSession getClientSession() {
|
||||
return mongoClient.startSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends IEntity<?>> MongoCollection<E> getCollection(Class<E> entityClazz) {
|
||||
var collectionName = collectionNameMap.get(entityClazz);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TransactionTest {
|
||||
var context = new ClassPathXmlApplicationContext("application.xml");
|
||||
|
||||
/* Step 1: Start a client session. */
|
||||
var clientSession = OrmContext.getOrmManager().getClientSession();
|
||||
var clientSession = OrmContext.getOrmManager().mongoClient().startSession();
|
||||
|
||||
/* Step 2: Optional. Define options to use for the transaction. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user