1.2.0 增加 IRepository IQuery的工厂方法,避免无用的空白接口编写

This commit is contained in:
2022-08-22 15:16:41 +08:00
parent 3c23c26a64
commit 53709b6fc3
9 changed files with 127 additions and 24 deletions

View File

@@ -51,4 +51,16 @@ class MongodbRepoRegister : Register() {
}
return result
}
private fun addDefaultProxyBean(result: MutableMap<String, BeanDefinition>) {
// IRepository proxy
val builder = BeanDefinitionBuilder.genericBeanDefinition(IRepository::class.java)
builder.addConstructorArgValue(IRepository::class.java)
builder.addConstructorArgValue(this._beanFactory)
builder.addConstructorArgValue(emptyArray<String>())
val definition = builder.rawBeanDefinition as GenericBeanDefinition
definition.beanClass = MongodbRepoFactory::class.java
definition.autowireMode = GenericBeanDefinition.AUTOWIRE_BY_TYPE
result[IRepository::class.java.name] = definition
}
}

View File

@@ -0,0 +1,23 @@
package com.synebula.gaea.mongodb.query
import com.synebula.gaea.query.IQuery
import com.synebula.gaea.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)
}
}

View File

@@ -0,0 +1,24 @@
package com.synebula.gaea.mongodb.repository
import com.synebula.gaea.domain.model.IAggregateRoot
import com.synebula.gaea.domain.repository.IRepository
import com.synebula.gaea.domain.repository.IRepositoryFactory
import org.springframework.data.mongodb.core.MongoTemplate
class MongodbRepositoryFactory(var template: MongoTemplate) : IRepositoryFactory {
/**
* 创建IRepository接口类型
*/
override fun createRawRepository(clazz: Class<*>): IRepository<*, *> {
val constructor = MongodbRepository::class.java.getConstructor(Class::class.java, MongoTemplate::class.java)
return constructor.newInstance(clazz, this.template)
}
/**
* 创建IRepository接口类型
*/
override fun <T : IAggregateRoot<I>, I> createRepository(clazz: Class<T>): IRepository<T, I> {
return MongodbRepository(clazz, template)
}
}