[DEV] work on uuid and callbak migration
This commit is contained in:
parent
56609e4f59
commit
41fb181545
@ -22,6 +22,7 @@ import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
public class AnnotationTools {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
|
||||
@ -75,14 +76,14 @@ public class AnnotationTools {
|
||||
}
|
||||
|
||||
public static String getDefault(final Field element) throws Exception {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataDefault.class);
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DefaultValue.class);
|
||||
if (annotation.length == 0) {
|
||||
return null;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more than 1 element @DataDefault on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((DataDefault) annotation[0]).value();
|
||||
return ((DefaultValue) annotation[0]).value();
|
||||
}
|
||||
|
||||
public static ManyToOne getManyToOne(final Field element) throws Exception {
|
||||
|
@ -1,14 +0,0 @@
|
||||
package org.kar.archidata.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ ElementType.TYPE, ElementType.FIELD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DataDefault {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
@ -10,6 +10,7 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
@ -19,7 +20,6 @@ import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.annotation.CreationTimestamp;
|
||||
import org.kar.archidata.annotation.DataDefault;
|
||||
import org.kar.archidata.annotation.UpdateTimestamp;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||
@ -35,12 +35,14 @@ import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.DateTools;
|
||||
import org.kar.archidata.tools.UuidUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
|
||||
/* TODO list:
|
||||
@ -197,7 +199,8 @@ public class DataAccess {
|
||||
if (tmp == null) {
|
||||
ps.setNull(iii.value, Types.BINARY);
|
||||
} else {
|
||||
ps.setObject(iii.value, tmp);
|
||||
final byte[] dataByte = UuidUtils.asBytes((UUID) tmp);
|
||||
ps.setBytes(iii.value, dataByte);
|
||||
}
|
||||
} else if (type == Long.class) {
|
||||
final Object tmp = field.get(data);
|
||||
@ -259,6 +262,14 @@ public class DataAccess {
|
||||
final Timestamp sqlDate = java.sql.Timestamp.from(((Date) tmp).toInstant());
|
||||
ps.setTimestamp(iii.value, sqlDate);
|
||||
}
|
||||
} else if (type == Instant.class) {
|
||||
final Object tmp = field.get(data);
|
||||
if (tmp == null) {
|
||||
ps.setNull(iii.value, Types.INTEGER);
|
||||
} else {
|
||||
final String sqlDate = ((Instant) tmp).toString();
|
||||
ps.setString(iii.value, sqlDate);
|
||||
}
|
||||
} else if (type == LocalDate.class) {
|
||||
final Object tmp = field.get(data);
|
||||
if (tmp == null) {
|
||||
@ -297,11 +308,14 @@ public class DataAccess {
|
||||
|
||||
protected static <T> void setValueFromDb(final Class<?> type, final Object data, final CountInOut count, final Field field, final ResultSet rs, final CountInOut countNotNull) throws Exception {
|
||||
if (type == UUID.class) {
|
||||
final UUID tmp = rs.getObject(count.value, UUID.class);
|
||||
final byte[] tmp = rs.getBytes(count.value);
|
||||
//final UUID tmp = rs.getObject(count.value, UUID.class);
|
||||
if (rs.wasNull()) {
|
||||
field.set(data, null);
|
||||
} else {
|
||||
field.set(data, tmp);
|
||||
//field.set(data, tmp);
|
||||
final UUID uuid = UuidUtils.asUuid(tmp);
|
||||
field.set(data, uuid);
|
||||
countNotNull.inc();
|
||||
}
|
||||
} else if (type == Long.class) {
|
||||
@ -413,6 +427,14 @@ public class DataAccess {
|
||||
countNotNull.inc();
|
||||
}
|
||||
}
|
||||
} else if (type == Instant.class) {
|
||||
final String tmp = rs.getString(count.value);
|
||||
if (rs.wasNull()) {
|
||||
field.set(data, null);
|
||||
} else {
|
||||
field.set(data, Instant.parse(tmp));
|
||||
countNotNull.inc();
|
||||
}
|
||||
} else if (type == LocalDate.class) {
|
||||
final java.sql.Date tmp = rs.getDate(count.value);
|
||||
if (rs.wasNull()) {
|
||||
@ -467,11 +489,15 @@ public class DataAccess {
|
||||
final Class<?> type = field.getType();
|
||||
if (type == UUID.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final UUID tmp = rs.getObject(count, UUID.class);
|
||||
|
||||
final byte[] tmp = rs.getBytes(count);
|
||||
//final UUID tmp = rs.getObject(count, UUID.class);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
//field.set(obj, tmp);
|
||||
final UUID uuid = UuidUtils.asUuid(tmp);
|
||||
field.set(obj, uuid);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -607,6 +633,16 @@ public class DataAccess {
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Instant.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final String tmp = rs.getString(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Instant.parse(tmp));
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == LocalDate.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final java.sql.Date tmp = rs.getDate(count);
|
||||
@ -735,7 +771,7 @@ public class DataAccess {
|
||||
}
|
||||
if (!field.getClass().isPrimitive()) {
|
||||
final Object tmp = field.get(data);
|
||||
if (tmp == null && field.getDeclaredAnnotationsByType(DataDefault.class).length != 0) {
|
||||
if (tmp == null && field.getDeclaredAnnotationsByType(DefaultValue.class).length != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -799,7 +835,7 @@ public class DataAccess {
|
||||
final Class<?> type = elem.getType();
|
||||
if (!type.isPrimitive()) {
|
||||
final Object tmp = elem.get(data);
|
||||
if (tmp == null && elem.getDeclaredAnnotationsByType(DataDefault.class).length != 0) {
|
||||
if (tmp == null && elem.getDeclaredAnnotationsByType(DefaultValue.class).length != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -816,7 +852,9 @@ public class DataAccess {
|
||||
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
|
||||
if (generatedKeys.next()) {
|
||||
if (primaryKeyField.getType() == UUID.class) {
|
||||
uniqueSQLUUID = generatedKeys.getObject(1, UUID.class);
|
||||
//uniqueSQLUUID = generatedKeys.getObject(1, UUID.class);
|
||||
final byte[] tmpid = generatedKeys.getBytes(1);
|
||||
uniqueSQLUUID = UuidUtils.asUuid(tmpid);
|
||||
} else {
|
||||
uniqueSQLID = generatedKeys.getLong(1);
|
||||
}
|
||||
@ -933,13 +971,21 @@ public class DataAccess {
|
||||
* @param filterValue
|
||||
* @return the affected rows.
|
||||
* @throws Exception */
|
||||
public static <T, ID_TYPE> int update(final T data, final ID_TYPE id, final List<String> updateColomn) throws Exception {
|
||||
return updateWhere(data, new Condition(getTableIdCondition(data.getClass(), id)), new FilterValue(updateColomn), new TransmitKey(id));
|
||||
public static <T, ID_TYPE> int update(final T data, final ID_TYPE id, final List<String> updateColomn, final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(data.getClass(), id)));
|
||||
options.add(new FilterValue(updateColomn));
|
||||
options.add(new TransmitKey(id));
|
||||
return updateWhere(data, options);
|
||||
}
|
||||
|
||||
public static <T> int updateWhere(final T data, final QueryOption... option) throws Exception {
|
||||
final Class<?> clazz = data.getClass();
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
return updateWhere(data, options);
|
||||
}
|
||||
|
||||
public static <T> int updateWhere(final T data, final QueryOptions options) throws Exception {
|
||||
final Class<?> clazz = data.getClass();
|
||||
final Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
throw new DataAccessException("request a gets without any condition");
|
||||
@ -991,7 +1037,7 @@ public class DataAccess {
|
||||
}
|
||||
if (!field.getClass().isPrimitive()) {
|
||||
final Object tmp = field.get(data);
|
||||
if (tmp == null && field.getDeclaredAnnotationsByType(DataDefault.class).length != 0) {
|
||||
if (tmp == null && field.getDeclaredAnnotationsByType(DefaultValue.class).length != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -1038,7 +1084,7 @@ public class DataAccess {
|
||||
final Class<?> type = field.getType();
|
||||
if (!type.isPrimitive()) {
|
||||
final Object tmp = field.get(data);
|
||||
if (tmp == null && field.getDeclaredAnnotationsByType(DataDefault.class).length != 0) {
|
||||
if (tmp == null && field.getDeclaredAnnotationsByType(DefaultValue.class).length != 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
@ -165,6 +166,17 @@ public class DataExport {
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Instant.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final String tmp = rs.getString(count);
|
||||
if (!rs.wasNull()) {
|
||||
final Instant date = Instant.parse(tmp);
|
||||
LOGGER.error("Fail to parse the SQL time !!! {}", date);
|
||||
final List<Object> data = (List<Object>) (obj);
|
||||
data.set(id, date);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == LocalDate.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final java.sql.Date tmp = rs.getDate(count);
|
||||
|
@ -2,6 +2,7 @@ package org.kar.archidata.dataAccess;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
@ -46,6 +47,9 @@ public class DataFactory {
|
||||
if (type == Double.class || type == double.class) {
|
||||
return "double";
|
||||
}
|
||||
if (type == Instant.class) {
|
||||
return "varchar(33)";
|
||||
}
|
||||
if (type == Date.class || type == Timestamp.class) {
|
||||
return "timestamp(3)";
|
||||
}
|
||||
@ -97,6 +101,9 @@ public class DataFactory {
|
||||
if (type == Double.class || type == double.class) {
|
||||
return "REAL";
|
||||
}
|
||||
if (type == Instant.class) {
|
||||
return "text";
|
||||
}
|
||||
if (type == Date.class || type == Timestamp.class) {
|
||||
return "DATETIME";
|
||||
}
|
||||
@ -179,16 +186,24 @@ public class DataFactory {
|
||||
}
|
||||
if (defaultValue == null) {
|
||||
if (updateTime || createTime) {
|
||||
if ("varchar(33)".equals(typeValue)) {
|
||||
mainTableBuilder.append("DEFAULT DATE_FORMAT(now(6), '%Y-%m-%dT%H:%m:%s.%fZ')");
|
||||
} else {
|
||||
mainTableBuilder.append("DEFAULT CURRENT_TIMESTAMP");
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
mainTableBuilder.append("(3)");
|
||||
}
|
||||
}
|
||||
mainTableBuilder.append(" ");
|
||||
}
|
||||
if (updateTime) {
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
if ("varchar(33)".equals(typeValue)) {
|
||||
mainTableBuilder.append("ON UPDATE DATE_FORMAT(now(6), '%Y-%m-%dT%H:%m:%s.%fZ')");
|
||||
} else {
|
||||
mainTableBuilder.append("ON UPDATE CURRENT_TIMESTAMP");
|
||||
mainTableBuilder.append("(3)");
|
||||
}
|
||||
} else {
|
||||
// TODO: add trigger:
|
||||
/* CREATE TRIGGER your_table_trig AFTER UPDATE ON your_table BEGIN update your_table SET updated_on = datetime('now') WHERE user_id = NEW.user_id; END; */
|
||||
@ -202,7 +217,11 @@ public class DataFactory {
|
||||
triggerBuilder.append(" SET ");
|
||||
triggerBuilder.append(name);
|
||||
// triggerBuilder.append(" = datetime('now') WHERE id = NEW.id; \n");
|
||||
if ("varchar(33)".equals(typeValue)) {
|
||||
triggerBuilder.append(" = strftime('%Y-%m-%dT%H:%M:%fZ', 'now') WHERE id = NEW.id; \n");
|
||||
} else {
|
||||
triggerBuilder.append(" = strftime('%Y-%m-%d %H:%M:%f', 'now') WHERE id = NEW.id; \n");
|
||||
}
|
||||
triggerBuilder.append("END;");
|
||||
|
||||
postOtherTables.add(triggerBuilder.toString());
|
||||
@ -248,8 +267,11 @@ public class DataFactory {
|
||||
mainTableBuilder.append("PRIMARY KEY ");
|
||||
|
||||
}
|
||||
|
||||
if (strategy == GenerationType.IDENTITY) {
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
if ("binary(16)".equals(typeValue)) {
|
||||
|
||||
} else if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
mainTableBuilder.append("AUTO_INCREMENT ");
|
||||
} else {
|
||||
mainTableBuilder.append("AUTOINCREMENT ");
|
||||
|
5
src/org/kar/archidata/migration/AsyncCall.java
Normal file
5
src/org/kar/archidata/migration/AsyncCall.java
Normal file
@ -0,0 +1,5 @@
|
||||
package org.kar.archidata.migration;
|
||||
|
||||
public interface AsyncCall {
|
||||
void doRequest() throws Exception;
|
||||
}
|
@ -13,13 +13,20 @@ import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
record Action(String action, List<String> filterDB) {
|
||||
record Action(String action, AsyncCall async, List<String> filterDB) {
|
||||
public Action(final String action) {
|
||||
this(action, List.of());
|
||||
this(action, null, List.of());
|
||||
}
|
||||
|
||||
public Action(final String action, final String filterDB) {
|
||||
this(action, List.of(filterDB));
|
||||
this(action, null, List.of(filterDB));
|
||||
}
|
||||
public Action(final AsyncCall async) {
|
||||
this(null, async, List.of());
|
||||
}
|
||||
|
||||
public Action(final AsyncCall async, final String filterDB) {
|
||||
this(null, async, List.of(filterDB));
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +47,11 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
}
|
||||
for (int iii = 0; iii < this.actions.size(); iii++) {
|
||||
final Action action = this.actions.get(iii);
|
||||
if (action.action() != null) {
|
||||
LOGGER.info(" >>>> SQL ACTION : {}/{} ==> filter='{}'\n{}", iii, this.actions.size(), action.filterDB(), action.action());
|
||||
} else {
|
||||
LOGGER.info(" >>>> SQL ACTION : {}/{} ==> filter='{}'\nAsync lambda", iii, this.actions.size(), action.filterDB());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,8 +74,13 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
LOGGER.info(" >>>> SQL ACTION : {}/{}", iii + 1, this.actions.size());
|
||||
final Action action = this.actions.get(iii);
|
||||
|
||||
if (action.action() != null) {
|
||||
LOGGER.info("SQL request: ```{}``` on '{}' current={}", action.action(), action.filterDB(), ConfigBaseVariable.getDBType());
|
||||
log.append("SQL: " + action.action() + " on " + action.filterDB() + "\n");
|
||||
} else {
|
||||
LOGGER.info("SQL request: <Lambda> on '{}' current={}", action.filterDB(), ConfigBaseVariable.getDBType());
|
||||
log.append("SQL: <Lambda> on " + action.filterDB() + "\n");
|
||||
}
|
||||
boolean isValid = true;
|
||||
if (action.filterDB() != null && action.filterDB().size() > 0) {
|
||||
isValid = false;
|
||||
@ -80,7 +96,11 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (action.action() != null) {
|
||||
DataAccess.executeQuerry(action.action());
|
||||
} else {
|
||||
action.async().doRequest();
|
||||
}
|
||||
} catch (SQLException | IOException ex) {
|
||||
ex.printStackTrace();
|
||||
LOGGER.info("SQL request ERROR: ", ex.getMessage());
|
||||
@ -122,10 +142,16 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
public void addAction(final String action) {
|
||||
this.actions.add(new Action(action));
|
||||
}
|
||||
public void addAction(final AsyncCall async) {
|
||||
this.actions.add(new Action(async));
|
||||
}
|
||||
|
||||
public void addAction(final String action, final String filterdBType) {
|
||||
this.actions.add(new Action(action, filterdBType));
|
||||
}
|
||||
public void addAction(final AsyncCall async, final String filterdBType) {
|
||||
this.actions.add(new Action(async, filterdBType));
|
||||
}
|
||||
|
||||
public void addClass(final Class<?> clazz) throws Exception {
|
||||
final List<String> tmp = DataFactory.createTable(clazz);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.kar.archidata.migration.model;
|
||||
|
||||
import org.kar.archidata.annotation.DataDefault;
|
||||
import org.kar.archidata.annotation.DataIfNotExists;
|
||||
import org.kar.archidata.annotation.DataNotRead;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
@ -10,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
// For logs only
|
||||
//public static final String TABLE_NAME = "KAR_migration";
|
||||
@ -24,11 +24,11 @@ public class Migration extends GenericDataSoftDelete {
|
||||
@Column(length = 256)
|
||||
public String name;
|
||||
@DataNotRead
|
||||
@DataDefault("'2'")
|
||||
@DefaultValue("'2'")
|
||||
@Schema(description = "Version of the migration engine")
|
||||
public Integer version;
|
||||
@Column(nullable = false)
|
||||
@DataDefault("'0'")
|
||||
@DefaultValue("'0'")
|
||||
@Schema(description = "if the migration is well terminated or not")
|
||||
public Boolean terminated = false;
|
||||
@Schema(description = "index in the migration progression")
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.kar.archidata.migration.model;
|
||||
|
||||
import org.kar.archidata.annotation.DataDefault;
|
||||
import org.kar.archidata.annotation.DataIfNotExists;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
@ -9,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
// For logs only
|
||||
//public static final String TABLE_NAME = "KAR_migration";
|
||||
@ -22,7 +22,7 @@ public class Migration1 extends GenericDataSoftDelete {
|
||||
@Column(length = 256)
|
||||
public String name;
|
||||
@Column(nullable = false)
|
||||
@DataDefault("'0'")
|
||||
@DefaultValue("'0'")
|
||||
@Schema(description = "if the migration is well terminated or not")
|
||||
public Boolean terminated = false;
|
||||
@Schema(description = "index in the migration progression")
|
||||
|
@ -1,17 +1,17 @@
|
||||
package org.kar.archidata.model;
|
||||
|
||||
import org.kar.archidata.annotation.DataDefault;
|
||||
import org.kar.archidata.annotation.DataDeleted;
|
||||
import org.kar.archidata.annotation.DataNotRead;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
public class GenericDataSoftDelete extends GenericData {
|
||||
@DataNotRead
|
||||
@Column(nullable = false)
|
||||
@DataDefault("'0'")
|
||||
@DefaultValue("'0'")
|
||||
@DataDeleted
|
||||
@NotNull
|
||||
@Schema(description = "Deleted state", hidden = true, required = false, readOnly = true)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.kar.archidata.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
|
||||
import org.kar.archidata.annotation.CreationTimestamp;
|
||||
@ -27,8 +26,10 @@ public class GenericTiming {
|
||||
@DataNotRead
|
||||
@UpdateTimestamp
|
||||
@Column(nullable = false)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@NotNull
|
||||
@Schema(description = "When update the object", required = false, example = "2000-01-23T00:23:45.678Z", readOnly = true)
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
|
||||
public Instant updatedAt = null;
|
||||
//public Instant updatedAt = null;
|
||||
public Date updatedAt = null;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
public class UUIDGenericData extends GenericTiming {
|
||||
@Id
|
||||
@DefaultValue("UUID_TO_BIN(UUID())")
|
||||
@DefaultValue("(UUID_TO_BIN(UUID(), TRUE))")
|
||||
@Column(nullable = false, unique = true)
|
||||
@Schema(description = "Unique UUID of the object", required = false, readOnly = true, example = "e6b33c1c-d24d-11ee-b616-02420a030102")
|
||||
public UUID id = null;
|
||||
|
@ -1,17 +1,17 @@
|
||||
package org.kar.archidata.model;
|
||||
|
||||
import org.kar.archidata.annotation.DataDefault;
|
||||
import org.kar.archidata.annotation.DataDeleted;
|
||||
import org.kar.archidata.annotation.DataNotRead;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
public class UUIDGenericDataSoftDelete extends UUIDGenericData {
|
||||
@DataNotRead
|
||||
@Column(nullable = false)
|
||||
@DataDefault("'0'")
|
||||
@DefaultValue("'0'")
|
||||
@DataDeleted
|
||||
@NotNull
|
||||
@Schema(description = "Deleted state", hidden = true, required = false, readOnly = true)
|
||||
|
@ -17,7 +17,6 @@ CREATE TABLE `user` (
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.DataDefault;
|
||||
import org.kar.archidata.annotation.DataIfNotExists;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
@ -26,6 +25,7 @@ import jakarta.persistence.Column;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
|
||||
@Table(name = "user")
|
||||
@DataIfNotExists
|
||||
@ -35,13 +35,13 @@ public class User extends GenericDataSoftDelete {
|
||||
public String login = null;
|
||||
|
||||
public Timestamp lastConnection = null;
|
||||
@DataDefault("'0'")
|
||||
@DefaultValue("'0'")
|
||||
@Column(nullable = false)
|
||||
public boolean admin = false;
|
||||
@DataDefault("'0'")
|
||||
@DefaultValue("'0'")
|
||||
@Column(nullable = false)
|
||||
public boolean blocked = false;
|
||||
@DataDefault("'0'")
|
||||
@DefaultValue("'0'")
|
||||
@Column(nullable = false)
|
||||
public boolean removed = false;
|
||||
|
||||
|
21
src/org/kar/archidata/tools/UuidUtils.java
Normal file
21
src/org/kar/archidata/tools/UuidUtils.java
Normal file
@ -0,0 +1,21 @@
|
||||
package org.kar.archidata.tools;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UuidUtils {
|
||||
|
||||
public static UUID asUuid(final byte[] bytes) {
|
||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
final long firstLong = bb.getLong();
|
||||
final long secondLong = bb.getLong();
|
||||
return new UUID(firstLong, secondLong);
|
||||
}
|
||||
|
||||
public static byte[] asBytes(final UUID uuid) {
|
||||
final ByteBuffer bb = ByteBuffer.allocate(16);
|
||||
bb.putLong(uuid.getMostSignificantBits());
|
||||
bb.putLong(uuid.getLeastSignificantBits());
|
||||
return bb.array();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user