repo增加count方法

修改before remove的监听器返回值类型
This commit is contained in:
2020-10-27 23:37:18 +08:00
parent d1c843cbae
commit ca13018c9f
10 changed files with 63 additions and 27 deletions

View File

@@ -2,8 +2,10 @@ package com.synebula.gaea.mongo.repository
import com.synebula.gaea.domain.model.IAggregateRoot
import com.synebula.gaea.domain.repository.IRepository
import com.synebula.gaea.mongo.where
import com.synebula.gaea.mongo.whereId
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.query.Query
/**
* 实现ITypedRepository的mongo仓储类
@@ -16,15 +18,15 @@ open class MongoRepository(private var repo: MongoTemplate) : IRepository {
}
override fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> get(
id: TKey,
clazz: Class<TAggregateRoot>
id: TKey,
clazz: Class<TAggregateRoot>
): TAggregateRoot {
return this.repo.findOne(whereId(id), clazz) as TAggregateRoot
}
override fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> update(
obj: TAggregateRoot,
clazz: Class<TAggregateRoot>
obj: TAggregateRoot,
clazz: Class<TAggregateRoot>
) {
this.repo.save(obj)
}
@@ -32,4 +34,10 @@ open class MongoRepository(private var repo: MongoTemplate) : IRepository {
override fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> add(obj: TAggregateRoot, clazz: Class<TAggregateRoot>) {
this.repo.save(obj)
}
override fun <TAggregateRoot> count(params: Map<String, Any>?, clazz: Class<TAggregateRoot>): Int {
val query = Query()
return this.repo.count(query.where(params, clazz), clazz).toInt()
}
}

View File

@@ -2,15 +2,17 @@ package com.synebula.gaea.mongo.repository
import com.synebula.gaea.domain.model.IAggregateRoot
import com.synebula.gaea.domain.repository.ISpecificRepository
import com.synebula.gaea.mongo.where
import com.synebula.gaea.mongo.whereId
import org.springframework.data.mongodb.core.MongoTemplate
import org.springframework.data.mongodb.core.query.Query
/**
* 实现IAggregateRoot的mongo仓储类
* @param repo MongoRepo对象
*/
class MongoSpecificRepository<TAggregateRoot : IAggregateRoot<String>>(private var repo: MongoTemplate) :
ISpecificRepository<TAggregateRoot, String> {
ISpecificRepository<TAggregateRoot, String> {
/**
* 仓储的对象类
@@ -43,9 +45,15 @@ class MongoSpecificRepository<TAggregateRoot : IAggregateRoot<String>>(private v
}
override fun <TAggregateRoot : IAggregateRoot<TKey>, TKey> get(
id: TKey,
clazz: Class<TAggregateRoot>
id: TKey,
clazz: Class<TAggregateRoot>
): TAggregateRoot {
return this.repo.findOne(whereId(id.toString()), clazz) as TAggregateRoot
}
override fun <TAggregateRoot> count(params: Map<String, Any>?): Int {
val query = Query()
return this.repo.count(query.where(params, this.clazz!!), this.clazz!!).toInt()
}
}