重构Gaea服务, 升级版本
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
package com.synebula.gaea.domain.repository
|
||||
|
||||
import com.synebula.gaea.domain.model.complex.IComplexAggregateRoot
|
||||
|
||||
/**
|
||||
* 继承本接口表示对象为仓储类。
|
||||
*
|
||||
* @param <TAggregateRoot> this T is the parameter
|
||||
* @author alex
|
||||
*/
|
||||
interface IComplexRepository<TAggregateRoot : IComplexAggregateRoot<TKey, TSecond>, TKey, TSecond> {
|
||||
|
||||
/**
|
||||
* 插入单个对象。
|
||||
*
|
||||
* @param obj 需要插入的对象。
|
||||
* @return 返回原对象,如果对象ID为自增,则补充自增ID。
|
||||
*/
|
||||
fun add(obj: TAggregateRoot)
|
||||
|
||||
/**
|
||||
* 更新对象。
|
||||
*
|
||||
* @param obj 需要更新的对象。
|
||||
* @return
|
||||
*/
|
||||
fun update(obj: TAggregateRoot)
|
||||
|
||||
/**
|
||||
* 通过id删除该条数据
|
||||
*
|
||||
* @param key 对象ID。
|
||||
* @param secondary 对象副主键。
|
||||
* @return
|
||||
*/
|
||||
fun remove(key: TKey, secondary: TSecond)
|
||||
|
||||
/**
|
||||
* 根据ID获取对象。
|
||||
*
|
||||
* @param key 对象ID。
|
||||
* @return
|
||||
*/
|
||||
operator fun get(key: TKey, secondary: TSecond): TAggregateRoot
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
* @param <TAggregateRoot> this T is the parameter
|
||||
* @author alex
|
||||
*/
|
||||
interface IGenericRepository<TAggregateRoot : IAggregateRoot<TKey>, TKey> {
|
||||
interface ISpecificRepository<TAggregateRoot : IAggregateRoot<TKey>, TKey> {
|
||||
|
||||
/**
|
||||
* 仓储的对象类
|
||||
@@ -1,56 +0,0 @@
|
||||
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.IComplexRepository
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
/**
|
||||
* 复合主键的服务基类
|
||||
*
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
* @since 2020-05-15
|
||||
*/
|
||||
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>>()
|
||||
val root = this.convert(command)
|
||||
repository.add(root)
|
||||
msg.data = Pair<TKey, TSecond>(root.id!!, root.secondary!!)
|
||||
return msg
|
||||
}
|
||||
|
||||
override fun update(key: TKey, secondary: TSecond, command: ICommand) {
|
||||
val root = this.convert(command)
|
||||
root.id = key
|
||||
root.secondary = secondary
|
||||
repository.update(root)
|
||||
}
|
||||
|
||||
override fun remove(key: TKey, secondary: TSecond) {
|
||||
repository.remove(key, secondary)
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换ICommand类型到聚合根类型,默认实现,根据需要进行覆写。
|
||||
*
|
||||
* @param command
|
||||
* @return
|
||||
*/
|
||||
protected fun convert(command: ICommand): TAggregateRoot {
|
||||
try {
|
||||
return converter.convert(command, clazz)
|
||||
} catch (ex: Exception) {
|
||||
throw RuntimeException("command not match aggregate root", ex)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.synebula.gaea.domain.service
|
||||
|
||||
import com.synebula.gaea.data.message.Message
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
/**
|
||||
* class IFlatService
|
||||
*
|
||||
* @author alex
|
||||
* @version 0.1
|
||||
* @since 2020-05-15
|
||||
*/
|
||||
interface IComplexService<TKey, TSecond> {
|
||||
/**
|
||||
* 日志组件。
|
||||
*/
|
||||
var logger: ILogger
|
||||
|
||||
fun add(command: ICommand): Message<Pair<TKey, TSecond>>
|
||||
|
||||
fun update(key: TKey, secondary: TSecond, command: ICommand)
|
||||
|
||||
fun remove(key: TKey, secondary: TSecond)
|
||||
}
|
||||
@@ -8,8 +8,8 @@ import com.synebula.gaea.log.ILogger
|
||||
|
||||
|
||||
/**
|
||||
* 依赖了IRepositoryTyped仓储借口的服务实现类 ServiceTyped
|
||||
* 该类依赖仓储接口 @see IRepositoryTyped ,需要显式提供聚合根的class对象
|
||||
* 依赖了IRepository仓储借口的服务实现类 Service
|
||||
* 该类依赖仓储接口 @see IRepository, 需要显式提供聚合根的class对象
|
||||
*
|
||||
* @param repository 仓储对象
|
||||
* @param clazz 聚合根类对象
|
||||
@@ -20,10 +20,10 @@ import com.synebula.gaea.log.ILogger
|
||||
* @since 2020-05-17
|
||||
*/
|
||||
open class Service<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
protected open var clazz: Class<TAggregateRoot>,
|
||||
protected open var repository: IRepository,
|
||||
protected open var converter: IObjectConverter,
|
||||
override var logger: ILogger
|
||||
protected open var clazz: Class<TAggregateRoot>,
|
||||
protected open var repository: IRepository,
|
||||
protected open var converter: IObjectConverter,
|
||||
override var logger: ILogger
|
||||
) : IService<TKey> {
|
||||
|
||||
override fun add(command: ICommand): Message<TKey> {
|
||||
|
||||
@@ -3,12 +3,13 @@ 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.IGenericRepository
|
||||
import com.synebula.gaea.domain.repository.ISpecificRepository
|
||||
import com.synebula.gaea.log.ILogger
|
||||
|
||||
|
||||
/**
|
||||
* class FlatService
|
||||
* 依赖了ISpecificRepository仓储借口的服务实现类 Service
|
||||
* 该类依赖仓储接口 @see ISpecificRepository, 泛型类上指定了仓储实例的类型
|
||||
*
|
||||
* @param repository 仓储对象
|
||||
* @param clazz 聚合根类对象
|
||||
@@ -18,9 +19,9 @@ import com.synebula.gaea.log.ILogger
|
||||
* @version 0.1
|
||||
* @since 2020-05-15
|
||||
*/
|
||||
open class GenericService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
open class SpecificService<TAggregateRoot : IAggregateRoot<TKey>, TKey>(
|
||||
protected var clazz: Class<TAggregateRoot>,
|
||||
protected var repository: IGenericRepository<TAggregateRoot, TKey>,
|
||||
protected var repository: ISpecificRepository<TAggregateRoot, TKey>,
|
||||
protected var converter: IObjectConverter,
|
||||
override var logger: ILogger
|
||||
) : IService<TKey> {
|
||||
@@ -33,8 +33,8 @@ interface IQuery {
|
||||
/**
|
||||
* 根据实体类条件查询所有符合条件记录(分页查询)
|
||||
*
|
||||
* @param param 分页条件
|
||||
* @param params 分页条件
|
||||
* @return 分页数据
|
||||
*/
|
||||
fun <TView> paging(param: Params, clazz: Class<TView>): Page<TView>
|
||||
fun <TView> paging(params: Params, clazz: Class<TView>): Page<TView>
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.synebula.gaea.query
|
||||
|
||||
/**
|
||||
* 查询基接口。
|
||||
*
|
||||
* @author wxf
|
||||
*/
|
||||
interface IQueryComplex<TView, TKey, TSecond> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据Key获取对象。
|
||||
*
|
||||
* @param key 对象Key。
|
||||
* @return
|
||||
*/
|
||||
fun get(key: TKey, secondary: TSecond): TView
|
||||
|
||||
/**
|
||||
* 根据实体类条件查询所有符合条件记录
|
||||
*
|
||||
* @param parameters 查询条件。
|
||||
* @return list
|
||||
*/
|
||||
fun list(parameters: Map<String, Any>): List<TView>
|
||||
|
||||
/**
|
||||
* 根据条件查询符合条件记录的数量
|
||||
*
|
||||
* @param parameters 查询条件。
|
||||
* @return int
|
||||
*/
|
||||
fun count(parameters: Map<String, Any>): Int
|
||||
|
||||
/**
|
||||
* 根据实体类条件查询所有符合条件记录(分页查询)
|
||||
*
|
||||
* @param param 分页条件
|
||||
* @return
|
||||
*/
|
||||
fun paging(param: Params): Page<TView>
|
||||
}
|
||||
@@ -5,7 +5,7 @@ package com.synebula.gaea.query
|
||||
*
|
||||
* @author alex
|
||||
*/
|
||||
interface IGenericQuery<TView, TKey> {
|
||||
interface ISpecificQuery<TView, TKey> {
|
||||
|
||||
|
||||
/**
|
||||
Reference in New Issue
Block a user