Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRUNK-6280: Migrate GlobalProperty from Hibernate Mapping XML to JPA annotations #4805

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions api/src/main/java/org/openmrs/GlobalProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,84 @@
import java.util.Date;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.envers.Audited;
import org.openmrs.customdatatype.CustomDatatype;
import org.openmrs.customdatatype.CustomDatatypeUtil;
import org.openmrs.customdatatype.CustomValueDescriptor;
import org.openmrs.customdatatype.SingleCustomValue;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
* Global properties are simple key-value pairs persisted in the database GPs can be thought of as
* something similar to environment variables used in operating systems.
*/
@Entity
@Table(name = "global_property")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Audited
public class GlobalProperty extends BaseOpenmrsObject implements CustomValueDescriptor, SingleCustomValue<GlobalProperty> {

private static final long serialVersionUID = 1L;

@Id
@Column(name = "property", nullable = false, length = 255)
private String property = "";

@Column(name = "property_value", columnDefinition = "TEXT")
@Lob
private String propertyValue = "";

private transient Object typedValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need transient here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wikumChamith I updated the PR


// if true, indicates that setValue has been called, and we need to invoke CustomDatatype's save
@Transient
private boolean dirty = false;

@Column(name = "description", columnDefinition = "TEXT")
@Lob
private String description = "";

@Column(name = "datatype", length = 255)
private String datatypeClassname;

@Column(name = "datatype_config", columnDefinition = "TEXT")
@Lob
private String datatypeConfig;

@Column(name = "preferred_handler", length = 255)
private String preferredHandlerClassname;

@Column(name = "handler_config", columnDefinition = "TEXT")
@Lob
private String handlerConfig;

@ManyToOne
@JoinColumn(name = "changed_by")
private User changedBy;

@Column(name = "date_changed")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a length for this column in XML mapping?

private Date dateChanged;

@ManyToOne
@JoinColumn(name = "view_privilege")
private Privilege viewPrivilege;

@ManyToOne
@JoinColumn(name = "edit_privilege")
private Privilege editPrivilege;

@ManyToOne
@JoinColumn(name = "delete_privilege")
private Privilege deletePrivilege;


Expand Down
1 change: 0 additions & 1 deletion api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<mapping resource="org/openmrs/api/db/hibernate/Form.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/FormField.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/FormResource.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/GlobalProperty.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Obs.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Person.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/PersonAttribute.hbm.xml" />
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
.addAnnotatedClass(PatientIdentifierType.class)
.addAnnotatedClass(ProgramAttributeType.class)
.addAnnotatedClass(HL7InError.class)
.addAnnotatedClass(GlobalProperty.class)
.addAnnotatedClass(OrderType.class)
.getMetadataBuilder().build();

Expand Down
Loading