=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2011-02-14 04:01:17 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2011-04-02 09:48:38 +0000 @@ -127,7 +127,6 @@ @SuppressWarnings( "unchecked" ) public Collection searchDataElementByName( String key ) { - Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria( DataElement.class ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2010-12-30 09:13:41 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2011-04-02 09:48:38 +0000 @@ -351,8 +351,8 @@ } @SuppressWarnings( "unchecked" ) - public Collection searchUsersByName( String key ){ - + public Collection searchUsersByName( String key ) + { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria( UserCredentials.class ); @@ -432,7 +432,6 @@ return userRoleStore.getBetweenByName( name, first, max ); } - // =================== public Collection getUsersByOrganisationUnitBetween( OrganisationUnit orgUnit, int first, int max ) { return getBlockUser( toUserCredentials( getUsersByOrganisationUnit( orgUnit ) ), first, max ); @@ -454,10 +453,6 @@ return findByName( toUserCredentials( getUsersByOrganisationUnit( orgUnit ) ), name ).size(); } - // ------------------------------------------------------------------------- - // - // ------------------------------------------------------------------------- - public Collection getUsersWithoutOrganisationUnitBetween( int first, int max ) { return getBlockUser( toUserCredentials( getUsersWithoutOrganisationUnit()), first, max ); @@ -465,7 +460,6 @@ public Collection getUsersWithoutOrganisationUnitBetweenByName( String name, int first, int max ) { - return getBlockUser( findByName( toUserCredentials( getUsersWithoutOrganisationUnit() ), name ), first, max ); } === modified file 'dhis-2/dhis-services/dhis-service-options/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-options/src/main/resources/META-INF/dhis/beans.xml 2011-03-31 12:37:13 +0000 +++ dhis-2/dhis-services/dhis-service-options/src/main/resources/META-INF/dhis/beans.xml 2011-04-02 09:48:38 +0000 @@ -26,6 +26,7 @@ class="org.hisp.dhis.hibernate.HibernateGenericStore"> + implements GenericIdentifiableObjectStore { - //TODO cacheable - protected SessionFactory sessionFactory; public void setSessionFactory( SessionFactory sessionFactory ) @@ -74,6 +72,24 @@ this.clazz = clazz; } + private boolean cacheable = false; + + /** + * Could be overridden programmatically. + */ + protected boolean isCacheable() + { + return cacheable; + } + + /** + * Could be injected through container. + */ + public void setCacheable( boolean cacheable ) + { + this.cacheable = cacheable; + } + // ------------------------------------------------------------------------- // Convenience methods // ------------------------------------------------------------------------- @@ -86,7 +102,9 @@ */ protected final Query getQuery( String hql ) { - return sessionFactory.getCurrentSession().createQuery( hql ); + Query query = sessionFactory.getCurrentSession().createQuery( hql ); + query.setCacheable( cacheable ); + return query; } /** @@ -97,7 +115,9 @@ */ protected final SQLQuery getSqlQuery( String sql ) { - return sessionFactory.getCurrentSession().createSQLQuery( sql ); + SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery( sql ); + query.setCacheable( cacheable ); + return query; } /** @@ -107,7 +127,9 @@ */ protected final Criteria getCriteria() { - return sessionFactory.getCurrentSession().createCriteria( getClazz() ); + Criteria criteria = sessionFactory.getCurrentSession().createCriteria( getClazz() ); + criteria.setCacheable( cacheable ); + return criteria; } /** @@ -119,7 +141,7 @@ */ protected final Criteria getCriteria( Criterion... expressions ) { - Criteria criteria = sessionFactory.getCurrentSession().createCriteria( getClazz() ); + Criteria criteria = getCriteria(); for ( Criterion expression : expressions ) {