├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── ddal-bom └── pom.xml ├── ddal-core ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── hellojavaer │ └── ddal │ └── core │ └── utils │ └── Assert.java ├── ddal-datasource ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── datasource │ │ ├── DDALDataSource.java │ │ ├── DefaultDDALDataSource.java │ │ └── spring │ │ └── DDALBeanInfoFactory.java │ └── resources │ └── META-INF │ └── spring.factories ├── ddal-ddr ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── ddr │ │ ├── cluster │ │ ├── DBClusterManager.java │ │ ├── DBClusterRoute.java │ │ ├── DBClusterRouteContext.java │ │ ├── DefaultDBClusterManager.java │ │ └── exception │ │ │ ├── DBClusterException.java │ │ │ └── DBClusterNotFoundException.java │ │ ├── datasource │ │ ├── DataSourceSchemasBinding.java │ │ ├── WeightedDataSource.java │ │ ├── exception │ │ │ ├── AmbiguousDataSourceBindingException.java │ │ │ ├── CrossDataSourceException.java │ │ │ ├── CrossPreparedStatementException.java │ │ │ ├── DDRDataSourceException.java │ │ │ ├── DataSourceNotFoundException.java │ │ │ ├── IllegalMetaDataException.java │ │ │ ├── StatementInitializationException.java │ │ │ ├── UninitializedStatusException.java │ │ │ ├── UnsupportedConnectionInvocationException.java │ │ │ ├── UnsupportedDataSourceInvocationException.java │ │ │ └── UnsupportedPreparedStatementInvocationException.java │ │ ├── jdbc │ │ │ ├── AbstractDDRDataSource.java │ │ │ ├── DDRCallableStatement.java │ │ │ ├── DDRDataSource.java │ │ │ ├── DDRPreparedStatement.java │ │ │ ├── DDRPreparedStatementImpl.java │ │ │ ├── DDRStatement.java │ │ │ ├── DDRStatementImpl.java │ │ │ ├── DataSourceWrapper.java │ │ │ ├── DefaultDDRDataSource.java │ │ │ ├── StatementWrapper.java │ │ │ ├── init │ │ │ │ ├── InnerBean.java │ │ │ │ ├── UninitializedConnectionProcessor.java │ │ │ │ ├── UninitializedDataSourceProcessor.java │ │ │ │ └── UninitializedStatementProcessor.java │ │ │ └── property │ │ │ │ ├── ConnectionProperty.java │ │ │ │ ├── DataSourceProperty.java │ │ │ │ └── StatementProperty.java │ │ ├── manager │ │ │ ├── DataSourceManager.java │ │ │ ├── DataSourceParam.java │ │ │ ├── SingleDataSourceManager.java │ │ │ └── rw │ │ │ │ ├── DefaultReadWriteDataSourceManager.java │ │ │ │ ├── ReadOnlyDataSourceBinding.java │ │ │ │ ├── ReadWriteDataSourceManager.java │ │ │ │ ├── WriteOnlyDataSourceBinding.java │ │ │ │ └── monitor │ │ │ │ ├── ReadOnlyDataSourceMonitor.java │ │ │ │ ├── ReadOnlyDataSourceMonitorServer.java │ │ │ │ ├── WriterMethodInvokeResult.java │ │ │ │ └── mbean │ │ │ │ ├── MBeanReadOnlyDataSourceMonitorServer.java │ │ │ │ └── ReadOnlyDataSourceMonitorMXBean.java │ │ └── security │ │ │ └── metadata │ │ │ ├── DefaultMetaDataChecker.java │ │ │ └── MetaDataChecker.java │ │ ├── expression │ │ ├── ShardRouteRuleExpressionContext.java │ │ ├── el │ │ │ ├── function │ │ │ │ ├── FormatFunction.java │ │ │ │ └── MathFunction.java │ │ │ └── spel │ │ │ │ └── DDRSpelEvaluationContext.java │ │ └── range │ │ │ ├── RangeExpressionException.java │ │ │ ├── RangeExpressionItemVisitor.java │ │ │ ├── RangeExpressionParser.java │ │ │ ├── Token.java │ │ │ ├── TokenKind.java │ │ │ └── Tokenizer.java │ │ ├── lb │ │ └── random │ │ │ ├── WeightItem.java │ │ │ └── WeightedRandom.java │ │ ├── shard │ │ ├── RangeShardValue.java │ │ ├── ShardParser.java │ │ ├── ShardRoute.java │ │ ├── ShardRouteConfig.java │ │ ├── ShardRouteContext.java │ │ ├── ShardRouteInfo.java │ │ ├── ShardRouteRule.java │ │ ├── ShardRouteRuleBinding.java │ │ ├── ShardRouteUtils.java │ │ ├── ShardRouter.java │ │ ├── exception │ │ │ ├── AmbiguousRouteRuleBindingException.java │ │ │ ├── CrossTableException.java │ │ │ ├── DDRShardException.java │ │ │ ├── DuplicateRouteRuleBindingException.java │ │ │ ├── ExpressionValueNotFoundException.java │ │ │ ├── IllegalShardValueException.java │ │ │ ├── OutOfRangeSizeLimitException.java │ │ │ ├── ShardRouteException.java │ │ │ ├── ShardValueNotFoundException.java │ │ │ └── UnsupportedShardValueTypeException.java │ │ ├── rule │ │ │ ├── DivideShardRouteRule.java │ │ │ └── SpelShardRouteRule.java │ │ └── simple │ │ │ ├── SimpleShardParser.java │ │ │ ├── SimpleShardRouteRuleBinding.java │ │ │ └── SimpleShardRouter.java │ │ ├── sqlparse │ │ ├── SQLParsedResult.java │ │ ├── SQLParsedState.java │ │ ├── SQLParser.java │ │ ├── cache │ │ │ ├── LRUSQLParserCache.java │ │ │ └── SQLParserCache.java │ │ └── exception │ │ │ ├── AmbiguousRouteResultException.java │ │ │ ├── DDRSQLParseException.java │ │ │ ├── GetRouteInfoException.java │ │ │ ├── IllegalSQLParameterException.java │ │ │ ├── SQLParserCompatibilityException.java │ │ │ ├── SQLSyntaxErrorException.java │ │ │ ├── UnsupportedSQLExpressionException.java │ │ │ ├── UnsupportedSQLParameterTypeException.java │ │ │ └── UnsupportedSQLStatementException.java │ │ └── utils │ │ ├── DDRJSONUtils.java │ │ ├── DDRStringUtils.java │ │ └── DDRToStringBuilder.java │ └── test │ └── java │ └── org │ └── hellojavaer │ └── ddal │ └── ddr │ ├── cluster │ └── DBClusterRouteContextTest.java │ ├── expression │ ├── ShardRouteRuleExpressionContextTest.java │ ├── el │ │ └── function │ │ │ └── FormatFunctionTest.java │ └── range │ │ └── RangeExpressionParserTest.java │ ├── shard │ ├── ShardContextUtilsTest.java │ ├── ShardRouteContextTest.java │ └── rule │ │ ├── DivideShardRouteRuleTest.java │ │ └── SpelShardRouteRuleTest.java │ └── utils │ ├── DDRJSONUtilsTest.java │ ├── DDRStringUtilsTest.java │ └── DDRToStringBuilderTest.java ├── ddal-example ├── README.md ├── ddal-example-example0 │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── hellojavaer │ │ │ │ └── ddal │ │ │ │ └── example │ │ │ │ └── example0 │ │ │ │ ├── dao │ │ │ │ ├── UserDao.java │ │ │ │ └── impl │ │ │ │ │ └── UserDaoImpl.java │ │ │ │ ├── entity │ │ │ │ └── UserEntity.java │ │ │ │ └── init │ │ │ │ └── InitDatabaseSqlBuilder.java │ │ └── resources │ │ │ ├── context.xml │ │ │ ├── datasource.xml │ │ │ ├── log4j.xml │ │ │ ├── mapper │ │ │ └── user.xml │ │ │ └── mybatis.xml │ │ └── test │ │ └── java │ │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── example │ │ └── example0 │ │ └── UserDaoTest.java ├── ddal-example-example1 │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── hellojavaer │ │ │ │ └── ddal │ │ │ │ └── example │ │ │ │ └── example1 │ │ │ │ ├── dao │ │ │ │ ├── RoleDao.java │ │ │ │ └── impl │ │ │ │ │ └── RoleDaoImpl.java │ │ │ │ └── entitry │ │ │ │ └── RoleEntity.java │ │ └── resources │ │ │ ├── context.xml │ │ │ ├── datasource.xml │ │ │ ├── log4j.xml │ │ │ ├── mapper │ │ │ └── role.xml │ │ │ └── mybatis.xml │ │ └── test │ │ └── java │ │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── example │ │ └── example1 │ │ └── RoleDaoTest.java └── pom.xml ├── ddal-jsqlparser ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── jsqlparser │ │ ├── JSQLBaseVisitor.java │ │ ├── JSQLParser.java │ │ └── JSQLParserAdapter.java │ └── test │ └── java │ └── org.hellojavaer.ddal.jsqlparser │ ├── BaseTestShardParser.java │ ├── DeleteTest.java │ ├── InsertTest.java │ ├── JSQLParserAdapterTest.java │ ├── LimitTest.java │ ├── SelectTest.java │ └── UpdateTest.java ├── ddal-sequence ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── sequence │ │ ├── DatabaseSequenceRangeGetter.java │ │ ├── ExceptionHandler.java │ │ ├── GroupSequence.java │ │ ├── HttpSequenceRangeGetter.java │ │ ├── LinkedCycleList.java │ │ ├── PollingGroupSequence.java │ │ ├── Sequence.java │ │ ├── SequenceCache.java │ │ ├── SequenceRange.java │ │ ├── SequenceRangeGetter.java │ │ ├── SingleSequence.java │ │ ├── SummedBlockingQueue.java │ │ └── exception │ │ ├── GetSequenceFailedException.java │ │ ├── GetSequenceTimeoutException.java │ │ ├── IllegalSequenceRangeException.java │ │ ├── NoAvailableSequenceRangeFoundException.java │ │ └── SequenceException.java │ └── test │ └── java │ └── org │ └── hellojavaer │ └── ddal │ └── sequence │ └── LinkedCycleListTest.java ├── ddal-server ├── ddal-server-datasource │ └── pom.xml └── pom.xml ├── ddal-spring ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── spring │ │ └── scan │ │ ├── EnableDBClusterRouteAnnotation.java │ │ ├── EnableShardRouteAnnotation.java │ │ └── MethodBasedSpelExpression.java │ └── test │ ├── java │ └── org │ │ └── hellojavaer │ │ └── ddal │ │ └── spring │ │ └── scan │ │ ├── EnableShardRouteAnnotationTest.java │ │ ├── ShardRouteTestComponent.java │ │ ├── UserEntity.java │ │ └── dbcluster │ │ ├── DBClusterRouteTestComponent.java │ │ └── EnableDBClusterRouteAnnotationTest.java │ └── resources │ └── spring.xml ├── doc └── img │ ├── design_00.jpeg │ ├── design_01.jpeg │ └── design_02.jpeg └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.java.hsp 2 | *.sonarj 3 | *.sw* 4 | jxl.log 5 | jmx.log 6 | .settings 7 | .DS_Store 8 | .springBeans 9 | 10 | classes/ 11 | target/ 12 | 13 | # Eclipse 14 | .classpath 15 | .project 16 | 17 | # IDEA 18 | *.iml 19 | *.ipr 20 | *.iws 21 | .idea 22 | out 23 | test-output 24 | atlassian-ide-plugin.xml 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk7 4 | 5 | after_success: 6 | - mvn clean cobertura:cobertura coveralls:report 7 | -------------------------------------------------------------------------------- /ddal-datasource/src/main/java/org/hellojavaer/ddal/datasource/DDALDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.datasource; 17 | 18 | import org.hellojavaer.ddal.ddr.shard.ShardRouter; 19 | import org.hellojavaer.ddal.sequence.Sequence; 20 | 21 | import javax.sql.DataSource; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 15/07/2017. 26 | */ 27 | public interface DDALDataSource extends DataSource { 28 | 29 | Sequence getSequence(); 30 | 31 | ShardRouter getShardRouter(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ddal-datasource/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.beans.BeanInfoFactory=org.hellojavaer.ddal.datasource.spring.DDALBeanInfoFactory 2 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/cluster/DBClusterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.cluster; 17 | 18 | import javax.sql.DataSource; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 2018/5/27. 23 | */ 24 | public interface DBClusterManager extends DataSource { 25 | 26 | DataSource determineDataSource(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/cluster/DBClusterRoute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.cluster; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 2018/5/27. 23 | */ 24 | @Target({ ElementType.METHOD }) 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Documented 27 | public @interface DBClusterRoute { 28 | 29 | String clusterName() default ""; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/cluster/exception/DBClusterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.cluster.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 2018/5/27. 21 | */ 22 | public class DBClusterException extends RuntimeException { 23 | 24 | public DBClusterException() { 25 | } 26 | 27 | public DBClusterException(String message) { 28 | super(message); 29 | } 30 | 31 | public DBClusterException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public DBClusterException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public DBClusterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 40 | super(message, cause, enableSuppression, writableStackTrace); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/cluster/exception/DBClusterNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.cluster.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 2018/5/27. 21 | */ 22 | public class DBClusterNotFoundException extends DBClusterException { 23 | 24 | public DBClusterNotFoundException() { 25 | } 26 | 27 | public DBClusterNotFoundException(String message) { 28 | super(message); 29 | } 30 | 31 | public DBClusterNotFoundException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public DBClusterNotFoundException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public DBClusterNotFoundException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/DataSourceSchemasBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource; 17 | 18 | import org.hellojavaer.ddal.ddr.utils.DDRToStringBuilder; 19 | 20 | import javax.sql.DataSource; 21 | import java.util.Set; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 10/12/2016. 26 | */ 27 | public class DataSourceSchemasBinding { 28 | 29 | private DataSource dataSource; 30 | private Set schemas; 31 | 32 | public DataSourceSchemasBinding() { 33 | } 34 | 35 | public DataSourceSchemasBinding(DataSource dataSource, Set schemas) { 36 | this.dataSource = dataSource; 37 | this.schemas = schemas; 38 | } 39 | 40 | public DataSource getDataSource() { 41 | return dataSource; 42 | } 43 | 44 | public void setDataSource(DataSource dataSource) { 45 | this.dataSource = dataSource; 46 | } 47 | 48 | public Set getSchemas() { 49 | return schemas; 50 | } 51 | 52 | public void setSchemas(Set schemas) { 53 | this.schemas = schemas; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return new DDRToStringBuilder().append("schemas", schemas).append("dataSource", dataSource).toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/WeightedDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource; 17 | 18 | import org.hellojavaer.ddal.ddr.utils.DDRToStringBuilder; 19 | 20 | import javax.sql.DataSource; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 23/11/2016. 25 | */ 26 | public class WeightedDataSource { 27 | 28 | private DataSource dataSource; 29 | private Integer weight; 30 | private String name; 31 | private String desc; 32 | 33 | public WeightedDataSource() { 34 | } 35 | 36 | public WeightedDataSource(DataSource dataSource, Integer weight) { 37 | this(dataSource, weight, null); 38 | } 39 | 40 | public WeightedDataSource(DataSource dataSource, Integer weight, String name) { 41 | this(dataSource, weight, name, null); 42 | } 43 | 44 | public WeightedDataSource(DataSource dataSource, Integer weight, String name, String desc) { 45 | this.dataSource = dataSource; 46 | this.weight = weight; 47 | this.name = name; 48 | this.desc = desc; 49 | } 50 | 51 | public DataSource getDataSource() { 52 | return dataSource; 53 | } 54 | 55 | public void setDataSource(DataSource dataSource) { 56 | this.dataSource = dataSource; 57 | } 58 | 59 | public Integer getWeight() { 60 | return weight; 61 | } 62 | 63 | public void setWeight(Integer weight) { 64 | this.weight = weight; 65 | } 66 | 67 | public String getName() { 68 | return name; 69 | } 70 | 71 | public void setName(String name) { 72 | this.name = name; 73 | } 74 | 75 | public String getDesc() { 76 | return desc; 77 | } 78 | 79 | public void setDesc(String desc) { 80 | this.desc = desc; 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return new DDRToStringBuilder().append("name", name).append("weight", weight).append("desc", desc).append("dataSource", 86 | dataSource).toString(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/AmbiguousDataSourceBindingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/12/2016. 21 | */ 22 | public class AmbiguousDataSourceBindingException extends DDRDataSourceException { 23 | 24 | public AmbiguousDataSourceBindingException() { 25 | } 26 | 27 | public AmbiguousDataSourceBindingException(String message) { 28 | super(message); 29 | } 30 | 31 | public AmbiguousDataSourceBindingException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public AmbiguousDataSourceBindingException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public AmbiguousDataSourceBindingException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/CrossDataSourceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 13/12/2016. 21 | */ 22 | public class CrossDataSourceException extends DDRDataSourceException { 23 | 24 | public CrossDataSourceException() { 25 | } 26 | 27 | public CrossDataSourceException(String message) { 28 | super(message); 29 | } 30 | 31 | public CrossDataSourceException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public CrossDataSourceException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public CrossDataSourceException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/CrossPreparedStatementException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 17/12/2016. 21 | */ 22 | public class CrossPreparedStatementException extends DDRDataSourceException { 23 | 24 | public CrossPreparedStatementException() { 25 | } 26 | 27 | public CrossPreparedStatementException(String message) { 28 | super(message); 29 | } 30 | 31 | public CrossPreparedStatementException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public CrossPreparedStatementException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public CrossPreparedStatementException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/DDRDataSourceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 16/12/2016. 21 | */ 22 | public class DDRDataSourceException extends RuntimeException { 23 | 24 | public DDRDataSourceException() { 25 | } 26 | 27 | public DDRDataSourceException(String message) { 28 | super(message); 29 | } 30 | 31 | public DDRDataSourceException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public DDRDataSourceException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public DDRDataSourceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 40 | super(message, cause, enableSuppression, writableStackTrace); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/DataSourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 24/12/2016. 21 | */ 22 | public class DataSourceNotFoundException extends DDRDataSourceException { 23 | 24 | public DataSourceNotFoundException() { 25 | } 26 | 27 | public DataSourceNotFoundException(String message) { 28 | super(message); 29 | } 30 | 31 | public DataSourceNotFoundException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public DataSourceNotFoundException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public DataSourceNotFoundException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/IllegalMetaDataException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 25/12/2016. 21 | */ 22 | public class IllegalMetaDataException extends DDRDataSourceException { 23 | 24 | public IllegalMetaDataException() { 25 | } 26 | 27 | public IllegalMetaDataException(String message) { 28 | super(message); 29 | } 30 | 31 | public IllegalMetaDataException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public IllegalMetaDataException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public IllegalMetaDataException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/StatementInitializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 28/01/2017. 21 | */ 22 | public class StatementInitializationException extends DDRDataSourceException { 23 | 24 | public StatementInitializationException() { 25 | } 26 | 27 | public StatementInitializationException(String message) { 28 | super(message); 29 | } 30 | 31 | public StatementInitializationException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public StatementInitializationException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public StatementInitializationException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/UninitializedStatusException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 13/12/2016. 21 | */ 22 | public class UninitializedStatusException extends DDRDataSourceException { 23 | 24 | public UninitializedStatusException() { 25 | } 26 | 27 | public UninitializedStatusException(String message) { 28 | super(message); 29 | } 30 | 31 | public UninitializedStatusException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UninitializedStatusException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UninitializedStatusException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/UnsupportedConnectionInvocationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 25/12/2016. 21 | */ 22 | public class UnsupportedConnectionInvocationException extends DDRDataSourceException { 23 | 24 | public UnsupportedConnectionInvocationException() { 25 | } 26 | 27 | public UnsupportedConnectionInvocationException(String message) { 28 | super(message); 29 | } 30 | 31 | public UnsupportedConnectionInvocationException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UnsupportedConnectionInvocationException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UnsupportedConnectionInvocationException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/UnsupportedDataSourceInvocationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 28/12/2016. 21 | */ 22 | public class UnsupportedDataSourceInvocationException extends DDRDataSourceException { 23 | 24 | public UnsupportedDataSourceInvocationException() { 25 | } 26 | 27 | public UnsupportedDataSourceInvocationException(String message) { 28 | super(message); 29 | } 30 | 31 | public UnsupportedDataSourceInvocationException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UnsupportedDataSourceInvocationException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UnsupportedDataSourceInvocationException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/exception/UnsupportedPreparedStatementInvocationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 25/12/2016. 21 | */ 22 | public class UnsupportedPreparedStatementInvocationException extends DDRDataSourceException { 23 | 24 | public UnsupportedPreparedStatementInvocationException() { 25 | } 26 | 27 | public UnsupportedPreparedStatementInvocationException(String message) { 28 | super(message); 29 | } 30 | 31 | public UnsupportedPreparedStatementInvocationException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UnsupportedPreparedStatementInvocationException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UnsupportedPreparedStatementInvocationException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/DDRCallableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc; 17 | 18 | import java.sql.CallableStatement; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 18/12/2016. 23 | */ 24 | public interface DDRCallableStatement extends CallableStatement, DDRPreparedStatement { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/DDRDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.manager.DataSourceParam; 19 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParsedResult; 20 | 21 | import javax.sql.DataSource; 22 | import java.util.Map; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 09/12/2016. 27 | */ 28 | public interface DDRDataSource extends DataSource { 29 | 30 | SQLParsedResult parseSql(String sql, Map jdbcParam); 31 | 32 | DataSourceWrapper getDataSource(DataSourceParam param); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/DDRPreparedStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc; 17 | 18 | import java.sql.PreparedStatement; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 11/12/2016. 23 | */ 24 | public interface DDRPreparedStatement extends PreparedStatement, DDRStatement { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/DDRStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.manager.DataSourceParam; 19 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParsedResult; 20 | 21 | import java.sql.SQLException; 22 | import java.sql.Statement; 23 | import java.util.Map; 24 | 25 | /** 26 | * 27 | * @author Kaiming Zou,created on 11/12/2016. 28 | */ 29 | public interface DDRStatement extends Statement { 30 | 31 | SQLParsedResult parseSql(String sql, Map jdbcParams) throws SQLException; 32 | 33 | StatementWrapper getStatement(DataSourceParam param, String sql) throws SQLException; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/DataSourceWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc; 17 | 18 | import org.hellojavaer.ddal.ddr.utils.DDRToStringBuilder; 19 | 20 | import javax.sql.DataSource; 21 | import java.util.Set; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 28/12/2016. 26 | */ 27 | public class DataSourceWrapper { 28 | 29 | private DataSource dataSource; 30 | private Set schemas; 31 | 32 | public DataSourceWrapper() { 33 | } 34 | 35 | public DataSourceWrapper(DataSource dataSource, Set schemas) { 36 | this.dataSource = dataSource; 37 | this.schemas = schemas; 38 | } 39 | 40 | public DataSource getDataSource() { 41 | return dataSource; 42 | } 43 | 44 | public void setDataSource(DataSource dataSource) { 45 | this.dataSource = dataSource; 46 | } 47 | 48 | public Set getSchemas() { 49 | return schemas; 50 | } 51 | 52 | public void setSchemas(Set schemas) { 53 | this.schemas = schemas; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return new DDRToStringBuilder().append("schemas", schemas).append("dataSource", dataSource).toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/StatementWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc; 17 | 18 | import java.sql.Connection; 19 | import java.sql.Statement; 20 | import java.util.Set; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 13/12/2016. 25 | */ 26 | public class StatementWrapper { 27 | 28 | private Statement statement; 29 | private Connection connection; 30 | private Set schemas; 31 | 32 | public StatementWrapper(Connection connection, Statement statement, Set schemas) { 33 | this.connection = connection; 34 | this.statement = statement; 35 | this.schemas = schemas; 36 | } 37 | 38 | public Connection getConnection() { 39 | return connection; 40 | } 41 | 42 | public void setConnection(Connection connection) { 43 | this.connection = connection; 44 | } 45 | 46 | public Statement getStatement() { 47 | return statement; 48 | } 49 | 50 | public void setStatement(Statement statement) { 51 | this.statement = statement; 52 | } 53 | 54 | public Set getSchemas() { 55 | return schemas; 56 | } 57 | 58 | public void setSchemas(Set schemas) { 59 | this.schemas = schemas; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/init/InnerBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc.init; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 13/12/2016. 21 | */ 22 | class InnerBean { 23 | 24 | public InnerBean(Object val, boolean syncDefaultValue) { 25 | this.val = val; 26 | this.syncDefaultValue = syncDefaultValue; 27 | } 28 | 29 | private Object val; 30 | private boolean syncDefaultValue; 31 | 32 | public Object getVal() { 33 | return val; 34 | } 35 | 36 | public void setVal(Object val) { 37 | this.val = val; 38 | } 39 | 40 | public boolean isSyncDefaultValue() { 41 | return syncDefaultValue; 42 | } 43 | 44 | public void setSyncDefaultValue(boolean syncDefaultValue) { 45 | this.syncDefaultValue = syncDefaultValue; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/init/UninitializedConnectionProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc.init; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.exception.DDRDataSourceException; 19 | import org.hellojavaer.ddal.ddr.datasource.jdbc.property.ConnectionProperty; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 11/12/2016. 27 | */ 28 | public class UninitializedConnectionProcessor { 29 | 30 | private static Map map = new HashMap(); 31 | 32 | public static void setDefaultValue(ConnectionProperty prop, Object val, boolean isSyncDefaultValue) { 33 | if (prop == ConnectionProperty.metaData && isSyncDefaultValue) { 34 | throw new DDRDataSourceException("Can't execute update for metaData"); 35 | } 36 | map.put(prop, new InnerBean(val, isSyncDefaultValue)); 37 | } 38 | 39 | public static Object getDefaultValue(ConnectionProperty prop) { 40 | InnerBean obj = map.get(prop); 41 | if (obj != null) { 42 | return obj.getVal(); 43 | } else { 44 | return null; 45 | } 46 | } 47 | 48 | public static boolean isSetDefaultValue(ConnectionProperty prop) { 49 | return map.containsKey(prop); 50 | } 51 | 52 | public static boolean isSyncDefaultValue(ConnectionProperty prop) { 53 | InnerBean obj = map.get(prop); 54 | if (obj != null) { 55 | return obj.isSyncDefaultValue(); 56 | } else { 57 | return false; 58 | } 59 | } 60 | 61 | public static Object removeDefaultValue(ConnectionProperty prop) { 62 | return map.remove(prop); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/init/UninitializedDataSourceProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc.init; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.jdbc.property.DataSourceProperty; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 11/12/2016. 26 | */ 27 | public class UninitializedDataSourceProcessor { 28 | 29 | private static Map map = new HashMap(); 30 | 31 | public static void setDefaultValue(DataSourceProperty prop, Object val, boolean isSyncDefaultValue) { 32 | map.put(prop, new InnerBean(val, isSyncDefaultValue)); 33 | } 34 | 35 | public static Object getDefaultValue(DataSourceProperty prop) { 36 | InnerBean obj = map.get(prop); 37 | if (obj != null) { 38 | return obj.getVal(); 39 | } else { 40 | return null; 41 | } 42 | } 43 | 44 | public static boolean isSetDefaultValue(DataSourceProperty prop) { 45 | return map.containsKey(prop); 46 | } 47 | 48 | public static Object removeDefaultValue(DataSourceProperty prop) { 49 | return map.remove(prop); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/init/UninitializedStatementProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc.init; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.jdbc.property.StatementProperty; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 11/12/2016. 26 | */ 27 | public class UninitializedStatementProcessor { 28 | 29 | private static Map map = new HashMap(); 30 | 31 | public static void setDefaultValue(StatementProperty prop, Object val, boolean isSyncDefaultValue) { 32 | map.put(prop, new InnerBean(val, isSyncDefaultValue)); 33 | } 34 | 35 | public static Object getDefaultValue(StatementProperty prop) { 36 | InnerBean obj = map.get(prop); 37 | if (obj != null) { 38 | return obj.getVal(); 39 | } else { 40 | return null; 41 | } 42 | } 43 | 44 | public static boolean isSetDefaultValue(StatementProperty prop) { 45 | return map.containsKey(prop); 46 | } 47 | 48 | public static boolean isSyncDefaultValue(StatementProperty prop) { 49 | InnerBean obj = map.get(prop); 50 | if (obj != null) { 51 | return obj.isSyncDefaultValue(); 52 | } else { 53 | return false; 54 | } 55 | } 56 | 57 | public static Object removeDefaultValue(StatementProperty prop) { 58 | return map.remove(prop); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/property/ConnectionProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc.property; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 11/12/2016. 21 | */ 22 | public enum ConnectionProperty { 23 | 24 | readOnly, 25 | 26 | autoCommit, 27 | 28 | catalog, 29 | 30 | transactionIsolation, 31 | 32 | typeMap, 33 | 34 | holdability, 35 | 36 | schema, 37 | 38 | metaData; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/property/DataSourceProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc.property; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 11/12/2016. 21 | */ 22 | public enum DataSourceProperty { 23 | 24 | loginTimeout, 25 | 26 | logWriter; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/jdbc/property/StatementProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.jdbc.property; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 11/12/2016. 21 | */ 22 | public enum StatementProperty { 23 | 24 | maxFieldSize, 25 | 26 | maxRows, 27 | 28 | fetchDirection, 29 | 30 | fetchSize, 31 | 32 | queryTimeout, 33 | 34 | closeOnCompletion, 35 | 36 | poolable; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/DataSourceManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.jdbc.DataSourceWrapper; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 19/11/2016. 23 | */ 24 | public interface DataSourceManager { 25 | 26 | DataSourceWrapper getDataSource(DataSourceParam param); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/DataSourceParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager; 17 | 18 | import org.hellojavaer.ddal.ddr.utils.DDRToStringBuilder; 19 | 20 | import java.util.Set; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 19/11/2016. 25 | */ 26 | public class DataSourceParam { 27 | 28 | private Set scNames; 29 | private boolean readOnly; 30 | 31 | public Set getScNames() { 32 | return scNames; 33 | } 34 | 35 | public void setScNames(Set scNames) { 36 | this.scNames = scNames; 37 | } 38 | 39 | public boolean isReadOnly() { 40 | return readOnly; 41 | } 42 | 43 | public void setReadOnly(boolean readOnly) { 44 | this.readOnly = readOnly; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return new DDRToStringBuilder().append("readOnly", readOnly).append("scNames", scNames).toString(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/SingleDataSourceManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.jdbc.DataSourceWrapper; 19 | 20 | import javax.sql.DataSource; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 19/11/2016. 25 | */ 26 | public class SingleDataSourceManager implements DataSourceManager { 27 | 28 | private DataSource dataSource; 29 | 30 | private SingleDataSourceManager() { 31 | } 32 | 33 | public SingleDataSourceManager(DataSource dataSource) { 34 | this.dataSource = dataSource; 35 | } 36 | 37 | public DataSource getDataSource() { 38 | return dataSource; 39 | } 40 | 41 | private void setDataSource(DataSource dataSource) { 42 | this.dataSource = dataSource; 43 | } 44 | 45 | @Override 46 | public DataSourceWrapper getDataSource(DataSourceParam param) { 47 | DataSourceWrapper wrapper = new DataSourceWrapper(); 48 | wrapper.setDataSource(this.getDataSource()); 49 | return wrapper; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/rw/ReadOnlyDataSourceBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager.rw; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.WeightedDataSource; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 19/11/2016. 25 | */ 26 | public class ReadOnlyDataSourceBinding { 27 | 28 | private String scNames; 29 | private List dataSources; 30 | 31 | public ReadOnlyDataSourceBinding() { 32 | } 33 | 34 | public ReadOnlyDataSourceBinding(String scNames, List dataSources) { 35 | this.scNames = scNames; 36 | this.dataSources = dataSources; 37 | } 38 | 39 | public String getScNames() { 40 | return scNames; 41 | } 42 | 43 | public void setScNames(String scNames) { 44 | this.scNames = scNames; 45 | } 46 | 47 | public List getDataSources() { 48 | return dataSources; 49 | } 50 | 51 | public void setDataSources(List dataSources) { 52 | this.dataSources = dataSources; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/rw/ReadWriteDataSourceManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager.rw; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor.ReadOnlyDataSourceMonitorServer; 19 | import org.hellojavaer.ddal.ddr.datasource.manager.DataSourceManager; 20 | import org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor.ReadOnlyDataSourceMonitor; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 19/11/2016. 27 | */ 28 | public interface ReadWriteDataSourceManager extends DataSourceManager { 29 | 30 | List getWriteOnlyDataSources(); 31 | 32 | List getReadOnlyDataSources(); 33 | 34 | ReadOnlyDataSourceMonitor getReadOnlyDataSourceMonitor(); 35 | 36 | ReadOnlyDataSourceMonitorServer getReadOnlyDataSourceMonitorServer(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/rw/WriteOnlyDataSourceBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager.rw; 17 | 18 | import javax.sql.DataSource; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 19/11/2016. 23 | */ 24 | public class WriteOnlyDataSourceBinding { 25 | 26 | private String scNames; 27 | private DataSource dataSource; 28 | 29 | public WriteOnlyDataSourceBinding() { 30 | } 31 | 32 | public WriteOnlyDataSourceBinding(String scNames, DataSource dataSource) { 33 | this.scNames = scNames; 34 | this.dataSource = dataSource; 35 | } 36 | 37 | public String getScNames() { 38 | return scNames; 39 | } 40 | 41 | public void setScNames(String scNames) { 42 | this.scNames = scNames; 43 | } 44 | 45 | public DataSource getDataSource() { 46 | return dataSource; 47 | } 48 | 49 | public void setDataSource(DataSource dataSource) { 50 | this.dataSource = dataSource; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/rw/monitor/ReadOnlyDataSourceMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 21/12/2016. 21 | */ 22 | public interface ReadOnlyDataSourceMonitor { 23 | 24 | /** 25 | * 单个权重 26 | */ 27 | Integer getWeight(String scName, int index); 28 | 29 | String setWeight(String scName, int index, int weight); 30 | 31 | String restoreWeight(String scName, int index); 32 | 33 | Integer getWeight(String scName, String dataSourceName); 34 | 35 | String setWeight(String scName, String dataSourceName, int weight); 36 | 37 | String restoreWeight(String scName, String dataSourceName); 38 | 39 | /** 40 | * 批量权重 41 | */ 42 | String getWeight(String scName);// [1:{"name":"aa","desc":"bb",weight:1}] 43 | 44 | /** 45 | * batch updating load weight of datasource may cause cluster unstable,generally I suggest you updating weight of datasource one by one in a smoothing way. 46 | * 47 | * 由于同时更新多个数据源的权重可能会导致数据库集群整体负载失衡,通常的情况下我建议平滑的升降对单个数据源的负载,因此最后我决定去掉这个方法 48 | */ 49 | //String setWeight(String scName, String values);// [1:{"name":"aa","desc":"bb",weight:1}] 50 | 51 | String restoreWeight(String scName);// 52 | 53 | /** 54 | * 重置 55 | */ 56 | String restoreWeight(); 57 | 58 | /** 59 | * 读取全量配置 60 | */ 61 | String getOriginalWeightConfig(); 62 | 63 | /** 64 | * 读取全量配置 65 | */ 66 | String getCurrentWeightConfig(); 67 | } 68 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/rw/monitor/ReadOnlyDataSourceMonitorServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 21/12/2016. 21 | */ 22 | public interface ReadOnlyDataSourceMonitorServer { 23 | 24 | void init(ReadOnlyDataSourceMonitor readOnlyDataSourceMonitor); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/rw/monitor/WriterMethodInvokeResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor; 17 | 18 | import org.hellojavaer.ddal.ddr.utils.DDRToStringBuilder; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 22/12/2016. 25 | */ 26 | public class WriterMethodInvokeResult implements Serializable { 27 | 28 | private static final long serialVersionUID = 0L; 29 | 30 | public static final int CODE_OF_SUCCESS = 0; 31 | public static final int CODE_OF_ILLEGAL_ARGUMENT = 20; // 格式错误,参数必填项为空 32 | public static final int CODE_OF_DATA_IS_EMPTY = 40; // 33 | // public static final int CODE_OF_OPERATION_NOT_SUPPORTED = 60; 34 | 35 | private Integer code; 36 | private String desc; 37 | 38 | public WriterMethodInvokeResult() { 39 | } 40 | 41 | public WriterMethodInvokeResult(Integer code, String desc) { 42 | this.code = code; 43 | this.desc = desc; 44 | } 45 | 46 | public Integer getCode() { 47 | return code; 48 | } 49 | 50 | public void setCode(Integer code) { 51 | this.code = code; 52 | } 53 | 54 | public String getDesc() { 55 | return desc; 56 | } 57 | 58 | public void setDesc(String desc) { 59 | this.desc = desc; 60 | } 61 | 62 | @Override 63 | public String toString() { 64 | return new DDRToStringBuilder().append("code", code).append("desc", desc).toString(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/manager/rw/monitor/mbean/ReadOnlyDataSourceMonitorMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor.mbean; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor.ReadOnlyDataSourceMonitor; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 20/12/2016. 23 | */ 24 | public interface ReadOnlyDataSourceMonitorMXBean extends ReadOnlyDataSourceMonitor { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/datasource/security/metadata/MetaDataChecker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.datasource.security.metadata; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.exception.IllegalMetaDataException; 19 | 20 | import java.sql.Connection; 21 | import java.util.Collection; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 25/12/2016. 26 | */ 27 | public interface MetaDataChecker { 28 | 29 | void check(Connection conn, String scName, Collection tbNames) throws IllegalMetaDataException; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/expression/el/function/FormatFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2018 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 | package org.hellojavaer.ddal.ddr.expression.el.function; 17 | 18 | import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; 19 | import com.googlecode.concurrentlinkedhashmap.Weighers; 20 | 21 | import java.text.SimpleDateFormat; 22 | import java.util.Map; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 25/04/2017. 27 | */ 28 | public class FormatFunction { 29 | 30 | private static ThreadLocal dateFormatCache = new ThreadLocal() { 31 | 32 | @Override 33 | protected Map initialValue() { 34 | return new ConcurrentLinkedHashMap.Builder()// 35 | .maximumWeightedCapacity(100)// 36 | .weigher(Weighers.singleton())// 37 | .build(); 38 | } 39 | }; 40 | 41 | public static String format(String format, Object... args) { 42 | return String.format(format, args); 43 | } 44 | 45 | public static String dateFormat(String format, Object date) { 46 | Map map = dateFormatCache.get(); 47 | SimpleDateFormat df = map.get(format); 48 | if (df == null) { 49 | df = new SimpleDateFormat(format); 50 | map.put(format, df); 51 | } 52 | return df.format(date); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/expression/range/RangeExpressionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.expression.range; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 30/11/2016. 21 | */ 22 | public class RangeExpressionException extends RuntimeException { 23 | 24 | public RangeExpressionException(String expression, int pos, String msg) { 25 | super(build(expression, pos, msg)); 26 | } 27 | 28 | private static String build(String expression, int position, String msg) { 29 | StringBuilder output = new StringBuilder(); 30 | output.append("Expression '"); 31 | output.append(expression); 32 | output.append("'"); 33 | if (position != -1) { 34 | output.append(" @ "); 35 | output.append(position); 36 | } 37 | output.append(": "); 38 | output.append(msg); 39 | return output.toString(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/expression/range/RangeExpressionItemVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.expression.range; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 29/11/2016. 21 | */ 22 | public interface RangeExpressionItemVisitor { 23 | 24 | void visit(Object val); 25 | } 26 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/expression/range/Token.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.expression.range; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 02/08/2017. 21 | */ 22 | class Token { 23 | 24 | private TokenKind kind; 25 | 26 | private String data; 27 | 28 | private int startPos; 29 | 30 | private int endPos; 31 | 32 | public Token(TokenKind tokenKind, int startPos, int endPos) { 33 | this.kind = tokenKind; 34 | this.startPos = startPos; 35 | this.endPos = endPos; 36 | } 37 | 38 | public Token(TokenKind tokenKind, String data, int startPos, int endPos) { 39 | this(tokenKind, startPos, endPos); 40 | this.data = data; 41 | } 42 | 43 | public TokenKind getKind() { 44 | return this.kind; 45 | } 46 | 47 | public String getData() { 48 | return data; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | StringBuilder s = new StringBuilder(); 54 | s.append("[").append(this.kind.toString()); 55 | if (this.data != null) { 56 | s.append(":").append(this.data); 57 | } 58 | s.append("]"); 59 | s.append("(").append(this.startPos).append(",").append(this.endPos).append(")"); 60 | return s.toString(); 61 | } 62 | 63 | public int getStartPos() { 64 | return startPos; 65 | } 66 | 67 | public int getEndPos() { 68 | return endPos; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/expression/range/TokenKind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.expression.range; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 02/08/2017. 21 | */ 22 | enum TokenKind { 23 | 24 | LITERAL_INT, 25 | 26 | LITERAL_DOUBLE, 27 | 28 | LITERAL_STRING, 29 | 30 | LITERAL_LOWER_CHAR, 31 | 32 | LITERAL_UPPER_CHAR, 33 | 34 | COMMA(","), 35 | 36 | RSQUARE("]"), 37 | 38 | LSQUARE("["), 39 | 40 | TO(".."); 41 | 42 | private final String tokenString; 43 | 44 | private TokenKind(String tokenString) { 45 | this.tokenString = tokenString; 46 | } 47 | 48 | private TokenKind() { 49 | this(""); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return (name() + (this.tokenString.length() != 0 ? "(" + this.tokenString + ")" : "")); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/lb/random/WeightItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.lb.random; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/11/2016. 21 | */ 22 | public class WeightItem { 23 | 24 | private int weight; 25 | private Object value; 26 | 27 | public WeightItem() { 28 | } 29 | 30 | public WeightItem(int weight, Object value) { 31 | this.weight = weight; 32 | this.value = value; 33 | } 34 | 35 | public int getWeight() { 36 | return weight; 37 | } 38 | 39 | public void setWeight(int weight) { 40 | this.weight = weight; 41 | } 42 | 43 | public Object getValue() { 44 | return value; 45 | } 46 | 47 | public void setValue(Object value) { 48 | this.value = value; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/RangeShardValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 16/09/2017. 23 | */ 24 | public class RangeShardValue { 25 | 26 | private Long begin; 27 | private Long end; 28 | 29 | public RangeShardValue() { 30 | } 31 | 32 | public RangeShardValue(Long begin, Long end) { 33 | this.begin = begin; 34 | this.end = end; 35 | } 36 | 37 | public Long getBegin() { 38 | return begin; 39 | } 40 | 41 | public void setBegin(Long begin) { 42 | this.begin = begin; 43 | } 44 | 45 | public Long getEnd() { 46 | return end; 47 | } 48 | 49 | public void setEnd(Long end) { 50 | this.end = end; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "{" + "begin:" + begin + ",end:" + end + '}'; 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return Objects.hash(begin, end); 61 | } 62 | 63 | @Override 64 | public boolean equals(Object o) { 65 | if (this == o) return true; 66 | if (o == null || getClass() != o.getClass()) return false; 67 | 68 | RangeShardValue that = (RangeShardValue) o; 69 | 70 | if (begin != null ? !begin.equals(that.begin) : that.begin != null) return false; 71 | return end != null ? end.equals(that.end) : that.end == null; 72 | 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/ShardParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParsedResult; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 23/11/2016. 25 | */ 26 | public interface ShardParser { 27 | 28 | SQLParsedResult parse(String sql, Map jdbcParams); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/ShardRoute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * Setting the default route information for the schema 22 | *
23 |  * This configuration is fully equivalent to invoking #{org.hellojavaer.ddal.ddr.shard.ShardRouteContext.setRouteInfo},
24 |  * and this default route configuration will take effect only in the following case:
25 |  * 1. No 'sdKey' was specified in route rule configuration
26 |  * 2. Specified route rule in configuration but no 'sdKey' was found in sql and no associated route information was specified by #{org.hellojavaer.ddal.ddr.shard.ShardRouteContext.setRouteInfo}
27 |  *
28 |  * 'ShardRoute' is designed base on 'one schema one route rule'.
29 |  *
30 |  * But if you need to access one more schemas which have different route rule in one sql, you should add this annotation on its sub-invoking method.
31 |  *
32 |  *
33 | * @author Kaiming Zou,created on 01/01/2017. 34 | */ 35 | @Target({ ElementType.METHOD }) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | @Documented 38 | public @interface ShardRoute { 39 | 40 | /** 41 | * allow a comma-delimited list of scNames 42 | * 43 | * @return 44 | */ 45 | String scName() default ""; 46 | 47 | /** 48 | * 49 | * @return 50 | */ 51 | String sdValue() default ""; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/ShardRouteConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | import org.hellojavaer.ddal.ddr.utils.DDRToStringBuilder; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 20/12/2016. 23 | */ 24 | public class ShardRouteConfig { 25 | 26 | private String scName; 27 | private String tbName; 28 | private String sdKey; 29 | 30 | public ShardRouteConfig() { 31 | } 32 | 33 | public ShardRouteConfig(String scName, String tbName, String sdKey) { 34 | this.scName = scName; 35 | this.tbName = tbName; 36 | this.sdKey = sdKey; 37 | } 38 | 39 | public String getScName() { 40 | return scName; 41 | } 42 | 43 | public void setScName(String scName) { 44 | this.scName = scName; 45 | } 46 | 47 | public String getTbName() { 48 | return tbName; 49 | } 50 | 51 | public void setTbName(String tbName) { 52 | this.tbName = tbName; 53 | } 54 | 55 | public String getSdKey() { 56 | return sdKey; 57 | } 58 | 59 | public void setSdKey(String sdKey) { 60 | this.sdKey = sdKey; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return new DDRToStringBuilder().append("scName", scName).append("tbName", tbName).append("sdKey", sdKey).toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/ShardRouteInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 15/11/2016. 23 | */ 24 | public class ShardRouteInfo { 25 | 26 | private String scName; 27 | private String tbName; 28 | 29 | public ShardRouteInfo() { 30 | } 31 | 32 | public ShardRouteInfo(String scName, String tbName) { 33 | this.scName = scName; 34 | this.tbName = tbName; 35 | } 36 | 37 | public String getScName() { 38 | return scName; 39 | } 40 | 41 | public void setScName(String scName) { 42 | this.scName = scName; 43 | } 44 | 45 | public String getTbName() { 46 | return tbName; 47 | } 48 | 49 | public void setTbName(String tbName) { 50 | this.tbName = tbName; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | if (scName == null) { 56 | return tbName; 57 | } else { 58 | return new StringBuilder().append(scName).append('.').append(tbName).toString(); 59 | } 60 | } 61 | 62 | @Override 63 | public int hashCode() { 64 | return Objects.hash(scName, tbName); 65 | } 66 | 67 | @Override 68 | public boolean equals(Object o) { 69 | if (this == o) return true; 70 | if (o == null || getClass() != o.getClass()) return false; 71 | 72 | ShardRouteInfo routeInfo = (ShardRouteInfo) o; 73 | 74 | if (scName != null ? !scName.equals(routeInfo.scName) : routeInfo.scName != null) return false; 75 | return tbName != null ? tbName.equals(routeInfo.tbName) : routeInfo.tbName == null; 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/ShardRouteRule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | /** 22 | * 23 | * @author Kaiming Zou,created on 31/01/2017. 24 | */ 25 | public interface ShardRouteRule { 26 | 27 | String parseScName(String scName, Object sdValue); 28 | 29 | String parseTbName(String tbName, Object sdValue); 30 | 31 | Map> groupSdValuesByRouteInfo(String scName, String tbName, 32 | RangeShardValue rangeShardValue); 33 | } 34 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/ShardRouteRuleBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 31/01/2017. 21 | */ 22 | public interface ShardRouteRuleBinding { 23 | 24 | String getScName(); 25 | 26 | String getTbName(); 27 | 28 | String getSdKey(); 29 | 30 | ShardRouteRule getRule(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/ShardRouter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard; 17 | 18 | import org.hellojavaer.ddal.ddr.shard.exception.ShardRouteException; 19 | import org.hellojavaer.ddal.ddr.shard.exception.ShardValueNotFoundException; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | /** 26 | * All the shard route ways designed in 'DDR' can be summarized as two ways. 27 | *
28 |  * The one: one table one shard value.
29 |  *    this case can't used to to divide data which don't have strongly relevance. the great advantages of this way is you can use aggregate function in a ordinary way.
30 |  *    But as the limit you may lose some load balancing for reading and writing.
31 |  *
32 |  * The other: one table multiple shard values.
33 |  *   this dividing way can implement load balancing for reading and writing. But as the limit you can't use aggregate function in a ordinary way.
34 |  *
35 |  * 
36 | * @author Kaiming Zou,created on 05/11/2016. 37 | */ 38 | public interface ShardRouter { 39 | 40 | ShardRouteRule getRouteRule(String scName, String tbName); 41 | 42 | ShardRouteConfig getRouteConfig(String scName, String tbName); 43 | 44 | ShardRouteInfo getRouteInfo(String scName, String tbName, Object sdValue) throws ShardValueNotFoundException, 45 | ShardRouteException; 46 | 47 | List getRouteInfos(String scName, String tbName); 48 | 49 | Map> getRoutedTables(); 50 | } 51 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/AmbiguousRouteRuleBindingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/12/2016. 21 | */ 22 | public class AmbiguousRouteRuleBindingException extends DDRShardException { 23 | 24 | public AmbiguousRouteRuleBindingException() { 25 | } 26 | 27 | public AmbiguousRouteRuleBindingException(String message) { 28 | super(message); 29 | } 30 | 31 | public AmbiguousRouteRuleBindingException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public AmbiguousRouteRuleBindingException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public AmbiguousRouteRuleBindingException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/CrossTableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 16/09/2017. 21 | */ 22 | public class CrossTableException extends DDRShardException { 23 | 24 | public CrossTableException() { 25 | } 26 | 27 | public CrossTableException(String message) { 28 | super(message); 29 | } 30 | 31 | public CrossTableException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public CrossTableException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public CrossTableException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 40 | super(message, cause, enableSuppression, writableStackTrace); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/DDRShardException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/12/2016. 21 | */ 22 | public class DDRShardException extends RuntimeException { 23 | 24 | public DDRShardException() { 25 | } 26 | 27 | public DDRShardException(String message) { 28 | super(message); 29 | } 30 | 31 | public DDRShardException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public DDRShardException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public DDRShardException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 40 | super(message, cause, enableSuppression, writableStackTrace); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/DuplicateRouteRuleBindingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/12/2016. 21 | */ 22 | public class DuplicateRouteRuleBindingException extends DDRShardException { 23 | 24 | public DuplicateRouteRuleBindingException() { 25 | } 26 | 27 | public DuplicateRouteRuleBindingException(String message) { 28 | super(message); 29 | } 30 | 31 | public DuplicateRouteRuleBindingException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public DuplicateRouteRuleBindingException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public DuplicateRouteRuleBindingException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/ExpressionValueNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 02/01/2017. 21 | */ 22 | public class ExpressionValueNotFoundException extends DDRShardException { 23 | 24 | public ExpressionValueNotFoundException() { 25 | } 26 | 27 | public ExpressionValueNotFoundException(String message) { 28 | super(message); 29 | } 30 | 31 | public ExpressionValueNotFoundException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public ExpressionValueNotFoundException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public ExpressionValueNotFoundException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/IllegalShardValueException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 20/06/2017. 21 | */ 22 | public class IllegalShardValueException extends DDRShardException { 23 | 24 | public IllegalShardValueException() { 25 | } 26 | 27 | public IllegalShardValueException(String message) { 28 | super(message); 29 | } 30 | 31 | public IllegalShardValueException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public IllegalShardValueException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public IllegalShardValueException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/OutOfRangeSizeLimitException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 16/09/2017. 21 | */ 22 | public class OutOfRangeSizeLimitException extends DDRShardException { 23 | 24 | public OutOfRangeSizeLimitException() { 25 | } 26 | 27 | public OutOfRangeSizeLimitException(String message) { 28 | super(message); 29 | } 30 | 31 | public OutOfRangeSizeLimitException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public OutOfRangeSizeLimitException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public OutOfRangeSizeLimitException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/ShardRouteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | import org.hellojavaer.ddal.ddr.sqlparse.exception.DDRSQLParseException; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 02/01/2017. 23 | */ 24 | public class ShardRouteException extends DDRSQLParseException { 25 | 26 | public ShardRouteException() { 27 | } 28 | 29 | public ShardRouteException(String message) { 30 | super(message); 31 | } 32 | 33 | public ShardRouteException(String message, Throwable cause) { 34 | super(message, cause); 35 | } 36 | 37 | public ShardRouteException(Throwable cause) { 38 | super(cause); 39 | } 40 | 41 | public ShardRouteException(String message, Throwable cause, boolean enableSuppression, 42 | boolean writableStackTrace) { 43 | super(message, cause, enableSuppression, writableStackTrace); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/ShardValueNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/01/2017. 21 | */ 22 | public class ShardValueNotFoundException extends DDRShardException { 23 | 24 | public ShardValueNotFoundException() { 25 | } 26 | 27 | public ShardValueNotFoundException(String message) { 28 | super(message); 29 | } 30 | 31 | public ShardValueNotFoundException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public ShardValueNotFoundException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public ShardValueNotFoundException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/exception/UnsupportedShardValueTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.shard.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 16/09/2017. 21 | */ 22 | public class UnsupportedShardValueTypeException extends DDRShardException { 23 | 24 | public UnsupportedShardValueTypeException() { 25 | } 26 | 27 | public UnsupportedShardValueTypeException(String message) { 28 | super(message); 29 | } 30 | 31 | public UnsupportedShardValueTypeException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UnsupportedShardValueTypeException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UnsupportedShardValueTypeException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/simple/SimpleShardParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard.simple; 17 | 18 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParsedResult; 19 | import org.hellojavaer.ddal.ddr.shard.ShardParser; 20 | import org.hellojavaer.ddal.ddr.shard.ShardRouter; 21 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParsedState; 22 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParser; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * 28 | * @author Kaiming Zou,created on 15/11/2016. 29 | */ 30 | public class SimpleShardParser implements ShardParser { 31 | 32 | private ShardRouter shardRouter; 33 | private SQLParser sqlParser; 34 | 35 | private SimpleShardParser() { 36 | } 37 | 38 | public SimpleShardParser(SQLParser sqlParser, ShardRouter shardRouter) { 39 | setSqlParser(sqlParser); 40 | setShardRouter(shardRouter); 41 | } 42 | 43 | public ShardRouter getShardRouter() { 44 | return shardRouter; 45 | } 46 | 47 | public void setShardRouter(ShardRouter shardRouter) { 48 | this.shardRouter = shardRouter; 49 | } 50 | 51 | public SQLParser getSqlParser() { 52 | return sqlParser; 53 | } 54 | 55 | public void setSqlParser(SQLParser sqlParser) { 56 | this.sqlParser = sqlParser; 57 | } 58 | 59 | @Override 60 | public SQLParsedResult parse(String sql, Map jdbcParams) { 61 | SQLParsedState sqlParsedState = sqlParser.parse(sql, shardRouter); 62 | return sqlParsedState.parse(jdbcParams); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/shard/simple/SimpleShardRouteRuleBinding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.shard.simple; 17 | 18 | import org.hellojavaer.ddal.ddr.shard.ShardRouteRule; 19 | import org.hellojavaer.ddal.ddr.shard.ShardRouteRuleBinding; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 15/11/2016. 26 | */ 27 | public class SimpleShardRouteRuleBinding implements ShardRouteRuleBinding, Serializable { 28 | 29 | private static final long serialVersionUID = 0L; 30 | 31 | private String scName; 32 | private String tbName; 33 | private String sdKey; 34 | private ShardRouteRule rule; 35 | private String sdValues; 36 | 37 | public SimpleShardRouteRuleBinding() { 38 | } 39 | 40 | public SimpleShardRouteRuleBinding(String scName, String tbName, String sdKey, ShardRouteRule rule) { 41 | this(scName, tbName, sdKey, rule, null); 42 | } 43 | 44 | public SimpleShardRouteRuleBinding(String scName, String tbName, String sdKey, ShardRouteRule rule, String sdValues) { 45 | this.scName = scName; 46 | this.tbName = tbName; 47 | this.sdKey = sdKey; 48 | this.rule = rule; 49 | this.sdValues = sdValues; 50 | } 51 | 52 | @Override 53 | public String getScName() { 54 | return scName; 55 | } 56 | 57 | public void setScName(String scName) { 58 | this.scName = scName; 59 | } 60 | 61 | @Override 62 | public String getTbName() { 63 | return tbName; 64 | } 65 | 66 | public void setTbName(String tbName) { 67 | this.tbName = tbName; 68 | } 69 | 70 | @Override 71 | public String getSdKey() { 72 | return sdKey; 73 | } 74 | 75 | public void setSdKey(String sdKey) { 76 | this.sdKey = sdKey; 77 | } 78 | 79 | @Override 80 | public ShardRouteRule getRule() { 81 | return rule; 82 | } 83 | 84 | public void setRule(ShardRouteRule rule) { 85 | this.rule = rule; 86 | } 87 | 88 | public String getSdValues() { 89 | return sdValues; 90 | } 91 | 92 | public void setSdValues(String sdValues) { 93 | this.sdValues = sdValues; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/SQLParsedResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse; 17 | 18 | import org.hellojavaer.ddal.ddr.datasource.exception.CrossPreparedStatementException; 19 | import org.hellojavaer.ddal.ddr.utils.DDRToStringBuilder; 20 | 21 | import java.util.Map; 22 | import java.util.Set; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 17/12/2016. 27 | */ 28 | public class SQLParsedResult { 29 | 30 | private String sql; 31 | private Set schemas; 32 | 33 | public String getSql() { 34 | return sql; 35 | } 36 | 37 | public void setSql(String sql) { 38 | this.sql = sql; 39 | } 40 | 41 | public Set getSchemas() { 42 | return schemas; 43 | } 44 | 45 | public void setSchemas(Set schemas) { 46 | this.schemas = schemas; 47 | } 48 | 49 | public void checkIfCrossPreparedStatement(Map jdbcParam) throws CrossPreparedStatementException { 50 | 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return new DDRToStringBuilder().append("sql", sql).append("schemas", schemas).toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/SQLParsedState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse; 17 | 18 | import java.util.Map; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 11/01/2017. 23 | */ 24 | public interface SQLParsedState { 25 | 26 | SQLParsedResult parse(Map jdbcParams); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/SQLParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse; 17 | 18 | import org.hellojavaer.ddal.ddr.shard.ShardRouter; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 30/11/2016. 23 | */ 24 | public interface SQLParser { 25 | 26 | SQLParsedState parse(String sql, ShardRouter shardRouter); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/cache/SQLParserCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.cache; 17 | 18 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParser; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 11/01/2017. 23 | */ 24 | public interface SQLParserCache extends SQLParser { 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/AmbiguousRouteResultException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/12/2016. 21 | */ 22 | public class AmbiguousRouteResultException extends DDRSQLParseException { 23 | 24 | public AmbiguousRouteResultException() { 25 | } 26 | 27 | public AmbiguousRouteResultException(String message) { 28 | super(message); 29 | } 30 | 31 | public AmbiguousRouteResultException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public AmbiguousRouteResultException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public AmbiguousRouteResultException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/DDRSQLParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/12/2016. 21 | */ 22 | public class DDRSQLParseException extends RuntimeException { 23 | 24 | public DDRSQLParseException() { 25 | } 26 | 27 | public DDRSQLParseException(String message) { 28 | super(message); 29 | } 30 | 31 | public DDRSQLParseException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public DDRSQLParseException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public DDRSQLParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 40 | super(message, cause, enableSuppression, writableStackTrace); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/GetRouteInfoException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/01/2017. 21 | */ 22 | public class GetRouteInfoException extends DDRSQLParseException { 23 | 24 | public GetRouteInfoException() { 25 | } 26 | 27 | public GetRouteInfoException(String message) { 28 | super(message); 29 | } 30 | 31 | public GetRouteInfoException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public GetRouteInfoException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public GetRouteInfoException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/IllegalSQLParameterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 18/01/2017. 21 | */ 22 | public class IllegalSQLParameterException extends DDRSQLParseException { 23 | 24 | public IllegalSQLParameterException() { 25 | } 26 | 27 | public IllegalSQLParameterException(String message) { 28 | super(message); 29 | } 30 | 31 | public IllegalSQLParameterException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public IllegalSQLParameterException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public IllegalSQLParameterException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/SQLParserCompatibilityException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 2018/5/28. 21 | */ 22 | public class SQLParserCompatibilityException extends DDRSQLParseException { 23 | 24 | public SQLParserCompatibilityException() { 25 | } 26 | 27 | public SQLParserCompatibilityException(String message) { 28 | super(message); 29 | } 30 | 31 | public SQLParserCompatibilityException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public SQLParserCompatibilityException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public SQLParserCompatibilityException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/SQLSyntaxErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 09/01/2017. 21 | */ 22 | public class SQLSyntaxErrorException extends DDRSQLParseException { 23 | 24 | public SQLSyntaxErrorException() { 25 | } 26 | 27 | public SQLSyntaxErrorException(String message) { 28 | super(message); 29 | } 30 | 31 | public SQLSyntaxErrorException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public SQLSyntaxErrorException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public SQLSyntaxErrorException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/UnsupportedSQLExpressionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 12/01/2017. 21 | */ 22 | public class UnsupportedSQLExpressionException extends RuntimeException { 23 | 24 | public UnsupportedSQLExpressionException() { 25 | } 26 | 27 | public UnsupportedSQLExpressionException(String message) { 28 | super(message); 29 | } 30 | 31 | public UnsupportedSQLExpressionException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UnsupportedSQLExpressionException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UnsupportedSQLExpressionException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/UnsupportedSQLParameterTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 24/12/2016. 21 | */ 22 | public class UnsupportedSQLParameterTypeException extends DDRSQLParseException { 23 | 24 | public UnsupportedSQLParameterTypeException() { 25 | } 26 | 27 | public UnsupportedSQLParameterTypeException(String message) { 28 | super(message); 29 | } 30 | 31 | public UnsupportedSQLParameterTypeException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UnsupportedSQLParameterTypeException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UnsupportedSQLParameterTypeException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/sqlparse/exception/UnsupportedSQLStatementException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.sqlparse.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/12/2016. 21 | */ 22 | public class UnsupportedSQLStatementException extends DDRSQLParseException { 23 | 24 | public UnsupportedSQLStatementException() { 25 | } 26 | 27 | public UnsupportedSQLStatementException(String message) { 28 | super(message); 29 | } 30 | 31 | public UnsupportedSQLStatementException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public UnsupportedSQLStatementException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public UnsupportedSQLStatementException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/utils/DDRStringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.utils; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 19/11/2016. 21 | */ 22 | public class DDRStringUtils { 23 | 24 | public static String trimToNull(String str) { 25 | if (str == null) { 26 | return null; 27 | } else { 28 | str = str.trim(); 29 | if (str.length() == 0) { 30 | return null; 31 | } else { 32 | return str; 33 | } 34 | } 35 | } 36 | 37 | public static String toLowerCase(String str) { 38 | if (str == null) { 39 | return null; 40 | } else { 41 | str = str.trim(); 42 | if (str.length() == 0) { 43 | return null; 44 | } else { 45 | return str.toLowerCase(); 46 | } 47 | } 48 | } 49 | 50 | public static boolean equals(String s0, String s1) { 51 | if (s0 == null && s1 == null) { 52 | return true; 53 | } else if (s0 != null) { 54 | return s0.equals(s1); 55 | } else if (s1 != null) { 56 | return s1.equals(s0); 57 | } else { 58 | return false; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ddal-ddr/src/main/java/org/hellojavaer/ddal/ddr/utils/DDRToStringBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.utils; 17 | 18 | import java.util.Collection; 19 | import java.util.Map; 20 | 21 | /** 22 | * 23 | * @author Kaiming Zou,created on 25/12/2016. 24 | */ 25 | public class DDRToStringBuilder { 26 | 27 | private StringBuilder sb = new StringBuilder("{"); 28 | private int count = 0; 29 | 30 | public DDRToStringBuilder append(String name, Object val) { 31 | if (name == null) { 32 | sb.append("null"); 33 | sb.append(":"); 34 | } else { 35 | sb.append('\"'); 36 | sb.append(name); 37 | sb.append("\":"); 38 | } 39 | if (val == null) { 40 | sb.append("null"); 41 | } else if (val instanceof String || val instanceof Character) { 42 | sb.append('\"'); 43 | sb.append(val); 44 | sb.append('\"'); 45 | } else if (val instanceof Collection) { 46 | sb.append(DDRJSONUtils.toJSONString((Collection) val)); 47 | } else if (val instanceof Map) { 48 | sb.append(DDRJSONUtils.toJSONString((Map) val)); 49 | } else { 50 | sb.append(val); 51 | } 52 | sb.append(','); 53 | count++; 54 | return this; 55 | } 56 | 57 | public String toString() { 58 | if (count > 0) { 59 | sb.deleteCharAt(sb.length() - 1); 60 | } 61 | sb.append('}'); 62 | String temp = sb.toString(); 63 | sb.deleteCharAt(sb.length() - 1); 64 | if (count > 0) { 65 | sb.append(','); 66 | } 67 | return temp; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ddal-ddr/src/test/java/org/hellojavaer/ddal/ddr/cluster/DBClusterRouteContextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.cluster; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.junit.Test; 20 | 21 | /** 22 | * 23 | * @author Kaiming Zou,created on 2018/5/28. 24 | */ 25 | public class DBClusterRouteContextTest { 26 | 27 | @Test 28 | public void test00() { 29 | Assert.notNull(DBClusterRouteContext.lookupVariable("format")); 30 | Assert.equals(DBClusterRouteContext.getVariable("format"), null); 31 | Assert.equals(DBClusterRouteContext.getClusterName(), null); 32 | // 33 | DBClusterRouteContext.setVariable("a", "1"); 34 | DBClusterRouteContext.setClusterName("US"); 35 | Assert.equals(DBClusterRouteContext.getVariable("a"), "1"); 36 | Assert.equals(DBClusterRouteContext.lookupVariable("a"), "1"); 37 | Assert.equals(DBClusterRouteContext.getClusterName(), "US"); 38 | // 39 | DBClusterRouteContext.pushContext(); 40 | Assert.equals(DBClusterRouteContext.getVariable("a"), null); 41 | Assert.equals(DBClusterRouteContext.lookupVariable("a"), "1"); 42 | Assert.equals(DBClusterRouteContext.getClusterName(), null); 43 | // 44 | DBClusterRouteContext.setVariable("a", "2"); 45 | DBClusterRouteContext.setClusterName("CN"); 46 | Assert.equals(DBClusterRouteContext.getVariable("a"), "2"); 47 | Assert.equals(DBClusterRouteContext.lookupVariable("a"), "2"); 48 | Assert.equals(DBClusterRouteContext.getClusterName(), "CN"); 49 | // 50 | DBClusterRouteContext.popContext(); 51 | Assert.equals(DBClusterRouteContext.getVariable("a"), "1"); 52 | Assert.equals(DBClusterRouteContext.lookupVariable("a"), "1"); 53 | Assert.equals(DBClusterRouteContext.getClusterName(), "US"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ddal-ddr/src/test/java/org/hellojavaer/ddal/ddr/expression/ShardRouteRuleExpressionContextTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.expression; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.junit.Test; 20 | 21 | /** 22 | * 23 | * @author Kaiming Zou,created on 2018/5/28. 24 | */ 25 | public class ShardRouteRuleExpressionContextTest { 26 | 27 | @Test 28 | public void test00() { 29 | Assert.notNull(ShardRouteRuleExpressionContext.lookupVariable("format")); 30 | Assert.equals(ShardRouteRuleExpressionContext.getVariable("format"), null); 31 | // 32 | ShardRouteRuleExpressionContext.setVariable("a", "1"); 33 | Assert.equals(ShardRouteRuleExpressionContext.getVariable("a"), "1"); 34 | Assert.equals(ShardRouteRuleExpressionContext.lookupVariable("a"), "1"); 35 | // 36 | ShardRouteRuleExpressionContext.pushContext(); 37 | Assert.equals(ShardRouteRuleExpressionContext.getVariable("a"), null); 38 | Assert.equals(ShardRouteRuleExpressionContext.lookupVariable("a"), "1"); 39 | // 40 | ShardRouteRuleExpressionContext.setVariable("a", "2"); 41 | Assert.equals(ShardRouteRuleExpressionContext.getVariable("a"), "2"); 42 | Assert.equals(ShardRouteRuleExpressionContext.lookupVariable("a"), "2"); 43 | // 44 | ShardRouteRuleExpressionContext.popContext(); 45 | Assert.equals(ShardRouteRuleExpressionContext.getVariable("a"), "1"); 46 | Assert.equals(ShardRouteRuleExpressionContext.lookupVariable("a"), "1"); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /ddal-ddr/src/test/java/org/hellojavaer/ddal/ddr/expression/el/function/FormatFunctionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.ddr.expression.el.function; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.junit.Test; 20 | 21 | /** 22 | * 23 | * @author Kaiming Zou,created on 2018/5/27. 24 | */ 25 | public class FormatFunctionTest { 26 | 27 | @Test 28 | public void format() { 29 | Assert.equals(FormatFunction.format("%04d", 12), "0012"); 30 | Assert.equals(FormatFunction.format("%04d", 12345), "12345"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ddal-ddr/src/test/java/org/hellojavaer/ddal/ddr/utils/DDRJSONUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.utils; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.junit.Test; 20 | 21 | import java.util.ArrayList; 22 | import java.util.LinkedHashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * 28 | * @author Kaiming Zou,created on 23/12/2016. 29 | */ 30 | public class DDRJSONUtilsTest { 31 | 32 | @Test 33 | public void test01() { 34 | List list = new ArrayList<>(); 35 | list.add("12"); 36 | list.add("34"); 37 | list.add(null); 38 | String src = DDRJSONUtils.toJSONString(list); 39 | Assert.equals(src, "[\"12\",\"34\",null]"); 40 | } 41 | 42 | @Test 43 | public void test02() { 44 | List list = new ArrayList<>(); 45 | list.add(1); 46 | list.add(2); 47 | list.add(null); 48 | String src = DDRJSONUtils.toJSONString(list); 49 | Assert.equals(src, "[1,2,null]"); 50 | } 51 | 52 | // list 测试 53 | @Test 54 | public void test03() { 55 | List list = new ArrayList(); 56 | list.add(1); 57 | list.add("2"); 58 | list.add(null); 59 | String src = DDRJSONUtils.toJSONString(list); 60 | Assert.equals(src, "[1,\"2\",null]"); 61 | } 62 | 63 | // map 测试 64 | @Test 65 | public void test04() { 66 | Map map = new LinkedHashMap<>(); 67 | map.put(1, "12"); 68 | map.put("2", 13); 69 | map.put("2", null); 70 | map.put(null, 14); 71 | String src = DDRJSONUtils.toJSONString(map); 72 | Assert.equals(src, "{1:\"12\",\"2\":null,null:14}"); 73 | } 74 | 75 | // 嵌套测试 76 | @Test 77 | public void test05() { 78 | Map map = new LinkedHashMap<>(); 79 | map.put(1, "12"); 80 | map.put("2", 13); 81 | List list = new ArrayList(); 82 | list.add("78"); 83 | list.add(90); 84 | map.put(56, list); 85 | String src = DDRJSONUtils.toJSONString(map); 86 | Assert.equals(src, "{1:\"12\",\"2\":13,56:[\"78\",90]}"); 87 | } 88 | 89 | @Test 90 | public void test06() { 91 | List list = new ArrayList(); 92 | list.add("78"); 93 | list.add(90); 94 | Map map = new LinkedHashMap<>(); 95 | map.put(1, "12"); 96 | map.put("2", 13); 97 | list.add(map); 98 | String src = DDRJSONUtils.toJSONString(list); 99 | Assert.equals(src, "[\"78\",90,{1:\"12\",\"2\":13}]"); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /ddal-ddr/src/test/java/org/hellojavaer/ddal/ddr/utils/DDRStringUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.utils; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.junit.Test; 20 | 21 | /** 22 | * 23 | * @author Kaiming Zou,created on 23/12/2016. 24 | */ 25 | public class DDRStringUtilsTest { 26 | 27 | @Test 28 | public void trim() { 29 | Assert.isTrue(DDRStringUtils.trimToNull(null) == null); 30 | Assert.isTrue(DDRStringUtils.trimToNull("") == null); 31 | Assert.isTrue(DDRStringUtils.trimToNull(" ") == null); 32 | Assert.isTrue(DDRStringUtils.trimToNull(" ") == null); 33 | Assert.isTrue(DDRStringUtils.trimToNull(" ") == null); 34 | Assert.equals(DDRStringUtils.trimToNull(" ab "), "ab"); 35 | Assert.equals(DDRStringUtils.trimToNull("ab"), "ab"); 36 | Assert.isTrue(!DDRStringUtils.trimToNull(" aB ").equals("ab")); 37 | } 38 | 39 | @Test 40 | public void toLowerCase() { 41 | Assert.isTrue(DDRStringUtils.toLowerCase(null) == null); 42 | Assert.isTrue(DDRStringUtils.toLowerCase("") == null); 43 | Assert.isTrue(DDRStringUtils.toLowerCase(" ") == null); 44 | Assert.isTrue(DDRStringUtils.toLowerCase(" ") == null); 45 | Assert.isTrue(DDRStringUtils.toLowerCase(" ") == null); 46 | Assert.equals(DDRStringUtils.toLowerCase(" ab "), "ab"); 47 | Assert.equals(DDRStringUtils.toLowerCase("ab"), "ab"); 48 | Assert.equals(DDRStringUtils.toLowerCase(" aB "), "ab"); 49 | Assert.isTrue(!DDRStringUtils.trimToNull("aB").equals("ac")); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ddal-ddr/src/test/java/org/hellojavaer/ddal/ddr/utils/DDRToStringBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.ddr.utils; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.junit.Test; 20 | 21 | import java.util.ArrayList; 22 | import java.util.LinkedHashMap; 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** 27 | * 28 | * @author Kaiming Zou,created on 27/12/2016. 29 | */ 30 | public class DDRToStringBuilderTest { 31 | 32 | @Test 33 | public void test00() { 34 | DDRToStringBuilder sb = new DDRToStringBuilder().append("a0", "b0")// 35 | .append("a1", 11)// 36 | .append("a2", true)// 37 | .append("a3", null)// 38 | .append(null, "dd");// 39 | Assert.equals(sb.toString(), "{\"a0\":\"b0\",\"a1\":11,\"a2\":true,\"a3\":null,null:\"dd\"}");// 40 | Assert.equals(sb.toString(), "{\"a0\":\"b0\",\"a1\":11,\"a2\":true,\"a3\":null,null:\"dd\"}");// 41 | sb.append("a4", "12");// 42 | Assert.equals(sb.toString(), "{\"a0\":\"b0\",\"a1\":11,\"a2\":true,\"a3\":null,null:\"dd\",\"a4\":\"12\"}");// 43 | } 44 | 45 | @Test 46 | public void test01() { 47 | Map map = new LinkedHashMap<>(); 48 | map.put("a", "b"); 49 | List list = new ArrayList(); 50 | list.add(1); 51 | list.add("2"); 52 | DDRToStringBuilder sb = new DDRToStringBuilder().append("a0", map)// 53 | .append("a1", list); 54 | Assert.equals(sb.toString(), "{\"a0\":{\"a\":\"b\"},\"a1\":[1,\"2\"]}");// 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example0/src/main/java/org/hellojavaer/ddal/example/example0/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.example.example0.dao; 17 | 18 | import org.hellojavaer.ddal.example.example0.entity.UserEntity; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 15/06/2017. 25 | */ 26 | public interface UserDao { 27 | 28 | /** 29 | * @param userEntity 30 | * @return id 31 | */ 32 | Long add(UserEntity userEntity); 33 | 34 | /** 35 | * 36 | * @param id 37 | * @return effective lines 38 | */ 39 | int deleteById(Long id); 40 | 41 | /** 42 | * 43 | * @param userEntity 44 | * @return effective lines 45 | */ 46 | int updateById(UserEntity userEntity); 47 | 48 | /** 49 | * 50 | * @param id 51 | * @return 52 | */ 53 | UserEntity getById(Long id); 54 | 55 | /** 56 | * 57 | * @return 58 | */ 59 | List scanQueryAll(); 60 | } 61 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example0/src/main/java/org/hellojavaer/ddal/example/example0/dao/impl/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.example.example0.dao.impl; 17 | 18 | import org.hellojavaer.ddal.example.example0.dao.UserDao; 19 | import org.hellojavaer.ddal.example.example0.entity.UserEntity; 20 | import org.hellojavaer.ddal.sequence.Sequence; 21 | import org.mybatis.spring.SqlSessionTemplate; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.stereotype.Repository; 24 | 25 | import java.util.List; 26 | import java.util.concurrent.TimeUnit; 27 | 28 | /** 29 | * 30 | * @author Kaiming Zou,created on 15/06/2017. 31 | */ 32 | @Repository 33 | public class UserDaoImpl implements UserDao { 34 | 35 | @Autowired 36 | private SqlSessionTemplate sqlSessionTemplate; 37 | 38 | @Autowired 39 | private Sequence sequence; 40 | 41 | @Override 42 | public Long add(UserEntity userEntity) { 43 | Long id = sequence.nextValue(100, TimeUnit.MILLISECONDS); 44 | userEntity.setId(id); 45 | sqlSessionTemplate.insert("user.add", userEntity); 46 | return id; 47 | } 48 | 49 | @Override 50 | public int deleteById(Long id) { 51 | return sqlSessionTemplate.delete("user.deleteById", id); 52 | } 53 | 54 | @Override 55 | public int updateById(UserEntity userEntity) { 56 | return sqlSessionTemplate.update("user.updateById", userEntity); 57 | } 58 | 59 | @Override 60 | public UserEntity getById(Long id) { 61 | return sqlSessionTemplate.selectOne("user.getById", id); 62 | } 63 | 64 | @Override 65 | public List scanQueryAll() { 66 | return sqlSessionTemplate.selectList("user.scanQueryAll"); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example0/src/main/java/org/hellojavaer/ddal/example/example0/entity/UserEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.example.example0.entity; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 16/06/2017. 21 | */ 22 | public class UserEntity { 23 | 24 | private Long id; 25 | private String name; 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "UserEntity{" + "id=" + id + ", name='" + name + '\'' + '}'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example0/src/main/resources/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | org.hellojavaer.ddal.sequence.Sequence 22 | 23 | 24 | 25 | 26 | 27 | org.hellojavaer.ddal.ddr.shard.ShardRouter 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example0/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example0/src/main/resources/mapper/user.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | INSERT INTO user (id, name) 9 | VALUES (#{id}, #{name}) 10 | 11 | 12 | 13 | DELETE FROM user 14 | WHERE id = #{id} 15 | 16 | 17 | 18 | UPDATE user 19 | SET name = #{name} 20 | WHERE id= #{id} 21 | 22 | 23 | 28 | 29 | 33 | 34 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example0/src/main/resources/mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example1/src/main/java/org/hellojavaer/ddal/example/example1/dao/RoleDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.example.example1.dao; 17 | 18 | import org.hellojavaer.ddal.example.example1.entitry.RoleEntity; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 22/07/2017. 23 | */ 24 | public interface RoleDao { 25 | 26 | /** 27 | * 28 | * @param roleEntity 29 | * @return 30 | */ 31 | Long add(RoleEntity roleEntity); 32 | 33 | /** 34 | * 35 | * @param id 36 | * @return effective lines 37 | */ 38 | int deleteById(Long id); 39 | 40 | /** 41 | * 42 | * @param roleEntity 43 | * @return 44 | */ 45 | int updateById(RoleEntity roleEntity); 46 | 47 | /** 48 | * 49 | * @param id 50 | * @return 51 | */ 52 | RoleEntity getById(Long id); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example1/src/main/java/org/hellojavaer/ddal/example/example1/dao/impl/RoleDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.example.example1.dao.impl; 17 | 18 | import org.hellojavaer.ddal.example.example1.dao.RoleDao; 19 | import org.hellojavaer.ddal.example.example1.entitry.RoleEntity; 20 | import org.mybatis.spring.SqlSessionTemplate; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.stereotype.Repository; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 22/07/2017. 27 | */ 28 | @Repository 29 | public class RoleDaoImpl implements RoleDao { 30 | 31 | @Autowired 32 | private SqlSessionTemplate sqlSessionTemplate; 33 | 34 | @Override 35 | public Long add(RoleEntity roleEntity) { 36 | sqlSessionTemplate.insert("role.add", roleEntity); 37 | return roleEntity.getId(); 38 | } 39 | 40 | @Override 41 | public int deleteById(Long id) { 42 | return sqlSessionTemplate.delete("role.deleteById", id); 43 | } 44 | 45 | @Override 46 | public int updateById(RoleEntity roleEntity) { 47 | return sqlSessionTemplate.update("role.updateById", roleEntity); 48 | } 49 | 50 | @Override 51 | public RoleEntity getById(Long id) { 52 | return sqlSessionTemplate.selectOne("role.getById", id); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example1/src/main/java/org/hellojavaer/ddal/example/example1/entitry/RoleEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.example.example1.entitry; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 22/07/2017. 21 | */ 22 | public class RoleEntity { 23 | 24 | private Long id; 25 | private String name; 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "RoleEntity{" + "id=" + id + ", name='" + name + '\'' + '}'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example1/src/main/resources/context.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 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example1/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example1/src/main/resources/mapper/role.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | INSERT INTO role(id, name) 9 | VALUES (#{id}, #{name}) 10 | 11 | SELECT last_insert_id() as id; 12 | 13 | 14 | 15 | 16 | DELETE FROM role 17 | WHERE id = #{id} 18 | 19 | 20 | 21 | UPDATE role 22 | SET name = #{name} 23 | WHERE id= #{id} 24 | 25 | 26 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ddal-example/ddal-example-example1/src/main/resources/mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ddal-jsqlparser/src/main/java/org/hellojavaer/ddal/jsqlparser/JSQLBaseVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * JSQLParser library 4 | * %% 5 | * Copyright (C) 2016 - 2017 JSQLParser 6 | * %% 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 2.1 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Lesser Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Lesser Public 18 | * License along with this program. If not, see 19 | * . 20 | * #L% 21 | */ 22 | package org.hellojavaer.ddal.jsqlparser; 23 | 24 | import net.sf.jsqlparser.schema.Column; 25 | import net.sf.jsqlparser.schema.Table; 26 | import net.sf.jsqlparser.statement.select.WithItem; 27 | import net.sf.jsqlparser.util.TablesNamesFinder; 28 | 29 | /** 30 | * 31 | * @author Kaiming Zou,created on 12/11/2016. 32 | */ 33 | public class JSQLBaseVisitor extends TablesNamesFinder { 34 | 35 | public void init() { 36 | // do nothing 37 | } 38 | 39 | public void init(boolean allowColumnProcessing) { 40 | // do nothing 41 | } 42 | 43 | @Override 44 | public void visit(Table tableName) { 45 | // do nothing 46 | } 47 | 48 | @Override 49 | public void visit(WithItem withItem) { 50 | withItem.getSelectBody().accept(this); 51 | } 52 | 53 | @Override 54 | public void visit(Column tableColumn) { 55 | // do nothing 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /ddal-jsqlparser/src/main/java/org/hellojavaer/ddal/jsqlparser/JSQLParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * #%L 3 | * ddal-jsqlparser 4 | * %% 5 | * Copyright (C) 2016 - 2017 the original author or authors. 6 | * %% 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 2.1 of the 10 | * License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Lesser Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Lesser Public 18 | * License along with this program. If not, see 19 | * . 20 | * #L% 21 | */ 22 | package org.hellojavaer.ddal.jsqlparser; 23 | 24 | import org.hellojavaer.ddal.ddr.shard.ShardRouter; 25 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParsedState; 26 | import org.hellojavaer.ddal.ddr.sqlparse.SQLParser; 27 | 28 | /** 29 | * 30 | * @author Kaiming Zou,created on 12/11/2016. 31 | */ 32 | public class JSQLParser implements SQLParser { 33 | 34 | private boolean enableLimitCheck = false; 35 | 36 | public boolean isEnableLimitCheck() { 37 | return enableLimitCheck; 38 | } 39 | 40 | public void setEnableLimitCheck(boolean enableLimitCheck) { 41 | this.enableLimitCheck = enableLimitCheck; 42 | } 43 | 44 | @Override 45 | public SQLParsedState parse(String sql, ShardRouter shardRouter) { 46 | JSQLParserAdapter sqlParser = new JSQLParserAdapter(sql, shardRouter, enableLimitCheck); 47 | return sqlParser.parse(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence; 17 | 18 | import java.util.concurrent.atomic.AtomicInteger; 19 | 20 | /** 21 | * 22 | * @author Kaiming Zou,created on 25/06/2017. 23 | */ 24 | public interface ExceptionHandler { 25 | 26 | /** 27 | * 28 | * @return true this exception will be ignore, false this exception will be transmitted to system processor. 29 | */ 30 | boolean handle(Throwable e, AtomicInteger retryCount); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/GroupSequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 25/06/2017. 21 | */ 22 | public interface GroupSequence extends Sequence { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/Sequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence; 17 | 18 | import org.hellojavaer.ddal.sequence.exception.GetSequenceTimeoutException; 19 | 20 | import java.util.concurrent.TimeUnit; 21 | 22 | /** 23 | * 24 | * @author Kaiming Zou,created on 03/01/2017. 25 | */ 26 | public interface Sequence { 27 | 28 | long nextValue(long timeout, TimeUnit timeUnit) throws GetSequenceTimeoutException; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/SequenceRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence; 17 | 18 | import java.io.Serializable; 19 | 20 | /** 21 | * [begin,end] closed interval 22 | * 23 | * @author Kaiming Zou,created on 04/01/2017. 24 | */ 25 | public class SequenceRange implements Serializable { 26 | 27 | private static final long serialVersionUID = 0L; 28 | 29 | private long beginValue; 30 | private long endValue; 31 | 32 | public SequenceRange() { 33 | } 34 | 35 | public SequenceRange(long beginValue, long endValue) { 36 | this.beginValue = beginValue; 37 | this.endValue = endValue; 38 | } 39 | 40 | public long getBeginValue() { 41 | return beginValue; 42 | } 43 | 44 | public void setBeginValue(long beginValue) { 45 | this.beginValue = beginValue; 46 | } 47 | 48 | public long getEndValue() { 49 | return endValue; 50 | } 51 | 52 | public void setEndValue(long endValue) { 53 | this.endValue = endValue; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return new StringBuilder().append("{beginValue:").append(beginValue).append(",endValue:").append(endValue).append('}').toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/SequenceRangeGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 04/01/2017. 21 | */ 22 | public interface SequenceRangeGetter { 23 | 24 | SequenceRange get(String schemaName, String tableName, int step) throws Exception; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/exception/GetSequenceFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 09/09/2017. 21 | */ 22 | public class GetSequenceFailedException extends SequenceException { 23 | 24 | public GetSequenceFailedException() { 25 | } 26 | 27 | public GetSequenceFailedException(String message) { 28 | super(message); 29 | } 30 | 31 | public GetSequenceFailedException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public GetSequenceFailedException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public GetSequenceFailedException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/exception/GetSequenceTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 19/07/2017. 21 | */ 22 | public class GetSequenceTimeoutException extends SequenceException { 23 | 24 | public GetSequenceTimeoutException() { 25 | } 26 | 27 | public GetSequenceTimeoutException(String message) { 28 | super(message); 29 | } 30 | 31 | public GetSequenceTimeoutException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public GetSequenceTimeoutException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public GetSequenceTimeoutException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/exception/IllegalSequenceRangeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/06/2017. 21 | */ 22 | public class IllegalSequenceRangeException extends SequenceException { 23 | 24 | public IllegalSequenceRangeException() { 25 | } 26 | 27 | public IllegalSequenceRangeException(String message) { 28 | super(message); 29 | } 30 | 31 | public IllegalSequenceRangeException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public IllegalSequenceRangeException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public IllegalSequenceRangeException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/exception/NoAvailableSequenceRangeFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/06/2017. 21 | */ 22 | public class NoAvailableSequenceRangeFoundException extends SequenceException { 23 | 24 | public NoAvailableSequenceRangeFoundException() { 25 | } 26 | 27 | public NoAvailableSequenceRangeFoundException(String message) { 28 | super(message); 29 | } 30 | 31 | public NoAvailableSequenceRangeFoundException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public NoAvailableSequenceRangeFoundException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public NoAvailableSequenceRangeFoundException(String message, Throwable cause, boolean enableSuppression, 40 | boolean writableStackTrace) { 41 | super(message, cause, enableSuppression, writableStackTrace); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ddal-sequence/src/main/java/org/hellojavaer/ddal/sequence/exception/SequenceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence.exception; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 23/06/2017. 21 | */ 22 | public class SequenceException extends RuntimeException { 23 | 24 | public SequenceException() { 25 | } 26 | 27 | public SequenceException(String message) { 28 | super(message); 29 | } 30 | 31 | public SequenceException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public SequenceException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | public SequenceException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 40 | super(message, cause, enableSuppression, writableStackTrace); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ddal-sequence/src/test/java/org/hellojavaer/ddal/sequence/LinkedCycleListTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2017 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 | package org.hellojavaer.ddal.sequence; 17 | 18 | import org.junit.Test; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 21/08/2017. 26 | */ 27 | public class LinkedCycleListTest { 28 | 29 | @Test 30 | public void test() { 31 | List list = new ArrayList<>(); 32 | list.add(1); 33 | list.add(5); 34 | list.add(3); 35 | list.add(7); 36 | list.add(9); 37 | LinkedCycleList cycleList = new LinkedCycleList(list); 38 | for (int i = 0; i < list.size() * 2; i++) { 39 | int j = i; 40 | for (Integer item : cycleList) { 41 | assertEqual(item, list.get(j % list.size())); 42 | j++; 43 | } 44 | cycleList.next(); 45 | } 46 | } 47 | 48 | private void assertEqual(int a, int b) { 49 | if (a != b) { 50 | throw new IllegalArgumentException("[Assertion failed] - " + a + " is not equal to " + b); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ddal-server/ddal-server-datasource/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | org.hellojavaer.ddal 9 | ddal-server-datasource 10 | 1.0.0-SNAPSHOT 11 | 12 | ddal-server-datasource 13 | https://github.com/hellojavaer/ddal 14 | 15 | 16 | 17 | hellojavaer 18 | Kaiming Zou 19 | hellojavaer@gmail.com 20 | 21 | owner 22 | developer 23 | 24 | 8 25 | 26 | 27 | 28 | https://github.com/hellojavaer/ddal.git 29 | scm:git:https://github.com/hellojavaer/ddal.git 30 | 31 | 32 | 33 | Apache 2 34 | http://www.apache.org/licenses/LICENSE-2.0.txt 35 | repo 36 | A business-friendly OSS license 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-deploy-plugin 45 | 2.8.2 46 | 47 | true 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /ddal-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | org.hellojavaer.ddal 9 | ddal-server 10 | 1.0.0-SNAPSHOT 11 | pom 12 | 13 | ddal-server 14 | https://github.com/hellojavaer/ddal 15 | 16 | 17 | ddal-server-datasource 18 | 19 | 20 | 21 | true 22 | 1.7 23 | UTF-8 24 | 25 | 26 | 27 | 28 | hellojavaer 29 | Kaiming Zou 30 | hellojavaer@gmail.com 31 | 32 | owner 33 | developer 34 | 35 | 8 36 | 37 | 38 | 39 | https://github.com/hellojavaer/ddal.git 40 | scm:git:https://github.com/hellojavaer/ddal.git 41 | 42 | 43 | 44 | Apache 2 45 | http://www.apache.org/licenses/LICENSE-2.0.txt 46 | repo 47 | A business-friendly OSS license 48 | 49 | 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-compiler-plugin 55 | 3.2 56 | 57 | ${jdk.version} 58 | ${jdk.version} 59 | ${project.build.sourceEncoding} 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.apache.maven.plugins 67 | maven-install-plugin 68 | 69 | 70 | default-install 71 | none 72 | 73 | 74 | 75 | 76 | org.apache.maven.plugins 77 | maven-deploy-plugin 78 | 2.8.2 79 | 80 | true 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /ddal-spring/src/main/java/org/hellojavaer/ddal/spring/scan/EnableDBClusterRouteAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.spring.scan; 17 | 18 | import org.aspectj.lang.ProceedingJoinPoint; 19 | import org.aspectj.lang.annotation.Around; 20 | import org.aspectj.lang.annotation.Aspect; 21 | import org.aspectj.lang.reflect.MethodSignature; 22 | import org.hellojavaer.ddal.ddr.cluster.DBClusterRoute; 23 | import org.hellojavaer.ddal.ddr.cluster.DBClusterRouteContext; 24 | import org.springframework.stereotype.Component; 25 | 26 | import java.lang.reflect.Method; 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | /** 31 | * add the following tags in spring configuration file 32 | *
33 |         
34 |         
35 |  * 
36 | * 37 | * @author Kaiming Zou,created on 2018/5/27. 38 | */ 39 | @Aspect 40 | @Component 41 | public class EnableDBClusterRouteAnnotation { 42 | 43 | private Map expressionCache = new HashMap<>(); 44 | 45 | @Around("@annotation(dbClusterRoute)") 46 | public Object around(ProceedingJoinPoint joinPoint, DBClusterRoute dbClusterRoute) throws Throwable { 47 | try { 48 | DBClusterRouteContext.pushContext(); 49 | Object[] args = joinPoint.getArgs(); 50 | MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); 51 | Method method = methodSignature.getMethod(); 52 | MethodBasedSpelExpression expression = expressionCache.get(method); 53 | if (expression == null) { 54 | synchronized (expressionCache) { 55 | expression = expressionCache.get(method); 56 | if (expression == null) { 57 | expression = new MethodBasedSpelExpression(dbClusterRoute.clusterName(), method); 58 | expressionCache.put(method, expression); 59 | } 60 | } 61 | } 62 | String targetClusterName = expression.parse(String.class, args); 63 | DBClusterRouteContext.setClusterName(targetClusterName); 64 | return joinPoint.proceed(args); 65 | } finally { 66 | DBClusterRouteContext.popContext(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ddal-spring/src/test/java/org/hellojavaer/ddal/spring/scan/EnableShardRouteAnnotationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.spring.scan; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.test.context.ContextConfiguration; 22 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 21/06/2017. 27 | */ 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @ContextConfiguration(locations = { "classpath:/spring.xml" }) 30 | public class EnableShardRouteAnnotationTest { 31 | 32 | @Autowired 33 | private ShardRouteTestComponent shardRouteTestComponent; 34 | 35 | @Test 36 | public void test01() { 37 | for (int i = 0; i < 100; i++) { 38 | shardRouteTestComponent.routeWithId((long) i); 39 | } 40 | } 41 | 42 | @Test 43 | public void test02() { 44 | for (long i = 0; i < 100; i++) { 45 | UserEntity userEntity = new UserEntity(); 46 | userEntity.setId(i); 47 | shardRouteTestComponent.routeWithEntity(userEntity); 48 | } 49 | } 50 | 51 | @Test 52 | public void testFormat() { 53 | for (long i = 0; i < 100; i++) { 54 | UserEntity userEntity = new UserEntity(); 55 | userEntity.setId(i); 56 | shardRouteTestComponent.testFunction(userEntity); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /ddal-spring/src/test/java/org/hellojavaer/ddal/spring/scan/ShardRouteTestComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.spring.scan; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.hellojavaer.ddal.ddr.shard.ShardRoute; 20 | import org.hellojavaer.ddal.ddr.shard.ShardRouteContext; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * 25 | * @author Kaiming Zou,created on 22/06/2017. 26 | */ 27 | @Component 28 | public class ShardRouteTestComponent { 29 | 30 | @ShardRoute(scName = "user,shop", sdValue = "{$0}") 31 | public void routeWithId(Long id) { 32 | Assert.isTrue(ShardRouteContext.getRouteInfo("user") == id); 33 | Assert.isTrue(ShardRouteContext.getRouteInfo("shop") == id); 34 | } 35 | 36 | @ShardRoute(scName = "user,shop", sdValue = "{$0.id}") 37 | public void routeWithEntity(UserEntity userEntity) { 38 | Assert.isTrue(ShardRouteContext.getRouteInfo("user") == userEntity.getId()); 39 | Assert.isTrue(ShardRouteContext.getRouteInfo("shop") == userEntity.getId()); 40 | } 41 | 42 | @ShardRoute(scName = "user,shop", sdValue = "tb_{format('%04d',$0.id)}") 43 | public void testFunction(UserEntity userEntity) { 44 | Assert.isTrue(ShardRouteContext.getRouteInfo("user").equals(String.format("tb_%04d", userEntity.getId()))); 45 | Assert.isTrue(ShardRouteContext.getRouteInfo("shop").equals(String.format("tb_%04d", userEntity.getId()))); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ddal-spring/src/test/java/org/hellojavaer/ddal/spring/scan/UserEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 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 | package org.hellojavaer.ddal.spring.scan; 17 | 18 | /** 19 | * 20 | * @author Kaiming Zou,created on 27/07/2017. 21 | */ 22 | public class UserEntity { 23 | 24 | private Long id; 25 | 26 | public Long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Long id) { 31 | this.id = id; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ddal-spring/src/test/java/org/hellojavaer/ddal/spring/scan/dbcluster/DBClusterRouteTestComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.spring.scan.dbcluster; 17 | 18 | import org.hellojavaer.ddal.core.utils.Assert; 19 | import org.hellojavaer.ddal.ddr.cluster.DBClusterRoute; 20 | import org.hellojavaer.ddal.ddr.cluster.DBClusterRouteContext; 21 | import org.hellojavaer.ddal.spring.scan.UserEntity; 22 | import org.springframework.stereotype.Component; 23 | 24 | /** 25 | * 26 | * @author Kaiming Zou,created on 2018/5/28. 27 | */ 28 | @Component 29 | public class DBClusterRouteTestComponent { 30 | 31 | @DBClusterRoute(clusterName = "-name-") 32 | public void test00() { 33 | Assert.equals(DBClusterRouteContext.getClusterName(), "-name-"); 34 | } 35 | 36 | @DBClusterRoute(clusterName = "-{$0}-") 37 | public void test01(String str) { 38 | Assert.equals(DBClusterRouteContext.getClusterName(), "-" + str + "-"); 39 | } 40 | 41 | @DBClusterRoute(clusterName = "{$0}") 42 | public void test02(int id) { 43 | Assert.equals(DBClusterRouteContext.getClusterName(), id + ""); 44 | } 45 | 46 | @DBClusterRoute(clusterName = "tb_{format('%04d',$0.id)}") 47 | public void testFunction(UserEntity userEntity) { 48 | Assert.equals(DBClusterRouteContext.getClusterName(), (String.format("tb_%04d", userEntity.getId()))); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ddal-spring/src/test/java/org/hellojavaer/ddal/spring/scan/dbcluster/EnableDBClusterRouteAnnotationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2018 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 | package org.hellojavaer.ddal.spring.scan.dbcluster; 17 | 18 | import org.hellojavaer.ddal.spring.scan.UserEntity; 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.test.context.ContextConfiguration; 23 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 24 | 25 | /** 26 | * 27 | * @author Kaiming Zou,created on 2018/5/28. 28 | */ 29 | @RunWith(SpringJUnit4ClassRunner.class) 30 | @ContextConfiguration(locations = { "classpath:/spring.xml" }) 31 | public class EnableDBClusterRouteAnnotationTest { 32 | 33 | @Autowired 34 | private DBClusterRouteTestComponent dbClusterRouteTestComponent; 35 | 36 | @Test 37 | public void test00() { 38 | dbClusterRouteTestComponent.test00(); 39 | } 40 | 41 | @Test 42 | public void test01() { 43 | for (int i = 0; i < 100; i++) { 44 | dbClusterRouteTestComponent.test01(i + ""); 45 | } 46 | } 47 | 48 | @Test 49 | public void test02() { 50 | for (int i = 0; i < 100; i++) { 51 | dbClusterRouteTestComponent.test02(i); 52 | } 53 | } 54 | 55 | @Test 56 | public void testFormat() { 57 | for (long i = 0; i < 100; i++) { 58 | UserEntity userEntity = new UserEntity(); 59 | userEntity.setId(i); 60 | dbClusterRouteTestComponent.testFunction(userEntity); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /ddal-spring/src/test/resources/spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/img/design_00.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellojavaer/ddal/876dc32ece8bb983df64e94bdcc9045f0ee5cc3b/doc/img/design_00.jpeg -------------------------------------------------------------------------------- /doc/img/design_01.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellojavaer/ddal/876dc32ece8bb983df64e94bdcc9045f0ee5cc3b/doc/img/design_01.jpeg -------------------------------------------------------------------------------- /doc/img/design_02.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellojavaer/ddal/876dc32ece8bb983df64e94bdcc9045f0ee5cc3b/doc/img/design_02.jpeg --------------------------------------------------------------------------------