
com.github.drinkjava2.jdialects.id.TimeStampIdGenerator Maven / Gradle / Ivy
/*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. See
* the lgpl.txt file in the root directory or
* .
*/
package com.github.drinkjava2.jdialects.id;
import com.github.drinkjava2.jdbpro.NormalJdbcTool;
import com.github.drinkjava2.jdialects.Dialect;
import com.github.drinkjava2.jdialects.Type;
import com.github.drinkjava2.jdialects.annotation.jpa.GenerationType;
/**
* This TimeStampGenerator return a long type value based on computer's current
* time
*
* @author Yong Zhu
* @version 1.0.0
* @since 1.0.0
*/
public class TimeStampIdGenerator implements IdGenerator {
public static final TimeStampIdGenerator INSTANCE = new TimeStampIdGenerator();
private static long count = 1;
@Override
public GenerationType getGenerationType() {
return GenerationType.TIMESTAMP;
}
@Override
public String getIdGenName() {
return "TimeStampId";
}
private static synchronized long getNextCount() {
if (count > 999999)
count = 1;
return ++count;
}
@Override
public Object getNextID(NormalJdbcTool jdbc, Dialect dialect, Type dataType) {
if (count > 999999)
count = 1;
return System.currentTimeMillis() * 1000000 + getNextCount();
}
@Override
public Boolean dependOnAutoIdGenerator() {
return false;
}
@Override
public IdGenerator newCopy() {
return INSTANCE;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy