From cf471466f78da3a1416eb0270d9924cfead24d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E4=B9=8B?= Date: Wed, 20 Feb 2019 23:08:52 +0800 Subject: [PATCH] create snowflake --- .../rule/KeyGeneratorConfiguration.java | 33 +++++++++++++++ .../core/constant/KeyGeneratorEnum.java | 42 +++++++++++++++++++ .../keygen/leaf/SnowFlakeKeyGenerator.java | 23 ++++++++++ 3 files changed, 98 insertions(+) create mode 100644 sharding-core/src/main/java/io/shardingsphere/api/config/rule/KeyGeneratorConfiguration.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/constant/KeyGeneratorEnum.java diff --git a/sharding-core/src/main/java/io/shardingsphere/api/config/rule/KeyGeneratorConfiguration.java b/sharding-core/src/main/java/io/shardingsphere/api/config/rule/KeyGeneratorConfiguration.java new file mode 100644 index 0000000000000..2e09c052d0204 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/api/config/rule/KeyGeneratorConfiguration.java @@ -0,0 +1,33 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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 io.shardingsphere.api.config.rule; + +import io.shardingsphere.core.constant.KeyGeneratorEnum; +import lombok.Builder; +import lombok.Data; + +/** + * @author:zhaodong.xzd + * @github https://github.com/Yaccc + */ +@Data +@Builder +public class KeyGeneratorConfiguration implements RuleConfiguration { + private KeyGeneratorEnum keyGeneratorType; + + +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/KeyGeneratorEnum.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/KeyGeneratorEnum.java new file mode 100644 index 0000000000000..49c267452b472 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/KeyGeneratorEnum.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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 io.shardingsphere.core.constant; + +import lombok.RequiredArgsConstructor; + +/** + * @author:zhaodong.xzd + * @github https://github.com/Yaccc + */ +@RequiredArgsConstructor +public enum KeyGeneratorEnum { + /** + * default snowflake + */ + DEFAULT("default"), + /** + * leaf snowflake with zookeeper + */ + LEAF_SNOWFLAKE("leaf_snowflake"), + /** + * leaf segement + */ + LEAF_SEGMENT("leaf_segment"); + + private final String typeName; + +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/keygen/leaf/SnowFlakeKeyGenerator.java b/sharding-core/src/main/java/io/shardingsphere/core/keygen/leaf/SnowFlakeKeyGenerator.java index 46b815d73728b..36f0212a6987b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/keygen/leaf/SnowFlakeKeyGenerator.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/keygen/leaf/SnowFlakeKeyGenerator.java @@ -1,7 +1,30 @@ +/* + * Copyright 2016-2018 shardingsphere.io. + *

+ * Licensed 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 io.shardingsphere.core.keygen.leaf; import io.shardingsphere.core.keygen.KeyGenerator; +/** + * snowflake from leaf + * + * @url https://github.com/Meituan-Dianping/Leaf + * @author:zhaodong.xzd + * + */ public class SnowFlakeKeyGenerator implements KeyGenerator { @Override public Number generateKey() {