### Set JAVA_HOME and MAVEN_HOME
Source: https://github.com/baidu/uid-generator/blob/master/README.md
Set the JAVA_HOME and MAVEN_HOME environment variables. Ensure the Maven bin directory is added to your PATH.
```shell
export MAVEN_HOME=/xxx/xxx/software/maven/apache-maven-3.3.9
export PATH=$MAVEN_HOME/bin:$PATH
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home";
export JAVA_HOME;
```
--------------------------------
### Mybatis Configuration for UID Generator
Source: https://github.com/baidu/uid-generator/blob/master/README.md
This XML configuration sets up Mybatis components including component scanning, SQL session factory, transaction management, mapper scanning, and data source configuration using Druid.
```xml
```
--------------------------------
### Generate and Parse UID with CachedUidGeneratorTest
Source: https://github.com/baidu/uid-generator/blob/master/README.md
This Java code demonstrates how to generate a unique ID using the UidGenerator and then parse it back into its components: timestamp, worker ID, and sequence number. Ensure the UidGenerator is properly injected.
```java
@Resource
private UidGenerator uidGenerator;
@Test
public void testSerialGenerate() {
// Generate UID
long uid = uidGenerator.getUID();
// Parse UID into [Timestamp, WorkerId, Sequence]
// {"UID":"180363646902239241","parsed":{ "timestamp":"2017-01-19 12:15:46", "workerId":"4", "sequence":"9" }}
System.out.println(uidGenerator.parseUID(uid));
}
```
--------------------------------
### Spring Configuration for CachedUidGenerator
Source: https://github.com/baidu/uid-generator/blob/master/README.md
Spring bean definition for the CachedUidGenerator, recommended for performance-sensitive applications. Includes options for buffer size, padding, and rejection policies.
```xml
```
--------------------------------
### Create WORKER_NODE Table SQL
Source: https://github.com/baidu/uid-generator/blob/master/README.md
SQL script to create the WORKER_NODE table in a MySQL database. Ensure to replace 'xxxx' with your actual database name.
```sql
DROP DATABASE IF EXISTS `xxxx`;
CREATE DATABASE `xxxx` ;
use `xxxx`;
DROP TABLE IF EXISTS WORKER_NODE;
CREATE TABLE WORKER_NODE
(
ID BIGINT NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
HIST_NAME VARCHAR(64) NOT NULL COMMENT 'host name',
PORT VARCHAR(64) NOT NULL COMMENT 'port',
TYPE INT NOT NULL COMMENT 'node type: ACTUAL or CONTAINER',
LAUNCH_DATE DATE NOT NULL COMMENT 'launch date',
MODIFIED TIMESTAMP NOT NULL COMMENT 'modified time',
CREATED TIMESTAMP NOT NULL COMMENT 'created time',
PRIMARY KEY(ID)
)
COMMENT='DB WorkerID Assigner for UID Generator',ENGINE = INNODB;
```
--------------------------------
### Spring Configuration for DefaultUidGenerator
Source: https://github.com/baidu/uid-generator/blob/master/README.md
Spring bean definition for the DefaultUidGenerator. Configure 'workerIdAssigner' and optionally 'timeBits', 'workerBits', 'seqBits', and 'epochStr' as needed.
```xml
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.