增加query factory
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.synebula.gaea.mongodb.db.query
|
||||
|
||||
import com.synebula.gaea.db.query.IQuery
|
||||
import com.synebula.gaea.db.query.IQueryFactory
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
|
||||
class MongodbQueryFactory(var template: MongoTemplate) : IQueryFactory {
|
||||
|
||||
/**
|
||||
* 创建IQuery接口类型
|
||||
*/
|
||||
override fun createRawQuery(clazz: Class<*>): IQuery<*, *> {
|
||||
val constructor = MongodbQuery::class.java.getConstructor(Class::class.java, MongoTemplate::class.java)
|
||||
return constructor.newInstance(clazz, this.template)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建IQuery接口类型
|
||||
*/
|
||||
override fun <T, I> createQuery(clazz: Class<T>): IQuery<T, I> {
|
||||
return MongodbQuery(clazz, template)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.synebula.gaea.db.query
|
||||
|
||||
/**
|
||||
* Query 工厂接口。 定义了Query的创建方法。
|
||||
*/
|
||||
interface IQueryFactory {
|
||||
|
||||
/**
|
||||
* 创建原始类型的IQuery接口类型
|
||||
*/
|
||||
fun createRawQuery(clazz: Class<*>): IQuery<*, *>
|
||||
|
||||
/**
|
||||
* 创建指定类型的IQuery接口类型
|
||||
*/
|
||||
fun <T, I> createQuery(clazz: Class<T>): IQuery<T, I>
|
||||
}
|
||||
Reference in New Issue
Block a user