This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 861de455c83 move `CosIdLocalDateTimeConvertor` to `CosId` (#24670)
861de455c83 is described below

commit 861de455c83d9f37f60778aedb2d1d3d53e454bf
Author: Ahoo Wang <[email protected]>
AuthorDate: Mon Mar 20 00:43:53 2023 +0800

    move `CosIdLocalDateTimeConvertor` to `CosId` (#24670)
    
    * add CosId keygen documentation
    
    * Update String ID Description
    
    * add CosId keygen English-documentation
    
    * move `CosIdLocalDateTimeConvertor` to `CosId`
---
 features/sharding/plugin/cosid/pom.xml             |  2 +-
 .../AbstractCosIdIntervalShardingAlgorithm.java    |  6 +-
 .../interval/CosIdIntervalShardingAlgorithm.java   |  8 +--
 .../CosIdSnowflakeIntervalShardingAlgorithm.java   |  8 +--
 .../convertor/CosIdLocalDateTimeConvertor.java     | 34 ---------
 .../impl/SnowflakeCosIdLocalDateTimeConvertor.java | 50 -------------
 .../impl/StandardCosIdLocalDateTimeConvertor.java  | 84 ----------------------
 7 files changed, 12 insertions(+), 180 deletions(-)

diff --git a/features/sharding/plugin/cosid/pom.xml 
b/features/sharding/plugin/cosid/pom.xml
index 866d183d772..43907388627 100644
--- a/features/sharding/plugin/cosid/pom.xml
+++ b/features/sharding/plugin/cosid/pom.xml
@@ -28,7 +28,7 @@
     <name>${project.artifactId}</name>
     
     <properties>
-        <cosid.version>1.16.0</cosid.version>
+        <cosid.version>1.18.5</cosid.version>
     </properties>
     
     <dependencies>
diff --git 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/AbstractCosIdIntervalShardingAlgorithm.java
 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/AbstractCosIdIntervalShardingAlgorithm.java
index 3b165da0f9e..3fc4e1d39bc 100644
--- 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/AbstractCosIdIntervalShardingAlgorithm.java
+++ 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/AbstractCosIdIntervalShardingAlgorithm.java
@@ -21,12 +21,12 @@ import com.google.common.collect.BoundType;
 import com.google.common.collect.Range;
 import me.ahoo.cosid.sharding.IntervalStep;
 import me.ahoo.cosid.sharding.IntervalTimeline;
+import me.ahoo.cosid.sharding.LocalDateTimeConvertor;
 import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
 import 
org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
 import 
org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
 import 
org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.convertor.CosIdLocalDateTimeConvertor;
 import org.apache.shardingsphere.sharding.exception.ShardingPluginException;
 
 import java.time.LocalDateTime;
@@ -56,7 +56,7 @@ public abstract class 
AbstractCosIdIntervalShardingAlgorithm<T extends Comparabl
     
     private IntervalTimeline intervalTimeline;
     
-    private CosIdLocalDateTimeConvertor localDateTimeConvertor;
+    private LocalDateTimeConvertor localDateTimeConvertor;
     
     @Override
     public void init(final Properties props) {
@@ -79,7 +79,7 @@ public abstract class 
AbstractCosIdIntervalShardingAlgorithm<T extends Comparabl
         return props.getProperty(key);
     }
     
-    protected abstract CosIdLocalDateTimeConvertor 
createLocalDateTimeConvertor(Properties props);
+    protected abstract LocalDateTimeConvertor 
createLocalDateTimeConvertor(Properties props);
     
     @Override
     public String doSharding(final Collection<String> availableTargetNames, 
final PreciseShardingValue<T> shardingValue) {
diff --git 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
index 0ae4ab33df6..c79b5a55246 100644
--- 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
+++ 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdIntervalShardingAlgorithm.java
@@ -17,9 +17,9 @@
 
 package org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval;
 
+import me.ahoo.cosid.sharding.LocalDateTimeConvertor;
+import me.ahoo.cosid.sharding.StandardLocalDateTimeConvertor;
 import 
org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.convertor.impl.StandardCosIdLocalDateTimeConvertor;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.convertor.CosIdLocalDateTimeConvertor;
 
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
@@ -39,11 +39,11 @@ public final class CosIdIntervalShardingAlgorithm extends 
AbstractCosIdIntervalS
     private static final String TIMESTAMP_UNIT_KEY = "ts-unit";
     
     @Override
-    protected CosIdLocalDateTimeConvertor createLocalDateTimeConvertor(final 
Properties props) {
+    protected LocalDateTimeConvertor createLocalDateTimeConvertor(final 
Properties props) {
         ZoneId zoneId = props.containsKey(ZONE_ID_KEY) ? 
ZoneId.of(props.getProperty(ZONE_ID_KEY)) : ZoneId.systemDefault();
         boolean isSecondTs = props.containsKey(TIMESTAMP_UNIT_KEY) && 
TIMESTAMP_SECOND_UNIT.equalsIgnoreCase(props.getProperty(TIMESTAMP_UNIT_KEY));
         DateTimeFormatter dateTimeFormatter = 
DateTimeFormatter.ofPattern(props.getProperty(DATE_TIME_PATTERN_KEY, 
DEFAULT_DATE_TIME_PATTERN));
-        return new StandardCosIdLocalDateTimeConvertor(zoneId, isSecondTs, 
dateTimeFormatter);
+        return new StandardLocalDateTimeConvertor(zoneId, isSecondTs, 
dateTimeFormatter);
     }
     
     @Override
diff --git 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
index 001c31b3da0..4e18f9e700c 100644
--- 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
+++ 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/CosIdSnowflakeIntervalShardingAlgorithm.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval;
 
+import me.ahoo.cosid.sharding.LocalDateTimeConvertor;
+import me.ahoo.cosid.sharding.SnowflakeLocalDateTimeConvertor;
 import me.ahoo.cosid.snowflake.MillisecondSnowflakeId;
 import me.ahoo.cosid.snowflake.MillisecondSnowflakeIdStateParser;
 import me.ahoo.cosid.snowflake.SnowflakeIdStateParser;
 import 
org.apache.shardingsphere.sharding.cosid.algorithm.CosIdAlgorithmConstants;
 import 
org.apache.shardingsphere.sharding.cosid.algorithm.keygen.CosIdSnowflakeKeyGenerateAlgorithm;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.convertor.CosIdLocalDateTimeConvertor;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.convertor.impl.SnowflakeCosIdLocalDateTimeConvertor;
 
 import java.time.ZoneId;
 import java.util.Properties;
@@ -38,8 +38,8 @@ public final class CosIdSnowflakeIntervalShardingAlgorithm 
extends AbstractCosId
     private static final String ZONE_ID_KEY = "zone-id";
     
     @Override
-    protected CosIdLocalDateTimeConvertor createLocalDateTimeConvertor(final 
Properties props) {
-        return new 
SnowflakeCosIdLocalDateTimeConvertor(createSnowflakeIdStateParser(props));
+    protected LocalDateTimeConvertor createLocalDateTimeConvertor(final 
Properties props) {
+        return new 
SnowflakeLocalDateTimeConvertor(createSnowflakeIdStateParser(props));
     }
     
     private SnowflakeIdStateParser createSnowflakeIdStateParser(final 
Properties props) {
diff --git 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/CosIdLocalDateTimeConvertor.java
 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/CosIdLocalDateTimeConvertor.java
deleted file mode 100644
index 81f6b455eb1..00000000000
--- 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/CosIdLocalDateTimeConvertor.java
+++ /dev/null
@@ -1,34 +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.cosid.algorithm.sharding.interval.convertor;
-
-import java.time.LocalDateTime;
-
-/**
- * Local date time convertor for CosId.
- */
-public interface CosIdLocalDateTimeConvertor {
-    
-    /**
-     * To local date time.
-     * 
-     * @param value value to be converted
-     * @return converted local date time
-     */
-    LocalDateTime toLocalDateTime(Comparable<?> value);
-}
diff --git 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/impl/SnowflakeCosIdLocalDateTimeConvertor.java
 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/impl/SnowflakeCosIdLocalDateTimeConvertor.java
deleted file mode 100644
index 6e5837cb1d1..00000000000
--- 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/impl/SnowflakeCosIdLocalDateTimeConvertor.java
+++ /dev/null
@@ -1,50 +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.cosid.algorithm.sharding.interval.convertor.impl;
-
-import lombok.RequiredArgsConstructor;
-import me.ahoo.cosid.converter.Radix62IdConverter;
-import me.ahoo.cosid.snowflake.SnowflakeIdStateParser;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.convertor.CosIdLocalDateTimeConvertor;
-import org.apache.shardingsphere.sharding.exception.ShardingPluginException;
-
-import java.time.LocalDateTime;
-
-/**
- * Snowflake local date time convertor for Snowflake.
- */
-@RequiredArgsConstructor
-public final class SnowflakeCosIdLocalDateTimeConvertor implements 
CosIdLocalDateTimeConvertor {
-    
-    private final SnowflakeIdStateParser snowflakeIdStateParser;
-    
-    @Override
-    public LocalDateTime toLocalDateTime(final Comparable<?> value) {
-        return 
snowflakeIdStateParser.parseTimestamp(convertToSnowflakeId(value));
-    }
-    
-    private Long convertToSnowflakeId(final Comparable<?> value) {
-        if (value instanceof Long) {
-            return (Long) value;
-        }
-        if (value instanceof String) {
-            return Radix62IdConverter.PAD_START.asLong((String) value);
-        }
-        throw new ShardingPluginException("Unsupported sharding value type 
`%s`.", value);
-    }
-}
diff --git 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/impl/StandardCosIdLocalDateTimeConvertor.java
 
b/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/impl/StandardCosIdLocalDateTimeConvertor.java
deleted file mode 100644
index 16b1577f1ed..00000000000
--- 
a/features/sharding/plugin/cosid/src/main/java/org/apache/shardingsphere/sharding/cosid/algorithm/sharding/interval/convertor/impl/StandardCosIdLocalDateTimeConvertor.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.sharding.cosid.algorithm.sharding.interval.convertor.impl;
-
-import lombok.RequiredArgsConstructor;
-import me.ahoo.cosid.util.LocalDateTimeConvert;
-import 
org.apache.shardingsphere.sharding.cosid.algorithm.sharding.interval.convertor.CosIdLocalDateTimeConvertor;
-import org.apache.shardingsphere.sharding.exception.ShardingPluginException;
-
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.OffsetDateTime;
-import java.time.Year;
-import java.time.YearMonth;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.Date;
-
-/**
- * Standard local date time convertor for CosId.
- */
-@RequiredArgsConstructor
-public final class StandardCosIdLocalDateTimeConvertor implements 
CosIdLocalDateTimeConvertor {
-    
-    private final ZoneId zoneId;
-    
-    private final boolean isSecondTs;
-    
-    private final DateTimeFormatter dateTimeFormatter;
-    
-    @Override
-    public LocalDateTime toLocalDateTime(final Comparable<?> value) {
-        if (value instanceof LocalDateTime) {
-            return (LocalDateTime) value;
-        }
-        if (value instanceof ZonedDateTime) {
-            return ((ZonedDateTime) value).toLocalDateTime();
-        }
-        if (value instanceof OffsetDateTime) {
-            return ((OffsetDateTime) value).toLocalDateTime();
-        }
-        if (value instanceof Instant) {
-            return LocalDateTimeConvert.fromInstant((Instant) value, zoneId);
-        }
-        if (value instanceof LocalDate) {
-            return LocalDateTime.of((LocalDate) value, LocalTime.MIN);
-        }
-        if (value instanceof Date) {
-            return LocalDateTimeConvert.fromDate((Date) value, zoneId);
-        }
-        if (value instanceof YearMonth) {
-            YearMonth yearMonth = (YearMonth) value;
-            return LocalDateTime.of(yearMonth.getYear(), 
yearMonth.getMonthValue(), 1, 0, 0);
-        }
-        if (value instanceof Year) {
-            return LocalDateTime.of(((Year) value).getValue(), 1, 1, 0, 0);
-        }
-        if (value instanceof Long) {
-            return isSecondTs ? 
LocalDateTimeConvert.fromTimestampSecond((Long) value, zoneId) : 
LocalDateTimeConvert.fromTimestamp((Long) value, zoneId);
-        }
-        if (value instanceof String) {
-            return LocalDateTimeConvert.fromString((String) value, 
dateTimeFormatter);
-        }
-        throw new ShardingPluginException("Unsupported sharding value type 
`%s`.", value);
-    }
-}

Reply via email to