List of usage examples for org.hibernate FlushMode ALWAYS
FlushMode ALWAYS
To view the source code for org.hibernate FlushMode ALWAYS.
Click Source Link
From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java
private Integer complianceTeamCount(Integer roadOperationId, Integer teamId) { /* Get Count of Summons For Road Operation */ Criteria criteriaCompliance = this.hibernateTemplate.getSessionFactory().getCurrentSession() .createCriteria(ComplianceDO.class, "c"); criteriaCompliance.add(Restrictions.eq("c.roadOperation.roadOperationId", roadOperationId)); if (this.getStaffIdForTeam(teamId) != null) { criteriaCompliance.add(Restrictions.in("c.taStaff.staffId", this.getStaffIdForTeam(teamId))); criteriaCompliance.setProjection(Projections.rowCount()); criteriaCompliance.setFetchMode("c", FetchMode.LAZY); criteriaCompliance.setFlushMode(FlushMode.ALWAYS); Iterator iterator = criteriaCompliance.list().iterator(); Integer complainceCount = (Integer) iterator.next(); return complainceCount; } else// w w w. j a v a 2 s .c om return 0; }
From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java
private Integer complianceCount(Integer roadOperationId, Integer personId, String personType) { /* Get Count of Summons For Road Operation */ Criteria criteriaCompliance = this.hibernateTemplate.getSessionFactory().getCurrentSession() .createCriteria(ComplianceDO.class, "c"); criteriaCompliance.add(Restrictions.eq("c.roadOperation.roadOperationId", roadOperationId)); if (personType.equalsIgnoreCase(Constants.PersonType.TA_STAFF)) { criteriaCompliance.createAlias("c.taStaff", "ta"); criteriaCompliance.createAlias("ta.person", "p"); } else {/*from ww w .j av a 2 s . co m*/ return -1; } criteriaCompliance.add(Restrictions.eq("p.personId", personId)); criteriaCompliance.setProjection(Projections.rowCount()); criteriaCompliance.setFetchMode("c", FetchMode.LAZY); criteriaCompliance.setFlushMode(FlushMode.ALWAYS); Iterator iterator = criteriaCompliance.list().iterator(); Integer complainceCount = (Integer) iterator.next(); return complainceCount; }
From source file:fsl.ta.toms.roms.dao.impl.ReportDAOImpl.java
/*************************** * UR-057 /* w ww. j a v a 2 s. c om*/ *********************/ private Integer absentPersonTypeCount(Integer roadOperationId, String personType) { /* Get Count of Absent Persons */ Criteria criteriaAssignedPersons = this.hibernateTemplate.getSessionFactory().getCurrentSession() .createCriteria(AssignedPersonDO.class, "a"); List<Integer> teamIds = getTeamIdsForRoadOp(roadOperationId); if (teamIds != null && teamIds.size() > 0) { criteriaAssignedPersons.add(Restrictions.in("a.assignedPersonKey.team.teamId", teamIds)); criteriaAssignedPersons.add(Restrictions.eq("a.assignedPersonKey.personType.personTypeId", personType)); } criteriaAssignedPersons.add(Restrictions.eq("a.attended", "n").ignoreCase()); criteriaAssignedPersons.setProjection(Projections.count("a.attended")); criteriaAssignedPersons.setFetchMode("a", FetchMode.LAZY); Iterator iterator = criteriaAssignedPersons.list().iterator(); Integer AbsentPersonTypeCount = (Integer) iterator.next(); criteriaAssignedPersons.setFlushMode(FlushMode.ALWAYS); return AbsentPersonTypeCount; }
From source file:ma.massarpro.beans.MassarProPersistentManager.java
private MassarProPersistentManager() throws PersistentException { super(_connectionSetting, _sessionType, _timeToAlive, new String[] {}, _extraProperties); setFlushMode(FlushMode.ALWAYS); }
From source file:org.agnitas.web.filter.OpenSessionInViewFilter.java
License:Open Source License
protected org.hibernate.Session getSession(org.hibernate.SessionFactory sessionFactory) throws org.springframework.dao.DataAccessResourceFailureException { Session aSession = org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(sessionFactory, true); aSession.setFlushMode(FlushMode.ALWAYS); return aSession; }
From source file:org.apache.ignite.cache.store.hibernate.CacheHibernateBlobStoreSelfTest.java
License:Apache License
/** {@inheritDoc} */ @Override/*from www. j a va2 s . c o m*/ protected void afterTest() throws Exception { super.afterTest(); Session s = store.session(null); if (s == null) return; try { s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName()) .setFlushMode(FlushMode.ALWAYS).executeUpdate(); Transaction hTx = s.getTransaction(); if (hTx != null && hTx.isActive()) hTx.commit(); } finally { s.close(); } }
From source file:org.apache.ignite.examples.datagrid.store.hibernate.CacheHibernatePersonStore.java
License:Apache License
/** {@inheritDoc} */ @SuppressWarnings({ "JpaQueryApiInspection" }) @Override//from ww w .ja va 2 s .c om public void delete(Object key) { Transaction tx = transaction(); System.out.println(">>> Store remove [key=" + key + ", xid=" + (tx == null ? null : tx.xid()) + ']'); Session ses = session(tx); try { ses.createQuery("delete " + Person.class.getSimpleName() + " where key = :key").setParameter("key", key) .setFlushMode(FlushMode.ALWAYS).executeUpdate(); } catch (HibernateException e) { rollback(ses, tx); throw new CacheWriterException("Failed to remove value from cache store with key: " + key, e); } finally { end(ses, tx); } }
From source file:org.codehaus.grepo.query.hibernate.repository.DefaultHibernateRepository.java
License:Apache License
/** * Apply the flush mode that's been specified. * * @param sessionHolder The current session holder. * @param queryOptions the query options. *///from w w w . j a va 2 s. co m protected void applyFlushMode(CurrentSessionHolder sessionHolder, HibernateQueryOptions queryOptions) { HibernateFlushMode flushModeToUse = getFlushMode(queryOptions); if (flushModeToUse != null) { FlushMode flushModeToSet = null; FlushMode previousFlushMode = null; if (flushModeToUse == HibernateFlushMode.MANUAL) { if (sessionHolder.isExistingTransaction()) { previousFlushMode = sessionHolder.getSession().getFlushMode(); if (!previousFlushMode.lessThan(FlushMode.COMMIT)) { flushModeToSet = FlushMode.MANUAL; } } else { flushModeToSet = FlushMode.MANUAL; } } else if (flushModeToUse == HibernateFlushMode.EAGER) { if (sessionHolder.isExistingTransaction()) { previousFlushMode = sessionHolder.getSession().getFlushMode(); if (!previousFlushMode.equals(FlushMode.AUTO)) { flushModeToSet = FlushMode.AUTO; } } // else rely on default FlushMode.AUTO } else if (flushModeToUse == HibernateFlushMode.COMMIT) { if (sessionHolder.isExistingTransaction()) { previousFlushMode = sessionHolder.getSession().getFlushMode(); if (previousFlushMode.equals(FlushMode.AUTO) || previousFlushMode.equals(FlushMode.ALWAYS)) { flushModeToSet = FlushMode.COMMIT; } } else { flushModeToSet = FlushMode.COMMIT; } } else if (flushModeToUse == HibernateFlushMode.ALWAYS) { if (sessionHolder.isExistingTransaction()) { previousFlushMode = sessionHolder.getSession().getFlushMode(); if (!previousFlushMode.equals(FlushMode.ALWAYS)) { flushModeToSet = FlushMode.ALWAYS; } } else { flushModeToSet = FlushMode.ALWAYS; } } if (flushModeToSet != null) { logger.debug("Setting flushMode to '{}' for generic repository execution", flushModeToSet); sessionHolder.getSession().setFlushMode(flushModeToSet); } if (previousFlushMode != null) { sessionHolder.setPreviousFlushMode(previousFlushMode); } } }
From source file:org.esupportail.commons.services.database.hibernate.HibernateThreadConnectionData.java
License:Apache License
/** * Open the session.//from ww w . ja v a 2 s . c o m */ void openSession() { sessionFactory = (SessionFactory) BeanUtils.getBean(sessionFactoryBeanName); if (TransactionSynchronizationManager.hasResource(sessionFactory)) { if (logger.isDebugEnabled()) { logger.debug("OPEN(" + sessionFactoryBeanName + ") ***** participate!"); } participate = true; return; } if (logger.isDebugEnabled()) { logger.debug("OPEN(" + sessionFactoryBeanName + ")"); } session = SessionFactoryUtils.getSession(sessionFactory, true); session.setFlushMode(FlushMode.ALWAYS); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); }
From source file:org.grails.orm.hibernate.GrailsHibernateTemplate.java
License:Apache License
/** * Apply the flush mode that's been specified for this accessor to the given Session. * * @param session the current Hibernate Session * @param existingTransaction if executing within an existing transaction * @return the previous flush mode to restore after the operation, or <code>null</code> if none * @see #setFlushMode// www. ja va 2 s.c om * @see org.hibernate.Session#setFlushMode */ protected FlushMode applyFlushMode(Session session, boolean existingTransaction) { if (isApplyFlushModeOnlyToNonExistingTransactions() && existingTransaction) { return null; } if (getFlushMode() == FLUSH_NEVER) { if (existingTransaction) { FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session); if (!previousFlushMode.lessThan(FlushMode.COMMIT)) { session.setFlushMode(FlushMode.MANUAL); return previousFlushMode; } } else { session.setFlushMode(FlushMode.MANUAL); } } else if (getFlushMode() == FLUSH_EAGER) { if (existingTransaction) { FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session); if (!previousFlushMode.equals(FlushMode.AUTO)) { session.setFlushMode(FlushMode.AUTO); return previousFlushMode; } } else { // rely on default FlushMode.AUTO } } else if (getFlushMode() == FLUSH_COMMIT) { if (existingTransaction) { FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session); if (previousFlushMode.equals(FlushMode.AUTO) || previousFlushMode.equals(FlushMode.ALWAYS)) { session.setFlushMode(FlushMode.COMMIT); return previousFlushMode; } } else { session.setFlushMode(FlushMode.COMMIT); } } else if (getFlushMode() == FLUSH_ALWAYS) { if (existingTransaction) { FlushMode previousFlushMode = HibernateVersionSupport.getFlushMode(session); if (!previousFlushMode.equals(FlushMode.ALWAYS)) { session.setFlushMode(FlushMode.ALWAYS); return previousFlushMode; } } else { session.setFlushMode(FlushMode.ALWAYS); } } return null; }