diff --git a/shardingsphere-features/shardingsphere-sharding/pom.xml b/shardingsphere-features/shardingsphere-sharding/pom.xml index 62a63d3e7e0a2df4e40430de792a0c32a321e475..b27f9dd7d5693232a16cde88687640a4e87e2740 100644 --- a/shardingsphere-features/shardingsphere-sharding/pom.xml +++ b/shardingsphere-features/shardingsphere-sharding/pom.xml @@ -33,7 +33,6 @@ shardingsphere-sharding-route shardingsphere-sharding-rewrite shardingsphere-sharding-merge - shardingsphere-sharding-time-service shardingsphere-sharding-spring diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/pom.xml b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/pom.xml index 15c0e75b36c38e366cb5e6e80e1d30b9669242f5..ac3d58a9984ca18f7ae80339042552444c572fd5 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/pom.xml +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/pom.xml @@ -38,6 +38,11 @@ shardingsphere-infra-route ${project.version} + + org.apache.shardingsphere + shardingsphere-system-datetime + ${project.version} + org.apache.shardingsphere diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java index b183688c693426b7ef89e14d7f1a7f78a73fc084..ada5eb3806f61654f975ebc630ad78fcf9bf72a2 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactory.java @@ -19,7 +19,9 @@ package org.apache.shardingsphere.sharding.route.engine.condition.engine; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; import org.apache.shardingsphere.infra.sql.LogicSQL; +import org.apache.shardingsphere.infra.datetime.DatetimeService; import org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine; import org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.WhereClauseShardingConditionEngine; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -32,6 +34,10 @@ import org.apache.shardingsphere.sql.parser.binder.statement.dml.InsertStatement @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ShardingConditionEngineFactory { + static { + ShardingSphereServiceLoader.register(DatetimeService.class); + } + /** * Create new instance of sharding condition engine. * diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java index e7be2bbc0492f4368f89991e97ed3626234205b8..dfea1d56dbf633e8027cd17a80e07d0bedc326e9 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/impl/InsertClauseShardingConditionEngine.java @@ -20,8 +20,8 @@ package org.apache.shardingsphere.sharding.route.engine.condition.engine.impl; import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.exception.ShardingSphereException; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeService; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeServiceFactory; +import org.apache.shardingsphere.infra.spi.required.RequiredSPIRegistry; +import org.apache.shardingsphere.infra.datetime.DatetimeService; import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils; import org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition; import org.apache.shardingsphere.sharding.route.engine.condition.engine.ShardingConditionEngine; @@ -86,7 +86,7 @@ public final class InsertClauseShardingConditionEngine implements ShardingCondit private ShardingCondition createShardingCondition(final String tableName, final Iterator columnNames, final InsertValueContext insertValueContext, final List parameters) { ShardingCondition result = new ShardingCondition(); - DatetimeService datetimeService = DatetimeServiceFactory.newInstance(); + DatetimeService datetimeService = RequiredSPIRegistry.getRegisteredService(DatetimeService.class); for (ExpressionSegment each : insertValueContext.getValueExpressions()) { String columnName = columnNames.next(); if (shardingRule.isShardingColumn(columnName, tableName)) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java index 51dc480351189500514009525ddb4a28eec046cc..f9a93dd9231d3e2b49c59302f8c1725efd3924f5 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGenerator.java @@ -18,7 +18,8 @@ package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl; import com.google.common.collect.Range; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeServiceFactory; +import org.apache.shardingsphere.infra.spi.required.RequiredSPIRegistry; +import org.apache.shardingsphere.infra.datetime.DatetimeService; import org.apache.shardingsphere.sharding.route.engine.condition.Column; import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils; import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue; @@ -44,7 +45,7 @@ public final class ConditionValueBetweenOperatorGenerator implements ConditionVa if (betweenConditionValue.isPresent() && andConditionValue.isPresent()) { return Optional.of(new RangeShardingConditionValue<>(column.getName(), column.getTableName(), SafeNumberOperationUtils.safeClosed(betweenConditionValue.get(), andConditionValue.get()))); } - Date datetime = DatetimeServiceFactory.newInstance().getDatetime(); + Date datetime = RequiredSPIRegistry.getRegisteredService(DatetimeService.class).getDatetime(); if (!betweenConditionValue.isPresent() && ExpressionConditionUtils.isNowExpression(predicate.getBetweenExpr())) { betweenConditionValue = Optional.of(datetime); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java index 9ba3d9ac9af20aa88f91ab7faca8fc29f3db0abd..a21e39696457336df536c5d8b12fcbae11026053 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueCompareOperatorGenerator.java @@ -19,7 +19,8 @@ package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl import com.google.common.collect.Lists; import com.google.common.collect.Range; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeServiceFactory; +import org.apache.shardingsphere.infra.spi.required.RequiredSPIRegistry; +import org.apache.shardingsphere.infra.datetime.DatetimeService; import org.apache.shardingsphere.sharding.route.engine.condition.Column; import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils; import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue; @@ -61,7 +62,7 @@ public final class ConditionValueCompareOperatorGenerator implements ConditionVa return generate(conditionValue.get(), column, operator); } if (ExpressionConditionUtils.isNowExpression(predicate.getRight())) { - return generate(DatetimeServiceFactory.newInstance().getDatetime(), column, operator); + return generate(RequiredSPIRegistry.getRegisteredService(DatetimeService.class).getDatetime(), column, operator); } return Optional.empty(); } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java index 302332fb8bfd772fc7a9d2bbf8659ba051630fe0..c255604d7b4dd3e918ccab074ba0ce3aa0b7ec63 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueInOperatorGenerator.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeService; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeServiceFactory; +import org.apache.shardingsphere.infra.spi.required.RequiredSPIRegistry; +import org.apache.shardingsphere.infra.datetime.DatetimeService; import org.apache.shardingsphere.sharding.route.engine.condition.Column; import org.apache.shardingsphere.sharding.route.engine.condition.ExpressionConditionUtils; import org.apache.shardingsphere.sharding.route.engine.condition.generator.ConditionValue; @@ -40,7 +40,7 @@ public final class ConditionValueInOperatorGenerator implements ConditionValueGe @Override public Optional generate(final InExpression predicate, final Column column, final List parameters) { List> shardingConditionValues = new LinkedList<>(); - DatetimeService datetimeService = DatetimeServiceFactory.newInstance(); + DatetimeService datetimeService = RequiredSPIRegistry.getRegisteredService(DatetimeService.class); for (ExpressionSegment each : predicate.getExpressionList()) { Optional> shardingConditionValue = new ConditionValue(each, parameters).getValue(); if (shardingConditionValue.isPresent()) { diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/datatime/fixture/DatetimeServiceFixture.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/datatime/fixture/DatetimeServiceFixture.java deleted file mode 100644 index 5f753b3bf16a63a7af1feccf1e3e47cd29ad30cf..0000000000000000000000000000000000000000 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/datatime/fixture/DatetimeServiceFixture.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.sharding.route.datatime.fixture; - -import lombok.Getter; -import lombok.Setter; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeService; - -import java.util.Date; - -@Getter -@Setter -public final class DatetimeServiceFixture implements DatetimeService { - - private Date date; - - @Override - public Date getDatetime() { - return null == date ? new Date() : date; - } -} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java index 99e70417a31086ea37f004f4b5f972b4b62dfe29..1f3499a4a41adf70d11036689934325c82dc5537 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/generator/impl/ConditionValueBetweenOperatorGeneratorTest.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.sharding.route.engine.condition.generator.impl; +import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; +import org.apache.shardingsphere.infra.datetime.DatetimeService; import org.apache.shardingsphere.sharding.route.engine.condition.Column; import org.apache.shardingsphere.sharding.route.engine.condition.value.RangeShardingConditionValue; import org.apache.shardingsphere.sharding.route.engine.condition.value.ShardingConditionValue; @@ -42,6 +44,10 @@ public final class ConditionValueBetweenOperatorGeneratorTest { private final Column column = new Column("id", "tbl"); + static { + ShardingSphereServiceLoader.register(DatetimeService.class); + } + @SuppressWarnings("unchecked") @Test public void assertGenerateConditionValue() { diff --git a/shardingsphere-infra/pom.xml b/shardingsphere-infra/pom.xml index d3060a592a010f89953cb078d913010e49a0bb8b..ddbbd4c6a43b37a42bd1c81b80bd1b743f0aa285 100644 --- a/shardingsphere-infra/pom.xml +++ b/shardingsphere-infra/pom.xml @@ -36,5 +36,6 @@ shardingsphere-infra-executor shardingsphere-infra-merge shardingsphere-infra-context + shardingsphere-infra-datetime diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/required/RequiredSPI.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/required/RequiredSPI.java new file mode 100644 index 0000000000000000000000000000000000000000..bebd75d1079931d5376ad0d62d89f5ec2dd13634 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/required/RequiredSPI.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.infra.spi.required; + +/** + * Required SPI. + */ +public interface RequiredSPI { + + /** + * Judge whether default service provider. + * + * @return is default service provider or not + */ + boolean isDefault(); +} diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DatetimeServiceFactory.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/required/RequiredSPIRegistry.java similarity index 52% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DatetimeServiceFactory.java rename to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/required/RequiredSPIRegistry.java index 3ca1580aec79c5c4f17cec9c6626be8d7924c584..df24099f66ff5650483e07ac921cf03768e0fc82 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DatetimeServiceFactory.java +++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/required/RequiredSPIRegistry.java @@ -15,28 +15,36 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.datatime; +package org.apache.shardingsphere.infra.spi.required; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; +import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException; + +import java.util.Collection; /** - * Datetime service factory. + * Required SPI registry. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class DatetimeServiceFactory { - - static { - ShardingSphereServiceLoader.register(DatetimeService.class); - } +public final class RequiredSPIRegistry { /** - * Create new instance of datetime service. - * - * @return datetime service + * Get registered service. + * + * @param requiredSPIClass required SPI class + * @param type + * @return registered service */ - public static DatetimeService newInstance() { - return ShardingSphereServiceLoader.newServiceInstances(DatetimeService.class).stream().findFirst().orElseGet(DefaultDatetimeService::new); + public static T getRegisteredService(final Class requiredSPIClass) { + Collection services = ShardingSphereServiceLoader.newServiceInstances(requiredSPIClass); + if (services.isEmpty()) { + throw new ServiceProviderNotFoundException(requiredSPIClass); + } + if (1 == services.size()) { + return services.iterator().next(); + } + return services.stream().filter(each -> !each.isDefault()).findFirst().orElse(services.iterator().next()); } } diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoader.java deleted file mode 100644 index 0326778ff9e2a5fc858029e655d48dd8914268df..0000000000000000000000000000000000000000 --- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoader.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.infra.spi.singleton; - -import java.util.Collection; -import java.util.LinkedList; -import java.util.Map; -import java.util.Optional; -import java.util.ServiceLoader; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Singleton service loader. - */ -public final class SingletonServiceLoader { - - private static final Map, SingletonServiceLoader> LOADERS = new ConcurrentHashMap<>(); - - private final Map, Collection> serviceMap = new ConcurrentHashMap<>(); - - private final Class service; - - private SingletonServiceLoader(final Class service) { - this.service = service; - register(service); - } - - /** - * Get singleton service loader. - * - * @param service service type - * @param type of service - * @return singleton service loader. - */ - @SuppressWarnings("unchecked") - public static SingletonServiceLoader getServiceLoader(final Class service) { - if (null == service) { - throw new NullPointerException("extension clazz is null"); - } - if (!service.isInterface()) { - throw new IllegalArgumentException("extension clazz (" + service + "is not interface!"); - } - SingletonServiceLoader serviceLoader = (SingletonServiceLoader) LOADERS.get(service); - if (null != serviceLoader) { - return serviceLoader; - } - LOADERS.putIfAbsent(service, new SingletonServiceLoader<>(service)); - return (SingletonServiceLoader) LOADERS.get(service); - } - - /** - * New service instances. - * - * @return service instances - */ - public Optional newServiceInstances() { - return serviceMap.get(service).stream().findFirst(); - } - - private void register(final Class service) { - if (serviceMap.containsKey(service)) { - return; - } - serviceMap.put(service, new LinkedList<>()); - for (T each : ServiceLoader.load(service)) { - serviceMap.get(service).add(each); - } - } -} diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java deleted file mode 100644 index b57ec04abd8aea931c92594b7f1a77cdce3f8371..0000000000000000000000000000000000000000 --- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoaderTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.shardingsphere.infra.spi.singleton; - -import org.apache.shardingsphere.infra.spi.fixture.TypedSPIFixture; -import org.apache.shardingsphere.infra.spi.type.TypedSPI; -import org.junit.Test; - -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; - -public final class SingletonServiceLoaderTest { - - @Test - public void assertGetSingletonServiceLoader() { - SingletonServiceLoader actualFirstServiceLoader = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class); - assertNotNull(actualFirstServiceLoader); - SingletonServiceLoader actualSecondServiceLoader = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class); - assertNotNull(actualSecondServiceLoader); - assertThat(actualFirstServiceLoader, is(actualSecondServiceLoader)); - } - - @Test(expected = NullPointerException.class) - public void assertGetSingletonServiceLoaderWhenServiceIsNull() { - SingletonServiceLoader.getServiceLoader(null); - } - - @Test(expected = IllegalArgumentException.class) - public void assertGetSingletonServiceLoaderWhenServiceIsNotAnInterface() { - SingletonServiceLoader.getServiceLoader(String.class); - } - - @Test - public void assertNewServiceInstanceWhenIsNotExist() { - Optional actual = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class).newServiceInstances(); - assertTrue(actual.isPresent()); - } - - @Test - public void assertNewServiceInstanceWhenServiceDoesNotFind() { - Optional actual = SingletonServiceLoader.getServiceLoader(NoImplTypedSPI.class).newServiceInstances(); - assertFalse(actual.isPresent()); - } - - interface NoImplTypedSPI extends TypedSPI { - - } -} diff --git a/shardingsphere-infra/shardingsphere-infra-datetime/pom.xml b/shardingsphere-infra/shardingsphere-infra-datetime/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..9f406b7cee8a2466fe536478eb13db7090ccd201 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-datetime/pom.xml @@ -0,0 +1,36 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra + 5.0.0-RC1-SNAPSHOT + + shardingsphere-infra-datetime + pom + ${project.artifactId} + + + shardingsphere-infra-datetime-spi + shardingsphere-infra-datetime-type + + diff --git a/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-spi/pom.xml b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-spi/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..251d56b0e41d850401285dfb033b251de157e942 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-spi/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra-datetime + 5.0.0-RC1-SNAPSHOT + + shardingsphere-infra-datetime-spi + ${project.artifactId} + + + + org.apache.shardingsphere + shardingsphere-infra-common + ${project.version} + + + diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DatetimeService.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-spi/src/main/java/org/apache/shardingsphere/infra/datetime/DatetimeService.java similarity index 84% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DatetimeService.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-spi/src/main/java/org/apache/shardingsphere/infra/datetime/DatetimeService.java index 13af2207e5ee3ca7d8651a169125211813c69431..e6f1544880b7ee149f45d70dbc2ae2571821a707 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DatetimeService.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-spi/src/main/java/org/apache/shardingsphere/infra/datetime/DatetimeService.java @@ -15,14 +15,16 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.datatime; +package org.apache.shardingsphere.infra.datetime; + +import org.apache.shardingsphere.infra.spi.required.RequiredSPI; import java.util.Date; /** * Datetime service. */ -public interface DatetimeService { +public interface DatetimeService extends RequiredSPI { /** * Get datetime. diff --git a/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/pom.xml b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b02c3e37b11f3b441f5b0432f1b205cd5b6284f3 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/pom.xml @@ -0,0 +1,36 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra-datetime + 5.0.0-RC1-SNAPSHOT + + shardingsphere-infra-datetime-type + pom + ${project.artifactId} + + + shardingsphere-system-datetime + shardingsphere-database-datetime + + diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/pom.xml b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/pom.xml similarity index 78% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/pom.xml rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/pom.xml index 630714838da86a4eb43495ebb1769fb4e1fc06dd..897b776d9bf586db0cff5fa825c6869966c7f8b6 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/pom.xml +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/pom.xml @@ -16,17 +16,24 @@ ~ limitations under the License. --> - + 4.0.0 org.apache.shardingsphere - shardingsphere-sharding + shardingsphere-infra-datetime-type 5.0.0-RC1-SNAPSHOT - shardingsphere-sharding-time-service - ${project.artifactId} + shardingsphere-database-datetime + + org.apache.shardingsphere + shardingsphere-infra-datetime-spi + ${project.version} + + org.apache.shardingsphere shardingsphere-sharding-route diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/DatabaseDatetimeServiceDelegate.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/DatabaseDatetimeServiceDelegate.java similarity index 80% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/DatabaseDatetimeServiceDelegate.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/DatabaseDatetimeServiceDelegate.java index 25c11aa270c7f6dbaec464f878f16a21d4f9dd6d..8d12f445aed105f66955e42655af9ffafd0fcebf 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/DatabaseDatetimeServiceDelegate.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/DatabaseDatetimeServiceDelegate.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time; +package org.apache.shardingsphere.datetime.database; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeService; -import org.apache.shardingsphere.sharding.route.time.impl.TimeServiceFactory; +import org.apache.shardingsphere.infra.datetime.DatetimeService; +import org.apache.shardingsphere.datetime.database.impl.TimeServiceFactory; import java.util.Date; @@ -33,4 +33,9 @@ public final class DatabaseDatetimeServiceDelegate implements DatetimeService { public Date getDatetime() { return INSTANCE.getDatetime(); } + + @Override + public boolean isDefault() { + return false; + } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/TimeServiceConfiguration.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/TimeServiceConfiguration.java similarity index 95% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/TimeServiceConfiguration.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/TimeServiceConfiguration.java index a0c9f9d8dc34e56c79514bea717eac3716585a19..470a13da74f880cd79ea57d53ce96a93179c2432 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/TimeServiceConfiguration.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/TimeServiceConfiguration.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time; +package org.apache.shardingsphere.datetime.database; import lombok.Getter; -import org.apache.shardingsphere.sharding.route.time.exception.TimeServiceInitException; +import org.apache.shardingsphere.datetime.database.exception.TimeServiceInitException; import javax.sql.DataSource; import java.beans.IntrospectionException; diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/exception/NoDatabaseSQLEntrySupportException.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/exception/NoDatabaseSQLEntrySupportException.java similarity index 93% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/exception/NoDatabaseSQLEntrySupportException.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/exception/NoDatabaseSQLEntrySupportException.java index a330c4d01b706bb71c05c3c78982026301370de6..ba9a5c017aef645052684322e9e8e55544777938 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/exception/NoDatabaseSQLEntrySupportException.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/exception/NoDatabaseSQLEntrySupportException.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.exception; +package org.apache.shardingsphere.datetime.database.exception; /** * No database SQL entry support. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/exception/TimeServiceInitException.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/exception/TimeServiceInitException.java similarity index 94% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/exception/TimeServiceInitException.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/exception/TimeServiceInitException.java index 4a1696926bdccfa3bda9c231123660dc069b0592..293243ff5dfbc30fad30791a7c6527c3dd6b5235 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/exception/TimeServiceInitException.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/exception/TimeServiceInitException.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.exception; +package org.apache.shardingsphere.datetime.database.exception; /** * Time service init exception. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/impl/DatabaseDatetimeService.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/impl/DatabaseDatetimeService.java similarity index 89% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/impl/DatabaseDatetimeService.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/impl/DatabaseDatetimeService.java index 2b416b32d86d6da885cbbdac06bb248717bc4137..6a434a5633ece9885930ad4d197953ecaa18cf51 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/impl/DatabaseDatetimeService.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/impl/DatabaseDatetimeService.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.impl; +package org.apache.shardingsphere.datetime.database.impl; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeService; +import org.apache.shardingsphere.infra.datetime.DatetimeService; import javax.sql.DataSource; import java.sql.Connection; @@ -49,4 +49,9 @@ public final class DatabaseDatetimeService implements DatetimeService { } return new Date(); } + + @Override + public boolean isDefault() { + return false; + } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/impl/TimeServiceFactory.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/impl/TimeServiceFactory.java similarity index 83% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/impl/TimeServiceFactory.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/impl/TimeServiceFactory.java index 9427708ba22c48c8e50ae4a6ea19fe7fcd9341ab..a3244e18ee6d048132c3489911503ede8731735c 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/impl/TimeServiceFactory.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/impl/TimeServiceFactory.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.impl; +package org.apache.shardingsphere.datetime.database.impl; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.sharding.route.datatime.DatetimeService; -import org.apache.shardingsphere.sharding.route.time.TimeServiceConfiguration; -import org.apache.shardingsphere.sharding.route.time.spi.SPIDataBaseSQLEntry; +import org.apache.shardingsphere.infra.datetime.DatetimeService; +import org.apache.shardingsphere.datetime.database.TimeServiceConfiguration; +import org.apache.shardingsphere.datetime.database.spi.SPIDataBaseSQLEntry; /** * Time service factory. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/DatabaseSQLEntry.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/DatabaseSQLEntry.java similarity index 95% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/DatabaseSQLEntry.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/DatabaseSQLEntry.java index 93ba309f69fec068ace596e4989b4afa3a8c9f93..64d75b619e91ca6a616191dc628a41c852854b86 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/DatabaseSQLEntry.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/DatabaseSQLEntry.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.spi; +package org.apache.shardingsphere.datetime.database.spi; /** * Database SQL entry. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/MySQLDatabaseSQLEntry.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/MySQLDatabaseSQLEntry.java similarity index 95% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/MySQLDatabaseSQLEntry.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/MySQLDatabaseSQLEntry.java index 67542b57b3770e013a22c770696e82dc5f9c281d..e89ddf5e392837de75ab12d6a846a0a06287b455 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/MySQLDatabaseSQLEntry.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/MySQLDatabaseSQLEntry.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.spi; +package org.apache.shardingsphere.datetime.database.spi; /** * MySQL entry. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/OracleDatabaseSQLEntry.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/OracleDatabaseSQLEntry.java similarity index 95% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/OracleDatabaseSQLEntry.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/OracleDatabaseSQLEntry.java index f42528d8fe5928bb78cac40c20bb7ca8f986a9fc..7beeda466d67247ba937fb35625c66788ee5018b 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/OracleDatabaseSQLEntry.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/OracleDatabaseSQLEntry.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.spi; +package org.apache.shardingsphere.datetime.database.spi; /** * Oracle entry. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/PostgreSQLDatabaseSQLEntry.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/PostgreSQLDatabaseSQLEntry.java similarity index 95% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/PostgreSQLDatabaseSQLEntry.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/PostgreSQLDatabaseSQLEntry.java index 363ea83aef72381e8a6b72e27b415c94a73f6b1f..599941ed222ea76ac6d417a050761e0a64074124 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/PostgreSQLDatabaseSQLEntry.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/PostgreSQLDatabaseSQLEntry.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.spi; +package org.apache.shardingsphere.datetime.database.spi; /** * PostgreSQL entry. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/SPIDataBaseSQLEntry.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/SPIDataBaseSQLEntry.java similarity index 91% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/SPIDataBaseSQLEntry.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/SPIDataBaseSQLEntry.java index 6748b2ade53890812ed8dbdd29d292cd29494ddd..c3344a6f4c40b09cb29e9548b637529a105fbebc 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/SPIDataBaseSQLEntry.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/SPIDataBaseSQLEntry.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.spi; +package org.apache.shardingsphere.datetime.database.spi; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.sharding.route.time.exception.NoDatabaseSQLEntrySupportException; +import org.apache.shardingsphere.datetime.database.exception.NoDatabaseSQLEntrySupportException; import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; import java.util.Collection; diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/SQLServerDatabaseSQLEntry.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/SQLServerDatabaseSQLEntry.java similarity index 95% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/SQLServerDatabaseSQLEntry.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/SQLServerDatabaseSQLEntry.java index ca9ff3e20d5640fcbedea33887a3257139125004..d101421d03faa38b4123f230a95c808dadad2a95 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/java/org/apache/shardingsphere/sharding/route/time/spi/SQLServerDatabaseSQLEntry.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/java/org/apache/shardingsphere/datetime/database/spi/SQLServerDatabaseSQLEntry.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time.spi; +package org.apache.shardingsphere.datetime.database.spi; /** * SQLServer entry. diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.datatime.DatetimeService b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datetime.DatetimeService similarity index 90% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.datatime.DatetimeService rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datetime.DatetimeService index 957abd536a7d522e5c91a6abff72c99ad675826d..f52f04f68232f3529f8502200a802c79618dc04f 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.datatime.DatetimeService +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datetime.DatetimeService @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.sharding.route.time.DatabaseDatetimeServiceDelegate +org.apache.shardingsphere.datetime.database.DatabaseDatetimeServiceDelegate diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.time.spi.DatabaseSQLEntry b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.time.org.apache.shardingsphere.datetime.database.spi.DatabaseSQLEntry similarity index 72% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.time.spi.DatabaseSQLEntry rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.time.org.apache.shardingsphere.datetime.database.spi.DatabaseSQLEntry index 41a016a8e86dc4155555be8bc0be1581503a6a23..2e11df0e24beeb8559633cca33efe826bd89675d 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.time.spi.DatabaseSQLEntry +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.route.time.org.apache.shardingsphere.datetime.database.spi.DatabaseSQLEntry @@ -15,7 +15,7 @@ # limitations under the License. # -org.apache.shardingsphere.sharding.route.time.spi.MySQLDatabaseSQLEntry -org.apache.shardingsphere.sharding.route.time.spi.PostgreSQLDatabaseSQLEntry -org.apache.shardingsphere.sharding.route.time.spi.OracleDatabaseSQLEntry -org.apache.shardingsphere.sharding.route.time.spi.SQLServerDatabaseSQLEntry +org.apache.shardingsphere.datetime.database.spi.MySQLDatabaseSQLEntry +org.apache.shardingsphere.datetime.database.spi.PostgreSQLDatabaseSQLEntry +org.apache.shardingsphere.datetime.database.spi.OracleDatabaseSQLEntry +org.apache.shardingsphere.datetime.database.spi.SQLServerDatabaseSQLEntry diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/time-service.properties b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/time-service.properties similarity index 100% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/main/resources/time-service.properties rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/main/resources/time-service.properties diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/java/org/apache/shardingsphere/sharding/route/time/PropertiesUtils.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/PropertiesUtils.java similarity index 97% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/java/org/apache/shardingsphere/sharding/route/time/PropertiesUtils.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/PropertiesUtils.java index 3a11815bbef4fac26dc4b60821f432a6bba23ced..add23dc6d018004bd13b5b07651a1d9cb9ac9876 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/java/org/apache/shardingsphere/sharding/route/time/PropertiesUtils.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/PropertiesUtils.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time; +package org.apache.shardingsphere.datetime.database; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/java/org/apache/shardingsphere/sharding/route/time/TimeServiceConfigurationTest.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/TimeServiceConfigurationTest.java similarity index 95% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/java/org/apache/shardingsphere/sharding/route/time/TimeServiceConfigurationTest.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/TimeServiceConfigurationTest.java index 5b727cedb8f0261af465d741cd23d2b31a4f7356..f0d66b4943d23f00c383583687a811c06c3ab1d1 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/java/org/apache/shardingsphere/sharding/route/time/TimeServiceConfigurationTest.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/java/org/apache/shardingsphere/datetime/database/TimeServiceConfigurationTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.time; +package org.apache.shardingsphere.datetime.database; import org.junit.Test; diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/resources/logback-test.xml b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/resources/logback-test.xml similarity index 100% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-time-service/src/test/resources/logback-test.xml rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-database-datetime/src/test/resources/logback-test.xml diff --git a/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/pom.xml b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..955c01a4dbb3539f455a99be3f0b2f4ed9197c43 --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/pom.xml @@ -0,0 +1,37 @@ + + + + + 4.0.0 + + org.apache.shardingsphere + shardingsphere-infra-datetime-type + 5.0.0-RC1-SNAPSHOT + + shardingsphere-system-datetime + + + + org.apache.shardingsphere + shardingsphere-infra-datetime-spi + ${project.version} + + + diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DefaultDatetimeService.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/main/java/org/apache/shardingsphere/datetime/system/SystemDatetimeService.java similarity index 78% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DefaultDatetimeService.java rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/main/java/org/apache/shardingsphere/datetime/system/SystemDatetimeService.java index c51ce6dab9662bcbf71f413004a31f9bdb0f7666..8f628ea9457819c78c6cdebc7f891c57d8e0e597 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/datatime/DefaultDatetimeService.java +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/main/java/org/apache/shardingsphere/datetime/system/SystemDatetimeService.java @@ -15,17 +15,24 @@ * limitations under the License. */ -package org.apache.shardingsphere.sharding.route.datatime; +package org.apache.shardingsphere.datetime.system; + +import org.apache.shardingsphere.infra.datetime.DatetimeService; import java.util.Date; /** * Default datetime service. */ -public final class DefaultDatetimeService implements DatetimeService { +public final class SystemDatetimeService implements DatetimeService { @Override public Date getDatetime() { return new Date(); } + + @Override + public boolean isDefault() { + return true; + } } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.route.datatime.DatetimeService b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datetime.DatetimeService similarity index 90% rename from shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.route.datatime.DatetimeService rename to shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datetime.DatetimeService index c2fc432a0d5e75c6dfaa6422986aef478d6ab55f..c0030bd678e6d48ecfbec26d7da517f8e7b4d122 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/resources/META-INF/services/org.apache.shardingsphere.sharding.route.datatime.DatetimeService +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datetime.DatetimeService @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.sharding.route.datatime.fixture.DatetimeServiceFixture +org.apache.shardingsphere.datetime.system.SystemDatetimeService diff --git a/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/test/java/org/apache/shardingsphere/datetime/system/SystemDatetimeServiceTest.java b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/test/java/org/apache/shardingsphere/datetime/system/SystemDatetimeServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..df2e29dfcfbf770dfeb7ae9e07ee086392e1f82a --- /dev/null +++ b/shardingsphere-infra/shardingsphere-infra-datetime/shardingsphere-infra-datetime-type/shardingsphere-system-datetime/src/test/java/org/apache/shardingsphere/datetime/system/SystemDatetimeServiceTest.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.datetime.system; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public final class SystemDatetimeServiceTest { + + @Test + public void assertGetDatetime() { + assertTrue(new SystemDatetimeService().getDatetime().getTime() <= System.currentTimeMillis()); + } + + @Test + public void assertIsDefault() { + assertTrue(new SystemDatetimeService().isDefault()); + } +}