Skip to content

Commit d85a9d8

Browse files
author
Alex Devine
committed
TRUNK-5899: Replace Hibernate XML mapping with JPA annotations for ConceptAttributeType
- add source code form to ConceptAttributeTypeTest.java - removed jakarta.persistence dependency in pom.xml based on code review
1 parent 349db16 commit d85a9d8

File tree

5 files changed

+70
-89
lines changed

5 files changed

+70
-89
lines changed

api/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -395,5 +395,4 @@
395395
</build>
396396
</profile>
397397
</profiles>
398-
</project>
399-
398+
</project>

api/src/main/java/org/openmrs/ConceptAttributeType.java

+33-20
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,43 @@
99
*/
1010
package org.openmrs;
1111

12+
import javax.persistence.Entity;
13+
import javax.persistence.Table;
14+
import javax.persistence.Id;
15+
import javax.persistence.GeneratedValue;
16+
import javax.persistence.GenerationType;
17+
import javax.persistence.Column;
18+
19+
1220
import org.hibernate.envers.Audited;
1321
import org.openmrs.attribute.AttributeType;
1422
import org.openmrs.attribute.BaseAttributeType;
1523

1624
@Audited
25+
@Entity
26+
@Table(name = "concept_attribute_type")
1727
public class ConceptAttributeType extends BaseAttributeType<Concept> implements AttributeType<Concept> {
18-
19-
private Integer conceptAttributeTypeId;
20-
21-
public Integer getConceptAttributeTypeId() {
22-
return conceptAttributeTypeId;
23-
}
24-
25-
public void setConceptAttributeTypeId(Integer conceptAttributeTypeId) {
26-
this.conceptAttributeTypeId = conceptAttributeTypeId;
27-
}
28-
29-
@Override
30-
public Integer getId() {
31-
return getConceptAttributeTypeId();
32-
}
33-
34-
@Override
35-
public void setId(Integer id) {
36-
setConceptAttributeTypeId(id);
37-
}
28+
29+
@Id
30+
@GeneratedValue(strategy = GenerationType.IDENTITY)
31+
@Column(name = "concept_attribute_type_id")
32+
private Integer conceptAttributeTypeId;
33+
34+
public Integer getConceptAttributeTypeId() {
35+
return conceptAttributeTypeId;
36+
}
37+
38+
public void setConceptAttributeTypeId(Integer conceptAttributeTypeId) {
39+
this.conceptAttributeTypeId = conceptAttributeTypeId;
40+
}
41+
42+
@Override
43+
public Integer getId() {
44+
return getConceptAttributeTypeId();
45+
}
46+
47+
@Override
48+
public void setId(Integer id) {
49+
setConceptAttributeTypeId(id);
50+
}
3851
}

api/src/main/resources/hibernate.cfg.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<mapping resource="org/openmrs/api/db/hibernate/Concept.hbm.xml" />
2727
<mapping resource="org/openmrs/api/db/hibernate/ConceptAnswer.hbm.xml" />
2828
<mapping resource="org/openmrs/api/db/hibernate/ConceptAttribute.hbm.xml" />
29-
<mapping resource="org/openmrs/api/db/hibernate/ConceptAttributeType.hbm.xml" />
3029
<mapping resource="org/openmrs/api/db/hibernate/ConceptDescription.hbm.xml" />
3130
<mapping resource="org/openmrs/api/db/hibernate/ConceptName.hbm.xml" />
3231
<mapping resource="org/openmrs/api/db/hibernate/ConceptNameTag.hbm.xml" />
@@ -110,6 +109,7 @@
110109
<!-- These mappings are required because of rerefences in Obs & Concept -->
111110
<mapping class="org.openmrs.ObsReferenceRange"/>
112111
<mapping class="org.openmrs.ConceptReferenceRange"/>
112+
<mapping class="org.openmrs.ConceptAttributeType"/>
113113
</session-factory>
114114

115-
</hibernate-configuration>
115+
</hibernate-configuration>

api/src/main/resources/org/openmrs/api/db/hibernate/ConceptAttributeType.hbm.xml

-65
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* This Source Code Form is subject to the terms of the Mozilla Public License,
3+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4+
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
5+
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
6+
*
7+
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
8+
* graphic logo is a trademark of OpenMRS Inc.
9+
*/
10+
package org.openmrs;
11+
12+
import org.junit.jupiter.api.Test;
13+
import static org.junit.jupiter.api.Assertions.*;
14+
15+
import org.openmrs.api.context.Context;
16+
import org.openmrs.test.jupiter.BaseContextSensitiveTest;
17+
18+
public class ConceptAttributeTypeTest extends BaseContextSensitiveTest {
19+
20+
@Test
21+
public void shouldSaveAndFetchConceptAttributeType() {
22+
ConceptAttributeType type = new ConceptAttributeType();
23+
type.setName("JPA Test Type");
24+
type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
25+
type.setMinOccurs(0);
26+
type.setMaxOccurs(1);
27+
28+
Context.getConceptService().saveConceptAttributeType(type);
29+
30+
ConceptAttributeType fetched = Context.getConceptService().getConceptAttributeType(type.getId());
31+
assertNotNull(fetched);
32+
assertEquals("JPA Test Type", fetched.getName());
33+
}
34+
}

0 commit comments

Comments
 (0)