while (!isValid) { Session session = em.unwrap(Session.class); FlushMode current = session.getFlushMode(); try { if (!autoFlushSaveCart) { TransactionDefinition.PROPAGATION_REQUIRED, transactionManager); Session session = em.unwrap(Session.class); FlushMode current = session.getFlushMode(); try { if (!autoFlushSaveCart) { throw ex; } finally { if (!autoFlushSaveCart && !session.getFlushMode().equals(current)) { session.setFlushMode(current);
CartOperationRequest childCartOpRequest = new CartOperationRequest(context.getSeedData().getOrder(), childRequest, currentAddition == numAdditionRequests); Session session = em.unwrap(Session.class); FlushMode current = session.getFlushMode(); if (!autoFlushAddToCart) {
protected Order removeItemInternal(Long orderId, Long orderItemId, boolean priceOrder) throws WorkflowException { OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO(); orderItemRequestDTO.setOrderItemId(orderItemId); CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, priceOrder); Session session = em.unwrap(Session.class); FlushMode current = session.getFlushMode(); if (!autoFlushRemoveFromCart) { //Performance measure. Hibernate will sometimes perform an autoflush when performing query operations and this can //be expensive. It is possible to avoid the autoflush if there's no concern about queries in the flow returning //incorrect results because something has not been flushed to the database yet. session.setFlushMode(FlushMode.MANUAL); } ProcessContext<CartOperationRequest> context; try { context = (ProcessContext<CartOperationRequest>) removeItemWorkflow.doActivities(cartOpRequest); } finally { if (!autoFlushRemoveFromCart) { session.setFlushMode(current); } } context.getSeedData().getOrder().getOrderMessages().addAll(((ActivityMessages) context).getActivityMessages()); return context.getSeedData().getOrder(); }
CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, priceOrder); Session session = em.unwrap(Session.class); FlushMode current = session.getFlushMode(); if (!autoFlushUpdateCart) {
/** * Get the current flush mode for this session. * * @return The flush mode */ public FlushMode getFlushMode() { return getSession().getFlushMode(); }
FlushMode originalFlushMode = session.getFlushMode(); try { session.setFlushMode(FlushMode.MANUAL);
FlushMode current = session.getFlushMode(); if (!autoFlushAddToCart) {
@Override public List<PatientProgram> getPatientProgramByAttributeNameAndValue(String attributeName, String attributeValue) { FlushMode flushMode = sessionFactory.getCurrentSession().getFlushMode(); sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL); Query query; try { query = sessionFactory.getCurrentSession().createQuery( "SELECT pp FROM patient_program pp " + "INNER JOIN pp.attributes attr " + "INNER JOIN attr.attributeType attr_type " + "WHERE attr.valueReference = :attributeValue " + "AND attr_type.name = :attributeName " + "AND pp.voided = 0") .setParameter("attributeName", attributeName) .setParameter("attributeValue", attributeValue); return query.list(); } finally { sessionFactory.getCurrentSession().setFlushMode(flushMode); } }
/** * @see org.openmrs.api.db.ContextDAO#getUserByUuid(java.lang.String) */ @Override @Transactional(readOnly = true) public User getUserByUuid(String uuid) { // don't flush here in case we're in the AuditableInterceptor. Will cause a StackOverflowEx otherwise FlushMode flushMode = sessionFactory.getCurrentSession().getFlushMode(); sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL); User u = (User) sessionFactory.getCurrentSession().createQuery("from User u where u.uuid = :uuid").setString("uuid", uuid).uniqueResult(); // reset the flush mode to whatever it was before sessionFactory.getCurrentSession().setFlushMode(flushMode); return u; }
/** * @see org.openmrs.api.db.ConceptDAO#getDefaultConceptMapType() */ @Override public ConceptMapType getDefaultConceptMapType() throws DAOException { FlushMode previousFlushMode = sessionFactory.getCurrentSession().getFlushMode(); sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL); try { //Defaults to same-as if the gp is not set. String defaultConceptMapType = Context.getAdministrationService().getGlobalProperty( OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE); if (defaultConceptMapType == null) { throw new DAOException("The default concept map type is not set. You need to set the '" + OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE + "' global property."); } ConceptMapType conceptMapType = getConceptMapTypeByName(defaultConceptMapType); if (conceptMapType == null) { throw new DAOException("The default concept map type (name: " + defaultConceptMapType + ") does not exist! You need to set the '" + OpenmrsConstants.GP_DEFAULT_CONCEPT_MAP_TYPE + "' global property."); } return conceptMapType; } finally { sessionFactory.getCurrentSession().setFlushMode(previousFlushMode); } }
/** * @see org.openmrs.api.db.EncounterDAO#getSavedEncounterDatetime(org.openmrs.Encounter) */ @Override public Date getSavedEncounterDatetime(Encounter encounter) { //Usages of this method currently are internal and don't require a flush //Otherwise we end up with premature flushes of Immutable types like Obs //that are associated to the encounter before we void and replace them Session session = sessionFactory.getCurrentSession(); FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.MANUAL); try { SQLQuery sql = session .createSQLQuery("select encounter_datetime from encounter where encounter_id = :encounterId"); sql.setInteger("encounterId", encounter.getEncounterId()); return (Date) sql.uniqueResult(); } finally { session.setFlushMode(flushMode); } }
/** * @see org.openmrs.api.db.ObsDAO#getSavedStatus(org.openmrs.Obs) */ @Override public Obs.Status getSavedStatus(Obs obs) { // avoid premature flushes when this internal method is called from inside a service method Session session = sessionFactory.getCurrentSession(); FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.MANUAL); try { SQLQuery sql = session.createSQLQuery("select status from obs where obs_id = :obsId"); sql.setInteger("obsId", obs.getObsId()); return Obs.Status.valueOf((String) sql.uniqueResult()); } finally { session.setFlushMode(flushMode); } }
/** * @see org.openmrs.api.db.EncounterDAO#getSavedEncounterLocation(org.openmrs.Encounter) */ @Override public Location getSavedEncounterLocation(Encounter encounter) { Session session = sessionFactory.getCurrentSession(); FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.MANUAL); try { SQLQuery sql = session.createSQLQuery("select location_id from encounter where encounter_id = :encounterId"); sql.setInteger("encounterId", encounter.getEncounterId()); return Context.getLocationService().getLocation((Integer) sql.uniqueResult()); } finally { session.setFlushMode(flushMode); } }
FlushMode previousFlushMode = sessionFactory.getCurrentSession().getFlushMode(); sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL); try {
public Void doInHibernate(Session session) { if (!FlushMode.isManualFlushMode(session.getFlushMode())) { session.flush(); } return null; } });
protected void txFragment(Session session) throws Exception { FlushMode flushMode = session.getFlushMode(); session.setFlushMode(FlushMode.COMMIT); Query query = session.createQuery("from " + DataProviderImpl.class.getName() + " order by id"); query.setCacheable(true); results.addAll(query.list()); session.setFlushMode(flushMode); }}.execute(); return results;
@Override protected void closeSession(Session session, SessionFactory sessionFactory) { if (!FlushMode.isManualFlushMode(session.getFlushMode())) { session.flush(); } super.closeSession(session, sessionFactory); } }
/** {@inheritDoc} * */ public FlushMode getFlushMode() { try { return getDelegate().getFlushMode(); } catch (HibernateException ex) { throw handleException(ex); } }
/** {@inheritDoc} * */ public FlushMode getFlushMode() { try { return getDelegate().getFlushMode(); } catch (HibernateException ex) { throw handleException(ex); } }
private <T> T doWithManualSession(AbstractEvent event, Closure<T> callable) { Session session = event.getSession(); FlushMode current = session.getFlushMode(); try { session.setFlushMode(FlushMode.MANUAL); return callable.call(); } finally { session.setFlushMode(current); } }