From 8bf1363ec8648b2959487aa08bc737f5c4db0337 Mon Sep 17 00:00:00 2001 From: UNCANNY69 Date: Fri, 27 Dec 2024 11:55:06 +0530 Subject: [PATCH 1/2] TRUNK-5918 Switching from Hibernate Mappings to Annotations for ConceptName Domain. --- .../main/java/org/openmrs/ConceptName.java | 61 ++++++++++++++++- api/src/main/resources/hibernate.cfg.xml | 1 - .../api/db/hibernate/ConceptName.hbm.xml | 67 ------------------- .../org/openmrs/api/OrderServiceTest.java | 1 + 4 files changed, 61 insertions(+), 69 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/ConceptName.hbm.xml diff --git a/api/src/main/java/org/openmrs/ConceptName.java b/api/src/main/java/org/openmrs/ConceptName.java index b8ba7f856aaa..83fe0ed2bbe5 100644 --- a/api/src/main/java/org/openmrs/ConceptName.java +++ b/api/src/main/java/org/openmrs/ConceptName.java @@ -9,6 +9,20 @@ */ package org.openmrs; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.Table; import java.util.Collection; import java.util.Date; import java.util.HashSet; @@ -20,6 +34,11 @@ import org.apache.lucene.analysis.standard.StandardFilterFactory; import org.apache.lucene.analysis.standard.StandardTokenizerFactory; import org.codehaus.jackson.annotate.JsonIgnore; +import org.hibernate.annotations.BatchSize; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; +import org.hibernate.annotations.Parameter; +import org.hibernate.annotations.Type; import org.hibernate.envers.Audited; import org.hibernate.search.annotations.Analyze; import org.hibernate.search.annotations.Analyzer; @@ -38,6 +57,9 @@ * ConceptName is the real world term used to express a Concept within the idiom of a particular * locale. */ +@Entity +@Table(name = "concept_name") +@BatchSize(size = 25) @Indexed @AnalyzerDef( name = "ConceptNameAnalyzer", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = { @@ -46,48 +68,85 @@ @TokenFilterDef(factory = ASCIIFoldingFilterFactory.class) }) @Analyzer(definition = "ConceptNameAnalyzer") +@AttributeOverrides(value = { + @AttributeOverride( + name = "uuid", + column = @Column(name = "uuid", length = 38, unique = true) + ) +}) @Audited public class ConceptName extends BaseOpenmrsObject implements Auditable, Voidable, java.io.Serializable { public static final long serialVersionUID = 2L; + @Id + @Column(name = "concept_name_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) @DocumentId private Integer conceptNameId; - + @ManyToOne + @JoinColumn(name = "concept_id",nullable = false) @IndexedEmbedded(includeEmbeddedObjectId = true) private Concept concept; @Field + @Column(name = "name",nullable = false) private String name; @Field(analyze = Analyze.NO) @FieldBridge(impl = LocaleFieldBridge.class) + @Column(name = "locale", nullable = false, length = 50) // ABK: upgraded from a plain string to a full locale object private Locale locale; + @ManyToOne + @JoinColumn(name = "creator", nullable = false) private User creator; + @Column(name="date_created", nullable = false) private Date dateCreated; @Field + @Column(name="voided", nullable = false, length = 1) private Boolean voided = false; + @ManyToOne + @JoinColumn(name = "voided_by") private User voidedBy; + @Column(name = "date_voided", length = 19) private Date dateVoided; + @Column(name = "void_reason") private String voidReason; + @ManyToMany + @JoinTable( + name = "concept_name_tag_map", + joinColumns = @JoinColumn(name = "concept_name_id"), + inverseJoinColumns = @JoinColumn(name = "concept_name_tag_id") + ) + @Cascade(CascadeType.SAVE_UPDATE) private Collection tags; @Field + @Enumerated(EnumType.STRING) + @Column(name = "concept_name_type", length = 50) + @Type(type = "org.hibernate.type.EnumType", parameters = { + @Parameter(name = "enumClass", value = "org.openmrs.api.ConceptNameType"), + @Parameter(name = "useNamed", value = "true") + }) private ConceptNameType conceptNameType; @Field + @Column(name = "locale_preferred", nullable = false, length = 1) private Boolean localePreferred = false; + @ManyToOne + @JoinColumn(name = "changed_by") private User changedBy; + @Column(name = "date_changed", length = 19) private Date dateChanged; // Constructors diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 2bd3c6ad8dc1..6d2475d5e3cc 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -28,7 +28,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/ConceptName.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/ConceptName.hbm.xml deleted file mode 100644 index aeb2e83f422d..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/ConceptName.hbm.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - concept_name_concept_name_id_seq - - - - - - - - - - - - - - - - - - - - - - - - org.openmrs.api.ConceptNameType - true - - - - - - - - - - - diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index 6d553c038256..d20297d01ece 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -2736,6 +2736,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(PatientState.class) .addAnnotatedClass(DrugIngredient.class) .addAnnotatedClass(AlertRecipient.class) + .addAnnotatedClass(ConceptName.class) .addAnnotatedClass(PatientIdentifierType.class) .addAnnotatedClass(ProgramAttributeType.class) .addAnnotatedClass(HL7InError.class) From 40529549cbca2f13aecafddb6b5d6cea98fd62de Mon Sep 17 00:00:00 2001 From: UNCANNY69 Date: Sat, 28 Dec 2024 06:20:07 +0530 Subject: [PATCH 2/2] TRUNK-5918 Switching from Hibernate Mappings to Annotations for ConceptName Domain. --- api/src/main/java/org/openmrs/ConceptName.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/openmrs/ConceptName.java b/api/src/main/java/org/openmrs/ConceptName.java index 83fe0ed2bbe5..cd10d38ae930 100644 --- a/api/src/main/java/org/openmrs/ConceptName.java +++ b/api/src/main/java/org/openmrs/ConceptName.java @@ -69,10 +69,7 @@ }) @Analyzer(definition = "ConceptNameAnalyzer") @AttributeOverrides(value = { - @AttributeOverride( - name = "uuid", - column = @Column(name = "uuid", length = 38, unique = true) - ) + @AttributeOverride(name = "uuid", column = @Column(name = "uuid", length = 38, unique = true)) }) @Audited public class ConceptName extends BaseOpenmrsObject implements Auditable, Voidable, java.io.Serializable { @@ -84,6 +81,7 @@ public class ConceptName extends BaseOpenmrsObject implements Auditable, Voidabl @GeneratedValue(strategy = GenerationType.IDENTITY) @DocumentId private Integer conceptNameId; + @ManyToOne @JoinColumn(name = "concept_id",nullable = false) @IndexedEmbedded(includeEmbeddedObjectId = true)