Apache-Dbutils

基于Apache开源的Dbutils和阿里巴巴开源的Druid进行封装的DBUtils,全自定义SQL风格

License

License

GroupId

GroupId

com.github.duanxinyuan
ArtifactId

ArtifactId

library-apache-dbutils
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Apache-Dbutils
基于Apache开源的Dbutils和阿里巴巴开源的Druid进行封装的DBUtils,全自定义SQL风格
Project URL

Project URL

https://github.com/duanxinyuan/Apache-Dbutils
Source Code Management

Source Code Management

https://github.com/duanxinyuan/Apache-Dbutils

Download library-apache-dbutils

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.duanxinyuan/library-apache-dbutils/ -->
<dependency>
    <groupId>com.github.duanxinyuan</groupId>
    <artifactId>library-apache-dbutils</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.duanxinyuan/library-apache-dbutils/
implementation 'com.github.duanxinyuan:library-apache-dbutils:1.0.0'
// https://jarcasting.com/artifacts/com.github.duanxinyuan/library-apache-dbutils/
implementation ("com.github.duanxinyuan:library-apache-dbutils:1.0.0")
'com.github.duanxinyuan:library-apache-dbutils:jar:1.0.0'
<dependency org="com.github.duanxinyuan" name="library-apache-dbutils" rev="1.0.0">
  <artifact name="library-apache-dbutils" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.duanxinyuan', module='library-apache-dbutils', version='1.0.0')
)
libraryDependencies += "com.github.duanxinyuan" % "library-apache-dbutils" % "1.0.0"
[com.github.duanxinyuan/library-apache-dbutils "1.0.0"]

Dependencies

compile (8)

Group / Artifact Type Version
com.github.duanxinyuan : library-common-util jar 1.0.0
com.alibaba : druid jar 1.1.5
commons-dbutils : commons-dbutils jar 1.6
commons-lang : commons-lang jar 2.6
commons-collections : commons-collections jar 3.2.2
org.slf4j : slf4j-api jar 1.7.25
com.google.guava : guava jar 25.0-jre
org.projectlombok : lombok jar 1.16.20

Project Modules

There are no modules declared in this project.

雪花Id(分布式Id)算法工具库

Twitter雪花算法-普通版

Twitter的雪花算法,用于生成分布式Id

Maven依赖

<dependency>
    <groupId>com.github.duanxinyuan</groupId>
    <artifactId>util-snowflake</artifactId>
</dependency>
  • Twitter雪花算法工具类:SnowflakeIdUtils

Twitter雪花算法-完美版

  • 增加了使用Redis分配workerId和datacenterId的逻辑,确保不会重复
  • 最多可以分配32*32=1024个workerId+datacenterId的组合

Maven依赖

<dependency>
    <groupId>com.github.duanxinyuan</groupId>
    <artifactId>util-snowflake-prefect</artifactId>
</dependency>
  • Twitter雪花算法工具类:SnowflakeIdUtils

配置示例

properties 配置示例

#雪花算法模块名
snowflake.module=test
#Redis缓存类型,single/sentinel/sharded/cluster,必须配置
cache.redis.type.snowflake=single
#Redis节点信息列表,多个使用逗号隔开,必须配置
cache.redis.nodes.snowflake=127.0.0.1:6380
#Redis密码,没有密码不需要配置
cache.redis.password.snowflake=123456

yaml 配置示例

snowflake:
    #雪花算法模块名
    module: test
cache:
    redis:
        #Redis缓存类型,single/sentinel/sharded/cluster,必须配置
        type:
            snowflake: single
        #Redis节点信息列表,多个使用逗号隔开,必须配置
        nodes:
            snowflake: 127.0.0.1:6380
        #Redis密码,没有密码不需要配置
        password:
            snowflake: 123456

使用示例

import com.dxy.library.json.jackson.JacksonUtil;
import com.dxy.library.snowflake.SnowflakeIdUtils;
import org.junit.Test;

import java.time.Clock;
import java.util.List;
import java.util.Map;

/**
 * @author duanxinyuan
 * 2019/1/14 21:54
 */
public class SnowflakeIdUtilsTest {

    @Test
    public void getAllDataCenterWorkerId() {
        Map<String, Map<String, Long>> allDataCenterWorkerId = SnowflakeIdUtils.getAllDataCenterWorkerId();
        System.out.println(JacksonUtil.to(allDataCenterWorkerId));
    }

    @Test
    public void getWorkerId() {
        long workerId = SnowflakeIdUtils.getWorkerId();
        long datacenterId = SnowflakeIdUtils.getDatacenterId();
        System.out.println(workerId);
        System.out.println(datacenterId);
    }

    @Test
    public void testSnowflakeId() {
        System.out.println(SnowflakeIdUtils.getAsLong());
        System.out.println(SnowflakeIdUtils.getAsString());
    }

    @Test
    public void testSnowflakeIdBatch() {
        long start = Clock.systemUTC().millis();
        for (int i = 0; i < 100000; i++) {
            System.out.println(SnowflakeIdUtils.getAsLong());
        }
        System.out.println(Clock.systemUTC().millis() - start);
    }

}

Versions

Version
1.0.0