Skip to content

Commit

Permalink
Update the NullUUIDGenerator generator
Browse files Browse the repository at this point in the history
  • Loading branch information
epuzanov committed Jan 29, 2024
1 parent e4cbeb0 commit 2e8c29d
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 76 deletions.
10 changes: 1 addition & 9 deletions gsrs-core-entities/src/main/java/ix/core/models/Edit.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,9 @@ public static <T> Edit create(T before, T after){

@JsonIgnore
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false)

// @JsonIgnore
// @Id
// @GeneratedValue
public UUID id; // internal random id


//don't use @CreateDate annotation here just set it on creation time and mark it final
public final Long created = TimeUtil.getCurrentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
@DiscriminatorOptions(force = true)
public class FileData extends BaseModel {
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false)
public UUID id; // internal id
public String mimeType;

Expand Down
5 changes: 1 addition & 4 deletions gsrs-core-entities/src/main/java/ix/core/models/Payload.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
@Indexable(indexed = false)//we don't want this indexed
public class Payload extends BaseModel {
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false)
public UUID id;

@ManyToOne(cascade = CascadeType.PERSIST)
Expand Down
18 changes: 3 additions & 15 deletions gsrs-core-entities/src/main/java/ix/core/models/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,11 @@
@History(store=false)
public class Session extends BaseModel {
@Id
@GenericGenerator(
name = "NullUUIDGenerator",
strategy = "ix.ginas.models.generators.NullUUIDGenerator"
)
@GeneratedValue(
generator = "NullUUIDGenerator"
)
@Type(
type = "uuid-char"
)
@Column(
length = 40,
updatable = false
)
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
public UUID id;

@OneToOne(cascade=CascadeType.ALL)
@ManyToOne(cascade=CascadeType.ALL)
public UserProfile profile;

public final long created = TimeUtil.getCurrentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
public class GinasCommonData extends NoIdGinasCommonData{

@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
public UUID uuid;
@Indexable()
public UUID getUuid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;
import java.util.UUID;

public class NullUUIDGenerator implements IdentifierGenerator {

public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
Serializable id = session.getEntityPersister(null, object).getIdentifier(object, session);
public Object generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
Object id = session.getEntityPersister(null, object).getIdentifier(object, session);
return id != null ? id : UUID.randomUUID();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
public class ImportProcessingJob implements GeneralPurposeJob {

@Id
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
private UUID id;

@Lob
private String data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,17 @@ public class ImportData {
/**
* Foreign key, referencing ImportMetadata
*/
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = false)
@Indexable(name="RecordId")
private UUID recordId;

/**
* Primary key
*/
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
@Indexable(name="instanceId")
private UUID instanceId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,16 @@ public enum RecordProcessStatus {
indexed
}

@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
private UUID instanceId; //always unique! changes when data change

/**
* Primary key. value is assigned in code
*/
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
//@OneToOne
private UUID recordId; //stays the same for a given record

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public enum ImportValidationType {
/**
* foreign key to ImportData object
*/
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = false)
@Indexable
private UUID instanceId;

Expand All @@ -59,11 +56,8 @@ public enum ImportValidationType {
* Unique, primary key
*/
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
@Indexable
private UUID ValidationId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,18 @@ public class KeyValueMapping {
* Primary key
*/
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
private UUID mappingId;

/**
* Foreign key to ImportData
*/
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = false)
private UUID instanceId;

/**
* Foreign key to ImportMetadata
*/
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = false)
private UUID recordId;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
@Data
public class RawImportData {
@Id
@GenericGenerator(name = "NullUUIDGenerator", strategy = "ix.ginas.models.generators.NullUUIDGenerator")
@GenericGenerator(name = "NullUUIDGenerator", type = ix.ginas.models.generators.NullUUIDGenerator.class)
@GeneratedValue(generator = "NullUUIDGenerator")
//maintain backwards compatibility with old GSRS store it as varchar(40) by default hibernate will store uuids as binary
@Type(type = "uuid-char" )
@Column(length =40, updatable = false, unique = true)
private UUID recordId;

@Lob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ server.servlet.encoding.charset="UTF-8"
server.servlet.encoding.force=true

spring.jpa.properties.hibernate.entity_dirtiness_strategy=gsrs.GsrsEntityDirtinessStrategy
spring.jpa.properties.hibernate.type.preferred_uuid_jdbc_type=CHAR
spring.jackson.serialization.fail-on-empty-beans=false
spring.jackson.deserialization.fail-on-unknown-properties=false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
spring.jackson.deserialization.fail-on-unknown-properties=false
spring.jackson.serialization.fail-on-empty-beans=false
spring.jpa.properties.hibernate.entity_dirtiness_strategy=gsrs.GsrsEntityDirtinessStrategy
spring.jpa.properties.hibernate.type.preferred_uuid_jdbc_type=CHAR

gsrs.exchange="test_exchange"

Expand Down

0 comments on commit 2e8c29d

Please sign in to comment.