|
16 | 16 | import java.util.Date;
|
17 | 17 | import java.util.List;
|
18 | 18 |
|
19 |
| -import org.apache.commons.lang.StringUtils; |
20 | 19 | import org.apache.commons.logging.Log;
|
21 | 20 | import org.apache.commons.logging.LogFactory;
|
22 | 21 | import org.hibernate.Criteria;
|
23 |
| -import org.hibernate.LockMode; |
| 22 | +import org.hibernate.Query; |
24 | 23 | import org.hibernate.SessionFactory;
|
25 | 24 | import org.hibernate.criterion.Criterion;
|
26 | 25 | import org.hibernate.criterion.Disjunction;
|
27 | 26 | import org.hibernate.criterion.Restrictions;
|
28 | 27 | import org.openmrs.CareSetting;
|
29 | 28 | import org.openmrs.Concept;
|
30 | 29 | import org.openmrs.Encounter;
|
31 |
| -import org.openmrs.GlobalProperty; |
32 | 30 | import org.openmrs.Order;
|
33 | 31 | import org.openmrs.Order.Action;
|
34 | 32 | import org.openmrs.OrderFrequency;
|
@@ -162,34 +160,28 @@ public Order getOrderByOrderNumber(String orderNumber) {
|
162 | 160 | */
|
163 | 161 | @Override
|
164 | 162 | public Long getNextOrderNumberSeedSequenceValue() {
|
165 |
| - Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(GlobalProperty.class); |
166 |
| - searchCriteria.add(Restrictions.eq("property", OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER_SEED)); |
167 |
| - searchCriteria.setLockMode(LockMode.PESSIMISTIC_WRITE); |
| 163 | + Query query = sessionFactory.getCurrentSession().createSQLQuery( |
| 164 | + "select property_value from global_property where property = '" |
| 165 | + + OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER_SEED + "' for update"); |
168 | 166 |
|
169 |
| - GlobalProperty globalProperty = (GlobalProperty) searchCriteria.uniqueResult(); |
170 |
| - if (globalProperty == null) { |
| 167 | + List results = query.list(); |
| 168 | + if (results.size() == 0) { |
171 | 169 | throw new APIException("Missing global property named: "
|
172 | 170 | + OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER_SEED);
|
173 | 171 | }
|
174 | 172 |
|
175 |
| - String gpTextValue = globalProperty.getPropertyValue(); |
176 |
| - if (StringUtils.isBlank(gpTextValue)) { |
177 |
| - throw new APIException("Invalid value for global property named: " |
178 |
| - + OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER_SEED); |
179 |
| - } |
180 |
| - |
181 | 173 | Long gpNumericValue = null;
|
182 | 174 | try {
|
183 |
| - gpNumericValue = Long.parseLong(gpTextValue); |
| 175 | + gpNumericValue = Long.parseLong(results.get(0).toString()); |
184 | 176 | }
|
185 | 177 | catch (NumberFormatException ex) {
|
186 | 178 | throw new APIException("Invalid value for global property named: "
|
187 | 179 | + OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER_SEED);
|
188 | 180 | }
|
189 | 181 |
|
190 |
| - globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1)); |
191 |
| - |
192 |
| - sessionFactory.getCurrentSession().save(globalProperty); |
| 182 | + sessionFactory.getCurrentSession().createSQLQuery( |
| 183 | + "update global_property set property_value = '" + String.valueOf(gpNumericValue + 1) + "' where property = '" |
| 184 | + + OpenmrsConstants.GLOBAL_PROPERTY_NEXT_ORDER_NUMBER_SEED + "'").executeUpdate(); |
193 | 185 |
|
194 | 186 | return gpNumericValue;
|
195 | 187 | }
|
|
0 commit comments