重新命名类型和泛型相关的repo/srv/query
This commit is contained in:
@@ -8,7 +8,7 @@ import com.synebula.gaea.domain.model.complex.IComplexAggregateRoot
|
||||
* @param <TAggregateRoot> this T is the parameter
|
||||
* @author alex
|
||||
*/
|
||||
interface IRepositoryComplex<TAggregateRoot : IComplexAggregateRoot<TKey, TSecond>, TKey, TSecond> {
|
||||
interface IComplexRepository<TAggregateRoot : IComplexAggregateRoot<TKey, TSecond>, TKey, TSecond> {
|
||||
|
||||
/**
|
||||
* 插入单个对象。
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.synebula.gaea.domain.repository
|
||||
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
|
||||
/**
|
||||
* 继承本接口表示对象为仓储类。
|
||||
* 定义了提供增删改的仓储接口。
|
||||
* 本接口泛型定义在类上,不需要显式提供聚合根的class对象,class对象作为类的成员变量声明。
|
||||
*
|
||||
* @param <TAggregateRoot> this T is the parameter
|
||||
* @author alex
|
||||
*/
|
||||
interface IGenericRepository<TAggregateRoot : IAggregateRoot<TKey>, TKey> {
|
||||
|
||||
/**
|
||||
* 仓储的对象类
|
||||
*/
|
||||
var clazz: Class<TAggregateRoot>?
|
||||
|
||||
/**
|
||||
* 插入单个对象。
|
||||
*
|
||||
* @param obj 需要插入的对象。
|
||||
* @return 返回原对象,如果对象ID为自增,则补充自增ID。
|
||||
*/
|
||||
fun add(obj: TAggregateRoot)
|
||||
|
||||
/**
|
||||
* 更新对象。
|
||||
*
|
||||
* @param obj 需要更新的对象。
|
||||
* @return
|
||||
*/
|
||||
fun update(obj: TAggregateRoot)
|
||||
|
||||
/**
|
||||
* 通过id删除该条数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
fun remove(id: TKey)
|
||||
|
||||
/**
|
||||
* 根据ID获取对象。
|
||||
*
|
||||
* @param id 对象ID。
|
||||
* @return
|
||||
*/
|
||||
fun get(id: TKey): TAggregateRoot
|
||||
|
||||
/**
|
||||
* 根据ID获取对象。
|
||||
*
|
||||
* @param id id
|
||||
* @param clazz 操作数据的类型
|
||||
* @return 聚合根
|
||||
*/
|
||||
fun <T : IAggregateRoot<TKey>, TKey> get(id: TKey, clazz: Class<T>): T
|
||||
|
||||
}
|
||||
@@ -3,27 +3,17 @@ package com.synebula.gaea.domain.repository
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
|
||||
/**
|
||||
* 继承本接口表示对象为仓储类。
|
||||
* 定义了提供增删改的仓储接口。
|
||||
* 本接口泛型定义在类上,不需要显式提供聚合根的class对象,class对象作为类的成员变量声明。
|
||||
*
|
||||
* @param <TAggregateRoot> this T is the parameter
|
||||
* @author alex
|
||||
* 本接口泛型放置到方法上,并需要显式提供聚合根的class对象
|
||||
*/
|
||||
interface IRepository<TAggregateRoot : IAggregateRoot<TKey>, TKey> {
|
||||
|
||||
/**
|
||||
* 仓储的对象类
|
||||
*/
|
||||
var clazz: Class<TAggregateRoot>?
|
||||
|
||||
interface IRepository {
|
||||
/**
|
||||
* 插入单个对象。
|
||||
*
|
||||
* @param obj 需要插入的对象。
|
||||
* @return 返回原对象,如果对象ID为自增,则补充自增ID。
|
||||
*/
|
||||
fun add(obj: TAggregateRoot)
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> add(obj: TAggregateRoot, clazz: Class<TAggregateRoot>)
|
||||
|
||||
/**
|
||||
* 更新对象。
|
||||
@@ -31,23 +21,15 @@ interface IRepository<TAggregateRoot : IAggregateRoot<TKey>, TKey> {
|
||||
* @param obj 需要更新的对象。
|
||||
* @return
|
||||
*/
|
||||
fun update(obj: TAggregateRoot)
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> update(obj: TAggregateRoot, clazz: Class<TAggregateRoot>)
|
||||
|
||||
/**
|
||||
* 通过id删除该条数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
* @param id id
|
||||
* @param clazz 操作数据的类型
|
||||
*/
|
||||
fun remove(id: TKey)
|
||||
|
||||
/**
|
||||
* 根据ID获取对象。
|
||||
*
|
||||
* @param id 对象ID。
|
||||
* @return
|
||||
*/
|
||||
fun get(id: TKey): TAggregateRoot
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> remove(id: TKey, clazz: Class<TAggregateRoot>)
|
||||
|
||||
/**
|
||||
* 根据ID获取对象。
|
||||
@@ -56,6 +38,5 @@ interface IRepository<TAggregateRoot : IAggregateRoot<TKey>, TKey> {
|
||||
* @param clazz 操作数据的类型
|
||||
* @return 聚合根
|
||||
*/
|
||||
fun <T : IAggregateRoot<TKey>, TKey> get(id: TKey, clazz: Class<T>): T
|
||||
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> get(id: TKey, clazz: Class<TAggregateRoot>): TAggregateRoot
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.synebula.gaea.domain.repository
|
||||
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
|
||||
/**
|
||||
* 定义了提供增删改的仓储接口。
|
||||
* 本接口泛型放置到方法上,并需要显式提供聚合根的class对象
|
||||
*/
|
||||
interface IRepositoryTyped {
|
||||
/**
|
||||
* 插入单个对象。
|
||||
*
|
||||
* @param obj 需要插入的对象。
|
||||
* @return 返回原对象,如果对象ID为自增,则补充自增ID。
|
||||
*/
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> add(obj: TAggregateRoot, clazz: Class<TAggregateRoot>)
|
||||
|
||||
/**
|
||||
* 更新对象。
|
||||
*
|
||||
* @param obj 需要更新的对象。
|
||||
* @return
|
||||
*/
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> update(obj: TAggregateRoot, clazz: Class<TAggregateRoot>)
|
||||
|
||||
/**
|
||||
* 通过id删除该条数据
|
||||
*
|
||||
* @param id id
|
||||
* @param clazz 操作数据的类型
|
||||
*/
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> remove(id: TKey, clazz: Class<TAggregateRoot>)
|
||||
|
||||
/**
|
||||
* 根据ID获取对象。
|
||||
*
|
||||
* @param id id
|
||||
* @param clazz 操作数据的类型
|
||||
* @return 聚合根
|
||||
*/
|
||||
fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> get(id: TKey, clazz: Class<TAggregateRoot>): TAggregateRoot
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.synebula.gaea.domain.service
|
||||
import com.synebula.gaea.data.IObjectConverter
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.domain.model.complex.IComplexAggregateRoot
|
||||
import com.synebula.gaea.domain.repository.IRepositoryComplex
|
||||
import com.synebula.gaea.domain.repository.IComplexRepository
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
/**
|
||||
@@ -13,10 +13,12 @@ import com.synebula.gaea.log.ILogger
|
||||
* @version 0.1
|
||||
* @since 2020-05-15
|
||||
*/
|
||||
open class ServiceComplex<TAggregateRoot : IComplexAggregateRoot<TKey, TSecond>, TKey, TSecond>
|
||||
(var logger: ILogger, protected var repository: IRepositoryComplex<TAggregateRoot, TKey, TSecond>,
|
||||
protected var converter: IObjectConverter, protected var aggregateRootClass: Class<TAggregateRoot>)
|
||||
: IServiceComplex<TKey, TSecond> {
|
||||
open class ComplexService<TAggregateRoot : IComplexAggregateRoot<TKey, TSecond>, TKey, TSecond>(
|
||||
protected var clazz: Class<TAggregateRoot>,
|
||||
protected var repository: IComplexRepository<TAggregateRoot, TKey, TSecond>,
|
||||
protected var converter: IObjectConverter,
|
||||
override var logger: ILogger
|
||||
) : IComplexService<TKey, TSecond> {
|
||||
|
||||
override fun add(command: ICommand): Message<Pair<TKey, TSecond>> {
|
||||
val msg = Message<Pair<TKey, TSecond>>()
|
||||
@@ -45,7 +47,7 @@ open class ServiceComplex<TAggregateRoot : IComplexAggregateRoot<TKey, TSecond>,
|
||||
*/
|
||||
protected fun convert(command: ICommand): TAggregateRoot {
|
||||
try {
|
||||
return converter.convert(command, aggregateRootClass)
|
||||
return converter.convert(command, clazz)
|
||||
} catch (ex: Exception) {
|
||||
throw RuntimeException("command not match aggregate root", ex)
|
||||
}
|
||||
@@ -3,32 +3,36 @@ package com.synebula.gaea.domain.service
|
||||
import com.synebula.gaea.data.IObjectConverter
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
import com.synebula.gaea.domain.repository.IRepositoryTyped
|
||||
import com.synebula.gaea.domain.repository.IGenericRepository
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
|
||||
/**
|
||||
* 依赖了IRepositoryTyped仓储借口的服务实现类 ServiceTyped
|
||||
* 该类依赖仓储接口 @see IRepositoryTyped ,需要显式提供聚合根的class对象
|
||||
* class FlatService
|
||||
*
|
||||
* @param repository 仓储对象
|
||||
* @param rootClass 聚合根类对象
|
||||
* @param clazz 聚合根类对象
|
||||
* @param converter 对象转换组件
|
||||
* @param logger 日志组件
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
* @since 2020-05-17
|
||||
* @since 2020-05-15
|
||||
*/
|
||||
open class ServiceTyped<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
protected var rootClass: Class<TAggregateRoot>,
|
||||
protected var repository: IRepositoryTyped,
|
||||
protected var converter: IObjectConverter,
|
||||
override var logger: ILogger) : IService<TKey> {
|
||||
open class GenericService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
protected var clazz: Class<TAggregateRoot>,
|
||||
protected var repository: IGenericRepository<TAggregateRoot, TKey>,
|
||||
protected var converter: IObjectConverter,
|
||||
override var logger: ILogger
|
||||
) : IService<TKey> {
|
||||
|
||||
init {
|
||||
this.repository.clazz = clazz
|
||||
}
|
||||
|
||||
override fun add(command: ICommand): Message<TKey> {
|
||||
val msg = Message<TKey>()
|
||||
val root = this.convert(command)
|
||||
this.repository.add(root, rootClass)
|
||||
this.repository.add(root)
|
||||
msg.data = root.id
|
||||
return msg
|
||||
}
|
||||
@@ -36,24 +40,29 @@ open class ServiceTyped<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
override fun update(key: TKey, command: ICommand) {
|
||||
val root = this.convert(command)
|
||||
root.id = key
|
||||
this.repository.update(root, rootClass)
|
||||
this.repository.update(root)
|
||||
}
|
||||
|
||||
override fun remove(key: TKey) {
|
||||
this.repository.remove(key, rootClass)
|
||||
this.repository.remove(key)
|
||||
}
|
||||
|
||||
fun get(key: TKey): TAggregateRoot {
|
||||
return this.repository.get(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换ICommand类型到聚合根类型,默认实现,根据需要进行覆写。
|
||||
*
|
||||
* @param command 需要转换的命令
|
||||
* @return 聚合根
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
protected fun convert(command: ICommand): TAggregateRoot {
|
||||
try {
|
||||
return converter.convert(command, rootClass)
|
||||
return converter.convert(command, this.clazz)
|
||||
} catch (ex: Exception) {
|
||||
throw RuntimeException("command not match aggregate root", ex)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.synebula.gaea.domain.service
|
||||
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
/**
|
||||
* class IFlatService
|
||||
@@ -9,7 +10,11 @@ import com.synebula.gaea.data.message.Message
|
||||
* @version 0.1
|
||||
* @since 2020-05-15
|
||||
*/
|
||||
interface IServiceComplex<TKey, TSecond> {
|
||||
interface IComplexService<TKey, TSecond> {
|
||||
/**
|
||||
* 日志组件。
|
||||
*/
|
||||
var logger: ILogger
|
||||
|
||||
fun add(command: ICommand): Message<Pair<TKey, TSecond>>
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.synebula.gaea.log.ILogger
|
||||
*/
|
||||
interface IService<TKey> {
|
||||
/**
|
||||
* 日志组件。若无日志组件则默认为NullLogger对象,不会为null。
|
||||
* 日志组件。
|
||||
*/
|
||||
var logger: ILogger
|
||||
|
||||
|
||||
@@ -8,30 +8,28 @@ import com.synebula.gaea.log.ILogger
|
||||
|
||||
|
||||
/**
|
||||
* class FlatService
|
||||
* 依赖了IRepositoryTyped仓储借口的服务实现类 ServiceTyped
|
||||
* 该类依赖仓储接口 @see IRepositoryTyped ,需要显式提供聚合根的class对象
|
||||
*
|
||||
* @param repository 仓储对象
|
||||
* @param rootClass 聚合根类对象
|
||||
* @param clazz 聚合根类对象
|
||||
* @param converter 对象转换组件
|
||||
* @param logger 日志组件
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
* @since 2020-05-15
|
||||
* @since 2020-05-17
|
||||
*/
|
||||
open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
protected var rootClass: Class<TAggregateRoot>,
|
||||
protected var repository: IRepository<TAggregateRoot, TKey>,
|
||||
protected var converter: IObjectConverter,
|
||||
override var logger: ILogger) : IService<TKey> {
|
||||
|
||||
init {
|
||||
this.repository.clazz = rootClass
|
||||
}
|
||||
protected var clazz: Class<TAggregateRoot>,
|
||||
protected var repository: IRepository,
|
||||
protected var converter: IObjectConverter,
|
||||
override var logger: ILogger
|
||||
) : IService<TKey> {
|
||||
|
||||
override fun add(command: ICommand): Message<TKey> {
|
||||
val msg = Message<TKey>()
|
||||
val root = this.convert(command)
|
||||
this.repository.add(root)
|
||||
this.repository.add(root, this.clazz)
|
||||
msg.data = root.id
|
||||
return msg
|
||||
}
|
||||
@@ -39,29 +37,24 @@ open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
override fun update(key: TKey, command: ICommand) {
|
||||
val root = this.convert(command)
|
||||
root.id = key
|
||||
this.repository.update(root)
|
||||
this.repository.update(root, this.clazz)
|
||||
}
|
||||
|
||||
override fun remove(key: TKey) {
|
||||
this.repository.remove(key)
|
||||
}
|
||||
|
||||
fun get(key: TKey): TAggregateRoot {
|
||||
return this.repository.get(key)
|
||||
this.repository.remove(key, this.clazz)
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换ICommand类型到聚合根类型,默认实现,根据需要进行覆写。
|
||||
*
|
||||
* @param command
|
||||
* @return
|
||||
* @param command 需要转换的命令
|
||||
* @return 聚合根
|
||||
*/
|
||||
protected fun convert(command: ICommand): TAggregateRoot {
|
||||
try {
|
||||
return converter.convert(command, rootClass)
|
||||
return converter.convert(command, this.clazz)
|
||||
} catch (ex: Exception) {
|
||||
throw RuntimeException("command not match aggregate root", ex)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
package com.synebula.gaea.query
|
||||
|
||||
/**
|
||||
* 查询基接口, 其中方法都指定了查询的视图类型。
|
||||
* 查询基接口。
|
||||
*
|
||||
* @author alex
|
||||
*/
|
||||
interface IQueryTyped {
|
||||
interface IGenericQuery<TView, TKey> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据Key获取对象。
|
||||
*
|
||||
* @param key 对象Key。
|
||||
* @return
|
||||
*/
|
||||
fun <TView, TKey> get(key: TKey, clazz: Class<TView>): TView?
|
||||
fun get(key: TKey): TView?
|
||||
|
||||
/**
|
||||
* 根据实体类条件查询所有符合条件记录
|
||||
@@ -20,7 +22,7 @@ interface IQueryTyped {
|
||||
* @param params 查询条件。
|
||||
* @return list
|
||||
*/
|
||||
fun <TView> list(params: Map<String, Any>?, clazz: Class<TView>): List<TView>
|
||||
fun list(params: Map<String, Any>?): List<TView>
|
||||
|
||||
/**
|
||||
* 根据条件查询符合条件记录的数量
|
||||
@@ -28,7 +30,7 @@ interface IQueryTyped {
|
||||
* @param params 查询条件。
|
||||
* @return int
|
||||
*/
|
||||
fun <TView> count(params: Map<String, Any>?, clazz: Class<TView>): Int
|
||||
fun count(params: Map<String, Any>?): Int
|
||||
|
||||
/**
|
||||
* 根据实体类条件查询所有符合条件记录(分页查询)
|
||||
@@ -36,5 +38,5 @@ interface IQueryTyped {
|
||||
* @param params 分页条件
|
||||
* @return 分页数据
|
||||
*/
|
||||
fun <TView> paging(params: PagingParam, clazz: Class<TView>): PagingData<TView>
|
||||
fun paging(params: PagingParam): PagingData<TView>
|
||||
}
|
||||
@@ -1,20 +1,18 @@
|
||||
package com.synebula.gaea.query
|
||||
|
||||
/**
|
||||
* 查询基接口。
|
||||
* 查询基接口, 其中方法都指定了查询的视图类型。
|
||||
*
|
||||
* @author alex
|
||||
*/
|
||||
interface IQuery<TView, TKey> {
|
||||
|
||||
|
||||
interface IQuery {
|
||||
/**
|
||||
* 根据Key获取对象。
|
||||
*
|
||||
* @param key 对象Key。
|
||||
* @return
|
||||
*/
|
||||
fun get(key: TKey): TView?
|
||||
fun <TView, TKey> get(key: TKey, clazz: Class<TView>): TView?
|
||||
|
||||
/**
|
||||
* 根据实体类条件查询所有符合条件记录
|
||||
@@ -22,7 +20,7 @@ interface IQuery<TView, TKey> {
|
||||
* @param params 查询条件。
|
||||
* @return list
|
||||
*/
|
||||
fun list(params: Map<String, Any>?): List<TView>
|
||||
fun <TView> list(params: Map<String, Any>?, clazz: Class<TView>): List<TView>
|
||||
|
||||
/**
|
||||
* 根据条件查询符合条件记录的数量
|
||||
@@ -30,7 +28,7 @@ interface IQuery<TView, TKey> {
|
||||
* @param params 查询条件。
|
||||
* @return int
|
||||
*/
|
||||
fun count(params: Map<String, Any>?): Int
|
||||
fun <TView> count(params: Map<String, Any>?, clazz: Class<TView>): Int
|
||||
|
||||
/**
|
||||
* 根据实体类条件查询所有符合条件记录(分页查询)
|
||||
@@ -38,5 +36,5 @@ interface IQuery<TView, TKey> {
|
||||
* @param params 分页条件
|
||||
* @return 分页数据
|
||||
*/
|
||||
fun paging(params: PagingParam): PagingData<TView>
|
||||
fun <TView> paging(params: PagingParam, clazz: Class<TView>): PagingData<TView>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user