diff --git a/build.gradle b/build.gradle index 8a84dbc..d20f1c6 100644 --- a/build.gradle +++ b/build.gradle @@ -21,8 +21,8 @@ allprojects { subprojects { ext { - version '0.2.1' - spring_version = "2.0.0.RELEASE" + version '0.3.0' + spring_version = "2.3.0.RELEASE" } buildscript { diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/CommandApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/CommandApp.kt new file mode 100644 index 0000000..4e10d9e --- /dev/null +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/CommandApp.kt @@ -0,0 +1,18 @@ +package com.synebula.gaea.app + +import com.synebula.gaea.domain.service.ICommand +import com.synebula.gaea.domain.service.IService +import com.synebula.gaea.log.ILogger + +/** + * 指令服务,同时实现ICommandApp + * + * @param name 业务名称 + * @param service 业务domain服务 + * @param logger 日志组件 + */ +open class CommandApp( + override var name: String, + override var service: IService?, + override var logger: ILogger) : ICommandApp { +} \ No newline at end of file diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IApplication.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IApplication.kt index 9ef43fb..5a7954f 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IApplication.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IApplication.kt @@ -1,6 +1,6 @@ package com.synebula.gaea.app -import com.synebula.gaea.app.components.HttpMessage +import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.data.message.Status import com.synebula.gaea.log.ILogger @@ -24,12 +24,12 @@ interface IApplication { val msg = HttpMessage(Status.Success) try { process(msg) - logger.debug("$name business execute success") + logger.debug(this, "$name business execute success") } catch (ex: Exception) { msg.status = Status.Error msg.message = if (error.isEmpty()) ex.message ?: "" else error msg.data = ex.message - logger.error(ex, "$error: ${ex.message}") + logger.error(this, "$error: ${ex.message}") } return msg } @@ -41,9 +41,9 @@ interface IApplication { val msg = HttpMessage(Status.Success) try { process(msg) - logger.debug("$name business execute success") + logger.debug(this, "$name business execute success") } catch (ex: Exception) { - logger.error(ex, "$error。异常消息将抛出!: ${ex.message}") + logger.error(this, ex, "$error。异常消息将抛出!: ${ex.message}") throw RuntimeException(error, ex) } return msg diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ICommandApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ICommandApp.kt index c6bc4e3..91e6c87 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ICommandApp.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/ICommandApp.kt @@ -1,6 +1,6 @@ package com.synebula.gaea.app -import com.synebula.gaea.app.components.HttpMessage +import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.data.message.Status import com.synebula.gaea.domain.service.ICommand import com.synebula.gaea.domain.service.IService diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IQueryApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IQueryApp.kt index dc70075..2e446fe 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IQueryApp.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/IQueryApp.kt @@ -1,6 +1,6 @@ package com.synebula.gaea.app -import com.synebula.gaea.app.components.HttpMessage +import com.synebula.gaea.app.component.HttpMessage import com.synebula.gaea.data.message.Status import com.synebula.gaea.query.IQuery import com.synebula.gaea.query.PagingParam diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/QueryApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/QueryApp.kt new file mode 100644 index 0000000..84dbe7c --- /dev/null +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/QueryApp.kt @@ -0,0 +1,17 @@ +package com.synebula.gaea.app + +import com.synebula.gaea.log.ILogger +import com.synebula.gaea.query.IQuery + +/** + * 联合服务,同时实现了ICommandApp和IQueryApp接口 + * + * @param name 业务名称 + * @param query 业务查询服务 + * @param logger 日志组件 + */ +open class QueryApp( + override var name: String, + override var query: IQuery?, + override var logger: ILogger) : IQueryApp { +} \ No newline at end of file diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/UnionApp.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/UnionApp.kt new file mode 100644 index 0000000..b4fc296 --- /dev/null +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/UnionApp.kt @@ -0,0 +1,22 @@ +package com.synebula.gaea.app + +import com.synebula.gaea.domain.service.ICommand +import com.synebula.gaea.domain.service.IService +import com.synebula.gaea.log.ILogger +import com.synebula.gaea.query.IQuery + +/** + * 联合服务,同时实现了ICommandApp和IQueryApp接口 + * + * @param name 业务名称 + * @param service 业务domain服务 + * @param query 业务查询服务 + * @param logger 日志组件 + */ +open class UnionApp( + override var name: String, + override var service: IService?, + override var query: IQuery?, + override var logger: ILogger) + : ICommandApp, IQueryApp { +} \ No newline at end of file diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/AllTypeFilter.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/AllTypeFilter.kt new file mode 100644 index 0000000..2e9d738 --- /dev/null +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/AllTypeFilter.kt @@ -0,0 +1,11 @@ +package com.synebula.gaea.app.component + +import org.springframework.core.type.classreading.MetadataReader +import org.springframework.core.type.classreading.MetadataReaderFactory +import org.springframework.core.type.filter.TypeFilter + +class AllTypeFilter : TypeFilter { + override fun match(metadataReader: MetadataReader, metadataReaderFactory: MetadataReaderFactory): Boolean { + return true + } +} \ No newline at end of file diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/DozerConverter.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/DozerConverter.kt new file mode 100644 index 0000000..a2f7421 --- /dev/null +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/DozerConverter.kt @@ -0,0 +1,12 @@ +package com.synebula.gaea.app.component + +import com.synebula.gaea.data.IObjectConverter +import org.dozer.DozerBeanMapper +import org.springframework.stereotype.Component + +@Component +class DozerConverter : IObjectConverter { + private val converter = DozerBeanMapper() + + override fun convert(src: Any, dest: Class): T = converter.map(src, dest) +} \ No newline at end of file diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/components/HttpMessage.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/HttpMessage.kt similarity index 88% rename from src/gaea.app/src/main/kotlin/com/synebula/gaea/app/components/HttpMessage.kt rename to src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/HttpMessage.kt index 2f50073..3b4b34f 100644 --- a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/components/HttpMessage.kt +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/HttpMessage.kt @@ -1,4 +1,4 @@ -package com.synebula.gaea.app.components +package com.synebula.gaea.app.component import com.synebula.gaea.data.message.Status import com.synebula.gaea.data.message.Message diff --git a/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/Logger.kt b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/Logger.kt new file mode 100644 index 0000000..fbbe6e1 --- /dev/null +++ b/src/gaea.app/src/main/kotlin/com/synebula/gaea/app/component/Logger.kt @@ -0,0 +1,276 @@ +package com.synebula.gaea.app.component + +import com.synebula.gaea.log.ILogger +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component + +import java.util.concurrent.ConcurrentHashMap + +/** + * 使用 log4j進行日志记录。 + * + * @author reize + * @version 0.0.1 + * @since 2016年9月18日 下午2:13:43 + */ +@Component +class Logger : ILogger { + + override val name: String + get() { + return this.logger.name + } + + /** + * 默认日志记录 + */ + private val logger = LoggerFactory.getLogger(Logger::class.java) + + /** + * 特殊日志记录字典 + */ + private val loggers = ConcurrentHashMap, org.slf4j.Logger>() + + init { + loggers[Logger::class.java] = logger + } + + override val isTraceEnabled: Boolean + get() { + return this.logger.isTraceEnabled + } + + + override fun trace(t: Throwable) { + this.logger.trace(t.toString()) + } + + + override fun trace(format: String, vararg args: Any) { + if (this.logger.isTraceEnabled) { + val message = String.format(format, *args) + this.logger.trace(message) + } + } + + + override fun trace(t: Throwable, format: String, vararg args: Any) { + if (this.logger.isTraceEnabled) { + val message = String.format(format, *args) + this.logger.trace(message, t) + } + } + + override fun trace(obj: Any, format: String, vararg args: Any) { + if (this.logger.isTraceEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.trace(message) + } + } + + override fun trace(obj: Any, t: Throwable?, format: String, vararg args: Any) { + if (this.logger.isTraceEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.trace(message, t) + } + } + + /** + * debug start + */ + override val isDebugEnabled: Boolean + get() { + return this.logger.isDebugEnabled + } + + + override fun debug(t: Throwable) { + if (this.logger.isDebugEnabled) { + this.logger.debug(t.toString()) + } + } + + + override fun debug(format: String, vararg args: Any) { + if (this.logger.isDebugEnabled) { + val message = String.format(format, *args) + this.logger.debug(message) + } + } + + + override fun debug(t: Throwable, format: String, vararg args: Any) { + if (this.logger.isDebugEnabled) { + val message = String.format(format, *args) + this.logger.debug(message, t) + } + } + + override fun debug(obj: Any, format: String, vararg args: Any) { + if (this.logger.isDebugEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.debug(message) + } + } + + override fun debug(obj: Any, t: Throwable?, format: String, vararg args: Any) { + if (this.logger.isDebugEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.debug(message, t) + } + } + + /** + * info start + */ + override val isInfoEnabled: Boolean + get() { + return this.logger.isInfoEnabled + } + + override fun info(t: Throwable) { + if (this.logger.isInfoEnabled) { + this.logger.info(t.toString()) + } + } + + override fun info(format: String, vararg args: Any) { + if (this.logger.isInfoEnabled) { + val message = String.format(format, *args) + this.logger.info(message) + } + } + + + override fun info(t: Throwable, format: String, vararg args: Any) { + if (this.logger.isInfoEnabled) { + val message = String.format(format, *args) + this.logger.info(message, t) + } + } + + override fun info(obj: Any, format: String, vararg args: Any) { + if (this.logger.isInfoEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.info(message) + } + } + + override fun info(obj: Any, t: Throwable?, format: String, vararg args: Any) { + if (this.logger.isInfoEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.info(message, t) + } + } + + /** + * warn start + */ + override val isWarnEnabled: Boolean + get() { + return this.logger.isWarnEnabled + } + + override fun warn(t: Throwable) { + if (this.logger.isWarnEnabled) { + this.logger.warn(t.toString()) + } + } + + override fun warn(format: String, vararg args: Any) { + if (this.logger.isWarnEnabled) { + val message = String.format(format, *args) + this.logger.warn(message) + } + } + + + override fun warn(t: Throwable, format: String, vararg args: Any) { + if (this.logger.isWarnEnabled) { + val message = String.format(format, *args) + this.logger.warn(message, t) + } + } + + override fun warn(obj: Any, format: String, vararg args: Any) { + if (this.logger.isWarnEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.warn(message) + } + } + + override fun warn(obj: Any, t: Throwable?, format: String, vararg args: Any) { + if (this.logger.isWarnEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.warn(message, t) + } + } + + + /** + * error start + */ + override val isErrorEnabled: Boolean + get() { + return this.logger.isErrorEnabled + } + + override fun error(t: Throwable) { + if (this.logger.isErrorEnabled) { + this.logger.error(t.toString()) + } + } + + + override fun error(format: String, vararg args: Any) { + if (this.logger.isErrorEnabled) { + val message = String.format(format, *args) + this.logger.error(message) + } + } + + + override fun error(t: Throwable, format: String, vararg args: Any) { + if (this.logger.isErrorEnabled) { + val message = String.format(format, *args) + this.logger.error(message, t) + } + } + + override fun error(obj: Any, format: String, vararg args: Any) { + if (this.logger.isErrorEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.error(message) + } + } + + override fun error(obj: Any, t: Throwable?, format: String, vararg args: Any) { + if (this.logger.isErrorEnabled) { + val real = this.getLogger(obj) + val message = String.format(format, *args) + real.error(message, t) + } + } + + + /** + * 获取日志记录器 + */ + private fun getLogger(obj: Any): org.slf4j.Logger { + var real = this.loggers.getOrDefault(obj.javaClass, null) + if (real == null) { + real = LoggerFactory.getLogger(obj::class.java) + this.loggers[obj::class.java] = real + } + return real!! + } +} diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/IMongoQuery.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/IMongoQuery.kt new file mode 100644 index 0000000..7083e42 --- /dev/null +++ b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/IMongoQuery.kt @@ -0,0 +1,153 @@ +package com.synebula.gaea.query.mongo + +import com.synebula.gaea.log.ILogger +import com.synebula.gaea.query.OrderType +import org.springframework.data.domain.Sort +import org.springframework.data.mongodb.core.query.Criteria +import org.springframework.data.mongodb.core.query.Query +import org.springframework.data.mongodb.core.query.isEqualTo +import java.lang.reflect.Field + +/** + * 声明了Mongo查询的特有方法 + */ +interface IMongoQuery { + /** + * 日志组件 + */ + var logger: ILogger? + + /** + * 系统类型 + */ + private fun systemClass() = arrayOf( + "String", + "Date", + "Int", + "Double", + "Float", + "BigDecimal", + "Decimal") + + /** + * 获取ID查询条件 + * + * @param id 业务ID + */ + fun idQuery(id: String): Query = Query(Criteria("_id").isEqualTo(id)) + + /** + * 获取视图对象的字段列表 + * + * @param clazz 视图对象类型 + */ + fun fields(clazz: Class): List { + return analyseFields(clazz.declaredFields) + } + + /** + * 获取查询条件 + * + * @param query 查询条件 + * @param fields 字段列表 + */ + fun select(query: Query, fields: Array): Query { + fields.forEach { + query.fields().include(it) + } + return query + } + + /** + * 根据参数获取查询条件 + * + * @param query 查询条件 + * @param params 参数列表 + * @param clazz 视图类对象 + */ + fun where(query: Query, params: Map?, clazz: Class): Query { + val criteria = Criteria() + if (params != null) { + for (param in params) { + val value = this.changeFieldType(param.key, param.value, clazz) + criteria.and(param.key).isEqualTo(value) + } + } + return query.addCriteria(criteria) + } + + /** + * 获取排序对象 + * + * @param orders 排序条件字段 + */ + fun order(orders: Map?): Sort { + val orderList = mutableListOf() + orders?.forEach() { + orderList.add(Sort.Order(Sort.Direction.valueOf(it.value.name), it.key)) + } + return if (orderList.size == 0) + Sort.by("_id") + else + Sort.by(orderList) + } + + /** + * 分析视图字段对象,获取深层字段列表 + * + * @param fields 需要分析的视图字段 + */ + fun analyseFields(fields: Array): List { + val names = mutableListOf() + fields.forEach { field -> + names.add(field.name) + if (!field.type.isPrimitive + && !field.type.isArray + && !this.systemClass().contains(field.type.simpleName)) + names.addAll(this.analyseFields(field.type.declaredFields).map { "${field.name}.$it" }) + } + return names + } + + /** + * 转换查询条件指定字段的类型 + * + * @param key 字段名称 + * @param value 字段值 + * @param clazz 视图类对象 + */ + fun changeFieldType(key: String, value: Any, clazz: Class): Any? { + val getter = clazz.getMethod("get${key.substring(0, 1).toUpperCase()}${key.substring(1)}") + return this.convertType(value.toString(), getter.returnType) + } + + + /** + * 转换String到指定类型 + * + * @param value 字段值 + * @param clazz 视图类对象 + */ + fun convertType(value: String, clazz: Class<*>): Any? { + if (!clazz.isPrimitive) { // 判断基本类型 + if (clazz == String::class.java) { // 如果是string则直接返回 + return value + } + // 如果不为null 则通过反射实例一个对象返回 + return if ("" == value) null else clazz.getConstructor(String::class.java).newInstance(value) + } + + // 下面处理基本类型,返回包装类 + return when (clazz.name) { + "int" -> Integer.parseInt(value) + "byte" -> java.lang.Byte.parseByte(value) + "boolean" -> java.lang.Boolean.parseBoolean(value) + "double" -> java.lang.Double.parseDouble(value) + "float" -> java.lang.Float.parseFloat(value) + "long" -> java.lang.Long.parseLong(value) + "short" -> java.lang.Short.parseShort(value) + else -> value + } + } + +} \ No newline at end of file diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/MongoQuery.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/MongoQuery.kt index 9c5a2a5..13f4f4d 100644 --- a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/MongoQuery.kt +++ b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/MongoQuery.kt @@ -1,137 +1,124 @@ package com.synebula.gaea.query.mongo +import com.synebula.gaea.log.ILogger import com.synebula.gaea.query.IQuery -import com.synebula.gaea.query.OrderType import com.synebula.gaea.query.PagingData import com.synebula.gaea.query.PagingParam -import org.springframework.data.domain.Sort import org.springframework.data.mongodb.core.MongoTemplate -import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query -import org.springframework.data.mongodb.core.query.isEqualTo -import java.lang.reflect.Field -import java.lang.reflect.ParameterizedType +import com.synebula.gaea.extension.* +/** + * 实现IQuery的Mongo查询类 + * @param repo MongoRepo对象 + */ +open class MongoQuery(var repo: MongoTemplate, override var logger: ILogger? = null) : IQuery, IMongoQuery { + /** + * 查询的对象类 + */ + var clazz: Class? = null -open class MongoQuery(var collection: String, var repo: MongoTemplate) : IQuery { + private var _collection = "" + /** + * 查询的集合名称 + */ + var collection: String = "" + set(value) { + field = value + } + get() = if (this._collection.isNotEmpty()) + this._collection + else { + if (this.clazz != null) + this.clazz!!.simpleName.removeSuffix("View").firstCharLowerCase() + else + "" + } + /** + * 构造方法 + * + * @param clazz 视图对象类型 + * @param repo MongoRepo对象 + */ + constructor(clazz: Class, repo: MongoTemplate) + : this(repo) { + this.clazz = clazz + } - @Suppress("UNCHECKED_CAST") - protected val viewClass: Class = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class + /** + * 构造方法 + * + * @param collection 查询的集合名称 + * @param repo MongoRepo对象 + */ + constructor(collection: String, repo: MongoTemplate) + : this(repo) { + this.collection = collection + } - private val _systemClass = arrayOf( - "String", - "Date", - "Int", - "Double", - "Float", - "BigDecimal", - "Decimal") + /** + * 构造方法 + * + * @param clazz 视图对象类型 + * @param repo MongoRepo对象 + */ + constructor(collection: String, clazz: Class, repo: MongoTemplate) + : this(clazz, repo) { + this.collection = collection + } override fun list(params: Map?): List { - val viewFields = this.viewFields() - val query = Query() - this.where(query, params) - this.select(query, viewFields.toTypedArray()) - return this.repo.find(query, this.viewClass, this.collection) + this.check() + return if (this.clazz != null) { + val viewFields = this.fields(this.clazz!!) + val query = Query() + this.where(query, params, this.clazz!!) + this.select(query, viewFields.toTypedArray()) + this.repo.find(query, this.clazz!!, this.collection) + } else listOf() } override fun count(params: Map?): Int { - val query = Query() - return this.repo.count(where(query, params), this.collection).toInt() + this.check() + return if (this.clazz != null) { + val query = Query() + this.repo.count(where(query, params, this.clazz!!), this.collection).toInt() + } else 0 } override fun paging(params: PagingParam): PagingData { - val viewFields = this.viewFields() - val result = PagingData(1, 10) - result.size = params.size - result.page = params.page - val query = Query() - this.where(query, params.parameters) - result.total = this.repo.count(query, this.collection).toInt() - this.select(query, viewFields.toTypedArray()) - query.with(order(params.orderBy)) - query.skip(params.index).limit(params.size) - result.data = this.repo.find(query, this.viewClass, this.collection) - return result + this.check() + return if (this.clazz != null) { + val viewFields = this.fields(this.clazz!!) + val result = PagingData(1, 10) + result.size = params.size + result.page = params.page + val query = Query() + this.where(query, params.parameters, this.clazz!!) + result.total = this.repo.count(query, this.collection).toInt() + this.select(query, viewFields.toTypedArray()) + query.with(order(params.orderBy)) + query.skip(params.index).limit(params.size) + result.data = this.repo.find(query, this.clazz!!, this.collection) + result + } else PagingData(1, 10) } override fun get(key: String): TView? { - return this.repo.findOne(Query.query(Criteria.where("_id").isEqualTo(key)) - , this.viewClass, this.collection) + this.check() + return if (this.clazz != null) { + val view = this.repo.findOne(idQuery(key), this.clazz!!, this.collection) + view + } else null } - protected fun viewFields(): List { - return traversalFields(viewClass.declaredFields) + private fun check() { + if (this.clazz == null) + throw RuntimeException("[${this.javaClass.name}] 没有声明查询View的类型") + if (this._collection.isEmpty()) + this.logger?.warn(this, null, "[${this.clazz!!.name}]没有声明查询集合名称, 后续尝试使用View对象名称解析集合") } - private fun traversalFields(fields: Array): List { - val names = mutableListOf() - fields.forEach { field -> - names.add(field.name) - if (!field.type.isPrimitive - && !field.type.isArray - && !this._systemClass.contains(field.type.simpleName)) - names.addAll(this.traversalFields(field.type.declaredFields).map { "${field.name}.$it" }) - } - return names - } - - protected open fun where(query: Query, params: Map?): Query { - val criteria = Criteria() - if (params != null) { - for (param in params) { - val value = this.convertFieldValueType(param.key, param.value) - criteria.and(param.key).isEqualTo(value) - } - } - return query.addCriteria(criteria) - } - - protected fun convertFieldValueType(key: String, value: Any): Any? { - val getter = this.viewClass.getMethod("get${key.substring(0, 1).toUpperCase()}${key.substring(1)}") - return this.convertClass(getter.returnType, value.toString()) - } - - protected open fun select(query: Query, fields: Array): Query { - fields.forEach { - query.fields().include(it) - } - return query - } - - protected open fun order(orders: MutableMap?): Sort { - val orderList = mutableListOf() - orders?.forEach() { - orderList.add(Sort.Order(Sort.Direction.valueOf(it.value.name), it.key)) - } - return if (orderList.size == 0) - Sort.by("_id") - else - Sort.by(orderList) - } - - private fun convertClass(type: Class<*>, value: String): Any? { - - if (!type.isPrimitive) { // 判断基本类型 - if (type == String::class.java) { // 如果是string则直接返回 - return value - } - // 如果不为null 则通过反射实例一个对象返回 - return if ("" == value) null else type.getConstructor(String::class.java).newInstance(value) - } - - // 下面处理基本类型,返回包装类 - return when (type.name) { - "int" -> Integer.parseInt(value) - "byte" -> java.lang.Byte.parseByte(value) - "boolean" -> java.lang.Boolean.parseBoolean(value) - "double" -> java.lang.Double.parseDouble(value) - "float" -> java.lang.Float.parseFloat(value) - "long" -> java.lang.Long.parseLong(value) - "short" -> java.lang.Short.parseShort(value) - else -> value - } - } } diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/MongoTypedQuery.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/MongoTypedQuery.kt new file mode 100644 index 0000000..fc62b2a --- /dev/null +++ b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/query/mongo/MongoTypedQuery.kt @@ -0,0 +1,52 @@ +package com.synebula.gaea.query.mongo + +import com.synebula.gaea.log.ILogger +import com.synebula.gaea.query.* +import org.springframework.data.domain.Sort +import org.springframework.data.mongodb.core.MongoTemplate +import org.springframework.data.mongodb.core.query.Criteria +import org.springframework.data.mongodb.core.query.Query +import org.springframework.data.mongodb.core.query.isEqualTo +import java.lang.reflect.Field + +/** + * 实现IQuery的Mongo查询类 + * @param repo MongoRepo对象 + */ + +open class MongoTypedQuery(var repo: MongoTemplate) : ITypedQuery, IMongoQuery { + override var logger: ILogger? = null + + override fun list(params: Map?, clazz: Class): List { + val viewFields = this.fields(clazz) + val query = Query() + this.where(query, params, clazz) + this.select(query, viewFields.toTypedArray()) + return this.repo.find(query, clazz, clazz.simpleName) + } + + override fun count(params: Map?, clazz: Class): Int { + val query = Query() + return this.repo.count(this.where(query, params, clazz), clazz.simpleName).toInt() + } + + override fun paging(params: PagingParam, clazz: Class): PagingData { + val viewFields = this.fields(clazz) + val result = PagingData(1, 10) + result.size = params.size + result.page = params.page + val query = Query() + this.where(query, params.parameters, clazz) + result.total = this.repo.count(query, clazz.simpleName).toInt() + this.select(query, viewFields.toTypedArray()) + query.with(order(params.orderBy)) + query.skip(params.index).limit(params.size) + result.data = this.repo.find(query, clazz, clazz.simpleName) + return result + } + + override fun get(key: String, clazz: Class): TView? { + return this.repo.findOne(idQuery(key), clazz, clazz.simpleName) + } + +} diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/repository/mongo/MongoRepository.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/repository/mongo/MongoRepository.kt index cc50e3c..0813e7c 100644 --- a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/repository/mongo/MongoRepository.kt +++ b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/repository/mongo/MongoRepository.kt @@ -1,35 +1,57 @@ package com.synebula.gaea.repository.mongo import com.synebula.gaea.domain.model.IAggregateRoot -import com.synebula.gaea.domain.repository.ITypedRepository -import org.springframework.beans.factory.annotation.Autowired +import com.synebula.gaea.domain.repository.IRepository import org.springframework.data.mongodb.core.MongoTemplate import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query import org.springframework.data.mongodb.core.query.isEqualTo -import org.springframework.stereotype.Repository -@Repository -abstract class MongoRepository> : ITypedRepository { +/** + * 实现IAggregateRoot的mongo仓储类 + * @param repo MongoRepo对象 + */ +class MongoRepository>(private var repo: MongoTemplate) + : IRepository { - @Autowired - private lateinit var repo: MongoTemplate + /** + * 仓储的对象类 + */ + override var clazz: Class? = null - override fun remove(id: String, clazz: Class) { - this.repo.remove(queryId(id), clazz) - } - - override fun get(id: String, clazz: Class): TAggregateRoot { - return this.repo.findOne(queryId(id), clazz) as TAggregateRoot - } - - override fun update(obj: TAggregateRoot) { - this.repo.save(obj) + /** + * 构造 + * @param clazz 仓储Domain对象 + * @param repo MongoRepo对象 + */ + constructor(clazz: Class, repo: MongoTemplate) : this(repo) { + this.clazz = clazz } override fun add(obj: TAggregateRoot) { this.repo.save(obj) } - protected fun queryId(id: String): Query = Query(Criteria("_id").isEqualTo(id)) + override fun update(obj: TAggregateRoot) { + this.repo.save(obj) + } + + override fun remove(id: String) { + this.repo.remove(idQuery(id), this.clazz!!) + } + + override fun get(id: String): TAggregateRoot { + return this.repo.findOne(idQuery(id), clazz!!) as TAggregateRoot + } + + override fun , TKey> get(id: TKey, clazz: Class): TAggregateRoot { + return this.repo.findOne(idQuery(id.toString()), clazz) as TAggregateRoot + } + + /** + * 获取ID查询条件 + * + * @param id 业务ID + */ + fun idQuery(id: String): Query = Query(Criteria("_id").isEqualTo(id)) } \ No newline at end of file diff --git a/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/repository/mongo/MongoRepositoryTyped.kt b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/repository/mongo/MongoRepositoryTyped.kt new file mode 100644 index 0000000..6b42e67 --- /dev/null +++ b/src/gaea.mongo/src/main/kotlin/com/synebula/gaea/repository/mongo/MongoRepositoryTyped.kt @@ -0,0 +1,39 @@ +package com.synebula.gaea.repository.mongo + +import com.synebula.gaea.domain.model.IAggregateRoot +import com.synebula.gaea.domain.repository.IRepositoryTyped +import org.springframework.data.mongodb.core.MongoTemplate +import org.springframework.data.mongodb.core.query.Criteria +import org.springframework.data.mongodb.core.query.Query +import org.springframework.data.mongodb.core.query.isEqualTo + +/** + * 实现ITypedRepository的mongo仓储类 + * @param repo MongoRepo对象 + */ +open class MongoRepositoryTyped(private var repo: MongoTemplate) + : IRepositoryTyped { + + override fun , TKey> remove(id: TKey, clazz: Class) { + this.repo.remove(idQuery(id), clazz) + } + + override fun , TKey> get(id: TKey, clazz: Class): TAggregateRoot { + return this.repo.findOne(idQuery(id), clazz) as TAggregateRoot + } + + override fun , TKey> update(obj: TAggregateRoot, clazz: Class) { + this.repo.save(obj) + } + + override fun , TKey> add(obj: TAggregateRoot, clazz: Class) { + this.repo.save(obj) + } + + /** + * 获取ID查询条件 + * + * @param id 业务ID + */ + fun idQuery(id: TKey): Query = Query(Criteria("_id").isEqualTo(id)) +} \ No newline at end of file diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/AggregateRoot.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/AggregateRoot.kt index b630ca8..c1bb7fb 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/AggregateRoot.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/AggregateRoot.kt @@ -1,3 +1,5 @@ package com.synebula.gaea.domain.model -abstract class AggregateRoot : Entity(), IAggregateRoot +abstract class AggregateRoot : Entity(), IAggregateRoot { + override var alive: Boolean = true +} diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IAggregateRoot.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IAggregateRoot.kt index 5653797..b442100 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IAggregateRoot.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IAggregateRoot.kt @@ -5,4 +5,10 @@ package com.synebula.gaea.domain.model * * @author alex **/ -interface IAggregateRoot : IEntity +interface IAggregateRoot : IEntity { + + /** + * 实体对象是否有效。 + */ + var alive: Boolean +} diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IEntity.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IEntity.kt index b64d221..3016f06 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IEntity.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/IEntity.kt @@ -12,10 +12,6 @@ interface IEntity { /** * 实体ID */ - var id: TKey + var id: TKey? - /** - * 实体对象是否有效。 - */ - var alive: Boolean } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/complex/IComplexEntity.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/complex/IComplexEntity.kt index b4ff554..0bbca4d 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/complex/IComplexEntity.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/model/complex/IComplexEntity.kt @@ -3,5 +3,5 @@ package com.synebula.gaea.domain.model.complex import com.synebula.gaea.domain.model.IEntity interface IComplexEntity : IEntity { - var secondary: TSecond + var secondary: TSecond? } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepository.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepository.kt index eda343c..196d2ad 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepository.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepository.kt @@ -10,6 +10,11 @@ import com.synebula.gaea.domain.model.IAggregateRoot */ interface IRepository, TKey> { + /** + * 仓储的对象类 + */ + var clazz: Class? + /** * 插入单个对象。 * @@ -40,5 +45,15 @@ interface IRepository, TKey> { * @param id 对象ID。 * @return */ - operator fun get(id: TKey): TAggregateRoot + fun get(id: TKey): TAggregateRoot + + /** + * 根据ID获取对象。 + * + * @param id id + * @param clazz 操作数据的类型 + * @return 聚合根 + */ + fun , TKey> get(id: TKey, clazz: Class): T + } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IComplexRepository.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepositoryComplex.kt similarity index 93% rename from src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IComplexRepository.kt rename to src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepositoryComplex.kt index cacc48d..6df44ee 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IComplexRepository.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepositoryComplex.kt @@ -8,7 +8,7 @@ import com.synebula.gaea.domain.model.complex.IComplexAggregateRoot * @param this T is the parameter * @author alex */ -interface IComplexRepository, TKey, TSecond> { +interface IRepositoryComplex, TKey, TSecond> { /** * 插入单个对象。 diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/ITypedRepository.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepositoryTyped.kt similarity index 58% rename from src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/ITypedRepository.kt rename to src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepositoryTyped.kt index 8e208ab..bd4660f 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/ITypedRepository.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/repository/IRepositoryTyped.kt @@ -2,14 +2,14 @@ package com.synebula.gaea.domain.repository import com.synebula.gaea.domain.model.IAggregateRoot -interface ITypedRepository, TKey> { +interface IRepositoryTyped { /** * 插入单个对象。 * * @param obj 需要插入的对象。 * @return 返回原对象,如果对象ID为自增,则补充自增ID。 */ - fun add(obj: TAggregateRoot) + fun , TKey> add(obj: TAggregateRoot, clazz: Class) /** * 更新对象。 @@ -17,7 +17,7 @@ interface ITypedRepository, TKey> { * @param obj 需要更新的对象。 * @return */ - fun update(obj: TAggregateRoot) + fun , TKey> update(obj: TAggregateRoot, clazz: Class) /** * 通过id删除该条数据 @@ -25,7 +25,7 @@ interface ITypedRepository, TKey> { * @param id id * @param clazz 操作数据的类型 */ - fun remove(id: TKey, clazz: Class) + fun , TKey> remove(id: TKey, clazz: Class) /** * 根据ID获取对象。 @@ -34,5 +34,5 @@ interface ITypedRepository, TKey> { * @param clazz 操作数据的类型 * @return 聚合根 */ - fun get(id: TKey, clazz: Class): TAggregateRoot + fun , TKey> get(id: TKey, clazz: Class): TAggregateRoot } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IService.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IService.kt index 6e283ab..b66ed12 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IService.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IService.kt @@ -1,6 +1,7 @@ package com.synebula.gaea.domain.service import com.synebula.gaea.data.message.Message +import com.synebula.gaea.domain.model.IAggregateRoot import com.synebula.gaea.log.ILogger @@ -21,4 +22,6 @@ interface IService { fun update(key: TKey, command: ICommand) fun remove(key: TKey) + + fun > get(key: TKey, clazz: Class): TAggregateRoot } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IComplexService.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IServiceComplex.kt similarity index 89% rename from src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IComplexService.kt rename to src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IServiceComplex.kt index 146ed06..9101014 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IComplexService.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/IServiceComplex.kt @@ -9,7 +9,7 @@ import com.synebula.gaea.data.message.Message * @version 0.1 * @since 2018 18-2-8 */ -interface IComplexService { +interface IServiceComplex { fun add(command: ICommand): Message> diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Service.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Service.kt index 27482c5..13eb12e 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Service.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/Service.kt @@ -10,20 +10,28 @@ import com.synebula.gaea.log.ILogger /** * class FlatService * + * @param repository 仓储对象 + * @param rootClass 聚合根类对象 + * @param converter 对象转换组件 + * @param logger 日志组件 * @author alex * @version 0.1 * @since 2018 18-2-8 */ -open class Service, TKey> -(override var logger: ILogger, - protected var repository: IRepository, - protected var converter: IObjectConverter, - protected var aggregateRootClass: Class) : IService { +open class Service, TKey>( + protected var rootClass: Class, + protected var repository: IRepository, + protected var converter: IObjectConverter, + override var logger: ILogger) : IService { + + init { + this.repository.clazz = rootClass + } override fun add(command: ICommand): Message { val msg = Message() val root = this.convert(command) - repository.add(root) + this.repository.add(root) msg.data = root.id return msg } @@ -31,11 +39,19 @@ open class Service, TKey> override fun update(key: TKey, command: ICommand) { val root = this.convert(command) root.id = key - repository.update(root) + this.repository.update(root) } override fun remove(key: TKey) { - repository.remove(key) + this.repository.remove(key) + } + + fun get(key: TKey): TAggregateRoot { + return this.repository.get(key) + } + + override fun > get(key: TKey, clazz: Class): T { + return this.repository.get(key, clazz) } /** @@ -46,7 +62,7 @@ open class Service, TKey> */ protected fun convert(command: ICommand): TAggregateRoot { try { - return converter.convert(command, aggregateRootClass) + return converter.convert(command, rootClass) } catch (ex: Exception) { throw RuntimeException("command not match aggregate root", ex) } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ComplexService.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ServiceComplex.kt similarity index 81% rename from src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ComplexService.kt rename to src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ServiceComplex.kt index ff41b82..f928302 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ComplexService.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ServiceComplex.kt @@ -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.IComplexRepository +import com.synebula.gaea.domain.repository.IRepositoryComplex import com.synebula.gaea.log.ILogger /** @@ -13,16 +13,16 @@ import com.synebula.gaea.log.ILogger * @version 0.1 * @since 2018 18-2-8 */ -open class ComplexService, TKey, TSecond> -(var logger: ILogger, protected var repository: IComplexRepository, +open class ServiceComplex, TKey, TSecond> +(var logger: ILogger, protected var repository: IRepositoryComplex, protected var converter: IObjectConverter, protected var aggregateRootClass: Class) - : IComplexService { + : IServiceComplex { override fun add(command: ICommand): Message> { val msg = Message>() val root = this.convert(command) repository.add(root) - msg.data = Pair(root.id, root.secondary) + msg.data = Pair(root.id!!, root.secondary!!) return msg } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ServiceTyped.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ServiceTyped.kt new file mode 100644 index 0000000..782c21f --- /dev/null +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/domain/service/ServiceTyped.kt @@ -0,0 +1,62 @@ +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.log.ILogger + + +/** + * class FlatService + * + * @param repository 仓储对象 + * @param rootClass 聚合根类对象 + * @param converter 对象转换组件 + * @param logger 日志组件 + * @author alex + * @version 0.1 + * @since 2018 18-2-8 + */ +open class ServiceTyped, TKey>( + protected var rootClass: Class, + protected var repository: IRepositoryTyped, + protected var converter: IObjectConverter, + override var logger: ILogger) : IService { + + override fun add(command: ICommand): Message { + val msg = Message() + val root = this.convert(command) + this.repository.add(root, rootClass) + msg.data = root.id + return msg + } + + override fun update(key: TKey, command: ICommand) { + val root = this.convert(command) + root.id = key + this.repository.update(root, rootClass) + } + + override fun remove(key: TKey) { + this.repository.remove(key, rootClass) + } + + override fun > get(key: TKey, clazz: Class): TAggregateRoot { + return this.repository.get(key, clazz) + } + + /** + * 转换ICommand类型到聚合根类型,默认实现,根据需要进行覆写。 + * + * @param command + * @return + */ + protected fun convert(command: ICommand): TAggregateRoot { + try { + return converter.convert(command, rootClass) + } catch (ex: Exception) { + throw RuntimeException("command not match aggregate root", ex) + } + } +} diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/extension/StringExt.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/extension/StringExt.kt new file mode 100644 index 0000000..bbb7df2 --- /dev/null +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/extension/StringExt.kt @@ -0,0 +1,9 @@ +package com.synebula.gaea.extension + +fun String.firstCharLowerCase(): String { + if (Character.isLowerCase(this.elementAt(0))) + return this + else + return StringBuilder().append(Character.toLowerCase(this.elementAt(0))) + .append(this.substring(1)).toString() +} \ No newline at end of file diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/log/NullLogger.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/log/NullLogger.kt index df3aa9e..922e442 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/log/NullLogger.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/log/NullLogger.kt @@ -27,43 +27,103 @@ class NullLogger : ILogger { override val name: String get() = NullLogger::class.simpleName!! - override fun trace(t: Throwable) {} + override fun trace(t: Throwable) { - override fun trace(format: String, vararg args: Any) {} + } - override fun trace(t: Throwable, format: String, vararg args: Any) {} + override fun trace(format: String, vararg args: Any) { - override fun trace(obj: Any, t: Throwable, format: String, vararg args: Any) {} + } - override fun debug(t: Throwable) {} + override fun trace(t: Throwable, format: String, vararg args: Any) { - override fun debug(format: String, vararg args: Any) {} + } - override fun debug(t: Throwable, format: String, vararg args: Any) {} + override fun trace(obj: Any, format: String, vararg args: Any) { - override fun debug(obj: Any, t: Throwable, format: String, vararg args: Any) {} + } - override fun info(t: Throwable) {} + override fun trace(obj: Any, t: Throwable?, format: String, vararg args: Any) { - override fun info(format: String, vararg args: Any) {} + } - override fun info(t: Throwable, format: String, vararg args: Any) {} + override fun debug(t: Throwable) { - override fun info(obj: Any, t: Throwable, format: String, vararg args: Any) {} + } - override fun warn(t: Throwable) {} + override fun debug(format: String, vararg args: Any) { - override fun warn(format: String, vararg args: Any) {} + } - override fun warn(t: Throwable, format: String, vararg args: Any) {} + override fun debug(t: Throwable, format: String, vararg args: Any) { - override fun warn(obj: Any, t: Throwable, format: String, vararg args: Any) {} + } - override fun error(t: Throwable) {} + override fun debug(obj: Any, format: String, vararg args: Any) { - override fun error(format: String, vararg args: Any) {} + } - override fun error(t: Throwable, format: String, vararg args: Any) {} + override fun debug(obj: Any, t: Throwable?, format: String, vararg args: Any) { - override fun error(obj: Any, t: Throwable, format: String, vararg args: Any) {} + } + + override fun info(t: Throwable) { + + } + + override fun info(format: String, vararg args: Any) { + + } + + override fun info(t: Throwable, format: String, vararg args: Any) { + + } + + override fun info(obj: Any, format: String, vararg args: Any) { + + } + + override fun info(obj: Any, t: Throwable?, format: String, vararg args: Any) { + + } + + override fun warn(t: Throwable) { + + } + + override fun warn(format: String, vararg args: Any) { + + } + + override fun warn(t: Throwable, format: String, vararg args: Any) { + + } + + override fun warn(obj: Any, format: String, vararg args: Any) { + + } + + override fun warn(obj: Any, t: Throwable?, format: String, vararg args: Any) { + + } + + override fun error(t: Throwable) { + + } + + override fun error(format: String, vararg args: Any) { + + } + + override fun error(t: Throwable, format: String, vararg args: Any) { + + } + + override fun error(obj: Any, format: String, vararg args: Any) { + + } + + override fun error(obj: Any, t: Throwable?, format: String, vararg args: Any) { + + } } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IDebugLogger.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IDebugLogger.kt index 655eb2f..5a1cbb1 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IDebugLogger.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IDebugLogger.kt @@ -35,6 +35,15 @@ interface IDebugLogger { */ fun debug(t: Throwable, format: String, vararg args: Any) + /** + * 打印 DEBUG 等级的日志 + * + * @param obj 输出错误对象 + * @param format 消息模板 + * @param args 参数 + */ + fun debug(obj: Any, format: String, vararg args: Any) + /** * 打印 DEBUG 等级的日志 * @@ -43,5 +52,5 @@ interface IDebugLogger { * @param format 消息模板 * @param args 参数 */ - fun debug(obj: Any, t: Throwable, format: String, vararg args: Any) + fun debug(obj: Any, t: Throwable?, format: String, vararg args: Any) } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IErrorLogger.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IErrorLogger.kt index b6ae32c..c561a55 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IErrorLogger.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IErrorLogger.kt @@ -34,6 +34,15 @@ interface IErrorLogger { */ fun error(t: Throwable, format: String, vararg args: Any) + /** + * 打印 ERROR 等级的日志 + * + * @param obj 输出错误对象 + * @param format 消息模板 + * @param args 参数 + */ + fun error(obj: Any, format: String, vararg args: Any) + /** * 打印 ERROR 等级的日志 * @@ -42,5 +51,5 @@ interface IErrorLogger { * @param format 消息模板 * @param args 参数 */ - fun error(obj: Any, t: Throwable, format: String, vararg args: Any) + fun error(obj: Any, t: Throwable?, format: String, vararg args: Any) } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IInfoLogger.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IInfoLogger.kt index b66fc93..fed35bd 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IInfoLogger.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IInfoLogger.kt @@ -34,6 +34,15 @@ interface IInfoLogger { */ fun info(t: Throwable, format: String, vararg args: Any) + /** + * 打印 INFO 等级的日志 + * + * @param obj 输出错误对象 + * @param format 消息模板 + * @param args 参数 + */ + fun info(obj: Any, format: String, vararg args: Any) + /** * 打印 INFO 等级的日志 * @@ -42,5 +51,5 @@ interface IInfoLogger { * @param format 消息模板 * @param args 参数 */ - fun info(obj: Any, t: Throwable, format: String, vararg args: Any) + fun info(obj: Any, t: Throwable?, format: String, vararg args: Any) } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/ITraceLogger.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/ITraceLogger.kt index aa579fe..ed29589 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/ITraceLogger.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/ITraceLogger.kt @@ -35,6 +35,16 @@ interface ITraceLogger { */ fun trace(t: Throwable, format: String, vararg args: Any) + /** + * 打印 TRACE 等级的日志 + * + * @param obj 输出错误对象 + * @param format 消息模板 + * @param args 参数 + */ + fun trace(obj: Any, format: String, vararg args: Any) + + /** * 打印 TRACE 等级的日志 * @@ -43,6 +53,6 @@ interface ITraceLogger { * @param format 消息模板 * @param args 参数 */ - fun trace(obj: Any, t: Throwable, format: String, vararg args: Any) + fun trace(obj: Any, t: Throwable?, format: String, vararg args: Any) } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IWarnLogger.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IWarnLogger.kt index 8eebbda..803aded 100644 --- a/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IWarnLogger.kt +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/log/logger/IWarnLogger.kt @@ -34,6 +34,16 @@ interface IWarnLogger { */ fun warn(t: Throwable, format: String, vararg args: Any) + + /** + * 打印 WARN 等级的日志 + * + * @param obj 输出错误对象 + * @param format 消息模板 + * @param args 参数 + */ + fun warn(obj: Any, format: String, vararg args: Any) + /** * 打印 WARN 等级的日志 * @@ -42,5 +52,5 @@ interface IWarnLogger { * @param format 消息模板 * @param args 参数 */ - fun warn(obj: Any, t: Throwable, format: String, vararg args: Any) + fun warn(obj: Any, t: Throwable?, format: String, vararg args: Any) } diff --git a/src/gaea/src/main/kotlin/com/synebula/gaea/query/ITypedQuery.kt b/src/gaea/src/main/kotlin/com/synebula/gaea/query/ITypedQuery.kt new file mode 100644 index 0000000..ad72df5 --- /dev/null +++ b/src/gaea/src/main/kotlin/com/synebula/gaea/query/ITypedQuery.kt @@ -0,0 +1,42 @@ +package com.synebula.gaea.query + +/** + * 查询基接口。 + * + * @author alex + */ +interface ITypedQuery { + + + /** + * 根据Key获取对象。 + * + * @param key 对象Key。 + * @return + */ + fun get(key: TKey, clazz: Class): TView? + + /** + * 根据实体类条件查询所有符合条件记录 + * + * @param params 查询条件。 + * @return list + */ + fun list(params: Map?, clazz: Class): List + + /** + * 根据条件查询符合条件记录的数量 + * + * @param params 查询条件。 + * @return int + */ + fun count(params: Map?, clazz: Class): Int + + /** + * 根据实体类条件查询所有符合条件记录(分页查询) + * + * @param params 分页条件 + * @return 分页数据 + */ + fun paging(params: PagingParam, clazz: Class): PagingData +}