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