未验证 提交 b7d13913 编写于 作者: L Liang Zhang 提交者: GitHub

Add shardingsphere-infra-datetime module (#7723)

* Add shardingsphere-infra-datetime structure

* Remove useless SingletonServiceLoader

* Add RequiredSPI

* Use RequiredSPI on DatetimeService

* Move DatetimeService to shardingsphere-infra-datetime-spi module

* Move SystemDatetimeService to shardingsphere-system-datetime module

* Add SystemDatetimeServiceTest

* Remove DatetimeServiceFixture

* Move shardingsphere-database-datetime

* Remove shardingsphere-sharding-time-service module

* Fix pom
上级 3134fbf3
......@@ -33,7 +33,6 @@
<module>shardingsphere-sharding-route</module>
<module>shardingsphere-sharding-rewrite</module>
<module>shardingsphere-sharding-merge</module>
<module>shardingsphere-sharding-time-service</module>
<module>shardingsphere-sharding-spring</module>
</modules>
</project>
......@@ -38,6 +38,11 @@
<artifactId>shardingsphere-infra-route</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-system-datetime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
......
......@@ -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.
*
......
......@@ -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<String> columnNames, final InsertValueContext insertValueContext, final List<Object> 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)) {
......
......@@ -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);
}
......
......@@ -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();
}
......
......@@ -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<ShardingConditionValue> generate(final InExpression predicate, final Column column, final List<Object> parameters) {
List<Comparable<?>> shardingConditionValues = new LinkedList<>();
DatetimeService datetimeService = DatetimeServiceFactory.newInstance();
DatetimeService datetimeService = RequiredSPIRegistry.getRegisteredService(DatetimeService.class);
for (ExpressionSegment each : predicate.getExpressionList()) {
Optional<Comparable<?>> shardingConditionValue = new ConditionValue(each, parameters).getValue();
if (shardingConditionValue.isPresent()) {
......
/*
* 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;
}
}
......@@ -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() {
......
......@@ -36,5 +36,6 @@
<module>shardingsphere-infra-executor</module>
<module>shardingsphere-infra-merge</module>
<module>shardingsphere-infra-context</module>
<module>shardingsphere-infra-datetime</module>
</modules>
</project>
/*
* 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();
}
......@@ -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 <T> type
* @return registered service
*/
public static DatetimeService newInstance() {
return ShardingSphereServiceLoader.newServiceInstances(DatetimeService.class).stream().findFirst().orElseGet(DefaultDatetimeService::new);
public static <T extends RequiredSPI> T getRegisteredService(final Class<T> requiredSPIClass) {
Collection<T> 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());
}
}
/*
* 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<T> {
private static final Map<Class<?>, SingletonServiceLoader<?>> LOADERS = new ConcurrentHashMap<>();
private final Map<Class<?>, Collection<T>> serviceMap = new ConcurrentHashMap<>();
private final Class<T> service;
private SingletonServiceLoader(final Class<T> service) {
this.service = service;
register(service);
}
/**
* Get singleton service loader.
*
* @param service service type
* @param <T> type of service
* @return singleton service loader.
*/
@SuppressWarnings("unchecked")
public static <T> SingletonServiceLoader<T> getServiceLoader(final Class<T> service) {
if (null == service) {
throw new NullPointerException("extension clazz is null");
}
if (!service.isInterface()) {
throw new IllegalArgumentException("extension clazz (" + service + "is not interface!");
}
SingletonServiceLoader<T> serviceLoader = (SingletonServiceLoader<T>) LOADERS.get(service);
if (null != serviceLoader) {
return serviceLoader;
}
LOADERS.putIfAbsent(service, new SingletonServiceLoader<>(service));
return (SingletonServiceLoader<T>) LOADERS.get(service);
}
/**
* New service instances.
*
* @return service instances
*/
public Optional<T> newServiceInstances() {
return serviceMap.get(service).stream().findFirst();
}
private void register(final Class<T> service) {
if (serviceMap.containsKey(service)) {
return;
}
serviceMap.put(service, new LinkedList<>());
for (T each : ServiceLoader.load(service)) {
serviceMap.get(service).add(each);
}
}
}
/*
* 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<TypedSPIFixture> actualFirstServiceLoader = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class);
assertNotNull(actualFirstServiceLoader);
SingletonServiceLoader<TypedSPIFixture> 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<TypedSPIFixture> actual = SingletonServiceLoader.getServiceLoader(TypedSPIFixture.class).newServiceInstances();
assertTrue(actual.isPresent());
}
@Test
public void assertNewServiceInstanceWhenServiceDoesNotFind() {
Optional<NoImplTypedSPI> actual = SingletonServiceLoader.getServiceLoader(NoImplTypedSPI.class).newServiceInstances();
assertFalse(actual.isPresent());
}
interface NoImplTypedSPI extends TypedSPI {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-infra-datetime</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
<module>shardingsphere-infra-datetime-spi</module>
<module>shardingsphere-infra-datetime-type</module>
</modules>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-datetime</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-infra-datetime-spi</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......@@ -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.
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-datetime</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-infra-datetime-type</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
<module>shardingsphere-system-datetime</module>
<module>shardingsphere-database-datetime</module>
</modules>
</project>
......@@ -16,17 +16,24 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-sharding</artifactId>
<artifactId>shardingsphere-infra-datetime-type</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-sharding-time-service</artifactId>
<name>${project.artifactId}</name>
<artifactId>shardingsphere-database-datetime</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-datetime-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-sharding-route</artifactId>
......
......@@ -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;
}
}
......@@ -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;
......
......@@ -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;
}
}
......@@ -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.
......
......@@ -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;
......
......@@ -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
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-datetime-type</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-system-datetime</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-datetime-spi</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......@@ -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;
}
}
/*
* 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());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册