/** * Return the Hibernate SessionFactory used by this DAO. */ public final SessionFactory getSessionFactory() { return (this.hibernateTemplate != null ? this.hibernateTemplate.getSessionFactory() : null); }
@Override public void afterPropertiesSet() { if (getSessionFactory() == null) { throw new IllegalArgumentException("Property 'sessionFactory' is required"); } }
/** * Set the Hibernate SessionFactory to be used by this DAO. * Will automatically create a HibernateTemplate for the given SessionFactory. * @see #createHibernateTemplate * @see #setHibernateTemplate */ public final void setSessionFactory(SessionFactory sessionFactory) { if (this.hibernateTemplate == null || sessionFactory != this.hibernateTemplate.getSessionFactory()) { this.hibernateTemplate = createHibernateTemplate(sessionFactory); } }
@Override public Filter enableFilter(String filterName) throws IllegalStateException { Session session = getSessionFactory().getCurrentSession(); Filter filter = session.getEnabledFilter(filterName); if (filter == null) { filter = session.enableFilter(filterName); } return filter; }
public void clearPermissionsForUser(final String gradebookUid, final String userId) { Long gradebookId = getGradebook(gradebookUid).getId(); // remove all current permissions for user final List<Permission> currentPermissions = getPermissionsForUser(gradebookId, userId); for (Permission currentPermission : currentPermissions) { getHibernateTemplate().getSessionFactory().getCurrentSession().delete(currentPermission); } }
boolean isNew = false; try { session = getSessionFactory().getCurrentSession(); session = getSessionFactory().openSession(); session.setFlushMode(FlushMode.MANUAL); isNew = true;
java.util.Date currentTime = new java.util.Date(); Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
java.util.Date currentTime = new java.util.Date(); Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
/** * Prepare the given Criteria object, applying cache settings and/or * a transaction timeout. * @param criteria the Criteria object to prepare * @see #setCacheQueries * @see #setQueryCacheRegion */ protected void prepareCriteria(Criteria criteria) { if (isCacheQueries()) { criteria.setCacheable(true); if (getQueryCacheRegion() != null) { criteria.setCacheRegion(getQueryCacheRegion()); } } if (getFetchSize() > 0) { criteria.setFetchSize(getFetchSize()); } if (getMaxResults() > 0) { criteria.setMaxResults(getMaxResults()); } SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory()); if (sessionHolder != null && sessionHolder.hasTimeout()) { criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds()); } }
/** * Prepare the given Query object, applying cache settings and/or * a transaction timeout. * @param queryObject the Query object to prepare * @see #setCacheQueries * @see #setQueryCacheRegion */ protected void prepareQuery(Query queryObject) { if (isCacheQueries()) { queryObject.setCacheable(true); if (getQueryCacheRegion() != null) { queryObject.setCacheRegion(getQueryCacheRegion()); } } if (getFetchSize() > 0) { queryObject.setFetchSize(getFetchSize()); } if (getMaxResults() > 0) { queryObject.setMaxResults(getMaxResults()); } SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory()); if (sessionHolder != null && sessionHolder.hasTimeout()) { queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds()); } }