Skip to content

Commit

Permalink
Merging: Replace deprecated method "Expression" with "Restrictions" -
Browse files Browse the repository at this point in the history
TRUNK-4098 author:lluismf
  • Loading branch information
dkayiwa committed Oct 24, 2013
1 parent 4f472b5 commit eb4edec
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 162 deletions.
Expand Up @@ -20,7 +20,6 @@
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
Expand Down Expand Up @@ -90,7 +89,7 @@ public Cohort deleteCohort(Cohort cohort) throws DAOException {
@SuppressWarnings("unchecked")
public List<Cohort> getCohorts(String nameFragment) throws DAOException {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Cohort.class);
criteria.add(Expression.ilike("name", nameFragment, MatchMode.ANYWHERE));
criteria.add(Restrictions.ilike("name", nameFragment, MatchMode.ANYWHERE));
criteria.addOrder(Order.asc("name"));
return criteria.list();
}
Expand Down
Expand Up @@ -378,7 +378,7 @@ public Drug getDrug(Integer drugId) throws DAOException {
@SuppressWarnings("unchecked")
public List<Drug> getDrugs(String drugName, Concept concept, boolean includeRetired) throws DAOException {
Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(Drug.class, "drug");
if (includeRetired == false)
if (!includeRetired)
searchCriteria.add(Restrictions.eq("drug.retired", false));
if (concept != null)
searchCriteria.add(Restrictions.eq("drug.concept", concept));
Expand Down Expand Up @@ -453,7 +453,7 @@ public List<ConceptClass> getAllConceptClasses(boolean includeRetired) throws DA
Criteria crit = sessionFactory.getCurrentSession().createCriteria(ConceptClass.class);

// Minor bug - was assigning includeRetired instead of evaluating
if (includeRetired == false)
if (!includeRetired)
crit.add(Restrictions.eq("retired", false));

return crit.list();
Expand Down Expand Up @@ -495,7 +495,7 @@ public ConceptDatatype getConceptDatatype(Integer i) {
public List<ConceptDatatype> getAllConceptDatatypes(boolean includeRetired) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(ConceptDatatype.class);

if (includeRetired == false)
if (!includeRetired)
crit.add(Restrictions.eq("retired", false));

return crit.list();
Expand Down Expand Up @@ -791,7 +791,7 @@ public void purgeConceptProposal(ConceptProposal cp) throws DAOException {
public List<ConceptProposal> getAllConceptProposals(boolean includeCompleted) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(ConceptProposal.class);

if (includeCompleted == false) {
if (!includeCompleted) {
crit.add(Restrictions.eq("state", OpenmrsConstants.CONCEPT_PROPOSAL_UNMAPPED));
}
crit.addOrder(Order.asc("originalText"));
Expand Down Expand Up @@ -935,7 +935,7 @@ public ConceptSource getConceptSource(Integer conceptSourceId) {
public List<ConceptSource> getAllConceptSources(boolean includeRetired) throws DAOException {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ConceptSource.class);

if (includeRetired == false)
if (!includeRetired)
criteria.add(Restrictions.eq("retired", false));

return criteria.list();
Expand Down Expand Up @@ -1353,7 +1353,7 @@ private Criteria createConceptWordSearchCriteria(String phrase, List<Locale> loc
Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(ConceptWord.class, "cw1");
searchCriteria.add(Restrictions.in("locale", locales));

if (includeRetired == false) {
if (!includeRetired) {
searchCriteria.createAlias("concept", "concept");
searchCriteria.add(Restrictions.eq("concept.retired", false));
}
Expand Down Expand Up @@ -1408,7 +1408,7 @@ public Long getCountOfDrugs(String drugName, Concept concept, boolean searchOnPh
if (StringUtils.isBlank(drugName) && concept == null)
return 0L;

if (includeRetired == false)
if (!includeRetired)
searchCriteria.add(Restrictions.eq("drug.retired", false));
if (concept != null)
searchCriteria.add(Restrictions.eq("drug.concept", concept));
Expand Down Expand Up @@ -1436,7 +1436,7 @@ public List<Drug> getDrugs(String drugName, Concept concept, boolean searchOnPhr
if (StringUtils.isBlank(drugName) && concept == null)
return Collections.emptyList();

if (includeRetired == false)
if (!includeRetired)
searchCriteria.add(Restrictions.eq("drug.retired", false));
if (concept != null)
searchCriteria.add(Restrictions.eq("drug.concept", concept));
Expand Down
Expand Up @@ -30,7 +30,6 @@
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Conjunction;
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
Expand Down Expand Up @@ -104,7 +103,7 @@ public Encounter getEncounter(Integer encounterId) throws DAOException {
@SuppressWarnings("unchecked")
public List<Encounter> getEncountersByPatientId(Integer patientId) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Encounter.class).createAlias("patient", "p").add(
Expression.eq("p.patientId", patientId)).add(Expression.eq("voided", false)).addOrder(
Restrictions.eq("p.patientId", patientId)).add(Restrictions.eq("voided", false)).addOrder(
Order.desc("encounterDatetime"));

return crit.list();
Expand All @@ -124,36 +123,36 @@ public List<Encounter> getEncounters(Patient patient, Location location, Date fr
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Encounter.class);

if (patient != null && patient.getPatientId() != null) {
crit.add(Expression.eq("patient", patient));
crit.add(Restrictions.eq("patient", patient));
}
if (location != null && location.getLocationId() != null) {
crit.add(Expression.eq("location", location));
crit.add(Restrictions.eq("location", location));
}
if (fromDate != null) {
crit.add(Expression.ge("encounterDatetime", fromDate));
crit.add(Restrictions.ge("encounterDatetime", fromDate));
}
if (toDate != null) {
crit.add(Expression.le("encounterDatetime", toDate));
crit.add(Restrictions.le("encounterDatetime", toDate));
}
if (enteredViaForms != null && enteredViaForms.size() > 0) {
crit.add(Expression.in("form", enteredViaForms));
crit.add(Restrictions.in("form", enteredViaForms));
}
if (encounterTypes != null && encounterTypes.size() > 0) {
crit.add(Expression.in("encounterType", encounterTypes));
crit.add(Restrictions.in("encounterType", encounterTypes));
}
if (providers != null && providers.size() > 0) {
crit.createAlias("encounterProviders", "ep");
crit.add(Expression.in("ep.provider", providers));
crit.add(Restrictions.in("ep.provider", providers));
}
if (visitTypes != null && visitTypes.size() > 0) {
crit.createAlias("visit", "v");
crit.add(Expression.in("v.visitType", visitTypes));
crit.add(Restrictions.in("v.visitType", visitTypes));
}
if (visits != null && visits.size() > 0) {
crit.add(Expression.in("visit", visits));
crit.add(Restrictions.in("visit", visits));
}
if (!includeVoided) {
crit.add(Expression.eq("voided", false));
crit.add(Restrictions.eq("voided", false));
}
crit.addOrder(Order.asc("encounterDatetime"));
return crit.list();
Expand Down Expand Up @@ -186,8 +185,8 @@ public EncounterType getEncounterType(Integer encounterTypeId) throws DAOExcepti
*/
public EncounterType getEncounterType(String name) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(EncounterType.class);
crit.add(Expression.eq("retired", false));
crit.add(Expression.eq("name", name));
crit.add(Restrictions.eq("retired", false));
crit.add(Restrictions.eq("name", name));
EncounterType encounterType = (EncounterType) crit.uniqueResult();

return encounterType;
Expand All @@ -203,8 +202,8 @@ public List<EncounterType> getAllEncounterTypes(Boolean includeRetired) throws D

criteria.addOrder(Order.asc("name"));

if (includeRetired == false)
criteria.add(Expression.eq("retired", false));
if (!includeRetired)
criteria.add(Restrictions.eq("retired", false));

return criteria.list();
}
Expand All @@ -216,7 +215,7 @@ public List<EncounterType> getAllEncounterTypes(Boolean includeRetired) throws D
public List<EncounterType> findEncounterTypes(String name) throws DAOException {
return sessionFactory.getCurrentSession().createCriteria(EncounterType.class)
// 'ilike' case insensitive search
.add(Expression.ilike("name", name, MatchMode.START)).addOrder(Order.asc("name")).addOrder(
.add(Restrictions.ilike("name", name, MatchMode.START)).addOrder(Order.asc("name")).addOrder(
Order.asc("retired")).list();
}

Expand Down Expand Up @@ -421,10 +420,10 @@ private Criteria createEncounterByQueryCriteria(String query, Integer patientId,
@Override
@SuppressWarnings("unchecked")
public List<Encounter> getEncountersByVisit(Visit visit, boolean includeVoided) {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Encounter.class)
.add(Expression.eq("visit", visit));
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Encounter.class).add(
Restrictions.eq("visit", visit));
if (!includeVoided) {
crit.add(Expression.eq("voided", false));
crit.add(Restrictions.eq("voided", false));
}
crit.addOrder(Order.asc("encounterDatetime"));

Expand Down
Expand Up @@ -24,7 +24,6 @@
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
Expand Down Expand Up @@ -104,8 +103,8 @@ public Form getForm(Integer formId) throws DAOException {
*/
@SuppressWarnings("unchecked")
public List<FormField> getFormFields(Form form) throws DAOException {
return sessionFactory.getCurrentSession().createCriteria(FormField.class, "ff").add(Expression.eq("ff.form", form))
.list();
return sessionFactory.getCurrentSession().createCriteria(FormField.class, "ff")
.add(Restrictions.eq("ff.form", form)).list();
}

/**
Expand All @@ -125,7 +124,7 @@ public List<Field> getFields(String search) throws DAOException {
@SuppressWarnings("unchecked")
public List<Field> getFieldsByConcept(Concept concept) throws DAOException {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Field.class);
criteria.add(Expression.eq("concept", concept));
criteria.add(Restrictions.eq("concept", concept));
criteria.addOrder(Order.asc("name"));
return criteria.list();
}
Expand All @@ -146,8 +145,8 @@ public Field getField(Integer fieldId) throws DAOException {
public List<Field> getAllFields(boolean includeRetired) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Field.class);

if (includeRetired == false)
crit.add(Expression.eq("retired", false));
if (!includeRetired)
crit.add(Restrictions.eq("retired", false));

return crit.list();
}
Expand All @@ -168,8 +167,8 @@ public FieldType getFieldType(Integer fieldTypeId) throws DAOException {
public List<FieldType> getAllFieldTypes(boolean includeRetired) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(FieldType.class);

if (includeRetired == false)
crit.add(Expression.eq("retired", false));
if (!includeRetired)
crit.add(Restrictions.eq("retired", false));

return crit.list();
}
Expand All @@ -196,7 +195,7 @@ public FormField getFormField(Form form, Concept concept, Collection<FormField>
return null;
}
Criteria crit = sessionFactory.getCurrentSession().createCriteria(FormField.class, "ff").createAlias("field",
"field").add(Expression.eq("field.concept", concept)).add(Expression.eq("form", form));
"field").add(Restrictions.eq("field.concept", concept)).add(Restrictions.eq("form", form));

// get the list of all formfields with this concept for this form
List<FormField> formFields = crit.list();
Expand Down Expand Up @@ -236,8 +235,8 @@ public FormField getFormField(Form form, Concept concept, Collection<FormField>
public List<Form> getAllForms(boolean includeRetired) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Form.class);

if (includeRetired == false)
crit.add(Expression.eq("retired", false));
if (!includeRetired)
crit.add(Restrictions.eq("retired", false));

crit.addOrder(Order.asc("name"));
crit.addOrder(Order.asc("formId"));
Expand Down Expand Up @@ -313,22 +312,22 @@ public List<Field> getFields(Collection<Form> forms, Collection<FieldType> field
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Field.class);

if (!forms.isEmpty())
crit.add(Expression.in("form", forms));
crit.add(Restrictions.in("form", forms));

if (!fieldTypes.isEmpty())
crit.add(Expression.in("fieldType", fieldTypes));
crit.add(Restrictions.in("fieldType", fieldTypes));

if (!concepts.isEmpty())
crit.add(Expression.in("concept", concepts));
crit.add(Restrictions.in("concept", concepts));

if (!tableNames.isEmpty())
crit.add(Expression.in("tableName", tableNames));
crit.add(Restrictions.in("tableName", tableNames));

if (!attributeNames.isEmpty())
crit.add(Expression.in("attributeName", attributeNames));
crit.add(Restrictions.in("attributeName", attributeNames));

if (selectMultiple != null)
crit.add(Expression.eq("selectMultiple", selectMultiple));
crit.add(Restrictions.eq("selectMultiple", selectMultiple));

if (!containsAllAnswers.isEmpty())
throw new APIException("containsAllAnswers must be empty because this is not yet implemented");
Expand All @@ -337,7 +336,7 @@ public List<Field> getFields(Collection<Form> forms, Collection<FieldType> field
throw new APIException("containsAnyAnswer must be empty because this is not yet implemented");

if (retired != null)
crit.add(Expression.eq("retired", retired));
crit.add(Restrictions.eq("retired", retired));

return crit.list();
}
Expand All @@ -348,8 +347,8 @@ public List<Field> getFields(Collection<Form> forms, Collection<FieldType> field
public Form getForm(String name, String version) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Form.class);

crit.add(Expression.eq("name", name));
crit.add(Expression.eq("version", version));
crit.add(Restrictions.eq("name", name));
crit.add(Restrictions.eq("version", version));

return (Form) crit.uniqueResult();
}
Expand Down Expand Up @@ -493,8 +492,8 @@ public FormField getFormFieldByUuid(String uuid) {
public List<Form> getFormsByName(String name) throws DAOException {
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Form.class);

crit.add(Expression.eq("name", name));
crit.add(Expression.eq("retired", false));
crit.add(Restrictions.eq("name", name));
crit.add(Restrictions.eq("retired", false));
crit.addOrder(Order.desc("version"));

return crit.list();
Expand Down

0 comments on commit eb4edec

Please sign in to comment.