├── antx.properties ├── .gitignore ├── model-client ├── src │ └── main │ │ └── java │ │ └── com │ │ └── concur │ │ └── meta │ │ └── client │ │ ├── utils │ │ ├── FieldFilter.java │ │ ├── NamingThreadFactory.java │ │ ├── MultiValueMap.java │ │ ├── FieldUtil.java │ │ └── CacheUtils.java │ │ ├── conversion │ │ ├── conveters │ │ │ ├── ConverterPackageInfo.java │ │ │ ├── Class2StringConverter.java │ │ │ ├── Boolean2IntegerConverter.java │ │ │ ├── Integer2BooleanConverter.java │ │ │ ├── Set2StringConverter.java │ │ │ ├── List2StringConverter.java │ │ │ ├── spring │ │ │ │ ├── support │ │ │ │ │ ├── ObjectToStringConverter.java │ │ │ │ │ ├── StringToLocaleConverter.java │ │ │ │ │ ├── StringToUUIDConverter.java │ │ │ │ │ ├── NumberToCharacterConverter.java │ │ │ │ │ ├── StringToCharacterConverter.java │ │ │ │ │ ├── PropertiesToStringConverter.java │ │ │ │ │ ├── StringToPropertiesConverter.java │ │ │ │ │ ├── ConfigurableConversionService.java │ │ │ │ │ ├── StringToBooleanConverter.java │ │ │ │ │ ├── EnumToStringConverter.java │ │ │ │ │ ├── StringToEnumConverterFactory.java │ │ │ │ │ ├── CharacterToNumberFactory.java │ │ │ │ │ ├── StringToNumberConverterFactory.java │ │ │ │ │ ├── ArrayToStringConverter.java │ │ │ │ │ ├── ConversionUtils.java │ │ │ │ │ └── ObjectToArrayConverter.java │ │ │ │ ├── converter │ │ │ │ │ ├── ConditionalGenericConverter.java │ │ │ │ │ ├── Converter.java │ │ │ │ │ ├── ConverterFactory.java │ │ │ │ │ ├── ConverterRegistry.java │ │ │ │ │ └── ConditionalConverter.java │ │ │ │ ├── ComparableComparator.java │ │ │ │ ├── ConversionException.java │ │ │ │ ├── ConverterNotFoundException.java │ │ │ │ ├── ParameterNameDiscoverer.java │ │ │ │ └── ConversionFailedException.java │ │ │ ├── String2SetConverter.java │ │ │ ├── String2ListConverter.java │ │ │ ├── Map2StringConverter.java │ │ │ └── String2MapConverter.java │ │ ├── Converter.uml │ │ ├── QueryJsonResult.java │ │ ├── Converter.java │ │ ├── CustomConverter.java │ │ ├── ConverterAdapter.java │ │ ├── ConverterService.java │ │ └── ConverterRegistry.java │ │ ├── domain │ │ ├── BaseModel.java │ │ ├── ToString.java │ │ ├── BaseMappedModel.java │ │ └── dto │ │ │ └── DataSourceDTO.java │ │ ├── api │ │ ├── transaction │ │ │ ├── Transaction.uml │ │ │ └── TransactionStatus.java │ │ ├── query │ │ │ ├── ClientQueryAction.java │ │ │ ├── AggregateType.java │ │ │ ├── SortType.java │ │ │ ├── HSFQuery.java │ │ │ ├── AbstractQuery.java │ │ │ ├── RangePair.java │ │ │ └── SqlQuery.java │ │ ├── persist │ │ │ ├── ActionStatus.java │ │ │ └── actions │ │ │ │ ├── operation │ │ │ │ ├── InsertOperation.java │ │ │ │ ├── BatchInsertOperation.java │ │ │ │ └── UpdateOperation.java │ │ │ │ └── BatchInsertAction.java │ │ ├── Tair.java │ │ ├── DB.java │ │ └── HSF.java │ │ ├── service │ │ ├── DataSourceService.java │ │ ├── server │ │ │ ├── MetaDataReadServerService.java │ │ │ └── MetaDataWriteServerService.java │ │ ├── MetaDataReadService.java │ │ ├── impl │ │ │ ├── TairDataServiceImpl.java │ │ │ └── BaseMetaDataService.java │ │ ├── CachedDataService.java │ │ └── TairDataService.java │ │ ├── common │ │ └── IResultCode.java │ │ ├── annotation │ │ ├── Version.java │ │ ├── LMeta.java │ │ ├── LColumn.java │ │ └── LModel.java │ │ ├── exception │ │ ├── ResponseTimeoutException.java │ │ ├── CheckFailException.java │ │ ├── TransactionFailException.java │ │ ├── MetaDataException.java │ │ ├── ConsistencyException.java │ │ ├── LModelException.java │ │ ├── ExecuteException.java │ │ └── base │ │ │ ├── NestedExceptionUtils.java │ │ │ └── BeansException.java │ │ ├── constants │ │ ├── ColumnType.java │ │ ├── QueryType.java │ │ ├── DataSourceType.java │ │ └── ParamKeys.java │ │ ├── config │ │ └── LmodelConfig.java │ │ ├── dataobject │ │ ├── MetaResponse.java │ │ └── ResponseResult.java │ │ ├── result │ │ ├── ClientResultCode.java │ │ └── ServerResultCode.java │ │ └── logger │ │ └── ExecuteLogger.java └── pom.xml ├── model-metadata ├── src │ └── main │ │ └── java │ │ └── com │ │ └── concur │ │ └── meta │ │ └── metadata │ │ ├── domain │ │ ├── dto │ │ │ ├── MetaModelDTO.java │ │ │ └── MetaDataSourceDTO.java │ │ ├── MetaBaseDO.java │ │ └── MetaDataSourceDO.java │ │ ├── service │ │ ├── MetaDataConfigService.java │ │ ├── impl │ │ │ ├── MetaDataConfigServiceImpl.java │ │ │ ├── DataSourceServiceImpl.java │ │ │ └── LMetaServiceImpl.java │ │ └── LMetaService.java │ │ └── util │ │ ├── ServiceUtil.java │ │ └── ApplicationContextUtils.java └── pom.xml ├── model-core └── src │ └── main │ ├── java │ └── com │ │ └── concur │ │ └── meta │ │ └── core │ │ ├── dbengine │ │ ├── meta │ │ │ ├── IndexMeta.java │ │ │ ├── MetaBuilder.java │ │ │ ├── metabuilder │ │ │ │ ├── AnnotationMetaBuilder.java │ │ │ │ └── ConfigurableMetaBuilder.java │ │ │ ├── TableMeta.java │ │ │ └── ColumnMeta.java │ │ ├── factory │ │ │ ├── DataSourceReloadable.java │ │ │ ├── MetaDataFactory.java │ │ │ ├── MetaDatasource.java │ │ │ └── impl │ │ │ │ └── NullMetaDataSource.java │ │ ├── execute │ │ │ ├── QueryAction.java │ │ │ ├── WriteAction.java │ │ │ ├── ActionContext.java │ │ │ ├── routing │ │ │ │ └── DynamicDBDataSource.java │ │ │ └── actions │ │ │ │ ├── AggQueryAction.java │ │ │ │ ├── SqlQueryAction.java │ │ │ │ └── BaseInsertAction.java │ │ ├── types │ │ │ ├── LongTypeHandler.java │ │ │ └── StringArrayTypeHandler.java │ │ ├── mapper │ │ │ └── ColumnMapper.java │ │ ├── logger │ │ │ └── LogableDynamicDBDataSource.java │ │ └── sql │ │ │ └── sqlbuilder │ │ │ └── SqlBuilder.java │ │ ├── manager │ │ ├── TableMetaManager.java │ │ ├── DataSourceManager.java │ │ └── impl │ │ │ └── TableMetaManagerImpl.java │ │ ├── datasource │ │ ├── DataSourceInitializer.java │ │ └── DataSourceInitializeHandle.java │ │ └── extension │ │ ├── postgre │ │ ├── PostgresSqlAutoMetaBuilder.java │ │ ├── PostgreSqlDatasourceImpl.java │ │ └── actions │ │ │ └── PostgresSqlInsertAction.java │ │ └── mysql │ │ └── MysqlDatasourceImpl.java │ └── resources │ ├── conf │ └── mybatis-config.xml │ ├── lmodel.datasource.xml │ └── lmodel-application.xml └── azure-pipelines.yml /antx.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | # schema: daily#APP#1 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | *.iml 3 | target/* 4 | **/target/** 5 | logs/* 6 | .DS_Store -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/utils/FieldFilter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.utils; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | /** 6 | * 属性过滤 7 | */ 8 | public interface FieldFilter { 9 | boolean doFilter(Field field, Object value); 10 | } -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/domain/dto/MetaModelDTO.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.domain.dto; 2 | 3 | /** 4 | * ${DESCRIPTION} 5 | * 6 | * @author yongfu.cyf 7 | * @create 2017-07-27 上午10:31 8 | **/ 9 | public class MetaModelDTO { 10 | } 11 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/domain/dto/MetaDataSourceDTO.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.domain.dto; 2 | 3 | /** 4 | * ${DESCRIPTION} 5 | * 6 | * @author yongfu.cyf 7 | * @create 2017-07-27 上午10:31 8 | **/ 9 | public class MetaDataSourceDTO { 10 | } 11 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/ConverterPackageInfo.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | /** 4 | * 此路径存放转换器实现类 5 | * 6 | * @author yongfu.cyf 7 | * @create 2017-10-11 下午7:11 8 | **/ 9 | public class ConverterPackageInfo { 10 | } 11 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/domain/BaseModel.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * DO基类 7 | * 第一期不支持级连更新 8 | * @author yongfu.cyf 9 | * @create 2017-06-28 下午4:13 10 | **/ 11 | public interface BaseModel extends Serializable { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/Converter.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | JAVA 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | All 12 | 13 | 14 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/transaction/Transaction.uml: -------------------------------------------------------------------------------- 1 | 2 | 3 | JAVA 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | All 12 | 13 | 14 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/meta/IndexMeta.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.meta; 2 | 3 | /** 4 | * 索引元数据信息 5 | * (用于后续做SQL优化) 6 | * 7 | * @author yongfu.cyf 8 | * @create 2017-07-04 上午9:51 9 | **/ 10 | public class IndexMeta { 11 | 12 | /** 13 | * 索引匹配 14 | * @return 匹配的列数 15 | */ 16 | public int matchScore() { 17 | 18 | return 0; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/service/MetaDataConfigService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.service; 2 | 3 | import javax.sql.DataSource; 4 | 5 | /** 6 | * 元数据配置服务 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-28 下午3:28 10 | **/ 11 | public interface MetaDataConfigService { 12 | 13 | /** 14 | * 获取配置数据源 15 | * @return 16 | */ 17 | DataSource getConfigDataSource(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/query/ClientQueryAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.query; 2 | 3 | import java.util.Map; 4 | 5 | import com.concur.meta.client.dataobject.ResponseResult; 6 | 7 | /** 8 | * 查询动作 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-09-01 下午3:27 12 | **/ 13 | public interface ClientQueryAction { 14 | 15 | /** 16 | * 执行查询 17 | * @return 18 | */ 19 | ResponseResult doQuery(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/DataSourceService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service; 2 | 3 | import com.concur.meta.client.domain.dto.DataSourceDTO; 4 | 5 | /** 6 | * 数据源服务接口 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-24 下午8:16 10 | **/ 11 | public interface DataSourceService { 12 | 13 | /** 14 | * 获取数据源 15 | * @param dataSourceId 16 | * @return 17 | */ 18 | DataSourceDTO getDataSource(long dataSourceId); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/common/IResultCode.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.common; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 错误信息接口 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-28 下午3:18 10 | */ 11 | public interface IResultCode extends Serializable { 12 | 13 | /** 14 | * 错误码 15 | * @return 16 | */ 17 | String getCode(); 18 | 19 | /** 20 | * 错误信息 21 | * @return 22 | */ 23 | String getMessage(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/annotation/Version.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 乐观锁版本号字段 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-09-21 下午9:33 13 | **/ 14 | @Target(ElementType.FIELD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface Version { 17 | } 18 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/ResponseTimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.exception; 2 | 3 | /** 4 | * 服务端执行或返回超时异常 5 | * 抛出此异常无法保证重试的幂等性, 比如服务端insert成功了, 但是返回时网络异常, 那么第二次重试insert就会主键重复异常 6 | * 7 | * @author yongfu.cyf 8 | * @create 2017-10-30 下午12:07 9 | **/ 10 | public class ResponseTimeoutException extends LModelException { 11 | 12 | public ResponseTimeoutException(Throwable cause) { 13 | super("服务端执行或返回超时异常", cause); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/persist/ActionStatus.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.persist; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 操作状态 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-12 下午8:06 10 | **/ 11 | public enum ActionStatus implements Serializable { 12 | 13 | /** 14 | * 初始化状态 15 | */ 16 | INIT, 17 | 18 | /** 19 | * 执行成功 20 | */ 21 | OK, 22 | 23 | /** 24 | * 已经撤销 25 | */ 26 | UNDO 27 | 28 | } 29 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/factory/DataSourceReloadable.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.factory; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 可重新加载的数据源 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-06 上午10:50 10 | **/ 11 | public interface DataSourceReloadable { 12 | 13 | /** 14 | * 重新加载触发执行方法 15 | * @param dataSourceId 数据源ID 16 | * @param classNames 类集合 17 | */ 18 | void onReload(long dataSourceId, List classNames); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/manager/TableMetaManager.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.manager; 2 | 3 | import com.concur.meta.core.dbengine.meta.TableMeta; 4 | 5 | /** 6 | * DB元数据信息管理接口 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-04 上午10:53 10 | **/ 11 | public interface TableMetaManager { 12 | 13 | /** 14 | * 获取表元数据信息 15 | * @param className 类名/模型编码 16 | * @return TableMeta 返回元数据服务提供的TableMeta 17 | */ 18 | TableMeta getTableMeta(String className); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /model-core/src/main/resources/conf/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/Tair.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api; 2 | 3 | import com.concur.meta.client.api.query.TairQuery; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Tair操作入口 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-07-28 下午3:26 12 | **/ 13 | public class Tair { 14 | 15 | public static class Query { 16 | public static TairQuery create(Class clazz) { 17 | return TairQuery.create(clazz); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/QueryJsonResult.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion; 2 | 3 | 4 | import java.io.Serializable; 5 | 6 | /** 7 | * 不用写返回DO的方式直接返回JSON对象 8 | * @author sherrichen 9 | * @date 2019-04-24 14:59 10 | */ 11 | public class QueryJsonResult implements Serializable { 12 | private String jsonData; 13 | 14 | public String getJsonData() { 15 | return jsonData; 16 | } 17 | 18 | public void setJsonData(String jsonData) { 19 | this.jsonData = jsonData; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/annotation/LMeta.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * LModel元数据 10 | *
  • 支持存储任意类型的元数据
  • 11 | *
  • 系统自动存储和索引
  • 12 | * @author yongfu.cyf 13 | * @create 2017-11-01 下午7:46 14 | **/ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | public @interface LMeta { 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/Class2StringConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import com.concur.meta.client.conversion.ConverterAdapter; 4 | 5 | /** 6 | * Class转字符串 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-24 下午12:00 10 | **/ 11 | public class Class2StringConverter extends ConverterAdapter { 12 | 13 | @Override 14 | public String convert(Class source, Object... objects) { 15 | if (source == null) { 16 | return null; 17 | } 18 | return source.getName(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/domain/ToString.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.apache.commons.lang.builder.ToStringBuilder; 6 | import org.apache.commons.lang.builder.ToStringStyle; 7 | 8 | /** 9 | * Created by taixu.zqq on 2017/2/4. 10 | */ 11 | public class ToString implements Serializable { 12 | 13 | private static final long serialVersionUID = 894815529144843913L; 14 | 15 | @Override 16 | public String toString(){ 17 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/constants/ColumnType.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.constants; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 字段存储类型 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-31 下午3:44 10 | **/ 11 | public enum ColumnType implements Serializable { 12 | /** 13 | * 字符串类型 14 | * 无需指定, 默认将非8种(以及Date)基本类型的属性转换成字符串进行存储 15 | */ 16 | STRING, 17 | /** 18 | * Attribues类型 19 | * 如果属性类型是Map, 无需指定, 将默认自动使用此选项 20 | */ 21 | ATTRIBUTES, 22 | /** 23 | * Json String类型 24 | * 自定义类型的属性可以使用JSON存储 25 | */ 26 | JSON, 27 | ; 28 | } 29 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/service/impl/MetaDataConfigServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.service.impl; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.concur.meta.metadata.service.MetaDataConfigService; 6 | import com.concur.meta.metadata.util.ServiceUtil; 7 | 8 | /** 9 | * 元数据配置服务实现 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-07-03 下午4:19 13 | **/ 14 | public class MetaDataConfigServiceImpl implements MetaDataConfigService { 15 | 16 | @Override 17 | public DataSource getConfigDataSource() { 18 | return ServiceUtil.getLmodelConfigDataSource(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/constants/QueryType.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.constants; 2 | 3 | /** 4 | * 查询类型 5 | * 6 | * @author yongfu.cyf 7 | * @create 2017-08-23 下午2:42 8 | **/ 9 | public enum QueryType { 10 | 11 | /** 12 | * 聚合查询 13 | */ 14 | AggQuery(1), 15 | 16 | /** 17 | * 分页查询 18 | */ 19 | PageQuery(2), 20 | 21 | /** 22 | * 指定SQL查询 23 | */ 24 | SqlQuery(3); 25 | 26 | private final int id; 27 | 28 | QueryType(int id) { 29 | this.id = id; 30 | } 31 | 32 | public int getId() { 33 | return id; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/Converter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.concur.meta.client.conversion; 5 | 6 | import java.lang.reflect.Type; 7 | 8 | /** 9 | * 抽象的转换者接口 10 | * @author jake 11 | * 12 | */ 13 | public interface Converter{ 14 | 15 | /** 16 | * 转换 17 | * @param source 源对象 18 | *@param objects 附加参数 @return 19 | */ 20 | T convert(S source, Object... objects); 21 | 22 | /** 23 | * 转换 24 | * @param source 源对象 25 | * @param targetType 目标类 26 | * @param objects 附加参数 @return 27 | */ 28 | T convert(S source, Type targetType, Object... objects); 29 | 30 | } -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/datasource/DataSourceInitializer.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.datasource; 2 | 3 | import java.util.Map; 4 | 5 | import javax.sql.DataSource; 6 | 7 | import com.concur.meta.client.constants.DataSourceType; 8 | 9 | /** 10 | * 数据源初始化器 11 | * 12 | * @author yongfu.cyf 13 | * @create 2017-08-25 上午11:41 14 | **/ 15 | public interface DataSourceInitializer { 16 | 17 | /** 18 | * 初始化数据源 19 | * @param attributes 属性 20 | * @return 21 | */ 22 | DataSource init(Map attributes); 23 | 24 | /** 25 | * 声明数据源类型 26 | * @return 27 | */ 28 | DataSourceType getDataSourceType(); 29 | } 30 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/domain/BaseMappedModel.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.domain; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.apache.commons.lang.builder.ToStringBuilder; 6 | 7 | /** 8 | * Map类型映射的DO基类 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-06-28 下午3:44 12 | **/ 13 | public abstract class BaseMappedModel extends HashMap implements BaseModel { 14 | 15 | @Override 16 | public T put(Object key, Object value) { 17 | super.put(key, value); 18 | return (T) this; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return ToStringBuilder.reflectionToString(this); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/manager/DataSourceManager.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.manager; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.concur.meta.metadata.domain.MetaDataSourceDO; 6 | 7 | /** 8 | * 数据源管理接口 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-07-05 上午11:58 12 | **/ 13 | public interface DataSourceManager { 14 | 15 | /** 16 | * 获取(初始化)数据源 17 | * @param dataSourceId 数据源ID 18 | * @return 19 | */ 20 | DataSource getDatasource(Long dataSourceId); 21 | 22 | /** 23 | * 获取数据源DO (带缓存) 24 | * @param dataSourceId 数据源ID 25 | * @return 26 | */ 27 | MetaDataSourceDO getMetaDataSource(Long dataSourceId); 28 | } 29 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/server/MetaDataReadServerService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service.server; 2 | 3 | 4 | import com.concur.meta.client.dataobject.MetaRequest; 5 | import com.concur.meta.client.dataobject.MetaResponse; 6 | 7 | /** 8 | * 元数据服务端读接口 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-06-28 下午4:06 12 | **/ 13 | public interface MetaDataReadServerService { 14 | 15 | /** 16 | * 根据主键获取数据 17 | * @param request 查询参数 18 | * @return 19 | */ 20 | MetaResponse get(MetaRequest request); 21 | 22 | /** 23 | * 分页查询 24 | * @param request 查询参数 25 | * @return 26 | */ 27 | MetaResponse query(MetaRequest request); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/execute/QueryAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.execute; 2 | 3 | import com.concur.meta.client.constants.QueryType; 4 | import com.concur.meta.client.dataobject.MetaRequest; 5 | import com.concur.meta.client.dataobject.MetaResponse; 6 | 7 | /** 8 | * 查询Action 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-08-23 上午11:51 12 | **/ 13 | public interface QueryAction { 14 | 15 | /** 16 | * 是否支持 17 | * @param type 18 | * @return 19 | */ 20 | boolean support(QueryType type); 21 | 22 | /** 23 | * 执行请求 24 | * @param request 查询请求 25 | * @return 26 | */ 27 | MetaResponse execute(MetaRequest request); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/execute/WriteAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.execute; 2 | 3 | import com.concur.meta.client.constants.DataSourceType; 4 | import com.concur.meta.client.dataobject.MetaRequest; 5 | import com.concur.meta.client.dataobject.MetaResponse; 6 | 7 | /** 8 | * 抽象的写入操作 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-09-07 上午10:27 12 | **/ 13 | public interface WriteAction { 14 | 15 | /** 16 | * 是否支数据源 17 | * @param type 18 | * @return 19 | */ 20 | boolean support(DataSourceType type); 21 | 22 | /** 23 | * 执行请求 24 | * @param request 查询请求 25 | * @return 26 | */ 27 | MetaResponse execute(MetaRequest request); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/CustomConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /** 6 | * 自定义转换器适配类(具体的转换器实现此类) 7 | * 通过support()判断是否调用次转换器 8 | * @author jake 9 | */ 10 | public abstract class CustomConverter implements Converter { 11 | 12 | /** 13 | * 是否支持转换 14 | * @param type Type 15 | * @return 16 | */ 17 | public abstract boolean support(Type type); 18 | 19 | @Override 20 | public T convert(S source, Object... objects) { 21 | return null; 22 | } 23 | 24 | @Override 25 | public T convert(S source, Type targetType, Object... objects) { 26 | return this.convert(source, objects); 27 | } 28 | 29 | 30 | } -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/annotation/LColumn.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import com.concur.meta.client.constants.ColumnType; 9 | 10 | /** 11 | * 字段配置 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-07-05 下午3:29 15 | **/ 16 | @Target(ElementType.FIELD) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | public @interface LColumn { 19 | 20 | /** 21 | * 指定属性名(驼峰形式) 22 | * @return 23 | */ 24 | String name() default ""; 25 | 26 | /** 27 | * 字段存储类型 28 | * @return 29 | */ 30 | ColumnType type() default ColumnType.STRING; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/meta/MetaBuilder.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.meta; 2 | 3 | import com.concur.meta.client.dataobject.MetaRequest; 4 | import com.concur.meta.core.dbengine.factory.MetaDatasource; 5 | import com.concur.meta.core.dbengine.mapper.ColumnMapper; 6 | 7 | /** 8 | * 元数据信息builder 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-06-29 上午10:44 12 | **/ 13 | public interface MetaBuilder { 14 | 15 | /** 16 | * 构建元数据信息 17 | * @param metaDatasource DataSource 对象所在的数据源 18 | * @param metaRequest MetaRequest 数据请求 19 | * @return 20 | */ 21 | TableMeta build(MetaDatasource metaDatasource, MetaRequest metaRequest); 22 | 23 | /** 24 | * 获取字段映射器 25 | * @return 26 | */ 27 | ColumnMapper getColumnMapper(); 28 | } 29 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/extension/postgre/PostgresSqlAutoMetaBuilder.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.extension.postgre; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DatabaseMetaData; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import com.concur.meta.core.dbengine.meta.metabuilder.DefaultAutoMetaBuilder; 9 | 10 | /** 11 | * 从数据库build元数据信息 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-09-06 下午9:00 15 | **/ 16 | public class PostgresSqlAutoMetaBuilder extends DefaultAutoMetaBuilder { 17 | 18 | @Override 19 | protected ResultSet getTablesResultSet(Connection conn, DatabaseMetaData dbMeta, String tableName) 20 | throws SQLException { 21 | return dbMeta.getTables(null, null, tableName, new String[]{"TABLE"}); // 不支持 view 生成 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/query/AggregateType.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.query; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 聚合类型 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-29 下午5:09 10 | **/ 11 | public enum AggregateType implements Serializable { 12 | 13 | /** 14 | * 统计数量 15 | */ 16 | COUNT("count", "统计个数"), 17 | 18 | /** 19 | * 求和 20 | */ 21 | SUM("sum", "求和"), 22 | 23 | ; 24 | 25 | AggregateType(String name, String desc) { 26 | this.name = name; 27 | this.desc = desc; 28 | } 29 | 30 | private String name; 31 | private String desc; 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public String getDesc() { 38 | return desc; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Maven 2 | # Build your Java project and run tests with Apache Maven. 3 | # Add steps that analyze code, save build artifacts, deploy, and more: 4 | # https://docs.microsoft.com/azure/devops/pipelines/languages/java 5 | 6 | trigger: 7 | - master 8 | 9 | steps: 10 | - task: Maven@3 11 | - task: DotNetCoreCLI@2 12 | inputs: 13 | command: 'build' 14 | projects: 'eew' 15 | inputs: 16 | mavenPomFile: 'pom.xml' 17 | mavenOptions: '-Xmx3072m' 18 | javaHomeOption: 'JDKVersion' 19 | jdkVersionOption: '1.8' 20 | jdkArchitectureOption: 'x64' 21 | publishJUnitResults: true 22 | testResultsFiles: '**/surefire-reports/TEST-*.xml' 23 | goals: 'package' 24 | - task: Bash@3 25 | inputs: 26 | targetType: 'inline' 27 | script: | 28 | # Write your commands here 29 | 30 | mvn deploy 31 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/utils/NamingThreadFactory.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.utils; 2 | 3 | import java.util.concurrent.ThreadFactory; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | /** 7 | * 可命名线程工厂 8 | * 9 | * @author jake 10 | */ 11 | public class NamingThreadFactory implements ThreadFactory { 12 | 13 | final ThreadGroup group; 14 | final AtomicInteger threadNumber = new AtomicInteger(1); 15 | final String namePrefix; 16 | 17 | public NamingThreadFactory(ThreadGroup group, String name) { 18 | this.group = group; 19 | namePrefix = group.getName() + ":" + name; 20 | } 21 | 22 | @Override 23 | public Thread newThread(Runnable r) { 24 | return new Thread(group, r, namePrefix 25 | + threadNumber.getAndIncrement(), 0); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/config/LmodelConfig.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.config; 2 | 3 | /** 4 | * Lmodel配置 5 | * 6 | * @author yongfu.cyf 7 | * @create 2017-09-20 下午7:11 8 | **/ 9 | public class LmodelConfig { 10 | 11 | /** 12 | * 是否展示Log 13 | */ 14 | private static boolean showLog = false; 15 | /** 16 | * 设置版本号 17 | */ 18 | private static long version = 0L; 19 | 20 | /** 21 | * 开启查询SQL日志 22 | */ 23 | public static void enableQueryLog() { 24 | showLog = true; 25 | } 26 | 27 | public static boolean isShowLog() { 28 | return showLog; 29 | } 30 | 31 | /** 32 | * 设置查询SQL日志开关 33 | * @param showLog 34 | */ 35 | public static void setShowLog(boolean showLog) { 36 | LmodelConfig.showLog = showLog; 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/dataobject/MetaResponse.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.dataobject; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | import com.concur.meta.client.common.ResultDO; 7 | 8 | /** 9 | * 元数据存取服务返回结果 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-06-28 下午4:25 13 | **/ 14 | public class MetaResponse extends ResultDO implements Serializable { 15 | 16 | private static final long serialVersionUID = -4986672710117496096L; 17 | 18 | /** 19 | * 执行日志 20 | */ 21 | private List executeLog; 22 | 23 | /** 24 | * 获取执行日志 25 | * @return 26 | */ 27 | public List getExecuteLog() { 28 | return executeLog; 29 | } 30 | 31 | public void setExecuteLog(List executeLog) { 32 | this.executeLog = executeLog; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/annotation/LModel.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * LModel数据DO 10 | *
  • 优先走配置,然后走注解
  • 11 | *
  • 需要指定数据源和建表
  • 12 | * @author yongfu.cyf 13 | * @create 2017-06-29 下午8:13 14 | **/ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | public @interface LModel { 18 | 19 | /** 20 | * 指定表名 21 | * @return 22 | */ 23 | String table(); 24 | 25 | /** 26 | * 指定默认数据源类型 27 | * @return 28 | */ 29 | long defaultDateSource() default -1L; 30 | 31 | /** 32 | * 模型描述 33 | * @return 34 | */ 35 | String description() default ""; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/ConverterAdapter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /** 6 | * 转换器适配类(具体的转换器实现此类) 7 | * @author jake 8 | */ 9 | public abstract class ConverterAdapter implements Converter { 10 | 11 | protected ConverterService converterService; 12 | 13 | public ConverterAdapter setConverterService(ConverterService converterService) { 14 | this.converterService = converterService; 15 | return this; 16 | } 17 | 18 | @Override 19 | public T convert(S source, Object... objects) { 20 | return null; 21 | } 22 | 23 | @Override 24 | public T convert(S source, Type targetType, Object... objects) { 25 | return this.convert(source, objects); 26 | } 27 | 28 | protected void postRegister() { 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/query/SortType.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.query; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 排序类型参数 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-29 下午4:26 10 | **/ 11 | public enum SortType implements Serializable { 12 | 13 | ASC("asc", "正序"), 14 | 15 | DESC("desc", "倒序"); 16 | 17 | SortType(String type, String desc) { 18 | this.type = type; 19 | this.desc = desc; 20 | } 21 | 22 | private String type; 23 | private String desc; 24 | 25 | public String getType() { 26 | return type; 27 | } 28 | 29 | public void setType(String type) { 30 | this.type = type; 31 | } 32 | 33 | public String getDesc() { 34 | return desc; 35 | } 36 | 37 | public void setDesc(String desc) { 38 | this.desc = desc; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/execute/ActionContext.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.execute; 2 | 3 | import com.concur.meta.client.dataobject.MetaRequest; 4 | import com.concur.meta.client.dataobject.MetaResponse; 5 | 6 | /** 7 | * 执行上下文 8 | * 9 | * @author yongfu.cyf 10 | * @create 2017-08-23 下午2:46 11 | **/ 12 | public class ActionContext { 13 | 14 | /** 15 | * 查询Action 16 | */ 17 | private QueryAction queryAction; 18 | 19 | /** 20 | * 执行请求 21 | * @param request MetaRequest 22 | */ 23 | public MetaResponse execute(MetaRequest request) { 24 | return this.queryAction.execute(request); 25 | } 26 | 27 | /** 28 | * 设置查询Action 29 | * @param queryAction 30 | */ 31 | public void setQueryAction(QueryAction queryAction) { 32 | this.queryAction = queryAction; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/meta/metabuilder/AnnotationMetaBuilder.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.meta.metabuilder; 2 | 3 | import com.concur.meta.client.dataobject.MetaRequest; 4 | import com.concur.meta.core.dbengine.factory.MetaDatasource; 5 | import com.concur.meta.core.dbengine.mapper.ColumnMapper; 6 | import com.concur.meta.core.dbengine.meta.MetaBuilder; 7 | import com.concur.meta.core.dbengine.meta.TableMeta; 8 | 9 | /** 10 | * 注解方式的元数据构建器 11 | * 12 | * @author yongfu.cyf 13 | * @create 2017-06-29 下午8:17 14 | **/ 15 | public class AnnotationMetaBuilder implements MetaBuilder { 16 | 17 | @Override 18 | public TableMeta build(MetaDatasource metaDatasource, MetaRequest metaRequest) { 19 | return null; 20 | } 21 | 22 | @Override 23 | public ColumnMapper getColumnMapper() { 24 | return null; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/MetaDataReadService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map; 5 | 6 | import com.concur.meta.client.api.query.AbstractQuery; 7 | import com.concur.meta.client.dataobject.ResponseResult; 8 | 9 | /** 10 | * 元数据服务读接口 11 | * 12 | * @author xinjie.qxj 13 | * 14 | */ 15 | public interface MetaDataReadService { 16 | 17 | /** 18 | * 根据主键获取数据 19 | * @param dataSourceId 数据源ID 20 | * @param clazz 数据定义类 21 | * @param id 主键值 22 | * @param 类型泛型 23 | * @return 24 | */ 25 | ResponseResult get(Long dataSourceId, Class clazz, Serializable id); 26 | 27 | /** 28 | * 分页查询 29 | * @param 30 | * @param query 查询参数 31 | * @return 32 | */ 33 | ResponseResult query(AbstractQuery query); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/impl/TairDataServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service.impl; 2 | 3 | import java.io.Serializable; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import com.concur.meta.client.service.TairDataService; 7 | 8 | /** 9 | * Tair数据读写服务实现 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-07-31 下午12:12 13 | **/ 14 | public class TairDataServiceImpl extends BaseMetaDataService implements TairDataService { 15 | 16 | @Override 17 | public T get(Class clazz, Serializable key) { 18 | return null; 19 | } 20 | 21 | @Override 22 | public boolean put(Class clazz, Serializable key, Serializable value, long timeOut, TimeUnit timeUnit) { 23 | return false; 24 | } 25 | 26 | @Override 27 | public boolean delete(Class clazz, Serializable key) { 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/Boolean2IntegerConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import com.concur.meta.client.conversion.ConverterAdapter; 4 | 5 | /** 6 | * Boolean转Integer 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-24 下午4:09 10 | **/ 11 | public class Boolean2IntegerConverter extends ConverterAdapter { 12 | 13 | @Override 14 | public Integer convert(Boolean source, Object... objects) { 15 | if (source == null) { 16 | return Integer.valueOf(0); 17 | } 18 | 19 | if (source) { 20 | return Integer.valueOf(1); 21 | } 22 | return Integer.valueOf(0); 23 | } 24 | 25 | @Override 26 | protected void postRegister() { 27 | converterService.registerConverter(boolean.class, Integer.class, this); 28 | converterService.registerConverter(boolean.class, int.class, this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/Integer2BooleanConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import com.concur.meta.client.conversion.ConverterAdapter; 4 | 5 | /** 6 | * Integer转Boolean 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-24 下午4:09 10 | **/ 11 | public class Integer2BooleanConverter extends ConverterAdapter { 12 | 13 | @Override 14 | public Boolean convert(Integer source, Object... objects) { 15 | if (source == null) { 16 | return Boolean.valueOf(false); 17 | } 18 | 19 | if (source > 0) { 20 | return Boolean.valueOf(true); 21 | } 22 | return Boolean.valueOf(false); 23 | } 24 | 25 | @Override 26 | protected void postRegister() { 27 | converterService.registerConverter(Integer.class, boolean.class, this); 28 | converterService.registerConverter(int.class, boolean.class, this); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/Set2StringConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import java.util.Set; 4 | 5 | import com.concur.meta.client.conversion.ConverterAdapter; 6 | import com.concur.meta.client.utils.ExtraUtil; 7 | 8 | /** 9 | * Set转字符串 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-07-24 下午4:09 13 | **/ 14 | public class Set2StringConverter extends ConverterAdapter { 15 | 16 | private static final String STRING_SPLITER = ","; 17 | 18 | @Override 19 | public String convert(Set source, Object... objects) { 20 | if (source == null || source.size() == 0) { 21 | return null; 22 | } 23 | 24 | StringBuilder result = new StringBuilder(); 25 | for (Object entry : source) { 26 | String value = converterService.convert(entry, String.class); 27 | result.append(ExtraUtil.encode(value)).append(STRING_SPLITER); 28 | } 29 | return result.toString(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/List2StringConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import java.util.List; 4 | 5 | import com.concur.meta.client.conversion.ConverterAdapter; 6 | import com.concur.meta.client.utils.ExtraUtil; 7 | 8 | /** 9 | * List转字符串 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-07-24 下午4:09 13 | **/ 14 | public class List2StringConverter extends ConverterAdapter { 15 | 16 | private static final String STRING_SPLITER = ","; 17 | 18 | @Override 19 | public String convert(List source, Object... objects) { 20 | if (source == null || source.size() == 0) { 21 | return null; 22 | } 23 | 24 | StringBuilder result = new StringBuilder(); 25 | for (Object entry : source) { 26 | String value = converterService.convert(entry, String.class); 27 | result.append(ExtraUtil.encode(value)).append(STRING_SPLITER); 28 | } 29 | return result.toString(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/factory/MetaDataFactory.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.factory; 2 | 3 | 4 | import java.util.List; 5 | 6 | import com.concur.meta.client.dataobject.MetaRequest; 7 | import com.concur.meta.metadata.domain.dto.MetaDataSourceDTO; 8 | import com.concur.meta.metadata.domain.dto.MetaModelDTO; 9 | 10 | /** 11 | * 元数据工厂 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-06-28 上午11:58 15 | **/ 16 | public interface MetaDataFactory { 17 | 18 | /** 19 | * 获取数据源 20 | * @param metaRequest 元数据请求 21 | * @return 22 | */ 23 | MetaDatasource getDataSource(MetaRequest metaRequest); 24 | 25 | /** 26 | * 重新缓存数据源 27 | * @param dataSourceList List 28 | * @param lmodelList List 29 | */ 30 | void reloadDataSource(List dataSourceList, List lmodelList); 31 | 32 | /** 33 | * 预先设置数据源 34 | * @param dataSourceId 35 | */ 36 | void preSetDataSource(Long dataSourceId); 37 | } 38 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/service/impl/DataSourceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.service.impl; 2 | 3 | import com.concur.meta.client.api.query.Query; 4 | import com.concur.meta.client.domain.dto.DataSourceDTO; 5 | import com.concur.meta.client.service.DataSourceService; 6 | import com.concur.meta.metadata.domain.MetaDataSourceDO; 7 | import org.springframework.beans.BeanUtils; 8 | 9 | /** 10 | * 数据源服务实现 11 | * 12 | * @author yongfu.cyf 13 | * @create 2017-07-24 下午8:17 14 | **/ 15 | public class DataSourceServiceImpl implements DataSourceService { 16 | 17 | @Override 18 | public DataSourceDTO getDataSource(long dataSourceId) { 19 | MetaDataSourceDO metaDataSourceDO = Query.create(MetaDataSourceDO.class) 20 | .get(dataSourceId).execute().getOne(); 21 | if (metaDataSourceDO == null) { 22 | return null; 23 | } 24 | DataSourceDTO dto = new DataSourceDTO(); 25 | BeanUtils.copyProperties(metaDataSourceDO, dto); 26 | return dto; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/CachedDataService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service; 2 | 3 | import java.io.Serializable; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | /** 7 | * 含缓存层数据 8 | * 9 | * @author yongfu.cyf 10 | * @create 2017-07-31 下午12:11 11 | **/ 12 | public interface CachedDataService { 13 | 14 | /** 15 | * 获取tair缓存值 16 | * @param clazz Class 17 | * @param key 缓存Key 18 | * @param 19 | * @return 20 | */ 21 | T get(Class clazz, Serializable key); 22 | 23 | /** 24 | * 写入tair缓存 25 | * @param clazz Class 26 | * @param key 缓存Key 27 | * @param value 缓存值 28 | * @param timeOut 失效时长 29 | * @param timeUnit 失效单位 30 | * @return 31 | */ 32 | boolean put(Class clazz, Serializable key, Serializable value, long timeOut, TimeUnit timeUnit); 33 | 34 | /** 35 | * 移除tair缓存值 36 | * @param clazz Class 37 | * @param key 缓存Key 38 | * @return 39 | */ 40 | boolean delete(Class clazz, Serializable key); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/TairDataService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service; 2 | 3 | import java.io.Serializable; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | /** 7 | * Tair数据读写服务接口 8 | * 9 | * @author yongfu.cyf 10 | * @create 2017-07-31 下午12:11 11 | **/ 12 | public interface TairDataService { 13 | 14 | /** 15 | * 获取tair缓存值 16 | * @param clazz Class 17 | * @param key 缓存Key 18 | * @param 19 | * @return 20 | */ 21 | T get(Class clazz, Serializable key); 22 | 23 | /** 24 | * 写入tair缓存 25 | * @param clazz Class 26 | * @param key 缓存Key 27 | * @param value 缓存值 28 | * @param timeOut 失效时长 29 | * @param timeUnit 失效单位 30 | * @return 31 | */ 32 | boolean put(Class clazz, Serializable key, Serializable value, long timeOut, TimeUnit timeUnit); 33 | 34 | /** 35 | * 移除tair缓存值 36 | * @param clazz Class 37 | * @param key 缓存Key 38 | * @return 39 | */ 40 | boolean delete(Class clazz, Serializable key); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/DB.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 数据库操作入口 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-28 下午3:18 10 | **/ 11 | public class DB { 12 | 13 | public static class Query { 14 | public static com.concur.meta.client.api.query.Query create(Class clazz) { 15 | return com.concur.meta.client.api.query.Query.create(clazz); 16 | } 17 | 18 | public static com.concur.meta.client.api.query.Query create(T example) { 19 | return com.concur.meta.client.api.query.Query.create(example); 20 | } 21 | } 22 | 23 | public static class Persist { 24 | public static com.concur.meta.client.api.persist.Persist create() { 25 | return com.concur.meta.client.api.persist.Persist.create(); 26 | } 27 | 28 | public static com.concur.meta.client.api.persist.Persist create(Class clazz) { 29 | return com.concur.meta.client.api.persist.Persist.create(clazz); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/util/ServiceUtil.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.util; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.concur.meta.metadata.service.LMetaService; 6 | 7 | /** 8 | * 服务工厂工具类 9 | *
  • lmodel-core 依赖lmodel-metadata的元数据服务,
  • 10 | *
  • lmodel-metadata可以使用lmodel-core的查询服务,但不需要指定datasourceId
  • 11 | *
  • 问题:互相依赖会不会死循环? 答:不会。就好像递归一样, 只要末尾判断处理好就能得到计算结果
  • 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-07-03 下午4:26 15 | **/ 16 | public class ServiceUtil { 17 | 18 | /** 19 | * LModel配置数据库数据源 20 | */ 21 | static DataSource lmodelConfigDataSource; 22 | /** 23 | * LMetaService 24 | */ 25 | static LMetaService lMetaService; 26 | 27 | static { 28 | lmodelConfigDataSource = (DataSource) ApplicationContextUtils.getContext().getBean("dataSource"); 29 | lMetaService = (LMetaService) ApplicationContextUtils.getContext().getBean("lMetaService"); 30 | } 31 | 32 | public static DataSource getLmodelConfigDataSource() { 33 | return lmodelConfigDataSource; 34 | } 35 | 36 | public static LMetaService getlMetaService() { 37 | return lMetaService; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/constants/DataSourceType.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.constants; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 数据源类型 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-28 下午5:53 10 | **/ 11 | public enum DataSourceType implements Serializable { 12 | 13 | MYSQL("mysql", "mysql数据库"), 14 | 15 | TAIR("tair", "tair缓存"), 16 | 17 | HBASE("hbase", "Hbase数据库"), 18 | 19 | GARUDA("garuda", "Garuda数据库"), 20 | 21 | POSTGRESQL("postgreSQL", "PostgreSQL数据库"), 22 | 23 | NULL("null", "未指定"), 24 | 25 | ; 26 | 27 | 28 | DataSourceType(String name, String desc) { 29 | this.name = name; 30 | this.desc = desc; 31 | } 32 | 33 | private final String name; 34 | private final String desc; 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public String getDesc() { 41 | return desc; 42 | } 43 | 44 | public static DataSourceType getByName(String name) { 45 | for (DataSourceType value : DataSourceType.values()) { 46 | if (value.getName().equals(name)) { 47 | return value; 48 | } 49 | } 50 | return null; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/meta/TableMeta.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.meta; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 表元信息 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-29 上午10:59 10 | **/ 11 | public interface TableMeta { 12 | 13 | /** 14 | * 获取表名 15 | * @return 16 | */ 17 | String getTableName(); 18 | 19 | /** 20 | * 获取主键 21 | * @return 22 | */ 23 | ColumnMeta getPrimaryKey(); 24 | 25 | /** 26 | * 获取主键名 27 | * @return 28 | */ 29 | String getPrimaryKeyName(); 30 | 31 | /** 32 | * 获取字段名列表 33 | * @return 34 | */ 35 | List getColumnNames(); 36 | 37 | /** 38 | * 获取所有的列 39 | * @return 40 | */ 41 | List getAllColums(); 42 | 43 | /** 44 | * 获取字段名 45 | * @param propertyName 属性名 46 | * @return 47 | */ 48 | String getColumnName(String propertyName); 49 | 50 | /** 51 | * 获取属性名 52 | * @param columnName 字段名 53 | * @return 54 | */ 55 | String getPropertyName(String columnName); 56 | 57 | /** 58 | * 校验是否存在属性 59 | * @param propertyName 属性名 60 | * @return 属性名 61 | */ 62 | String checkPropertyName(String propertyName); 63 | } 64 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/ObjectToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 20 | 21 | /** 22 | * Simply calls {@link Object#toString()} to convert a source Object to a String. 23 | * 24 | * @author Keith Donald 25 | * @since 3.0 26 | */ 27 | final class ObjectToStringConverter implements Converter { 28 | 29 | @Override 30 | public String convert(Object source) { 31 | return source.toString(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/types/LongTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.types; 2 | 3 | import java.sql.CallableStatement; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import org.apache.ibatis.type.BaseTypeHandler; 9 | import org.apache.ibatis.type.JdbcType; 10 | 11 | /** 12 | * Long数组转换器 13 | */ 14 | public class LongTypeHandler extends BaseTypeHandler { 15 | 16 | @Override 17 | public Long getNullableResult(ResultSet rs, String columnName) 18 | throws SQLException { 19 | return rs.getLong(columnName); 20 | } 21 | 22 | @Override 23 | public Long getNullableResult(ResultSet rs, int columnIndex) 24 | throws SQLException { 25 | return rs.getLong(columnIndex); 26 | } 27 | 28 | @Override 29 | public Long getNullableResult(CallableStatement cs, int columnIndex) 30 | throws SQLException { 31 | return cs.getLong(columnIndex); 32 | } 33 | 34 | @Override 35 | public void setNonNullParameter(PreparedStatement ps, int i, 36 | Long parameter, JdbcType jdbcType) throws SQLException { 37 | ps.setLong(i, parameter); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/StringToLocaleConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import java.util.Locale; 20 | 21 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 22 | import com.concur.meta.client.utils.StringUtils; 23 | 24 | /** 25 | * Converts a String to a Locale. 26 | * 27 | * @author Keith Donald 28 | * @since 3.0 29 | */ 30 | final class StringToLocaleConverter implements Converter { 31 | 32 | @Override 33 | public Locale convert(String source) { 34 | return StringUtils.parseLocaleString(source); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/mapper/ColumnMapper.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.mapper; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | /** 8 | * 属性-字段映射 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-07-07 下午2:40 12 | **/ 13 | public interface ColumnMapper { 14 | 15 | 16 | /** 17 | * 获取字段名 18 | * @param propertyName 属性名 19 | * @return 20 | */ 21 | String getColumnName(String propertyName); 22 | 23 | /** 24 | * 获取属性名 25 | * @param columnName 字段名 26 | * @return 27 | */ 28 | String getPropertyName(String columnName); 29 | 30 | /** 31 | * DO映射转换成表字段 32 | * @param model 33 | * @return 34 | */ 35 | Map mapModel(Map model); 36 | 37 | /** 38 | * 结果集行转换DO属性 39 | * @param models 40 | * @return 41 | */ 42 | List> mapModels(List> models); 43 | 44 | /** 45 | * 单行结果转换DO 46 | * @param row 47 | * @return 48 | */ 49 | Map mapRow(Map row); 50 | 51 | /** 52 | * 结果集列表转换DO 53 | * @param rows 54 | * @return 55 | */ 56 | List> mapRows(List> rows); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /model-core/src/main/resources/lmodel.datasource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/CheckFailException.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.exception; 2 | 3 | import com.concur.meta.client.common.IResultCode; 4 | 5 | /** 6 | * 校验失败异常 7 | * 需要对校验异常特殊处理时捕获此异常 8 | * @author yongfu.cyf 9 | * @create 2017-09-30 上午10:32 10 | **/ 11 | public class CheckFailException extends TransactionFailException { 12 | 13 | private static final long serialVersionUID = 760052370518979632L; 14 | 15 | public CheckFailException() { 16 | super(); 17 | } 18 | 19 | public CheckFailException(String message) { 20 | super(message); 21 | } 22 | 23 | public CheckFailException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | public CheckFailException(Throwable cause) { 28 | super(cause); 29 | } 30 | 31 | public CheckFailException(IResultCode iResultCode) { 32 | super(iResultCode.getCode() + ":" + iResultCode.getMessage()); 33 | } 34 | 35 | public CheckFailException(IResultCode iResultCode, Throwable cause) { 36 | super(iResultCode.getCode() + ":" + iResultCode.getMessage(), cause); 37 | } 38 | 39 | public CheckFailException(IResultCode iResultCode, String detail, Throwable cause) { 40 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + detail, cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/transaction/TransactionStatus.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.transaction; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 事务状态 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-07-11 下午9:30 10 | **/ 11 | public enum TransactionStatus implements Serializable { 12 | 13 | /** 14 | * 未使用事务,默认使用此值 15 | */ 16 | UNUSE("unuse", "未使用", 0), 17 | 18 | /** 19 | * 调用Transaction.start()方法之后置为此状态 20 | */ 21 | START("start", "开启了事务", 1), 22 | 23 | /** 24 | * 调用了提交(不代表成功) 25 | */ 26 | COMMIT("commit", "提交了事务", 2), 27 | 28 | /** 29 | * 事务提交成功了 30 | */ 31 | SUCCESS("success", "执行成功", 3), 32 | 33 | /** 34 | * 事务提交失败了 35 | */ 36 | FAIL("fail", "执行失败,未回滚", 4), 37 | 38 | /** 39 | * 事务回滚成功了 40 | */ 41 | ROLLBACK("rollback", "回滚了事务", 5); 42 | 43 | TransactionStatus(String name, String desc, int order) { 44 | this.name = name; 45 | this.desc = desc; 46 | this.order = order; 47 | } 48 | 49 | private String name; 50 | private String desc; 51 | private int order; 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public String getDesc() { 58 | return desc; 59 | } 60 | 61 | public int getOrder() { 62 | return order; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/HSF.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.concur.meta.client.api.query.HSFQuery; 6 | 7 | /** 8 | * 远程接口操作入口 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-09-25 下午10:48 12 | **/ 13 | public class HSF { 14 | 15 | public static class Query { 16 | public static HSFQuery create(Class clazz) { 17 | return HSFQuery.create(clazz); 18 | } 19 | } 20 | 21 | public static Dependency addDependency(String groupId) { 22 | Dependency dependency = new Dependency(groupId); 23 | return dependency; 24 | } 25 | 26 | /** 27 | * 依赖二方库 28 | */ 29 | public static class Dependency { 30 | private String groupId; 31 | private String artifactId; 32 | private String version; 33 | 34 | public Dependency(String groupId) { 35 | this.groupId = groupId; 36 | } 37 | public Dependency artifactId(String artifactId) { 38 | this.artifactId = artifactId; 39 | return this; 40 | } 41 | public Dependency version(String version) { 42 | this.version = version; 43 | return this; 44 | } 45 | 46 | /** 47 | * 导入依赖 48 | */ 49 | public void imports() { 50 | 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/converter/ConditionalGenericConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.converter; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.TypeDescriptor; 20 | 21 | /** 22 | * A {@link GenericConverter} that may conditionally execute based on attributes 23 | * of the {@code source} and {@code target} {@link TypeDescriptor}. 24 | * See {@link ConditionalConverter} for details. 25 | * 26 | * @author Keith Donald 27 | * @author Phillip Webb 28 | * @since 3.0 29 | * @see GenericConverter 30 | * @see ConditionalConverter 31 | */ 32 | public interface ConditionalGenericConverter extends GenericConverter, ConditionalConverter { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/ConverterService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | /** 8 | * 转换服务接口 9 | * @author jake 10 | * 11 | */ 12 | public interface ConverterService { 13 | 14 | 15 | /** 16 | * 将指定的对象转换为指定的类对象 17 | * @param 18 | * @param source 需要转换的对象 19 | * @param targetType 目标类 20 | * @return 21 | */ 22 | T convert(Object source, Class targetType, Object... objects); 23 | 24 | /** 25 | * 将指定的对象转换为指定的类对象 26 | * @param 27 | * @param source 需要转换的对象 28 | * @param targetType 目标类 29 | * @return 30 | */ 31 | T convert(Object source, Type targetType, Object... objects); 32 | 33 | 34 | /** 35 | * 将指定的对象转换为指定的类对象 36 | * @param 37 | * @param sourceCollection 需要转换的集合 38 | * @param targetType 目标类 39 | * @return 40 | */ 41 | List convertCollection(Collection sourceCollection, Class targetType, Object... objects); 42 | 43 | 44 | /** 45 | * 注册转换器 46 | * @param converter 转换器 47 | */ 48 | void registerConverter(Converter converter); 49 | 50 | /** 51 | * 注册转换器 52 | * @param sourceType 原类型 53 | * @param targetType 目标类型 54 | * @param converter 转换器 55 | */ 56 | void registerConverter(Class sourceType, Class targetType, Converter converter); 57 | } -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/service/LMetaService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.service; 2 | 3 | import java.util.List; 4 | 5 | import com.concur.meta.metadata.domain.MetaModelColDO; 6 | import com.concur.meta.metadata.domain.MetaModelDO; 7 | 8 | /** 9 | * LModel元数据模型服务接口 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-07-03 下午7:39 13 | **/ 14 | public interface LMetaService { 15 | 16 | /** 17 | * 获取LModelDO列表 18 | * @return 19 | */ 20 | List list(); 21 | 22 | /** 23 | * 根据类名获取元数据模型 24 | * @param className 25 | * @return 26 | */ 27 | MetaModelDO getByClassName(String className); 28 | 29 | /** 30 | * 根据类名获取元数据字段列表 31 | * @param className 32 | * @return 33 | */ 34 | List listColByClass(String className); 35 | 36 | /** 37 | * 添加LModelDO 38 | * @param lModelDO MetaModelDO 39 | * @return 40 | */ 41 | MetaModelDO add(MetaModelDO lModelDO); 42 | 43 | /** 44 | * 根据ID获取LModelDO 45 | * @param id 46 | * @return 47 | */ 48 | MetaModelDO get(Long id); 49 | 50 | /** 51 | * 更新LModelDO 52 | * @param lModelDO MetaModelDO 53 | * @return 54 | */ 55 | void update(MetaModelDO lModelDO); 56 | 57 | /** 58 | * 删除LModelDO 59 | * @param lModelDO MetaModelDO 60 | * @return 61 | */ 62 | void delete(MetaModelDO lModelDO); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/ComparableComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring; 18 | 19 | import java.util.Comparator; 20 | 21 | /** 22 | * Comparator that adapts Comparables to the Comparator interface. 23 | * Mainly for internal use in other Comparators, when supposed 24 | * to work on Comparables. 25 | * 26 | * @author Keith Donald 27 | * @since 1.2.2 28 | * @see Comparable 29 | */ 30 | public class ComparableComparator> implements Comparator { 31 | 32 | @SuppressWarnings("rawtypes") 33 | public static final ComparableComparator INSTANCE = new ComparableComparator(); 34 | 35 | @Override 36 | public int compare(T o1, T o2) { 37 | return o1.compareTo(o2); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/StringToUUIDConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import java.util.UUID; 20 | 21 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 22 | import com.concur.meta.client.utils.StringUtils; 23 | 24 | /** 25 | * Converts from a String to a java.util.UUID by calling {@link UUID#fromString(String)}. 26 | * 27 | * @author Phillip Webb 28 | * @since 3.2 29 | */ 30 | final class StringToUUIDConverter implements Converter { 31 | 32 | @Override 33 | public UUID convert(String source) { 34 | if(StringUtils.hasLength(source)) { 35 | return UUID.fromString(source.trim()); 36 | } 37 | return null; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/server/MetaDataWriteServerService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service.server; 2 | 3 | import com.concur.meta.client.dataobject.MetaResponse; 4 | import com.concur.meta.client.dataobject.MetaRequest; 5 | 6 | /** 7 | * 元数据服务端写接口 8 | * 9 | * @author yongfu.cyf 10 | * @create 2017-06-28 下午4:07 11 | **/ 12 | public interface MetaDataWriteServerService { 13 | 14 | /** 15 | * 更新数据 16 | * @param request 更新参数 17 | * @return 18 | */ 19 | MetaResponse update(MetaRequest request); 20 | 21 | /** 22 | * 部分字段更新 23 | * @param request 更新参数 24 | * @return 25 | */ 26 | MetaResponse updateSelective(MetaRequest request); 27 | 28 | /** 29 | * 添加数据 30 | * @param request 保存参数 31 | * @return 32 | */ 33 | MetaResponse insert(MetaRequest request); 34 | 35 | /** 36 | * 删除实体 37 | * @param request 删除参数 38 | * @return 39 | */ 40 | MetaResponse delete(MetaRequest request); 41 | 42 | /** 43 | * 批量添加 44 | * @param request 45 | * @return 46 | */ 47 | MetaResponse batchInsert(MetaRequest request); 48 | 49 | /** 50 | * 批量删除 51 | * @param request 52 | * @return 53 | */ 54 | MetaResponse batchDelete(MetaRequest request); 55 | 56 | /** 57 | * 执行所有操作 58 | * @param request 59 | * @return 60 | */ 61 | MetaResponse executeAll(MetaRequest request); 62 | } 63 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/NumberToCharacterConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 20 | 21 | /** 22 | * Converts from any JDK-standard Number implementation to a Character. 23 | * 24 | * @author Keith Donald 25 | * @since 3.0 26 | * @see Character 27 | * @see Short 28 | * @see Integer 29 | * @see Long 30 | * @see java.math.BigInteger 31 | * @see Float 32 | * @see Double 33 | * @see java.math.BigDecimal 34 | */ 35 | final class NumberToCharacterConverter implements Converter { 36 | 37 | @Override 38 | public Character convert(Number source) { 39 | return (char) source.shortValue(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/TransactionFailException.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.exception; 2 | 3 | import com.concur.meta.client.common.IResultCode; 4 | 5 | /** 6 | * 事务执行失败异常 7 | * 任何LModel内部运行时异常(包括ConsistencyException)都会转化成TransactionFailException 8 | * 一般都会有脏数据,需要显示catch并rollback 9 | * @author yongfu.cyf 10 | * @create 2017-07-28 上午11:52 11 | **/ 12 | public class TransactionFailException extends LModelException { 13 | 14 | private static final long serialVersionUID = 1658681069169052938L; 15 | 16 | public TransactionFailException() { 17 | super(); 18 | } 19 | 20 | public TransactionFailException(String message) { 21 | super(message); 22 | } 23 | 24 | public TransactionFailException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public TransactionFailException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | public TransactionFailException(IResultCode iResultCode) { 33 | super(iResultCode.getCode() + ":" + iResultCode.getMessage()); 34 | } 35 | 36 | public TransactionFailException(IResultCode iResultCode, Throwable cause) { 37 | super(iResultCode.getCode() + ":" + iResultCode.getMessage(), cause); 38 | } 39 | 40 | public TransactionFailException(IResultCode iResultCode, String detail, Throwable cause) { 41 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + detail, cause); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/StringToCharacterConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 20 | 21 | /** 22 | * Converts a String to a Character. 23 | * 24 | * @author Keith Donald 25 | * @since 3.0 26 | */ 27 | final class StringToCharacterConverter implements Converter { 28 | 29 | @Override 30 | public Character convert(String source) { 31 | if (source.length() == 0) { 32 | return null; 33 | } 34 | if (source.length() > 1) { 35 | throw new IllegalArgumentException( 36 | "Can only convert a [String] with length of 1 to a [Character]; string value '" + source + "' has length of " + source.length()); 37 | } 38 | return source.charAt(0); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/MetaDataException.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.exception; 2 | 3 | import com.concur.meta.client.common.IResultCode; 4 | 5 | /** 6 | * 元数据操作异常 7 | * 需要对元数据异常特殊处理时捕获此异常 8 | * @author yongfu.cyf 9 | * @create 2017-06-29 上午10:02 10 | **/ 11 | public class MetaDataException extends TransactionFailException { 12 | 13 | private static final long serialVersionUID = -323201361656657429L; 14 | 15 | public MetaDataException() { 16 | super(); 17 | } 18 | 19 | public MetaDataException(String message) { 20 | super(message); 21 | } 22 | 23 | public MetaDataException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | public MetaDataException(Throwable cause) { 28 | super(cause); 29 | } 30 | 31 | public MetaDataException(IResultCode iResultCode) { 32 | super(iResultCode.getCode() + ":" + iResultCode.getMessage()); 33 | } 34 | 35 | public MetaDataException(IResultCode iResultCode, String message) { 36 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + message); 37 | } 38 | 39 | public MetaDataException(IResultCode iResultCode, Throwable cause) { 40 | super(iResultCode.getCode() + ":" + iResultCode.getMessage(), cause); 41 | } 42 | 43 | public MetaDataException(IResultCode iResultCode, String detail, Throwable cause) { 44 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + detail, cause); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/meta/metabuilder/ConfigurableMetaBuilder.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.meta.metabuilder; 2 | 3 | import com.concur.meta.client.dataobject.MetaRequest; 4 | import com.concur.meta.client.exception.MetaDataException; 5 | import com.concur.meta.client.result.ServerResultCode; 6 | import com.concur.meta.core.dbengine.factory.MetaDatasource; 7 | import com.concur.meta.core.dbengine.mapper.ColumnMapper; 8 | import com.concur.meta.core.manager.TableMetaManager; 9 | import com.concur.meta.core.dbengine.meta.MetaBuilder; 10 | import com.concur.meta.core.dbengine.meta.TableMeta; 11 | import org.apache.commons.lang.StringUtils; 12 | 13 | /** 14 | * 从配置build元数据信息 15 | * 16 | * @author yongfu.cyf 17 | * @create 2017-06-29 上午10:46 18 | **/ 19 | public class ConfigurableMetaBuilder implements MetaBuilder { 20 | 21 | private TableMetaManager tableMetaManager; 22 | 23 | public ConfigurableMetaBuilder(TableMetaManager tableMetaManager) { 24 | this.tableMetaManager = tableMetaManager; 25 | } 26 | 27 | @Override 28 | public TableMeta build(MetaDatasource metaDatasource, MetaRequest metaRequest) { 29 | String className = metaRequest.getClassName(); 30 | if (StringUtils.isBlank(className)) { 31 | throw new MetaDataException(ServerResultCode.MATA_CLASS_NAME_IS_BLANK); 32 | } 33 | 34 | 35 | 36 | 37 | return null; 38 | } 39 | 40 | @Override 41 | public ColumnMapper getColumnMapper() { 42 | return null; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/result/ClientResultCode.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.result; 2 | 3 | import com.concur.meta.client.common.IResultCode; 4 | 5 | /** 6 | * client端错误码 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-29 下午3:22 10 | **/ 11 | public enum ClientResultCode implements IResultCode { 12 | 13 | DATA_CONVERT_EXCEPTION("client_data_convert_exception", "数据转换异常"), 14 | 15 | CLASS_CANOT_BE_NULL("client_entity class is null", "实体类不能为空"), 16 | 17 | DATA_SOUCE_GET_ERROR("client_data_source_get_exception", "数据源获取异常"), 18 | 19 | DATA_SOURCE_NOT_EXISTS("client_data_source_not_exists", "数据源不存在"), 20 | 21 | DATA_CONSISTENCY_EXCEPTION("client_data_consistency_exception", "数据不一致异常"), 22 | 23 | TRANSACTION_FAIL_EXCEPTION("client_transaction_fail_exception", "事务执行失败异常"), 24 | 25 | ENTITY_CLASS_MUST_IMPLEMENTS_SERIALIZABLE("client_entity_class_must_implements_serializable", 26 | "实体类型必须实现Serializable接口"), 27 | 28 | TRANSACTION_NOT_COMMIT_YET("transaction_not_commit_yet", "事务未提交不可回滚"), 29 | 30 | RESPONSE_RESOLVE_ERROR("write_response_resolve_error", "执行结果解析异常,数据可能已经写入"), 31 | ; 32 | 33 | ClientResultCode(String code, String msg) { 34 | this.code = code; 35 | this.msg = msg; 36 | } 37 | 38 | private String code; 39 | private String msg; 40 | 41 | @Override 42 | public String getCode() { 43 | return this.code; 44 | } 45 | 46 | @Override 47 | public String getMessage() { 48 | return this.msg; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/domain/MetaBaseDO.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.domain; 2 | 3 | import java.util.Date; 4 | 5 | import com.concur.meta.client.domain.BaseModel; 6 | import com.concur.meta.client.domain.ToString; 7 | 8 | /** 9 | * 元数据定义基类DO 10 | * 11 | * @author yongfu.cyf 12 | * @create 2017-10-31 上午11:37 13 | **/ 14 | public class MetaBaseDO extends ToString implements BaseModel { 15 | 16 | /** 17 | * 创建人(TODO) 18 | */ 19 | private String creator; 20 | 21 | /** 22 | * 最后一次修改人(TODO) 23 | */ 24 | private String lastModifier; 25 | 26 | /** 27 | * 创建时间 28 | */ 29 | private Date gmtCreate; 30 | 31 | /** 32 | * 最后修改时间 33 | */ 34 | private Date gmtModified; 35 | 36 | public String getCreator() { 37 | return creator; 38 | } 39 | 40 | public void setCreator(String creator) { 41 | this.creator = creator; 42 | } 43 | 44 | public String getLastModifier() { 45 | return lastModifier; 46 | } 47 | 48 | public void setLastModifier(String lastModifier) { 49 | this.lastModifier = lastModifier; 50 | } 51 | 52 | public Date getGmtCreate() { 53 | return gmtCreate; 54 | } 55 | 56 | public void setGmtCreate(Date gmtCreate) { 57 | this.gmtCreate = gmtCreate; 58 | } 59 | 60 | public Date getGmtModified() { 61 | return gmtModified; 62 | } 63 | 64 | public void setGmtModified(Date gmtModified) { 65 | this.gmtModified = gmtModified; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/extension/postgre/PostgreSqlDatasourceImpl.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.extension.postgre; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.concur.meta.client.constants.DataSourceType; 6 | import com.concur.meta.client.dataobject.MetaRequest; 7 | import com.concur.meta.core.dbengine.factory.impl.BaseMetaDatasource; 8 | import com.concur.meta.core.dbengine.sql.sqlbuilder.BaseBuilder; 9 | import com.concur.meta.core.dbengine.meta.MetaBuilder; 10 | import com.concur.meta.core.dbengine.meta.metabuilder.ConfigurableMetaBuilder; 11 | import com.concur.meta.core.dbengine.sql.sqlbuilder.SqlBuilder; 12 | 13 | /** 14 | * PostgreSQL数据源 15 | * 16 | * @author yongfu.cyf 17 | * @create 2017-07-03 下午3:38 18 | **/ 19 | public class PostgreSqlDatasourceImpl extends BaseMetaDatasource { 20 | 21 | public PostgreSqlDatasourceImpl(DataSource dataSource, String dataSourceKey) { 22 | super(dataSource, dataSourceKey); 23 | } 24 | 25 | @Override 26 | public DataSourceType getDataSourceType() { 27 | return DataSourceType.POSTGRESQL; 28 | } 29 | 30 | 31 | @Override 32 | public SqlBuilder getSqlBuilder() { 33 | return new BaseBuilder(new PostgreSqlDialect()); 34 | } 35 | 36 | @Override 37 | public MetaBuilder getMetaBuilder(MetaRequest metaRequest) { 38 | if (isAutoMetaBuilder(metaRequest)) { 39 | return new PostgresSqlAutoMetaBuilder(); 40 | } else { 41 | return new ConfigurableMetaBuilder(this.tableMetaManager); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/ConsistencyException.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.exception; 2 | 3 | import com.concur.meta.client.common.IResultCode; 4 | 5 | /** 6 | * 数据幂等性异常 7 | * 需要对幂等异常特殊处理时捕获此异常 8 | * @author yongfu.cyf 9 | * @create 2017-07-28 上午11:55 10 | **/ 11 | public class ConsistencyException extends TransactionFailException { 12 | 13 | private static final long serialVersionUID = -1932571583221069108L; 14 | 15 | public ConsistencyException() { 16 | super(); 17 | } 18 | 19 | public ConsistencyException(String message) { 20 | super(message); 21 | } 22 | 23 | public ConsistencyException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | public ConsistencyException(Throwable cause) { 28 | super(cause); 29 | } 30 | 31 | public ConsistencyException(IResultCode iResultCode) { 32 | super(iResultCode.getCode() + ":" + iResultCode.getMessage()); 33 | } 34 | 35 | public ConsistencyException(IResultCode iResultCode, String detail) { 36 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + detail); 37 | } 38 | 39 | public ConsistencyException(IResultCode iResultCode, Throwable cause) { 40 | super(iResultCode.getCode() + ":" + iResultCode.getMessage(), cause); 41 | } 42 | 43 | public ConsistencyException(IResultCode iResultCode, String detail, Throwable cause) { 44 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + detail, cause); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/query/HSFQuery.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.query; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map; 5 | 6 | /** 7 | * 远程接口查询 8 | * 9 | * @author yongfu.cyf 10 | * @create 2017-09-25 下午10:51 11 | **/ 12 | public class HSFQuery implements Serializable { 13 | 14 | private static final long serialVersionUID = -8824286705328452490L; 15 | 16 | /** 17 | * 查询的类 18 | */ 19 | protected Class clazz; 20 | 21 | /** 22 | * 服务名称 23 | */ 24 | protected String serviceName; 25 | 26 | /** 27 | * 服务接口 28 | */ 29 | protected String serviceMethod; 30 | 31 | /** 32 | * 参数 33 | */ 34 | private Map params; 35 | 36 | /** 37 | * 根据类型创建 38 | * @param clazz Class 39 | * @param 40 | * @return 41 | */ 42 | public static HSFQuery create(Class clazz) { 43 | HSFQuery query = new HSFQuery(); 44 | query.clazz = clazz; 45 | return query; 46 | } 47 | 48 | /** 49 | * 设置参数 50 | * @param params 51 | * @return 52 | */ 53 | public HSFQuery params(Map params) { 54 | this.params = params; 55 | return this; 56 | } 57 | 58 | /** 59 | * 设置参数 60 | * @param param 61 | * @return 62 | */ 63 | public

    HSFQuery params(P param) { 64 | this.params = params; 65 | return this; 66 | } 67 | 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/domain/MetaDataSourceDO.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.domain; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.concur.meta.client.annotation.LModel; 7 | import com.concur.meta.client.constants.DataSourceType; 8 | 9 | /** 10 | * 数据源DO 11 | * 12 | * @author yongfu.cyf 13 | * @create 2017-06-28 下午5:44 14 | **/ 15 | @LModel(table = "lmodel_datasource") 16 | public class MetaDataSourceDO extends MetaBaseDO { 17 | 18 | /** 19 | * 数据源ID(Client指定的值) 20 | */ 21 | private long id; 22 | 23 | /** 24 | * 数据源名称 25 | */ 26 | private String name; 27 | 28 | /** 29 | * 数据源类型 30 | * @see DataSourceType 31 | */ 32 | private String type; 33 | 34 | /** 35 | * 额外属性 36 | */ 37 | private Map attributes = new HashMap(); 38 | 39 | public long getId() { 40 | return id; 41 | } 42 | 43 | public void setId(long id) { 44 | this.id = id; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | public String getType() { 56 | return type; 57 | } 58 | 59 | public void setType(String type) { 60 | this.type = type; 61 | } 62 | 63 | public Map getAttributes() { 64 | return attributes; 65 | } 66 | 67 | public void setAttributes(Map attributes) { 68 | this.attributes = attributes; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/logger/ExecuteLogger.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.logger; 2 | 3 | import java.util.List; 4 | 5 | import com.concur.meta.client.dataobject.MetaResponse; 6 | import com.concur.meta.client.exception.LModelException; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | /** 11 | * 执行细节Log输出 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-09-22 下午4:41 15 | **/ 16 | public class ExecuteLogger { 17 | 18 | 19 | protected static final Logger SQL_LOGGER = LoggerFactory.getLogger("LMODEL_SQL_LOG"); 20 | 21 | /** 22 | * 输出日志 23 | * @param response 24 | */ 25 | public static void doLogger(MetaResponse response) { 26 | if (response == null) { 27 | return; 28 | } 29 | List loggers = response.getExecuteLog(); 30 | if (loggers != null && SQL_LOGGER.isErrorEnabled()) { 31 | for (String logger : loggers) { 32 | SQL_LOGGER.info(logger); 33 | } 34 | } 35 | } 36 | 37 | /** 38 | * 输出日志 39 | * @param e 40 | */ 41 | public static void doLogger(RuntimeException e) { 42 | if (e == null) { 43 | return; 44 | } 45 | if (!(e instanceof LModelException)) { 46 | return; 47 | } 48 | List loggers = ((LModelException)e).getExecuteLog(); 49 | if (loggers != null && SQL_LOGGER.isErrorEnabled()) { 50 | for (String logger : loggers) { 51 | SQL_LOGGER.info(logger); 52 | } 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/extension/mysql/MysqlDatasourceImpl.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.extension.mysql; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.concur.meta.client.constants.DataSourceType; 6 | import com.concur.meta.client.dataobject.MetaRequest; 7 | import com.concur.meta.core.dbengine.factory.impl.BaseMetaDatasource; 8 | import com.concur.meta.core.dbengine.meta.metabuilder.ConfigurableMetaBuilder; 9 | import com.concur.meta.core.dbengine.meta.metabuilder.DefaultAutoMetaBuilder; 10 | import com.concur.meta.core.dbengine.sql.sqlbuilder.BaseBuilder; 11 | import com.concur.meta.core.dbengine.sql.sqlbuilder.SqlBuilder; 12 | import com.concur.meta.core.dbengine.meta.MetaBuilder; 13 | 14 | /** 15 | * Mysql数据源 16 | * 17 | * @author yongfu.cyf 18 | * @create 2017-07-03 下午3:38 19 | **/ 20 | public class MysqlDatasourceImpl extends BaseMetaDatasource { 21 | 22 | public MysqlDatasourceImpl(DataSource dataSource, String dataSourceKey) { 23 | super(dataSource, dataSourceKey); 24 | } 25 | 26 | @Override 27 | public MetaBuilder getMetaBuilder(MetaRequest metaRequest) { 28 | if (isAutoMetaBuilder(metaRequest)) { 29 | return new DefaultAutoMetaBuilder(); 30 | } else { 31 | return new ConfigurableMetaBuilder(this.tableMetaManager); 32 | } 33 | } 34 | 35 | @Override 36 | public DataSourceType getDataSourceType() { 37 | return DataSourceType.MYSQL; 38 | } 39 | 40 | @Override 41 | public SqlBuilder getSqlBuilder() { 42 | return new BaseBuilder(new MysqlDialect()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/ConversionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring; 18 | 19 | import com.concur.meta.client.exception.base.NestedRuntimeException; 20 | 21 | /** 22 | * Base class for exceptions thrown by the conversion system. 23 | * 24 | * @author Keith Donald 25 | * @since 3.0 26 | */ 27 | @SuppressWarnings("serial") 28 | public abstract class ConversionException extends NestedRuntimeException { 29 | 30 | /** 31 | * Construct a new conversion exception. 32 | * @param message the exception message 33 | */ 34 | public ConversionException(String message) { 35 | super(message); 36 | } 37 | 38 | /** 39 | * Construct a new conversion exception. 40 | * @param message the exception message 41 | * @param cause the cause 42 | */ 43 | public ConversionException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/String2SetConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import com.concur.meta.client.conversion.ConverterAdapter; 9 | import com.concur.meta.client.utils.ExtraUtil; 10 | import com.concur.meta.client.utils.TypeUtils; 11 | import org.apache.commons.lang.StringUtils; 12 | 13 | /** 14 | * ${DESCRIPTION} 15 | * 16 | * @author yongfu.cyf 17 | * @create 2017-07-24 下午4:06 18 | **/ 19 | public class String2SetConverter extends ConverterAdapter { 20 | 21 | private static final String STRING_SPLITER = ","; 22 | 23 | @Override 24 | public Set convert(String source, Type targetType, Object... objects) { 25 | if (StringUtils.isBlank(source)) { 26 | return new HashSet(); 27 | } 28 | String[] array = source.split(STRING_SPLITER); 29 | Set result = new HashSet(); 30 | for (String elem : array) { 31 | if (StringUtils.isNotBlank(elem)) { 32 | elem = ExtraUtil.decode(elem); 33 | if (targetType instanceof ParameterizedType) { 34 | Object value = converterService.convert(elem, 35 | TypeUtils.getParameterizedType((ParameterizedType) targetType, 0)); 36 | result.add(value); 37 | } else { 38 | result.add(elem); 39 | } 40 | } 41 | } 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/String2ListConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import com.concur.meta.client.conversion.ConverterAdapter; 9 | import com.concur.meta.client.utils.ExtraUtil; 10 | import com.concur.meta.client.utils.TypeUtils; 11 | import org.apache.commons.lang.StringUtils; 12 | 13 | /** 14 | * 字符串转List 15 | * 16 | * @author yongfu.cyf 17 | * @create 2017-07-24 下午12:00 18 | **/ 19 | public class String2ListConverter extends ConverterAdapter { 20 | 21 | private static final String STRING_SPLITER = ","; 22 | 23 | @Override 24 | public List convert(String source, Type targetType, Object... objects) { 25 | if (StringUtils.isBlank(source)) { 26 | return new ArrayList(); 27 | } 28 | String[] array = source.split(STRING_SPLITER); 29 | List result = new ArrayList(); 30 | for (String elem : array) { 31 | if (StringUtils.isNotBlank(elem)) { 32 | elem = ExtraUtil.decode(elem); 33 | if (targetType instanceof ParameterizedType) { 34 | Object value = converterService.convert(elem, 35 | TypeUtils.getParameterizedType((ParameterizedType) targetType, 0)); 36 | result.add(value); 37 | } else { 38 | result.add(elem); 39 | } 40 | } 41 | } 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/factory/MetaDatasource.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.factory; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.concur.meta.client.constants.DataSourceType; 6 | import com.concur.meta.client.dataobject.MetaRequest; 7 | import com.concur.meta.core.dbengine.mapper.ColumnMapper; 8 | import com.concur.meta.core.dbengine.meta.MetaBuilder; 9 | import com.concur.meta.core.dbengine.param.ParameterBuilder; 10 | import com.concur.meta.core.dbengine.sql.sqlbuilder.SqlBuilder; 11 | 12 | /** 13 | * 元数据引擎 数据源接口 14 | * 15 | * @author yongfu.cyf 16 | * @create 2017-06-28 上午11:56 17 | **/ 18 | public interface MetaDatasource { 19 | 20 | /** 默认数据源类型 */ 21 | DataSourceType DEFAULT_DATASOURCE_TYPE = DataSourceType.MYSQL; 22 | 23 | /** 24 | * 获取数据源类型 25 | * @return 26 | */ 27 | DataSourceType getDataSourceType(); 28 | 29 | /** 30 | * 获取DB数据源 31 | * @return DataSource 32 | */ 33 | DataSource getDataSource(); 34 | 35 | /** 36 | * 获取数据源Key 37 | * @return 38 | */ 39 | String getDataSourceKey(); 40 | 41 | /** 42 | * 获取表信息构建器 43 | * @param metaRequest MetaRequest 44 | * @return 45 | */ 46 | MetaBuilder getMetaBuilderWithCache(MetaRequest metaRequest); 47 | 48 | /** 49 | * 获取SQL构建器 50 | * @return 51 | */ 52 | SqlBuilder getSqlBuilder(); 53 | 54 | /** 55 | * 获取参数构建器 56 | * @return 57 | */ 58 | ParameterBuilder getParameterBuilder(); 59 | 60 | /** 61 | * 获取字段映射器 62 | * @return 63 | */ 64 | ColumnMapper getColumnMapper(); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/converter/Converter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.converter; 18 | 19 | /** 20 | * A converter converts a source object of type S to a target of type T. 21 | * Implementations of this interface are thread-safe and can be shared. 22 | * 23 | *

    Implementations may additionally implement {@link ConditionalConverter}. 24 | * 25 | * @author Keith Donald 26 | * @since 3.0 27 | * @see ConditionalConverter 28 | * @param The source type 29 | * @param The target type 30 | */ 31 | public interface Converter { 32 | 33 | /** 34 | * Convert the source of type S to target type T. 35 | * @param source the source object to convert, which must be an instance of S 36 | * @return the converted object, which must be an instance of T 37 | * @throws IllegalArgumentException if the source could not be converted to the desired target type 38 | */ 39 | T convert(S source); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/constants/ParamKeys.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.constants; 2 | 3 | /** 4 | * 参数传递KEY 5 | * 6 | * @author yongfu.cyf 7 | * @create 2017-06-28 下午4:15 8 | **/ 9 | public interface ParamKeys { 10 | 11 | /** 12 | * DO的类名 13 | */ 14 | String DO_CLASS_NAME = "DO_CLASS_NAME"; 15 | 16 | /** 17 | * DO的值 18 | */ 19 | String DO_PROPERTIES = "DO_PROPERTIES"; 20 | 21 | /** 22 | * DO的主键 23 | */ 24 | String DO_PRIMARY_KEY = "DO_PRIMARY_KEY"; 25 | 26 | /** 27 | * 查询参数 28 | */ 29 | String QUERY_PARAM = "QUERY_PARAM"; 30 | 31 | /** 32 | * 分页查询参数 33 | */ 34 | String PAGE_QUERY_PARAM = "PAGE_QUERY_PARAM"; 35 | /** 36 | * LModel的表名 37 | */ 38 | String LMODEL_TABLE_NAME = "LMODEL_TABLE_NAME"; 39 | 40 | /** 41 | * LModel的默认的数据源 42 | */ 43 | String LMODEL_DEFAULT_DATASOURCE = "LMODEL_DEFAULT_DATASOURCE"; 44 | 45 | /** 46 | * 批量参数 47 | */ 48 | String BATCH_INSTANCE_LIST = "BATCH_INSTANCE_LIST"; 49 | 50 | /** 51 | * 组合请求 52 | */ 53 | String CONBINE_ACTIONS = "CONBINE_ACTIONS"; 54 | /** 55 | * 自动回滚 56 | */ 57 | String AUTO_ROLLBACK = "AUTO_ROLLBACK"; 58 | /** 59 | * 数据幂等性 60 | */ 61 | String DATA_CONSISTENCY = "DATA_CONSISTENCY"; 62 | /** 63 | * 查询类型 64 | */ 65 | String QUERY_TYPE = "QUERY_TYPE"; 66 | /** 67 | * 乐观锁属性名 68 | */ 69 | String MODEL_UPDATE_CAS_VERSION_FIELD = "MODEL_UPDATE_CAS_VERSION_FIELD"; 70 | /** 71 | * 乐观锁版本号 72 | */ 73 | String MODEL_UPDATE_CAS_VERSION = "MODEL_UPDATE_CAS_VERSION"; 74 | } 75 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/factory/impl/NullMetaDataSource.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.factory.impl; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.concur.meta.client.constants.DataSourceType; 6 | import com.concur.meta.client.dataobject.MetaRequest; 7 | import com.concur.meta.core.dbengine.meta.MetaBuilder; 8 | import com.concur.meta.core.dbengine.sql.sqlbuilder.BaseBuilder; 9 | import com.concur.meta.core.dbengine.meta.metabuilder.DefaultAutoMetaBuilder; 10 | import com.concur.meta.core.dbengine.sql.sqlbuilder.SqlBuilder; 11 | import com.concur.meta.core.extension.mysql.MysqlDialect; 12 | import com.concur.meta.metadata.util.ServiceUtil; 13 | 14 | /** 15 | * 默认数据源(未指定数据源ID情况下) 16 | * 17 | * @author yongfu.cyf 18 | * @create 2017-09-22 下午11:46 19 | **/ 20 | public class NullMetaDataSource extends BaseMetaDatasource { 21 | 22 | private static final String DATASOURCEKEY = "default"; 23 | 24 | public NullMetaDataSource() { 25 | super(null, DATASOURCEKEY); 26 | } 27 | 28 | @Override 29 | public DataSourceType getDataSourceType() { 30 | return DataSourceType.MYSQL; 31 | } 32 | 33 | @Override 34 | public SqlBuilder getSqlBuilder() { 35 | return new BaseBuilder(new MysqlDialect()); 36 | } 37 | 38 | @Override 39 | public MetaBuilder getMetaBuilder(MetaRequest metaRequest) { 40 | return new DefaultAutoMetaBuilder(); 41 | } 42 | 43 | @Override 44 | public String getDataSourceKey() { 45 | return DATASOURCEKEY; 46 | } 47 | 48 | @Override 49 | public DataSource getDataSource() { 50 | return ServiceUtil.getLmodelConfigDataSource(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/LModelException.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.exception; 2 | 3 | import java.util.List; 4 | 5 | import com.concur.meta.client.common.IResultCode; 6 | 7 | /** 8 | * LModel异常 9 | * 所有自定义异常的超类 10 | * @author yongfu.cyf 11 | * @create 2017-06-29 上午10:01 12 | **/ 13 | public abstract class LModelException extends RuntimeException { 14 | 15 | private static final long serialVersionUID = 2672538489232908376L; 16 | 17 | /** 18 | * 执行日志 19 | */ 20 | private List executeLog; 21 | 22 | public LModelException() { 23 | super(); 24 | } 25 | 26 | public LModelException(String message) { 27 | super(message); 28 | } 29 | 30 | public LModelException(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | 34 | public LModelException(Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | public LModelException(IResultCode iResultCode) { 39 | super(iResultCode.getCode() + ":" + iResultCode.getMessage()); 40 | } 41 | 42 | public LModelException(IResultCode iResultCode, Throwable cause) { 43 | super(iResultCode.getCode() + ":" + iResultCode.getMessage(), cause); 44 | } 45 | 46 | public LModelException(IResultCode iResultCode, String detail, Throwable cause) { 47 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + detail, cause); 48 | } 49 | 50 | public List getExecuteLog() { 51 | return executeLog; 52 | } 53 | 54 | public LModelException setExecuteLog(List executeLog) { 55 | this.executeLog = executeLog; 56 | return this; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/ExecuteException.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.exception; 2 | 3 | import com.concur.meta.client.common.IResultCode; 4 | import org.apache.commons.lang.StringUtils; 5 | 6 | /** 7 | * 引擎执行异常 8 | * 需要对执行异常特殊处理时捕获此异常 9 | * @author yongfu.cyf 10 | * @create 2017-06-29 上午11:14 11 | **/ 12 | public class ExecuteException extends TransactionFailException { 13 | 14 | private static final long serialVersionUID = -4979297838122534537L; 15 | 16 | public ExecuteException() { 17 | super(); 18 | } 19 | 20 | public ExecuteException(String message) { 21 | super(message); 22 | } 23 | 24 | public ExecuteException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public ExecuteException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | public ExecuteException(IResultCode iResultCode) { 33 | super(iResultCode.getCode() + ":" + iResultCode.getMessage()); 34 | } 35 | 36 | public ExecuteException(IResultCode iResultCode, Throwable cause) { 37 | super(iResultCode.getCode() + ":" + iResultCode.getMessage(), cause); 38 | } 39 | 40 | public ExecuteException(IResultCode iResultCode, String... message) { 41 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + StringUtils.join(message)); 42 | } 43 | 44 | public ExecuteException(IResultCode iResultCode, String detail, Throwable cause) { 45 | super(iResultCode.getCode() + ":" + iResultCode.getMessage() + ":" + detail, cause); 46 | } 47 | 48 | public ExecuteException(String errorCode, String errorMsg) { 49 | super(errorCode + ":" + errorMsg); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/converter/ConverterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.converter; 18 | 19 | /** 20 | * A factory for "ranged" converters that can convert objects from S to subtypes of R. 21 | * 22 | *

    Implementations may additionally implement {@link ConditionalConverter}. 23 | * 24 | * @author Keith Donald 25 | * @since 3.0 26 | * @see ConditionalConverter 27 | * @param The source type converters created by this factory can convert from 28 | * @param The target range (or base) type converters created by this factory can convert to; 29 | * for example {@link Number} for a set of number subtypes. 30 | */ 31 | public interface ConverterFactory { 32 | 33 | /** 34 | * Get the converter to convert from S to target type T, where T is also an instance of R. 35 | * @param the target type 36 | * @param targetType the target type to convert to 37 | * @return A converter from S to T 38 | */ 39 | Converter getConverter(Class targetType); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/types/StringArrayTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.types; 2 | 3 | import java.sql.CallableStatement; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import org.apache.ibatis.type.BaseTypeHandler; 9 | import org.apache.ibatis.type.JdbcType; 10 | 11 | /** 12 | * 字符串数组转换器 13 | */ 14 | public class StringArrayTypeHandler extends BaseTypeHandler { 15 | 16 | @Override 17 | public String[] getNullableResult(ResultSet rs, String columnName) 18 | throws SQLException { 19 | return getStringArray(rs.getString(columnName)); 20 | } 21 | 22 | @Override 23 | public String[] getNullableResult(ResultSet rs, int columnIndex) 24 | throws SQLException { 25 | return this.getStringArray(rs.getString(columnIndex)); 26 | } 27 | 28 | @Override 29 | public String[] getNullableResult(CallableStatement cs, int columnIndex) 30 | throws SQLException { 31 | return this.getStringArray(cs.getString(columnIndex)); 32 | } 33 | 34 | @Override 35 | public void setNonNullParameter(PreparedStatement ps, int i, 36 | String[] parameter, JdbcType jdbcType) throws SQLException { 37 | StringBuffer result = new StringBuffer(); 38 | for (String value : parameter) { result.append(value).append(","); } 39 | result.deleteCharAt(result.length()-1); 40 | ps.setString(i, result.toString()); 41 | } 42 | 43 | private String[] getStringArray(String columnValue) { 44 | if (columnValue == null) { return null; } 45 | return columnValue.split(","); 46 | } 47 | } -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/PropertiesToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import java.io.ByteArrayOutputStream; 20 | import java.io.IOException; 21 | import java.util.Properties; 22 | 23 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 24 | 25 | /** 26 | * Converts from a Properties to a String by calling {@link Properties#store(java.io.OutputStream, String)}. 27 | * Decodes with the ISO-8859-1 charset before returning the String. 28 | * 29 | * @author Keith Donald 30 | * @since 3.0 31 | */ 32 | final class PropertiesToStringConverter implements Converter { 33 | 34 | @Override 35 | public String convert(Properties source) { 36 | try { 37 | ByteArrayOutputStream os = new ByteArrayOutputStream(256); 38 | source.store(os, null); 39 | return os.toString("ISO-8859-1"); 40 | } 41 | catch (IOException ex) { 42 | // Should never happen. 43 | throw new IllegalArgumentException("Failed to store [" + source + "] into String", ex); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/result/ServerResultCode.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.result; 2 | 3 | import com.concur.meta.client.common.IResultCode; 4 | 5 | /** 6 | * server端错误码 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-29 下午3:32 10 | **/ 11 | public enum ServerResultCode implements IResultCode { 12 | 13 | MATA_CLASS_NAME_IS_BLANK("meta_request_classname_is_blank", "请求的类名不能为空"), 14 | 15 | GET_TABLE_META_EXCEPTION("get_table_meta_exception", "获取数据表的元数据信息异常"), 16 | 17 | PARAM_CONVERT_ERROR("param_convert_error", "参数转换错误"), 18 | 19 | CONBINE_INVOKE_EXCEPTION("conbine_invoke_exception", "事务提交失败"), 20 | 21 | ROLLBACK_EXCEPTION("rollback_exception", "回滚失败"), 22 | 23 | COLUMN_MAPPING_NOT_FOUND("column_map_not_found", "字段未找到"), 24 | 25 | DATA_SOURCE_NOT_EXISTS("data_source_not_exists", "数据源不存在"), 26 | 27 | DATA_SOURCE_INIT_FAILT("data_source_init_fail", "数据源初始化失败"), 28 | 29 | SERVER_DATA_CONSISTENCY_EXCEPTION("server_data_consistency_exception", "数据不一致异常"), 30 | 31 | DATA_SOURCE_TYPE_NOT_EXISTS("data_source_type_not_exists", "数据源类型暂不支持"), 32 | 33 | DATA_SOURCE_TYPE_NOT_SUPPORT_FOR_THE_OPERATION("data_source_type_not_support_for_the_operation", "该数据源类型暂不支持此操作"), 34 | 35 | SERVER_DATA_SOUCE_GET_ERROR("server_data_souce_get_error", "数据源获取异常"), 36 | 37 | OPERATION_PARAM_MISSION("operation_param_mission", "不支持此类型的操作"), 38 | 39 | ; 40 | 41 | ServerResultCode(String code, String msg) { 42 | this.code = code; 43 | this.msg = msg; 44 | } 45 | 46 | private String code; 47 | private String msg; 48 | 49 | @Override 50 | public String getCode() { 51 | return this.code; 52 | } 53 | 54 | @Override 55 | public String getMessage() { 56 | return this.msg; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/StringToPropertiesConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import java.io.ByteArrayInputStream; 20 | import java.util.Properties; 21 | 22 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 23 | 24 | /** 25 | * Converts a String to a Properties by calling Properties#load(java.io.InputStream). 26 | * Uses ISO-8559-1 encoding required by Properties. 27 | * 28 | * @author Keith Donald 29 | * @since 3.0 30 | */ 31 | final class StringToPropertiesConverter implements Converter { 32 | 33 | @Override 34 | public Properties convert(String source) { 35 | try { 36 | Properties props = new Properties(); 37 | // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. 38 | props.load(new ByteArrayInputStream(source.getBytes("ISO-8859-1"))); 39 | return props; 40 | } 41 | catch (Exception ex) { 42 | // Should never happen. 43 | throw new IllegalArgumentException("Failed to parse [" + source + "] into Properties", ex); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/util/ApplicationContextUtils.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.util; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 5 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.ApplicationContextAware; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

    12 |  * 这个Bean需要被配置在spring的配置中
    13 |  * 
    14 | * @author jake 15 | */ 16 | @Component 17 | public class ApplicationContextUtils implements ApplicationContextAware, BeanFactoryPostProcessor { 18 | 19 | private static ApplicationContext APPLICATION_CONTEXT; 20 | 21 | private static ConfigurableListableBeanFactory configurableListableBeanFactory; 22 | 23 | public static final ApplicationContext getContext() { 24 | return APPLICATION_CONTEXT; 25 | } 26 | 27 | public static ConfigurableListableBeanFactory getConfigurableListableBeanFactory() { 28 | return configurableListableBeanFactory; 29 | } 30 | 31 | /* 32 | * (non-Javadoc) 33 | * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context. 34 | * ApplicationContext) 35 | */ 36 | @Override 37 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 38 | APPLICATION_CONTEXT = applicationContext; 39 | } 40 | 41 | @Override 42 | public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) 43 | throws BeansException { 44 | ApplicationContextUtils.configurableListableBeanFactory = configurableListableBeanFactory; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/meta/ColumnMeta.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.meta; 2 | 3 | /** 4 | * 字段信息 5 | * 6 | * @author yongfu.cyf 7 | * @create 2017-06-29 上午11:00 8 | **/ 9 | public class ColumnMeta { 10 | 11 | /** 12 | * 字段名称 13 | */ 14 | private String columnName; 15 | /** 16 | * 属性名称 17 | */ 18 | private String propertyName; 19 | /** 20 | * Java数据类型 21 | */ 22 | private String javaType; 23 | /** 24 | * Jdbc类型 25 | */ 26 | private String jdbcType; 27 | 28 | public ColumnMeta() {} 29 | 30 | public ColumnMeta(String columnName) { 31 | this.columnName = columnName; 32 | } 33 | 34 | 35 | public String getColumnName() { 36 | return columnName; 37 | } 38 | 39 | public void setColumnName(String columnName) { 40 | this.columnName = columnName; 41 | } 42 | 43 | public String getJavaType() { 44 | return javaType; 45 | } 46 | 47 | public void setJavaType(String javaType) { 48 | this.javaType = javaType; 49 | } 50 | 51 | public String getPropertyName() { 52 | return propertyName; 53 | } 54 | 55 | public void setPropertyName(String propertyName) { 56 | this.propertyName = propertyName; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object o) { 61 | if (this == o) { return true; } 62 | if (!(o instanceof ColumnMeta)) { return false; } 63 | 64 | ColumnMeta that = (ColumnMeta)o; 65 | 66 | return columnName.equals(that.columnName); 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | return columnName.hashCode(); 72 | } 73 | 74 | public String getJdbcType() { 75 | return jdbcType; 76 | } 77 | 78 | public void setJdbcType(String jdbcType) { 79 | this.jdbcType = jdbcType; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/Map2StringConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | import java.util.Map.Entry; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | import java.util.concurrent.ConcurrentMap; 9 | 10 | import com.concur.meta.client.utils.ExtraUtil; 11 | import com.concur.meta.client.conversion.ConverterAdapter; 12 | 13 | /** 14 | * Map转字符串 15 | * 16 | * @author yongfu.cyf 17 | * @create 2017-07-24 下午12:00 18 | **/ 19 | public class Map2StringConverter extends ConverterAdapter { 20 | 21 | private static final String STRING_SPLITER = ";"; 22 | 23 | private static final String KEY_VALUE_SPLITER = ":"; 24 | 25 | @Override 26 | public String convert(Map source, Object... objects) { 27 | if (source == null || source.size() == 0) { 28 | return null; 29 | } 30 | 31 | Map map = (Map) source; 32 | StringBuilder result = new StringBuilder(); 33 | for (Entry entry : map.entrySet()) { 34 | String value = converterService.convert(entry.getValue(), String.class); 35 | result.append(ExtraUtil.encode(entry.getKey())).append(KEY_VALUE_SPLITER) 36 | .append(ExtraUtil.encode(value)).append(STRING_SPLITER); 37 | } 38 | return result.toString(); 39 | } 40 | 41 | @Override 42 | protected void postRegister() { 43 | converterService.registerConverter(HashMap.class, String.class, this); 44 | converterService.registerConverter(LinkedHashMap.class, String.class, this); 45 | converterService.registerConverter(ConcurrentMap.class, String.class, this); 46 | converterService.registerConverter(ConcurrentHashMap.class, String.class, this); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/dataobject/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.dataobject; 2 | 3 | import java.io.Serializable; 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.concur.meta.client.api.query.QueryParam; 9 | 10 | /** 11 | * 查询结果 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-06-29 上午11:48 15 | **/ 16 | public class ResponseResult implements Serializable { 17 | 18 | private static final long serialVersionUID = 8261473086611917022L; 19 | /** 20 | * 当前页页号,注意页号是从1开始的 21 | */ 22 | protected int pageNo = 1; 23 | /** 24 | * 总记录数 25 | */ 26 | protected int totalNum = -1; 27 | /** 28 | * list结果 29 | */ 30 | protected List list; 31 | 32 | public ResponseResult(QueryParam queryParam, int totalNum, T one) { 33 | this(queryParam, totalNum, Arrays.asList(one)); 34 | } 35 | 36 | public ResponseResult(QueryParam queryParam, int totalNum, List list) { 37 | if (queryParam != null && queryParam.getPageQuery() != null && queryParam.isNeedPagenation()) { 38 | this.pageNo = queryParam.getPageQuery().getPageNo(); 39 | int pageSize = queryParam.getPageQuery().getPageSize(); 40 | // fix pageNo 41 | int totalPageNum = (totalNum + pageSize - 1) / pageSize; 42 | if (this.pageNo > totalPageNum) { 43 | this.pageNo = totalPageNum; 44 | } 45 | this.totalNum = totalNum; 46 | } 47 | this.list = list; 48 | } 49 | 50 | public List getList() { 51 | if (this.list == null) { 52 | return Collections.emptyList(); 53 | } 54 | return this.list; 55 | } 56 | 57 | public int getPageNo() { 58 | return pageNo; 59 | } 60 | 61 | public int getTotalNum() { 62 | return totalNum; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/base/NestedExceptionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2008 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.exception.base; 18 | 19 | /** 20 | * Helper class for implementing exception classes which are capable of 21 | * holding nested exceptions. Necessary because we can't share a base 22 | * class among different exception types. 23 | * 24 | *

    Mainly for use within the framework. 25 | * 26 | * @author Juergen Hoeller 27 | * @since 2.0 28 | * @see NestedRuntimeException 29 | * @see NestedCheckedException 30 | * @see NestedIOException 31 | * @see org.springframework.web.util.NestedServletException 32 | */ 33 | public abstract class NestedExceptionUtils { 34 | 35 | /** 36 | * Build a message for the given base message and root cause. 37 | * @param message the base message 38 | * @param cause the root cause 39 | * @return the full exception message 40 | */ 41 | public static String buildMessage(String message, Throwable cause) { 42 | if (cause != null) { 43 | StringBuilder sb = new StringBuilder(); 44 | if (message != null) { 45 | sb.append(message).append("; "); 46 | } 47 | sb.append("nested exception is ").append(cause); 48 | return sb.toString(); 49 | } 50 | else { 51 | return message; 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/ConverterRegistry.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion; 2 | 3 | import java.lang.reflect.Modifier; 4 | import java.util.Set; 5 | 6 | import com.concur.meta.client.conversion.conveters.ConverterPackageInfo; 7 | import com.concur.meta.client.utils.ClassPathScanHandler; 8 | 9 | /** 10 | * 转换器注册 11 | * 12 | * @author yongfu.cyf 13 | * @create 2017-07-27 下午3:30 14 | **/ 15 | public class ConverterRegistry { 16 | 17 | protected ConverterService converterService; 18 | 19 | public ConverterRegistry(ConverterService converterService) { 20 | this.converterService = converterService; 21 | } 22 | 23 | private void registerClass(Set> classes) { 24 | for (Class clazz : classes) { 25 | if (Modifier.isAbstract(clazz.getModifiers())) { 26 | continue; 27 | } 28 | try { 29 | Converter converter = clazz.newInstance(); 30 | 31 | this.converterService.registerConverter(converter); 32 | if (converter instanceof ConverterAdapter) { 33 | ((ConverterAdapter)converter) 34 | .setConverterService(converterService) 35 | .postRegister(); 36 | } 37 | } catch (InstantiationException e) { 38 | e.printStackTrace(); 39 | } catch (IllegalAccessException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | } 44 | 45 | public void init() throws Exception { 46 | // 注册 47 | String scanPath = ConverterPackageInfo.class.getPackage().getName(); 48 | ClassPathScanHandler convertorScan = new ClassPathScanHandler(scanPath); 49 | Set> converterClass = convertorScan.getAllSubClassesByParent(Converter.class); 50 | this.registerClass(converterClass); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/utils/MultiValueMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.utils; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | /** 23 | * Extension of the {@code Map} interface that stores multiple values. 24 | * 25 | * @author Arjen Poutsma 26 | * @since 3.0 27 | */ 28 | public interface MultiValueMap extends Map> { 29 | 30 | /** 31 | * Return the first value for the given key. 32 | * @param key the key 33 | * @return the first value for the specified key, or {@code null} 34 | */ 35 | V getFirst(K key); 36 | 37 | /** 38 | * Add the given single value to the current list of values for the given key. 39 | * @param key the key 40 | * @param value the value to be added 41 | */ 42 | void add(K key, V value); 43 | 44 | /** 45 | * Set the given single value under the given key. 46 | * @param key the key 47 | * @param value the value to set 48 | */ 49 | void set(K key, V value); 50 | 51 | /** 52 | * Set the given values under. 53 | * @param values the values. 54 | */ 55 | void setAll(Map values); 56 | 57 | /** 58 | * Returns the first values contained in this {@code MultiValueMap}. 59 | * @return a single value representation of this map 60 | */ 61 | Map toSingleValueMap(); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/datasource/DataSourceInitializeHandle.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.datasource; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import javax.sql.DataSource; 7 | 8 | import com.concur.meta.client.constants.DataSourceType; 9 | import com.concur.meta.client.exception.ExecuteException; 10 | import com.concur.meta.client.result.ServerResultCode; 11 | import com.concur.meta.core.extension.mysql.MysqlDataSourceInitializer; 12 | import com.concur.meta.core.extension.postgre.PostgresSqlDataSourceInitializer; 13 | 14 | /** 15 | * 数据源初始化处理 16 | * 17 | * @author yongfu.cyf 18 | * @create 2017-08-25 上午11:57 19 | **/ 20 | public class DataSourceInitializeHandle { 21 | 22 | private static Map registry 23 | = new ConcurrentHashMap(); 24 | 25 | /** 26 | * 获取数据源连接 27 | * @param dataSourceTypeName 数据源类型 28 | * @param attributes 属性 29 | * @return 30 | */ 31 | public static DataSource getOrCreateDataSource(String dataSourceTypeName, Map attributes) { 32 | DataSourceType dataSourceType = DataSourceType.getByName(dataSourceTypeName); 33 | DataSourceInitializer dataSourceInitializer = registry.get(dataSourceType); 34 | if (dataSourceInitializer == null) { 35 | throw new ExecuteException(ServerResultCode.DATA_SOURCE_NOT_EXISTS, dataSourceTypeName); 36 | } 37 | return dataSourceInitializer.init(attributes); 38 | } 39 | 40 | /** 41 | * 注册数据源初始化器 42 | * @param dataSourceInitializer 数据源初始化器 43 | */ 44 | public static void register(DataSourceInitializer dataSourceInitializer) { 45 | registry.put(dataSourceInitializer.getDataSourceType(), dataSourceInitializer); 46 | } 47 | 48 | static { 49 | // 注册 50 | register(new MysqlDataSourceInitializer()); 51 | register(new PostgresSqlDataSourceInitializer()); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/utils/FieldUtil.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.utils; 2 | 3 | /** 4 | * FieldUtil 5 | */ 6 | public class FieldUtil { 7 | 8 | /** 9 | * 转换为下划线 10 | * 11 | * @param camelCaseName 12 | * @return 13 | */ 14 | public static String underscoreName(String camelCaseName) { 15 | StringBuilder result = new StringBuilder(); 16 | if (camelCaseName != null && camelCaseName.length() > 0) { 17 | result.append(camelCaseName.substring(0, 1).toLowerCase()); 18 | for (int i = 1; i < camelCaseName.length(); i++) { 19 | char ch = camelCaseName.charAt(i); 20 | if (Character.isUpperCase(ch)) { 21 | result.append("_"); 22 | result.append(Character.toLowerCase(ch)); 23 | } else { 24 | result.append(ch); 25 | } 26 | } 27 | } 28 | return result.toString(); 29 | } 30 | 31 | /** 32 | * 转换为驼峰 33 | * 34 | * @param underscoreName 35 | * @return 36 | */ 37 | public static String camelCaseName(String underscoreName) { 38 | StringBuilder result = new StringBuilder(); 39 | if (underscoreName != null && underscoreName.length() > 0) { 40 | boolean flag = false; 41 | for (int i = 0; i < underscoreName.length(); i++) { 42 | char ch = underscoreName.charAt(i); 43 | if ("_".charAt(0) == ch) { 44 | flag = true; 45 | } else { 46 | if (flag) { 47 | result.append(Character.toUpperCase(ch)); 48 | flag = false; 49 | } else { 50 | result.append(ch); 51 | } 52 | } 53 | } 54 | } 55 | return result.toString(); 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/manager/impl/TableMetaManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.manager.impl; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | import java.util.concurrent.ConcurrentMap; 6 | 7 | import com.concur.meta.client.exception.MetaDataException; 8 | import com.concur.meta.client.result.ServerResultCode; 9 | import com.concur.meta.core.dbengine.meta.TableMeta; 10 | import com.concur.meta.core.dbengine.factory.DataSourceReloadable; 11 | import com.concur.meta.core.manager.TableMetaManager; 12 | import org.apache.commons.lang.StringUtils; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.beans.factory.InitializingBean; 16 | 17 | /** 18 | * DB元数据信息管理 19 | * 20 | * @author yongfu.cyf 21 | * @create 2017-07-04 上午10:53 22 | **/ 23 | public class TableMetaManagerImpl implements TableMetaManager, InitializingBean, DataSourceReloadable { 24 | 25 | private static Logger logger = LoggerFactory.getLogger(TableMetaManagerImpl.class); 26 | 27 | private ConcurrentMap tableMetaMap = new ConcurrentHashMap(); 28 | 29 | private static final String DEFAULT_TABLE_NAME ="default"; 30 | 31 | @Override 32 | public void afterPropertiesSet() throws Exception { 33 | // 初始化配置端数据库信息 34 | 35 | } 36 | 37 | 38 | @Override 39 | public TableMeta getTableMeta(String className) { 40 | if (StringUtils.isBlank(className)) { 41 | throw new MetaDataException(ServerResultCode.MATA_CLASS_NAME_IS_BLANK); 42 | } 43 | 44 | // 获取缓存 45 | TableMeta tableMeta = tableMetaMap.get(className); 46 | if (tableMeta != null) { 47 | return tableMeta; 48 | } 49 | 50 | 51 | return null; 52 | } 53 | 54 | 55 | 56 | @Override 57 | public void onReload(long dataSourceId, List classNames) { 58 | for (String className : classNames) { 59 | tableMetaMap.remove(className); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/ConverterNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring; 18 | 19 | /** 20 | * Thrown when a suitable converter could not be found in a conversion service. 21 | * 22 | * @author Keith Donald 23 | * @since 3.0 24 | */ 25 | @SuppressWarnings("serial") 26 | public final class ConverterNotFoundException extends ConversionException { 27 | 28 | private final TypeDescriptor sourceType; 29 | 30 | private final TypeDescriptor targetType; 31 | 32 | 33 | /** 34 | * Creates a new conversion executor not found exception. 35 | * @param sourceType the source type requested to convert from 36 | * @param targetType the target type requested to convert to 37 | */ 38 | public ConverterNotFoundException(TypeDescriptor sourceType, TypeDescriptor targetType) { 39 | super("No converter found capable of converting from type " + sourceType + " to type " + targetType); 40 | this.sourceType = sourceType; 41 | this.targetType = targetType; 42 | } 43 | 44 | 45 | /** 46 | * Returns the source type that was requested to convert from. 47 | */ 48 | public TypeDescriptor getSourceType() { 49 | return this.sourceType; 50 | } 51 | 52 | /** 53 | * Returns the target type that was requested to convert to. 54 | */ 55 | public TypeDescriptor getTargetType() { 56 | return this.targetType; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/ConfigurableConversionService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.ConversionService; 20 | import com.concur.meta.client.conversion.conveters.spring.converter.ConverterRegistry; 21 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 22 | 23 | /** 24 | * Configuration interface to be implemented by most if not all {@link ConversionService} 25 | * types. Consolidates the read-only operations exposed by {@link ConversionService} and 26 | * the mutating operations of {@link ConverterRegistry} to allow for convenient ad-hoc 27 | * addition and removal of {@link Converter 28 | * Converters} through. The latter is particularly useful when working against a 29 | * {@link org.springframework.core.env.ConfigurableEnvironment ConfigurableEnvironment} 30 | * instance in application context bootstrapping code. 31 | * 32 | * @author Chris Beams 33 | * @since 3.1 34 | * @see org.springframework.core.env.ConfigurablePropertyResolver#getConversionService() 35 | * @see org.springframework.core.env.ConfigurableEnvironment 36 | * @see org.springframework.context.ConfigurableApplicationContext#getEnvironment() 37 | */ 38 | public interface ConfigurableConversionService extends ConversionService, ConverterRegistry { 39 | 40 | } 41 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/utils/CacheUtils.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.utils; 2 | 3 | import java.util.concurrent.Callable; 4 | import java.util.concurrent.LinkedBlockingQueue; 5 | import java.util.concurrent.ThreadPoolExecutor; 6 | import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import com.google.common.cache.CacheLoader; 10 | import com.google.common.util.concurrent.ListenableFuture; 11 | import com.google.common.util.concurrent.ListeningExecutorService; 12 | import com.google.common.util.concurrent.MoreExecutors; 13 | 14 | /** 15 | * 缓存增强工具 16 | * 17 | * @author yongfu.cyf 18 | * @create 2017-10-30 下午8:40 19 | **/ 20 | public class CacheUtils { 21 | 22 | /** 线程池大小 */ 23 | private static int threadNum = 4; 24 | 25 | private static ListeningExecutorService executor = createRefreshThreadPool(); 26 | 27 | /** 28 | * 创建缓存刷新线程池 29 | * @return 30 | */ 31 | private static ListeningExecutorService createRefreshThreadPool() { 32 | // 初始化消费线程池 33 | ThreadGroup threadGroup = new ThreadGroup("LModel缓存异步刷新线程"); 34 | NamingThreadFactory threadFactory = new NamingThreadFactory(threadGroup, "LModel缓存异步刷新线程池"); 35 | ThreadPoolExecutor threadPool = new ThreadPoolExecutor(threadNum, threadNum, 0L, TimeUnit.MILLISECONDS, 36 | new LinkedBlockingQueue(), 37 | threadFactory, new AbortPolicy()); 38 | return MoreExecutors.listeningDecorator(threadPool); 39 | } 40 | 41 | /** 42 | * 异步刷新缓存加载器 43 | * @param 44 | * @param 45 | */ 46 | public static abstract class AsynchronousCacheLoader extends CacheLoader { 47 | @Override 48 | public ListenableFuture reload(final K key, V oldValue) throws Exception { 49 | return executor.submit(new Callable() { 50 | @Override 51 | public V call() throws Exception { 52 | return AsynchronousCacheLoader.this.load(key); 53 | } 54 | }); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/StringToBooleanConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 23 | 24 | /** 25 | * Converts String to a Boolean. 26 | * 27 | * @author Keith Donald 28 | * @author Juergen Hoeller 29 | * @since 3.0 30 | */ 31 | final class StringToBooleanConverter implements Converter { 32 | 33 | private static final Set trueValues = new HashSet(4); 34 | 35 | private static final Set falseValues = new HashSet(4); 36 | 37 | static { 38 | trueValues.add("true"); 39 | trueValues.add("on"); 40 | trueValues.add("yes"); 41 | trueValues.add("1"); 42 | 43 | falseValues.add("false"); 44 | falseValues.add("off"); 45 | falseValues.add("no"); 46 | falseValues.add("0"); 47 | } 48 | 49 | @Override 50 | public Boolean convert(String source) { 51 | String value = source.trim(); 52 | if ("".equals(value)) { 53 | return null; 54 | } 55 | value = value.toLowerCase(); 56 | if (trueValues.contains(value)) { 57 | return Boolean.TRUE; 58 | } 59 | else if (falseValues.contains(value)) { 60 | return Boolean.FALSE; 61 | } 62 | else { 63 | throw new IllegalArgumentException("Invalid boolean value '" + source + "'"); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/ParameterNameDiscoverer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring; 18 | 19 | import java.lang.reflect.Constructor; 20 | import java.lang.reflect.Method; 21 | 22 | /** 23 | * Interface to discover parameter names for methods and constructors. 24 | * 25 | *

    Parameter name discovery is not always possible, but various strategies are 26 | * available to try, such as looking for debug information that may have been 27 | * emitted at compile time, and looking for argname annotation values optionally 28 | * accompanying AspectJ annotated methods. 29 | * 30 | * @author Rod Johnson 31 | * @author Adrian Colyer 32 | * @since 2.0 33 | */ 34 | public interface ParameterNameDiscoverer { 35 | 36 | /** 37 | * Return parameter names for this method, 38 | * or {@code null} if they cannot be determined. 39 | * @param method method to find parameter names for 40 | * @return an array of parameter names if the names can be resolved, 41 | * or {@code null} if they cannot 42 | */ 43 | String[] getParameterNames(Method method); 44 | 45 | /** 46 | * Return parameter names for this constructor, 47 | * or {@code null} if they cannot be determined. 48 | * @param ctor constructor to find parameter names for 49 | * @return an array of parameter names if the names can be resolved, 50 | * or {@code null} if they cannot 51 | */ 52 | String[] getParameterNames(Constructor ctor); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/String2MapConverter.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.conversion.conveters; 2 | 3 | import java.io.Serializable; 4 | import java.lang.reflect.ParameterizedType; 5 | import java.lang.reflect.Type; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import com.concur.meta.client.conversion.ConverterAdapter; 10 | import com.concur.meta.client.utils.ExtraUtil; 11 | import com.concur.meta.client.utils.TypeUtils; 12 | import org.apache.commons.lang.StringUtils; 13 | 14 | /** 15 | * 字符串转Map 16 | * 17 | * @author yongfu.cyf 18 | * @create 2017-07-24 下午12:00 19 | **/ 20 | public class String2MapConverter extends ConverterAdapter { 21 | 22 | private static final String STRING_SPLITER = ";"; 23 | 24 | private static final String KEY_VALUE_SPLITER = ":"; 25 | 26 | @Override 27 | public Map convert(String source, Type targetType, Object... objects) { 28 | if (StringUtils.isBlank(source)) { 29 | return new HashMap(); 30 | } 31 | String[] array = source.split(STRING_SPLITER); 32 | Map result = new HashMap(); 33 | for (String elem : array) { 34 | if (StringUtils.isNotBlank(elem)) { 35 | String[] entry = elem.split(KEY_VALUE_SPLITER); 36 | if (entry.length != 2) { 37 | continue; 38 | } 39 | String key = ExtraUtil.decode(entry[0]); 40 | String value = ExtraUtil.decode(entry[1]); 41 | if (targetType instanceof ParameterizedType) { 42 | key = converterService.convert(key, 43 | TypeUtils.getParameterizedType((ParameterizedType)targetType, 0)); 44 | value = converterService.convert(value, 45 | TypeUtils.getParameterizedType((ParameterizedType)targetType, 1)); 46 | result.put(key, value); 47 | } else { 48 | result.put(key, value); 49 | } 50 | } 51 | } 52 | return result; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/execute/routing/DynamicDBDataSource.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.execute.routing; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import javax.sql.DataSource; 7 | 8 | import com.concur.meta.core.dbengine.execute.ExecuteContext; 9 | import org.springframework.beans.factory.InitializingBean; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Qualifier; 12 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 13 | 14 | /** 15 | * DB多数据源 16 | * @author yongfu.cyf 17 | * @create 2017-07-05 下午3:41 18 | **/ 19 | public class DynamicDBDataSource extends AbstractRoutingDataSource implements InitializingBean { 20 | 21 | /** 22 | * 默认数据源 23 | */ 24 | @Autowired(required = true) 25 | @Qualifier("dataSource") 26 | private DataSource defaultDataSource; 27 | 28 | /** 29 | * 可选数据源映射 30 | */ 31 | private Map targetDataSource = new HashMap(); 32 | 33 | @Override 34 | protected Object determineCurrentLookupKey() { 35 | return ExecuteContext.getDataSource(); 36 | } 37 | 38 | /** 39 | * 初始化数据源 40 | */ 41 | public void initDataSources() { 42 | targetDataSource.put("default", defaultDataSource); 43 | this.setTargetDataSources(targetDataSource); 44 | this.setDefaultTargetDataSource(defaultDataSource); 45 | } 46 | 47 | public void setDefaultDataSource(DataSource defaultDataSource) { 48 | this.defaultDataSource = defaultDataSource; 49 | } 50 | 51 | /** 52 | * 添加数据源 53 | * @param key 数据源Key 54 | * @param dataSource DB数据源 55 | */ 56 | public void addDataSource(String key, DataSource dataSource) { 57 | targetDataSource.put(key, dataSource); 58 | super.afterPropertiesSet(); 59 | } 60 | 61 | @Override 62 | public void afterPropertiesSet() { 63 | this.initDataSources(); 64 | super.afterPropertiesSet(); 65 | } 66 | 67 | public DataSource getDefaultDataSource() { 68 | return defaultDataSource; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/EnumToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.ConversionService; 20 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 21 | import com.concur.meta.client.utils.ClassUtils; 22 | import com.concur.meta.client.conversion.conveters.spring.TypeDescriptor; 23 | import com.concur.meta.client.conversion.conveters.spring.converter.ConditionalConverter; 24 | 25 | /** 26 | * Calls {@link Enum#name()} to convert a source Enum to a String. This converter will 27 | * not match enums with interfaces that can be converterd. 28 | * @author Keith Donald 29 | * @author Phillip Webb 30 | * @since 3.0 31 | */ 32 | final class EnumToStringConverter implements Converter, String>, ConditionalConverter { 33 | 34 | private final ConversionService conversionService; 35 | 36 | public EnumToStringConverter(ConversionService conversionService) { 37 | this.conversionService = conversionService; 38 | } 39 | 40 | @Override 41 | public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { 42 | for (Class interfaceType : ClassUtils.getAllInterfacesForClass(sourceType.getType())) { 43 | if (conversionService.canConvert(TypeDescriptor.valueOf(interfaceType), targetType)) { 44 | return false; 45 | } 46 | } 47 | return true; 48 | } 49 | 50 | @Override 51 | public String convert(Enum source) { 52 | return source.name(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/exception/base/BeansException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.exception.base; 18 | 19 | import com.concur.meta.client.utils.ObjectUtils; 20 | 21 | /** 22 | * Abstract superclass for all exceptions thrown in the beans package 23 | * and subpackages. 24 | * 25 | *

    Note that this is a runtime (unchecked) exception. Beans exceptions 26 | * are usually fatal; there is no reason for them to be checked. 27 | * 28 | * @author Rod Johnson 29 | * @author Juergen Hoeller 30 | */ 31 | @SuppressWarnings("serial") 32 | public abstract class BeansException extends NestedRuntimeException { 33 | 34 | /** 35 | * Create a new BeansException with the specified message. 36 | * @param msg the detail message 37 | */ 38 | public BeansException(String msg) { 39 | super(msg); 40 | } 41 | 42 | /** 43 | * Create a new BeansException with the specified message 44 | * and root cause. 45 | * @param msg the detail message 46 | * @param cause the root cause 47 | */ 48 | public BeansException(String msg, Throwable cause) { 49 | super(msg, cause); 50 | } 51 | 52 | 53 | @Override 54 | public boolean equals(Object other) { 55 | if (this == other) { 56 | return true; 57 | } 58 | if (!(other instanceof BeansException)) { 59 | return false; 60 | } 61 | BeansException otherBe = (BeansException) other; 62 | return (getMessage().equals(otherBe.getMessage()) && 63 | ObjectUtils.nullSafeEquals(getCause(), otherBe.getCause())); 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | return getMessage().hashCode(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/persist/actions/operation/InsertOperation.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.persist.actions.operation; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.concur.meta.client.api.persist.PersistAction; 6 | import com.concur.meta.client.constants.DataSourceType; 7 | import com.concur.meta.client.dataobject.MetaRequest; 8 | import com.concur.meta.client.dataobject.MetaRequestCreator; 9 | import com.concur.meta.client.dataobject.MetaResponse; 10 | import com.concur.meta.client.exception.ExecuteException; 11 | 12 | /** 13 | * 写入原子操作 14 | * 15 | * @author yongfu.cyf 16 | * @create 2017-09-22 上午12:17 17 | **/ 18 | public class InsertOperation extends AbstractOperation { 19 | 20 | MetaRequest request; 21 | 22 | MetaResponse response; 23 | 24 | 25 | public InsertOperation(Long dataSourceId, Serializable instance, PersistAction undoAction) { 26 | super(dataSourceId); 27 | MetaRequest request = MetaRequestCreator.create(instance); 28 | DataSourceType dataSourceType = getDataSourceType(); 29 | request.setDataSourceType(dataSourceType); 30 | request.setDataSourceId(dataSourceId); 31 | this.request = request; 32 | this.undoOperation = undoAction.getUniqueOperation(); 33 | } 34 | 35 | 36 | @Override 37 | public InsertOperation operate() { 38 | MetaResponse response = getWriteServerService().insert(request); 39 | if (response.isFailured()) { 40 | throw new ExecuteException(response.getResultCode(), response.getErrorMsg()); 41 | } 42 | this.response = response; 43 | return this; 44 | } 45 | 46 | 47 | @Override 48 | public MetaResponse getResponse() { 49 | return this.response; 50 | } 51 | 52 | @Override 53 | public boolean isSuccess() { 54 | return response != null && response.getResult() != null; 55 | } 56 | 57 | @Override 58 | public String toDetailMessage() { 59 | return new StringBuilder("insert result:") 60 | .append(response != null ? response.getResult():null).toString(); 61 | } 62 | 63 | public InsertOperation setResponse(MetaResponse response) { 64 | this.response = response; 65 | return this; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/persist/actions/operation/BatchInsertOperation.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.persist.actions.operation; 2 | 3 | import java.util.Collection; 4 | 5 | import com.concur.meta.client.dataobject.MetaRequestCreator; 6 | import com.concur.meta.client.dataobject.MetaResponse; 7 | import com.concur.meta.client.constants.DataSourceType; 8 | import com.concur.meta.client.dataobject.MetaRequest; 9 | import com.concur.meta.client.exception.ExecuteException; 10 | 11 | /** 12 | * 批量写入原子操作 13 | * 14 | * @author yongfu.cyf 15 | * @create 2017-09-22 下午2:40 16 | **/ 17 | public class BatchInsertOperation extends AbstractOperation { 18 | 19 | MetaRequest request; 20 | 21 | MetaResponse response; 22 | 23 | private int instanceCount; 24 | 25 | public BatchInsertOperation(Long dataSourceId, Collection instances) { 26 | super(dataSourceId); 27 | this.instanceCount = instances.size(); 28 | MetaRequest request = MetaRequestCreator.create(instances); 29 | DataSourceType dataSourceType = getDataSourceType(); 30 | request.setDataSourceType(dataSourceType); 31 | request.setDataSourceId(dataSourceId); 32 | this.request = request; 33 | } 34 | 35 | @Override 36 | public BatchInsertOperation operate() { 37 | MetaResponse response = getWriteServerService().batchInsert(request); 38 | if (response.isFailured()) { 39 | throw new ExecuteException(response.getResultCode(), response.getErrorMsg()); 40 | } 41 | this.response = response; 42 | return this; 43 | } 44 | 45 | @Override 46 | public MetaResponse getResponse() { 47 | return this.response; 48 | } 49 | 50 | @Override 51 | public boolean isSuccess() { 52 | if (response == null) { 53 | return false; 54 | } 55 | Integer result = (Integer) response.getResult(); 56 | if (result != null && result >= instanceCount) { 57 | return true; 58 | } 59 | return false; 60 | } 61 | 62 | @Override 63 | public String toDetailMessage() { 64 | return new StringBuilder("batch insert count:") 65 | .append(response != null ? response.getResult():null).toString(); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/extension/postgre/actions/PostgresSqlInsertAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.extension.postgre.actions; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map; 5 | 6 | import com.concur.meta.client.constants.DataSourceType; 7 | import com.concur.meta.client.dataobject.MetaRequest; 8 | import com.concur.meta.core.dbengine.execute.SqlMapper; 9 | import com.concur.meta.core.dbengine.factory.MetaDatasource; 10 | import com.concur.meta.core.dbengine.execute.ActionTemplate; 11 | import com.concur.meta.core.dbengine.execute.WriteAction; 12 | import com.concur.meta.core.dbengine.factory.MetaDataFactory; 13 | import com.concur.meta.core.dbengine.meta.TableMeta; 14 | import org.apache.ibatis.session.SqlSessionFactory; 15 | import org.apache.ibatis.session.TransactionIsolationLevel; 16 | 17 | /** 18 | * PostgreSql写入操作 19 | * PG 不支持return ID 20 | * 21 | * @author yongfu.cyf 22 | * @create 2017-09-07 上午10:29 23 | **/ 24 | public class PostgresSqlInsertAction extends ActionTemplate implements WriteAction { 25 | 26 | public PostgresSqlInsertAction(MetaDataFactory metaDataFactory, SqlSessionFactory sqlSessionFactory) { 27 | this.metaDataFactory = metaDataFactory; 28 | this.sqlSessionFactory = sqlSessionFactory; 29 | } 30 | 31 | @Override 32 | public boolean support(DataSourceType type) { 33 | return DataSourceType.POSTGRESQL.equals(type); 34 | } 35 | 36 | @Override 37 | protected TransactionIsolationLevel getTransactionIsolationLevel() { 38 | return TransactionIsolationLevel.READ_COMMITTED; 39 | } 40 | 41 | @Override 42 | protected Object executeInner(MetaRequest request, MetaDatasource metaDatasource, 43 | SqlMapper sqlMapper, TableMeta tableMeta) { 44 | // 获取表元数据信息 45 | String sql = metaDatasource.getSqlBuilder().buildInsert(tableMeta, request); 46 | 47 | Map paramMap = metaDatasource.getParameterBuilder().forModelInsert(tableMeta, request); 48 | 49 | // PG 不支持return ID (keyProperty传null) 50 | int count = sqlMapper.insert(sql, paramMap, null); 51 | sqlMapper.commit(); 52 | if (count > 0) { 53 | return paramMap; 54 | } 55 | return null; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/persist/actions/BatchInsertAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.persist.actions; 2 | 3 | import java.util.Collection; 4 | 5 | import com.concur.meta.client.api.persist.PersistAction; 6 | import com.concur.meta.client.api.persist.actions.operation.AbstractOperation; 7 | import com.concur.meta.client.api.persist.actions.operation.BatchInsertOperation; 8 | import com.concur.meta.client.dataobject.MetaResponse; 9 | import org.apache.commons.collections.CollectionUtils; 10 | 11 | /** 12 | * 批量添加动作 13 | * 14 | * @author yongfu.cyf 15 | * @create 2017-07-12 上午11:00 16 | **/ 17 | public class BatchInsertAction extends PersistAction { 18 | 19 | private static final long serialVersionUID = 2590278481602205628L; 20 | /** 21 | * 实例集合 22 | */ 23 | private Collection instances; 24 | 25 | /** 26 | * 构造方法 27 | * @param instances 添加对象集合 28 | */ 29 | public BatchInsertAction(Collection instances) { 30 | this.instances = instances; 31 | } 32 | 33 | @Override 34 | public void execute() { 35 | if (!CollectionUtils.isEmpty(instances)) { 36 | AbstractOperation abstractOperation = getUniqueOperation(); 37 | abstractOperation.operateWithStatus(); 38 | resolveResult(abstractOperation.getResponse()); 39 | } 40 | } 41 | 42 | @Override 43 | public AbstractOperation initOperation() { 44 | return new BatchInsertOperation(this.dataSourceId, this.instances); 45 | } 46 | 47 | @Override 48 | public void resolveResult(MetaResponse response) { 49 | if (response == null) { 50 | this.count = 0; 51 | return; 52 | } 53 | Integer result = (Integer) response.getResult(); 54 | if (result != null) { 55 | this.count = result; 56 | } else { 57 | this.count = 0; 58 | } 59 | this.result = this.count; 60 | } 61 | 62 | @Override 63 | public boolean isSuccess() { 64 | return this.count >= this.instances.size(); 65 | } 66 | 67 | public Collection getInstances() { 68 | return instances; 69 | } 70 | 71 | public void setInstances(Collection instances) { 72 | this.instances = instances; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/execute/actions/AggQueryAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.execute.actions; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.concur.meta.client.api.query.QueryParam; 8 | import com.concur.meta.client.constants.ParamKeys; 9 | import com.concur.meta.client.constants.QueryType; 10 | import com.concur.meta.client.dataobject.MetaRequest; 11 | import com.concur.meta.client.dataobject.ResponseResult; 12 | import com.concur.meta.core.dbengine.execute.QueryAction; 13 | import com.concur.meta.core.dbengine.factory.MetaDatasource; 14 | import com.concur.meta.core.dbengine.factory.MetaDataFactory; 15 | import com.concur.meta.core.dbengine.meta.TableMeta; 16 | import com.concur.meta.core.dbengine.execute.ActionTemplate; 17 | import com.concur.meta.core.dbengine.execute.SqlMapper; 18 | import org.apache.ibatis.session.SqlSessionFactory; 19 | 20 | /** 21 | * 聚合查询Action 22 | * 23 | * @author yongfu.cyf 24 | * @create 2017-08-23 下午12:00 25 | **/ 26 | public class AggQueryAction extends ActionTemplate implements QueryAction { 27 | 28 | public AggQueryAction(MetaDataFactory metaDataFactory, SqlSessionFactory sqlSessionFactory) { 29 | this.metaDataFactory = metaDataFactory; 30 | this.sqlSessionFactory = sqlSessionFactory; 31 | } 32 | 33 | @Override 34 | public boolean support(QueryType type) { 35 | return QueryType.AggQuery == type; 36 | } 37 | 38 | @Override 39 | protected Object executeInner(MetaRequest request, MetaDatasource metaDatasource, 40 | SqlMapper sqlMapper, TableMeta tableMeta) { 41 | // 构建Sql 42 | String querySql = metaDatasource.getSqlBuilder().buildQuery(tableMeta, request); 43 | Map paramMap = metaDatasource.getParameterBuilder().forModelQuery(tableMeta, request); 44 | // 执行查询 45 | List> result = sqlMapper.selectList(querySql, paramMap); 46 | 47 | // 字段名转换 48 | result = metaDatasource.getColumnMapper().mapRows(result); 49 | // 返回结果 50 | QueryParam queryParam = (QueryParam) request.getParam(ParamKeys.QUERY_PARAM); 51 | return new ResponseResult(queryParam, -1, result); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/execute/actions/SqlQueryAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.execute.actions; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.concur.meta.client.api.query.QueryParam; 8 | import com.concur.meta.client.constants.ParamKeys; 9 | import com.concur.meta.client.constants.QueryType; 10 | import com.concur.meta.client.dataobject.MetaRequest; 11 | import com.concur.meta.client.dataobject.ResponseResult; 12 | import com.concur.meta.core.dbengine.execute.QueryAction; 13 | import com.concur.meta.core.dbengine.factory.MetaDatasource; 14 | import com.concur.meta.core.dbengine.factory.MetaDataFactory; 15 | import com.concur.meta.core.dbengine.execute.ActionTemplate; 16 | import com.concur.meta.core.dbengine.execute.SqlMapper; 17 | import com.concur.meta.core.dbengine.meta.TableMeta; 18 | import org.apache.ibatis.session.SqlSessionFactory; 19 | 20 | /** 21 | * Sql查询Action 22 | * 23 | * @author yongfu.cyf 24 | * @create 2017-08-23 下午12:00 25 | **/ 26 | public class SqlQueryAction extends ActionTemplate implements QueryAction { 27 | 28 | public SqlQueryAction(MetaDataFactory metaDataFactory, SqlSessionFactory sqlSessionFactory) { 29 | this.metaDataFactory = metaDataFactory; 30 | this.sqlSessionFactory = sqlSessionFactory; 31 | } 32 | 33 | @Override 34 | public boolean support(QueryType type) { 35 | return QueryType.SqlQuery == type; 36 | } 37 | 38 | @Override 39 | protected Object executeInner(MetaRequest request, MetaDatasource metaDatasource, SqlMapper sqlMapper, TableMeta tableMeta) { 40 | QueryParam queryParam = (QueryParam) request.getParam(ParamKeys.QUERY_PARAM); 41 | // 获取表元数据信息 42 | String querySql = queryParam.getSql(); 43 | Map paramMap = queryParam.getSqlParams(); 44 | 45 | List> result = sqlMapper.selectList(querySql, paramMap); 46 | // 字段名转换 47 | result = metaDatasource.getColumnMapper().mapRows(result); 48 | // 返回结果 49 | return new ResponseResult(queryParam, -1, result); 50 | } 51 | 52 | @Override 53 | protected TableMeta getTableMeta(MetaRequest request, MetaDatasource metaDatasource) { 54 | return null; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/StringToEnumConverterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2013 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 20 | import com.concur.meta.client.conversion.conveters.spring.converter.ConverterFactory; 21 | import com.concur.meta.client.utils.Assert; 22 | 23 | /** 24 | * Converts from a String to a java.lang.Enum by calling {@link Enum#valueOf(Class, String)}. 25 | * 26 | * @author Keith Donald 27 | * @since 3.0 28 | */ 29 | @SuppressWarnings({ "unchecked", "rawtypes" }) 30 | final class StringToEnumConverterFactory implements ConverterFactory { 31 | 32 | @Override 33 | public Converter getConverter(Class targetType) { 34 | Class enumType = targetType; 35 | while(enumType != null && !enumType.isEnum()) { 36 | enumType = enumType.getSuperclass(); 37 | } 38 | Assert.notNull(enumType, "The target type " + targetType.getName() 39 | + " does not refer to an enum"); 40 | return new StringToEnum(enumType); 41 | } 42 | 43 | private class StringToEnum implements Converter { 44 | 45 | private final Class enumType; 46 | 47 | public StringToEnum(Class enumType) { 48 | this.enumType = enumType; 49 | } 50 | 51 | @Override 52 | public T convert(String source) { 53 | if (source.length() == 0) { 54 | // It's an empty enum identifier: reset the enum value to null. 55 | return null; 56 | } 57 | return (T) Enum.valueOf(this.enumType, source.trim()); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /model-core/src/main/resources/lmodel-application.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/CharacterToNumberFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.utils.NumberUtils; 20 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 21 | import com.concur.meta.client.conversion.conveters.spring.converter.ConverterFactory; 22 | 23 | /** 24 | * Converts from a Character to any JDK-standard Number implementation. 25 | * 26 | *

    Support Number classes including Byte, Short, Integer, Float, Double, Long, BigInteger, BigDecimal. This class 27 | * delegates to {@link NumberUtils#convertNumberToTargetClass(Number, Class)} to perform the conversion. 28 | * 29 | * @author Keith Donald 30 | * @since 3.0 31 | * @see Byte 32 | * @see Short 33 | * @see Integer 34 | * @see Long 35 | * @see java.math.BigInteger 36 | * @see Float 37 | * @see Double 38 | * @see java.math.BigDecimal 39 | * @see NumberUtils 40 | */ 41 | final class CharacterToNumberFactory implements ConverterFactory { 42 | 43 | @Override 44 | public Converter getConverter(Class targetType) { 45 | return new CharacterToNumber(targetType); 46 | } 47 | 48 | private static final class CharacterToNumber implements Converter { 49 | 50 | private final Class targetType; 51 | 52 | public CharacterToNumber(Class targetType) { 53 | this.targetType = targetType; 54 | } 55 | 56 | @Override 57 | public T convert(Character source) { 58 | return NumberUtils.convertNumberToTargetClass((short) source.charValue(), this.targetType); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/logger/LogableDynamicDBDataSource.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.logger; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | import com.concur.meta.core.dbengine.execute.ExecuteContext; 7 | import com.concur.meta.core.dbengine.execute.routing.DynamicDBDataSource; 8 | import org.apache.ibatis.logging.Log; 9 | 10 | /** 11 | * 包含日志的动态数据源 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-09-16 下午9:06 15 | **/ 16 | public class LogableDynamicDBDataSource extends DynamicDBDataSource { 17 | 18 | @Override 19 | public Connection getConnection() throws SQLException { 20 | Connection connection = super.getConnection(); 21 | if (ExecuteContext.isShowLog()) { 22 | return ConnectionLogger.newInstance(connection, new ProxyLogger(), 0); 23 | } else { 24 | return connection; 25 | } 26 | } 27 | 28 | @Override 29 | public Connection getConnection(String username, String password) throws SQLException { 30 | Connection connection = super.getConnection(username, password); 31 | if (ExecuteContext.isShowLog()) { 32 | return ConnectionLogger.newInstance(connection, new ProxyLogger(), 0); 33 | } else { 34 | return connection; 35 | } 36 | } 37 | 38 | 39 | private static class ProxyLogger implements Log { 40 | 41 | @Override 42 | public boolean isDebugEnabled() { 43 | return true; 44 | } 45 | 46 | @Override 47 | public boolean isTraceEnabled() { 48 | return true; 49 | } 50 | 51 | @Override 52 | public void error(String s, Throwable e) { 53 | ExecuteContext.appendLog("ERROR:" + s); 54 | 55 | } 56 | 57 | @Override 58 | public void error(String s) { 59 | ExecuteContext.appendLog("ERROR:" + s); 60 | } 61 | 62 | @Override 63 | public void debug(String s) { 64 | ExecuteContext.appendLog("DEBUG:" + s); 65 | } 66 | 67 | @Override 68 | public void trace(String s) { 69 | ExecuteContext.appendLog("TRACE:" + s); 70 | } 71 | 72 | @Override 73 | public void warn(String s) { 74 | ExecuteContext.appendLog("WARN:" + s); 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/StringToNumberConverterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.converter.Converter; 20 | import com.concur.meta.client.conversion.conveters.spring.converter.ConverterFactory; 21 | import com.concur.meta.client.utils.NumberUtils; 22 | 23 | /** 24 | * Converts from a String any JDK-standard Number implementation. 25 | * 26 | *

    Support Number classes including Byte, Short, Integer, Float, Double, Long, BigInteger, BigDecimal. This class 27 | * delegates to {@link NumberUtils#parseNumber(String, Class)} to perform the conversion. 28 | * 29 | * @author Keith Donald 30 | * @since 3.0 31 | * @see Byte 32 | * @see Short 33 | * @see Integer 34 | * @see Long 35 | * @see java.math.BigInteger 36 | * @see Float 37 | * @see Double 38 | * @see java.math.BigDecimal 39 | * @see NumberUtils 40 | */ 41 | final class StringToNumberConverterFactory implements ConverterFactory { 42 | 43 | @Override 44 | public Converter getConverter(Class targetType) { 45 | return new StringToNumber(targetType); 46 | } 47 | 48 | private static final class StringToNumber implements Converter { 49 | 50 | private final Class targetType; 51 | 52 | public StringToNumber(Class targetType) { 53 | this.targetType = targetType; 54 | } 55 | 56 | @Override 57 | public T convert(String source) { 58 | if (source.length() == 0) { 59 | return null; 60 | } 61 | return NumberUtils.parseNumber(source, this.targetType); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/query/AbstractQuery.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.query; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.concur.meta.client.constants.QueryType; 6 | 7 | /** 8 | * 查询基础类 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-08-01 上午10:07 12 | **/ 13 | public abstract class AbstractQuery implements Serializable { 14 | 15 | private static final long serialVersionUID = -3087580292926609230L; 16 | /** 17 | * 查询的类 18 | */ 19 | protected Class clazz; 20 | /** 21 | * 查询参数 22 | */ 23 | protected QueryParam queryParam; 24 | /** 25 | * 数据源ID 26 | */ 27 | protected Long dataSourceId; 28 | /** 29 | * 模型编码 30 | */ 31 | public String code; 32 | 33 | public Long getDataSourceId() { 34 | return dataSourceId; 35 | } 36 | 37 | /** 38 | * 获取参数构造链 39 | * @return 40 | */ 41 | public QueryParam params() { 42 | return this.getQueryParam(); 43 | } 44 | 45 | public Class getClazz() { 46 | return clazz; 47 | } 48 | 49 | public QueryParam getQueryParam() { 50 | return queryParam; 51 | } 52 | 53 | /** 54 | * 获取查询类型 55 | * @return 56 | */ 57 | public abstract QueryType getQueryType(); 58 | 59 | public String getCode() { 60 | return code; 61 | } 62 | 63 | @Override 64 | public boolean equals(Object o) { 65 | if (this == o) { return true; } 66 | if (!(o instanceof AbstractQuery)) { return false; } 67 | 68 | AbstractQuery baseQuery = (AbstractQuery)o; 69 | 70 | if (clazz != null ? !clazz.equals(baseQuery.clazz) : baseQuery.clazz != null) { return false; } 71 | if (queryParam != null ? !queryParam.equals(baseQuery.queryParam) : baseQuery.queryParam != null) { 72 | return false; 73 | } 74 | return dataSourceId != null ? dataSourceId.equals(baseQuery.dataSourceId) : baseQuery.dataSourceId == null; 75 | } 76 | 77 | @Override 78 | public int hashCode() { 79 | int result = clazz != null ? clazz.hashCode() : 0; 80 | result = 31 * result + (queryParam != null ? queryParam.hashCode() : 0); 81 | result = 31 * result + (dataSourceId != null ? dataSourceId.hashCode() : 0); 82 | return result; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/domain/dto/DataSourceDTO.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.domain.dto; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import com.concur.meta.client.domain.ToString; 9 | 10 | /** 11 | * 数据源DTO 12 | * 13 | * @author yongfu.cyf 14 | * @create 2017-07-24 下午8:19 15 | **/ 16 | public class DataSourceDTO extends ToString implements Serializable { 17 | private static final long serialVersionUID = -4952513636068514253L; 18 | 19 | /** 20 | * 空数据源 21 | */ 22 | public static final DataSourceDTO NULL_DATASOURCE = new DataSourceDTO(); 23 | 24 | /** 25 | * 数据源ID 26 | */ 27 | private long id; 28 | 29 | /** 30 | * 创建时间 31 | */ 32 | private Date gmtCreate; 33 | 34 | /** 35 | * 最后修改时间 36 | */ 37 | private Date gmtModified; 38 | 39 | /** 40 | * 数据源名称 41 | */ 42 | private String name; 43 | 44 | /** 45 | * 数据源类型 46 | */ 47 | private String type; 48 | 49 | /** 50 | * 扩展属性 51 | */ 52 | private Map attributes= new HashMap(); 53 | 54 | public long getId() { 55 | return id; 56 | } 57 | 58 | public void setId(long id) { 59 | this.id = id; 60 | } 61 | 62 | public Date getGmtCreate() { 63 | return gmtCreate; 64 | } 65 | 66 | public void setGmtCreate(Date gmtCreate) { 67 | this.gmtCreate = gmtCreate; 68 | } 69 | 70 | public Date getGmtModified() { 71 | return gmtModified; 72 | } 73 | 74 | public void setGmtModified(Date gmtModified) { 75 | this.gmtModified = gmtModified; 76 | } 77 | 78 | public String getName() { 79 | return name; 80 | } 81 | 82 | public void setName(String name) { 83 | this.name = name; 84 | } 85 | 86 | public String getType() { 87 | return type; 88 | } 89 | 90 | public void setType(String type) { 91 | this.type = type; 92 | } 93 | 94 | public Map getAttributes() { 95 | return attributes; 96 | } 97 | 98 | public void setAttributes(Map attributes) { 99 | this.attributes = attributes; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /model-metadata/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | meta-model 8 | com.concur.meta 9 | 1.0.0-SNAPSHOT 10 | 11 | 4.0.0 12 | model-metadata 13 | model-metadata 14 | jar 15 | 16 | UTF-8 17 | 18 | 19 | 20 | com.concur.meta 21 | model-client 22 | 23 | 24 | 25 | org.slf4j 26 | slf4j-api 27 | 28 | 29 | org.slf4j 30 | jcl-over-slf4j 31 | 32 | 33 | ch.qos.logback 34 | logback-classic 35 | 36 | 37 | ch.qos.logback 38 | logback-core 39 | 40 | 41 | ch.qos.logback 42 | logback-access 43 | 44 | 45 | org.slf4j 46 | log4j-over-slf4j 47 | 48 | 49 | org.aspectj 50 | aspectjtools 51 | 52 | 53 | org.springframework 54 | spring-context-support 55 | 56 | 57 | org.springframework 58 | spring-jdbc 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /model-metadata/src/main/java/com/concur/meta/metadata/service/impl/LMetaServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.metadata.service.impl; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | import com.concur.meta.client.api.persist.Persist; 7 | import com.concur.meta.client.api.query.Query; 8 | import com.concur.meta.metadata.domain.MetaModelColDO; 9 | import com.concur.meta.metadata.domain.MetaModelDO; 10 | import com.concur.meta.metadata.service.LMetaService; 11 | 12 | /** 13 | * LModel元数据模型服务接口实现 14 | * 15 | * @author yongfu.cyf 16 | * @create 2017-07-03 下午7:43 17 | **/ 18 | public class LMetaServiceImpl implements LMetaService { 19 | 20 | private static final String CLASS_NAME = "className"; 21 | 22 | private static final String MODEL_ID = "modelId"; 23 | 24 | private static final String MODEL_PRIMARY_KEY = "id"; 25 | 26 | @Override 27 | public List list() { 28 | return Query.create(MetaModelDO.class) 29 | .execute().getList(); 30 | } 31 | 32 | @Override 33 | public MetaModelDO getByClassName(String className) { 34 | return Query.create(MetaModelDO.class) 35 | .condition(CLASS_NAME, className) 36 | .execute().getOne(); 37 | } 38 | 39 | @Override 40 | public List listColByClass(String className) { 41 | MetaModelDO lmodelDO = 42 | Query.create(MetaModelDO.class) 43 | .condition(CLASS_NAME, className) 44 | .execute().getOne(); 45 | 46 | if (lmodelDO == null) { 47 | return Collections.emptyList(); 48 | } 49 | 50 | return Query.create(MetaModelColDO.class) 51 | .condition(MODEL_ID, lmodelDO.getId()) 52 | .execute().getList(); 53 | } 54 | 55 | @Override 56 | public MetaModelDO add(MetaModelDO lModelDO) { 57 | return Persist.create(MetaModelDO.class).insert(lModelDO).getResult(); 58 | } 59 | 60 | @Override 61 | public MetaModelDO get(Long id) { 62 | return Query.create(MetaModelDO.class).get(id).execute().getOne(); 63 | } 64 | 65 | @Override 66 | public void update(MetaModelDO lModelDO) { 67 | Persist.create(MetaModelDO.class).update(lModelDO); 68 | } 69 | 70 | @Override 71 | public void delete(MetaModelDO lModelDO) { 72 | Persist.create(MetaModelDO.class).delete(lModelDO); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/persist/actions/operation/UpdateOperation.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.persist.actions.operation; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.concur.meta.client.dataobject.MetaResponse; 6 | import com.concur.meta.client.constants.DataSourceType; 7 | import com.concur.meta.client.dataobject.MetaRequest; 8 | import com.concur.meta.client.dataobject.MetaRequestCreator; 9 | import com.concur.meta.client.exception.ExecuteException; 10 | 11 | /** 12 | * 更新原子性操作 13 | * 14 | * @author yongfu.cyf 15 | * @create 2017-09-22 下午3:27 16 | **/ 17 | public class UpdateOperation extends AbstractOperation { 18 | 19 | MetaRequest request; 20 | 21 | MetaResponse response; 22 | 23 | private boolean selective; 24 | 25 | public UpdateOperation(Long dataSourceId, T instance, boolean selective, Serializable lastVersion) { 26 | super(dataSourceId); 27 | this.selective = selective; 28 | MetaRequest request = MetaRequestCreator.create(instance, lastVersion); 29 | DataSourceType dataSourceType = getDataSourceType(); 30 | request.setDataSourceType(dataSourceType); 31 | request.setDataSourceId(dataSourceId); 32 | this.request = request; 33 | } 34 | 35 | @Override 36 | public AbstractOperation operate() { 37 | if (this.selective) { 38 | this.response = getWriteServerService().updateSelective(request); 39 | } else { 40 | this.response = getWriteServerService().update(request); 41 | } 42 | if (this.response.isFailured()) { 43 | throw new ExecuteException(this.response.getResultCode(), this.response.getErrorMsg()); 44 | } 45 | return this; 46 | } 47 | 48 | @Override 49 | public MetaResponse getResponse() { 50 | return this.response; 51 | } 52 | 53 | @Override 54 | public boolean isSuccess() { 55 | if (response == null) { 56 | return false; 57 | } 58 | Integer result = (Integer) response.getResult(); 59 | if (result == null) { 60 | return false; 61 | } 62 | return result >= 1; 63 | } 64 | 65 | @Override 66 | public String toDetailMessage() { 67 | return new StringBuilder("update count:") 68 | .append(response != null ? response.getResult():null).toString(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/service/impl/BaseMetaDataService.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.service.impl; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | import com.google.common.cache.CacheBuilder; 7 | import com.google.common.cache.LoadingCache; 8 | import com.concur.meta.client.constants.DataSourceType; 9 | import com.concur.meta.client.domain.dto.DataSourceDTO; 10 | import com.concur.meta.client.exception.ExecuteException; 11 | import com.concur.meta.client.result.ClientResultCode; 12 | import com.concur.meta.client.service.ServiceFactory; 13 | import com.concur.meta.client.utils.CacheUtils; 14 | 15 | /** 16 | * 元数据服务读写服务基类 17 | * 18 | * @author yongfu.cyf 19 | * @create 2017-07-25 上午10:42 20 | **/ 21 | public abstract class BaseMetaDataService { 22 | 23 | /** 24 | * 数据源缓存 25 | */ 26 | protected LoadingCache DATASOURCE_CACHE = CacheBuilder.newBuilder() 27 | .concurrencyLevel(4) 28 | .maximumSize(1000) 29 | .refreshAfterWrite(5, TimeUnit.MINUTES) 30 | .build( 31 | new CacheUtils.AsynchronousCacheLoader() { 32 | @Override 33 | public DataSourceDTO load(Long key) { 34 | DataSourceDTO dto = ServiceFactory.getInstance() 35 | .getDataSourceService().getDataSource(key); 36 | if (dto != null) { 37 | return dto; 38 | } 39 | return DataSourceDTO.NULL_DATASOURCE; 40 | } 41 | }); 42 | 43 | /** 44 | * 获取数据源类型 45 | * @param dataSourceId 数据源ID 46 | * @return 47 | */ 48 | public DataSourceType getDataSourceType(Long dataSourceId) { 49 | if (dataSourceId == null) { 50 | return DataSourceType.NULL; 51 | } 52 | DataSourceDTO dataSourceDTO; 53 | try { 54 | dataSourceDTO = DATASOURCE_CACHE.get(dataSourceId); 55 | } catch (ExecutionException e) { 56 | throw new ExecuteException(ClientResultCode.DATA_SOUCE_GET_ERROR); 57 | } 58 | if (dataSourceDTO == null || DataSourceDTO.NULL_DATASOURCE == dataSourceDTO) { 59 | return DataSourceType.NULL; 60 | } 61 | return DataSourceType.getByName(dataSourceDTO.getType()); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/ArrayToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import java.util.Arrays; 20 | import java.util.Collections; 21 | import java.util.Set; 22 | 23 | import com.concur.meta.client.conversion.conveters.spring.ConversionService; 24 | import com.concur.meta.client.utils.ObjectUtils; 25 | import com.concur.meta.client.conversion.conveters.spring.TypeDescriptor; 26 | import com.concur.meta.client.conversion.conveters.spring.converter.ConditionalGenericConverter; 27 | 28 | /** 29 | * Converts an Array to a comma-delimited String. 30 | * This implementation first adapts the source Array to a List, then delegates to {@link CollectionToStringConverter} to perform the target String conversion. 31 | * 32 | * @author Keith Donald 33 | * @since 3.0 34 | */ 35 | final class ArrayToStringConverter implements ConditionalGenericConverter { 36 | 37 | private final CollectionToStringConverter helperConverter; 38 | 39 | public ArrayToStringConverter(ConversionService conversionService) { 40 | this.helperConverter = new CollectionToStringConverter(conversionService); 41 | } 42 | 43 | @Override 44 | public Set getConvertibleTypes() { 45 | return Collections.singleton(new ConvertiblePair(Object[].class, String.class)); 46 | } 47 | 48 | @Override 49 | public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { 50 | return this.helperConverter.matches(sourceType, targetType); 51 | } 52 | 53 | @Override 54 | public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { 55 | return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/execute/actions/BaseInsertAction.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.execute.actions; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map; 5 | 6 | import com.concur.meta.client.constants.DataSourceType; 7 | import com.concur.meta.client.dataobject.MetaRequest; 8 | import com.concur.meta.core.dbengine.execute.ActionTemplate; 9 | import com.concur.meta.core.dbengine.execute.SqlMapper; 10 | import com.concur.meta.core.dbengine.execute.WriteAction; 11 | import com.concur.meta.core.dbengine.factory.MetaDataFactory; 12 | import com.concur.meta.core.dbengine.factory.MetaDatasource; 13 | import com.concur.meta.core.dbengine.meta.ColumnMeta; 14 | import com.concur.meta.core.dbengine.meta.TableMeta; 15 | import org.apache.ibatis.session.SqlSessionFactory; 16 | import org.apache.ibatis.session.TransactionIsolationLevel; 17 | 18 | /** 19 | * Mysql写入操作 20 | * 21 | * @author yongfu.cyf 22 | * @create 2017-09-07 上午10:29 23 | **/ 24 | public class BaseInsertAction extends ActionTemplate implements WriteAction { 25 | 26 | public BaseInsertAction(MetaDataFactory metaDataFactory, SqlSessionFactory sqlSessionFactory) { 27 | this.metaDataFactory = metaDataFactory; 28 | this.sqlSessionFactory = sqlSessionFactory; 29 | } 30 | 31 | @Override 32 | public boolean support(DataSourceType type) { 33 | return true; 34 | } 35 | 36 | @Override 37 | protected TransactionIsolationLevel getTransactionIsolationLevel() { 38 | return TransactionIsolationLevel.READ_COMMITTED; 39 | } 40 | 41 | @Override 42 | public Object executeInner(MetaRequest request, MetaDatasource metaDatasource, 43 | SqlMapper sqlMapper, TableMeta tableMeta) { 44 | String sql = metaDatasource.getSqlBuilder().buildInsert(tableMeta, request); 45 | 46 | Map paramMap = metaDatasource.getParameterBuilder().forModelInsert(tableMeta, request); 47 | ColumnMeta primaryKey = tableMeta.getPrimaryKey(); 48 | 49 | int count = sqlMapper.insert(sql, paramMap, primaryKey.getPropertyName()); 50 | sqlMapper.commit(); 51 | if (count > 0) { 52 | // 获取主键 53 | Serializable primaryValue = paramMap.get(primaryKey.getPropertyName()); 54 | paramMap.put(primaryKey.getPropertyName(), primaryValue); 55 | return paramMap; 56 | } 57 | return null; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/ConversionFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2010 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring; 18 | 19 | import com.concur.meta.client.utils.ObjectUtils; 20 | 21 | /** 22 | * Exception to be thrown when an actual type conversion attempt fails. 23 | * 24 | * @author Keith Donald 25 | * @author Juergen Hoeller 26 | * @since 3.0 27 | */ 28 | @SuppressWarnings("serial") 29 | public final class ConversionFailedException extends ConversionException { 30 | 31 | private final TypeDescriptor sourceType; 32 | 33 | private final TypeDescriptor targetType; 34 | 35 | private final Object value; 36 | 37 | 38 | /** 39 | * Create a new conversion exception. 40 | * @param sourceType the value's original type 41 | * @param targetType the value's target type 42 | * @param value the value we tried to convert 43 | * @param cause the cause of the conversion failure 44 | */ 45 | public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) { 46 | super("Failed to convert from type " + sourceType + " to type " + targetType + " for value '" + ObjectUtils.nullSafeToString(value) + "'", cause); 47 | this.sourceType = sourceType; 48 | this.targetType = targetType; 49 | this.value = value; 50 | } 51 | 52 | 53 | /** 54 | * Return the source type we tried to convert the value from. 55 | */ 56 | public TypeDescriptor getSourceType() { 57 | return this.sourceType; 58 | } 59 | 60 | /** 61 | * Return the target type we tried to convert the value to. 62 | */ 63 | public TypeDescriptor getTargetType() { 64 | return this.targetType; 65 | } 66 | 67 | /** 68 | * Return the offending value. 69 | */ 70 | public Object getValue() { 71 | return this.value; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/ConversionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2011 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.ConversionFailedException; 20 | import com.concur.meta.client.conversion.conveters.spring.ConversionService; 21 | import com.concur.meta.client.conversion.conveters.spring.converter.GenericConverter; 22 | import com.concur.meta.client.conversion.conveters.spring.TypeDescriptor; 23 | 24 | /** 25 | * Internal utilities for the conversion package. 26 | * 27 | * @author Keith Donald 28 | * @since 3.0 29 | */ 30 | abstract class ConversionUtils { 31 | 32 | public static Object invokeConverter(GenericConverter converter, Object source, TypeDescriptor sourceType, 33 | TypeDescriptor targetType) { 34 | try { 35 | return converter.convert(source, sourceType, targetType); 36 | } 37 | catch (ConversionFailedException ex) { 38 | throw ex; 39 | } 40 | catch (Exception ex) { 41 | throw new ConversionFailedException(sourceType, targetType, source, ex); 42 | } 43 | } 44 | 45 | public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType, ConversionService conversionService) { 46 | if (targetElementType == null) { 47 | // yes 48 | return true; 49 | } 50 | if (sourceElementType == null) { 51 | // maybe 52 | return true; 53 | } 54 | if (conversionService.canConvert(sourceElementType, targetElementType)) { 55 | // yes 56 | return true; 57 | } 58 | else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) { 59 | // maybe; 60 | return true; 61 | } 62 | else { 63 | // no; 64 | return false; 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/converter/ConverterRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2009 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.converter; 18 | 19 | /** 20 | * For registering converters with a type conversion system. 21 | * 22 | * @author Keith Donald 23 | * @author Juergen Hoeller 24 | * @since 3.0 25 | */ 26 | public interface ConverterRegistry { 27 | 28 | /** 29 | * Add a plain converter to this registry. 30 | * The convertible sourceType/targetType pair is derived from the Converter's parameterized types. 31 | * @throws IllegalArgumentException if the parameterized types could not be resolved 32 | */ 33 | void addConverter(Converter converter); 34 | 35 | /** 36 | * Add a plain converter to this registry. 37 | * The convertible sourceType/targetType pair is specified explicitly. 38 | * Allows for a Converter to be reused for multiple distinct pairs without having to create a Converter class for each pair. 39 | * @since 3.1 40 | */ 41 | void addConverter(Class sourceType, Class targetType, Converter converter); 42 | 43 | /** 44 | * Add a generic converter to this registry. 45 | */ 46 | void addConverter(GenericConverter converter); 47 | 48 | /** 49 | * Add a ranged converter factory to this registry. 50 | * The convertible sourceType/rangeType pair is derived from the ConverterFactory's parameterized types. 51 | * @throws IllegalArgumentException if the parameterized types could not be resolved. 52 | */ 53 | void addConverterFactory(ConverterFactory converterFactory); 54 | 55 | /** 56 | * Remove any converters from sourceType to targetType. 57 | * @param sourceType the source type 58 | * @param targetType the target type 59 | */ 60 | void removeConvertible(Class sourceType, Class targetType); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/query/RangePair.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.query; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 范围参数 7 | * 8 | * @author yongfu.cyf 9 | * @create 2017-06-29 下午4:30 10 | **/ 11 | public class RangePair implements Serializable { 12 | 13 | private static final long serialVersionUID = 7263103860997238176L; 14 | /** 15 | * 起始值 16 | */ 17 | private Object start; 18 | /** 19 | * 结束值 20 | */ 21 | private Object end; 22 | 23 | /** 24 | * 是否包含起始值 25 | */ 26 | private boolean includeStart = true; 27 | /** 28 | * 是否包含结束值 29 | */ 30 | private boolean includeEnd = false; 31 | 32 | public boolean isIncludeStart() { 33 | return includeStart; 34 | } 35 | 36 | public void setIncludeStart(boolean includeStart) { 37 | this.includeStart = includeStart; 38 | } 39 | 40 | public boolean isIncludeEnd() { 41 | return includeEnd; 42 | } 43 | 44 | public void setIncludeEnd(boolean includeEnd) { 45 | this.includeEnd = includeEnd; 46 | } 47 | 48 | public RangePair(Object start, Object end) { 49 | this.start = start; 50 | this.end = end; 51 | } 52 | 53 | public Object getStart() { 54 | return start; 55 | } 56 | 57 | public void setStart(Object start) { 58 | this.start = start; 59 | } 60 | 61 | public Object getEnd() { 62 | return end; 63 | } 64 | 65 | public void setEnd(Object end) { 66 | this.end = end; 67 | } 68 | 69 | @Override 70 | public boolean equals(Object o) { 71 | if (this == o) { return true; } 72 | if (!(o instanceof RangePair)) { return false; } 73 | 74 | RangePair rangePair = (RangePair)o; 75 | 76 | if (includeStart != rangePair.includeStart) { return false; } 77 | if (includeEnd != rangePair.includeEnd) { return false; } 78 | if (start != null ? !start.equals(rangePair.start) : rangePair.start != null) { return false; } 79 | return end != null ? end.equals(rangePair.end) : rangePair.end == null; 80 | } 81 | 82 | @Override 83 | public int hashCode() { 84 | int result = start != null ? start.hashCode() : 0; 85 | result = 31 * result + (end != null ? end.hashCode() : 0); 86 | result = 31 * result + (includeStart ? 1 : 0); 87 | result = 31 * result + (includeEnd ? 1 : 0); 88 | return result; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/converter/ConditionalConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2014 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.converter; 18 | 19 | import com.concur.meta.client.conversion.conveters.spring.TypeDescriptor; 20 | 21 | /** 22 | * Allows a {@link Converter}, {@link GenericConverter} or {@link ConverterFactory} to 23 | * conditionally execute based on attributes of the {@code source} and {@code target} 24 | * {@link TypeDescriptor}. 25 | * 26 | *

    Often used to selectively match custom conversion logic based on the presence of a 27 | * field or class-level characteristic, such as an annotation or method. For example, when 28 | * converting from a String field to a Date field, an implementation might return 29 | * {@code true} if the target field has also been annotated with {@code @DateTimeFormat}. 30 | * 31 | *

    As another example, when converting from a String field to an {@code Account} field, 32 | * an implementation might return {@code true} if the target Account class defines a 33 | * {@code public static findAccount(String)} method. 34 | * 35 | * @author Phillip Webb 36 | * @author Keith Donald 37 | * @since 3.2 38 | * @see Converter 39 | * @see GenericConverter 40 | * @see ConverterFactory 41 | * @see ConditionalGenericConverter 42 | */ 43 | public interface ConditionalConverter { 44 | 45 | /** 46 | * Should the conversion from {@code sourceType} to {@code targetType} currently under 47 | * consideration be selected? 48 | * @param sourceType the type descriptor of the field we are converting from 49 | * @param targetType the type descriptor of the field we are converting to 50 | * @return true if conversion should be performed, false otherwise 51 | */ 52 | boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/api/query/SqlQuery.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.client.api.query; 2 | 3 | import java.io.Serializable; 4 | import java.util.Map; 5 | 6 | import com.concur.meta.client.api.result.SqlResult; 7 | import com.concur.meta.client.dataobject.ResponseResult; 8 | import com.concur.meta.client.service.ServiceFactory; 9 | import com.concur.meta.client.constants.QueryType; 10 | 11 | /** 12 | * SQL查询 13 | * 支持模型名到表名、属性名到属性名的替换 14 | * 1.${StoreRelation} : ot_store_relation表 15 | * 2.${StoreRelation.*} : ot_store_relation表的所有字段 16 | * 3.${StoreRelation.storeId} : ot_store_relation.store_id字段 17 | * @author yongfu.cyf 18 | * @create 2017-08-23 上午10:48 19 | **/ 20 | public class SqlQuery extends AbstractQuery { 21 | 22 | SqlQuery() { 23 | } 24 | 25 | SqlQuery(Query fromQuery, String sql) { 26 | this.clazz = (Class) fromQuery.getClazz(); 27 | this.dataSourceId = fromQuery.dataSourceId; 28 | this.queryParam = new QueryParam(); 29 | this.queryParam.setSql(sql); 30 | } 31 | 32 | /** 33 | * 指定数据源ID 34 | * @param dataSourceId Long 35 | * @return 36 | */ 37 | public SqlQuery dataSource(Long dataSourceId) { 38 | this.dataSourceId = dataSourceId; 39 | return this; 40 | } 41 | 42 | /** 43 | * 指定参数 44 | * @param params 参数 45 | * @return 46 | */ 47 | public SqlQuery params(Map params) { 48 | Map sqlParams = this.queryParam.getSqlParams(); 49 | sqlParams.putAll(params); 50 | return this; 51 | } 52 | 53 | /** 54 | * 指定参数 55 | * @param key 参数的key(属性名) 56 | * @param value 参数值 57 | * @return 58 | */ 59 | public SqlQuery param(String key, Serializable value) { 60 | Map sqlParams = this.queryParam.getSqlParams(); 61 | sqlParams.put(key, value); 62 | return this; 63 | } 64 | 65 | /** 66 | * 执行查询 67 | * @return 68 | */ 69 | public SqlResult execute() { 70 | return new SqlResult(this.clazz, new ClientQueryAction() { 71 | @Override 72 | public ResponseResult doQuery() { 73 | return ServiceFactory.getInstance() 74 | .getMetaDataReadService().query(SqlQuery.this); 75 | } 76 | }); 77 | } 78 | 79 | @Override 80 | public QueryType getQueryType() { 81 | return QueryType.SqlQuery; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /model-core/src/main/java/com/concur/meta/core/dbengine/sql/sqlbuilder/SqlBuilder.java: -------------------------------------------------------------------------------- 1 | package com.concur.meta.core.dbengine.sql.sqlbuilder; 2 | 3 | import com.concur.meta.client.dataobject.MetaRequest; 4 | import com.concur.meta.core.dbengine.sql.dialect.Dialect; 5 | import com.concur.meta.core.dbengine.meta.TableMeta; 6 | 7 | /** 8 | * SQL生成器接口 9 | * 10 | * @author yongfu.cyf 11 | * @create 2017-06-28 上午10:57 12 | **/ 13 | public interface SqlBuilder { 14 | 15 | /** 16 | * 生成Get的SQL语句 17 | * @param tableMeta 表元信息 18 | * @param metaRequest 元数据请求 19 | * @return SQL语句 20 | */ 21 | String buildGet(TableMeta tableMeta, MetaRequest metaRequest); 22 | 23 | /** 24 | * 生成添加的SQL语句 25 | * @param tableMeta 表元信息 26 | * @param metaRequest 元数据请求 27 | * @return SQL语句 28 | */ 29 | String buildInsert(TableMeta tableMeta, MetaRequest metaRequest); 30 | 31 | /** 32 | * 生成更新的SQL语句 33 | * @param tableMeta 表元信息 34 | * @param metaRequest 元数据请求 35 | * @return SQL语句 36 | */ 37 | String buildUpdate(TableMeta tableMeta, MetaRequest metaRequest); 38 | 39 | /** 40 | * 生成部分字段更新的SQL语句 41 | * @param tableMeta 表元信息 42 | * @param metaRequest 元数据请求 43 | * @return SQL语句 44 | */ 45 | String buildUpdateSelective(TableMeta tableMeta, MetaRequest metaRequest); 46 | 47 | /** 48 | * 生成删除的SQL语句 49 | * @param tableMeta 表元信息 50 | * @param metaRequest 元数据请求 51 | * @return SQL语句 52 | */ 53 | String buildDelete(TableMeta tableMeta, MetaRequest metaRequest); 54 | 55 | /** 56 | * 生成分页查询的SQL语句 57 | * @param tableMeta 表元信息 58 | * @param metaRequest 元数据请求 59 | * @return SQL语句 60 | */ 61 | String buildQuery(TableMeta tableMeta, MetaRequest metaRequest); 62 | 63 | /** 64 | * 生成统计数量查询的SQL语句 65 | * @param tableMeta 表元信息 66 | * @param metaRequest 元数据请求 67 | * @return SQL语句 68 | */ 69 | String buildCount(TableMeta tableMeta, MetaRequest metaRequest); 70 | 71 | /** 72 | * 生成批量添加的SQL语句 73 | * @param tableMeta 表元信息 74 | * @param metaRequest 元数据请求 75 | * @return SQL语句 76 | */ 77 | String buildBatchInsert(TableMeta tableMeta, MetaRequest metaRequest); 78 | 79 | /** 80 | * 生成批量删除的SQL语句 81 | * @param tableMeta 表元信息 82 | * @param metaRequest 元数据请求 83 | * @return SQL语句 84 | */ 85 | String buildBatchDelete(TableMeta tableMeta, MetaRequest metaRequest); 86 | 87 | /** 88 | * 获取字典 89 | * @return 当前使用的Dialect 90 | */ 91 | Dialect getDialect(); 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /model-client/src/main/java/com/concur/meta/client/conversion/conveters/spring/support/ObjectToArrayConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2012 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.concur.meta.client.conversion.conveters.spring.support; 18 | 19 | import java.lang.reflect.Array; 20 | import java.util.Collections; 21 | import java.util.Set; 22 | 23 | import com.concur.meta.client.conversion.conveters.spring.ConversionService; 24 | import com.concur.meta.client.conversion.conveters.spring.converter.ConditionalGenericConverter; 25 | import com.concur.meta.client.conversion.conveters.spring.TypeDescriptor; 26 | 27 | /** 28 | * Converts an Object to a single-element Array containing the Object. 29 | * Will convert the Object to the target Array's component type if necessary. 30 | * 31 | * @author Keith Donald 32 | * @since 3.0 33 | */ 34 | final class ObjectToArrayConverter implements ConditionalGenericConverter { 35 | 36 | private final ConversionService conversionService; 37 | 38 | public ObjectToArrayConverter(ConversionService conversionService) { 39 | this.conversionService = conversionService; 40 | } 41 | 42 | @Override 43 | public Set getConvertibleTypes() { 44 | return Collections.singleton(new ConvertiblePair(Object.class, Object[].class)); 45 | } 46 | 47 | @Override 48 | public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { 49 | return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), this.conversionService); 50 | } 51 | 52 | @Override 53 | public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { 54 | if (source == null) { 55 | return null; 56 | } 57 | Object target = Array.newInstance(targetType.getElementTypeDescriptor().getType(), 1); 58 | Object targetElement = this.conversionService.convert(source, sourceType, targetType.getElementTypeDescriptor()); 59 | Array.set(target, 0, targetElement); 60 | return target; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /model-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | meta-model 7 | com.concur.meta 8 | 1.0.0-SNAPSHOT 9 | 10 | model-client 11 | model-client 12 | 1.0.0-SNAPSHOT 13 | jar 14 | 15 | 16 | UTF-8 17 | 1.6 18 | 19 | 20 | 21 | commons-lang 22 | commons-lang 23 | 2.6 24 | 25 | 26 | org.slf4j 27 | slf4j-api 28 | 1.6.1 29 | true 30 | 31 | 32 | com.google.guava 33 | guava 34 | 20.0 35 | 36 | 37 | commons-collections 38 | commons-collections 39 | 3.2.2 40 | 41 | 42 | com.alibaba 43 | fastjson 44 | 1.2.8.sec01 45 | 46 | 47 | commons-beanutils 48 | commons-beanutils 49 | 1.9.3 50 | 51 | 52 | org.reflections 53 | reflections 54 | 0.9.10 55 | 56 | 57 | 58 | 59 | 60 | org.apache.maven.plugins 61 | maven-compiler-plugin 62 | 63 | ${project.jdk.version} 64 | ${project.jdk.version} 65 | ${project.build.sourceEncoding} 66 | 67 | 68 | 69 | 70 | 71 | --------------------------------------------------------------------------------