dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37275
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19080: DataEntryForm, introduced caching. Using GenericStore to remve boilerplate code.
------------------------------------------------------------
revno: 19080
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-05-03 16:12:07 +0200
message:
DataEntryForm, introduced caching. Using GenericStore to remve boilerplate code.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataentryform/hibernate/DataEntryForm.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormStore.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormStore.java 2015-05-03 14:12:07 +0000
@@ -31,7 +31,10 @@
import java.util.Collection;
import java.util.List;
+import org.hisp.dhis.common.GenericStore;
+
public interface DataEntryFormStore
+ extends GenericStore<DataEntryForm>
{
String ID = DataEntryFormStore.class.getName();
@@ -40,49 +43,12 @@
// -------------------------------------------------------------------------
/**
- * Adds a DataEntryForm.
- *
- * @param dataEntryForm The DataEntryForm to add.
- * @return The generated unique identifier for this DataEntryForm.
- */
- int addDataEntryForm( DataEntryForm dataEntryForm );
-
- /**
- * Updates a DataEntryForm.
- *
- * @param dataEntryForm The DataEntryForm to update.
- */
- void updateDataEntryForm( DataEntryForm dataEntryForm );
-
- /**
- * Deletes a DataEntryForm.
- *
- * @param dataEntryForm The DataEntryForm to delete.
- */
- void deleteDataEntryForm( DataEntryForm dataEntryForm );
-
- /**
- * Get a DataEntryForm
- *
- * @param id The unique identifier for the DataEntryForm to get.
- * @return The DataEntryForm with the given id or null if it does not exist.
- */
- DataEntryForm getDataEntryForm( int id );
-
- /**
* Returns a DataEntryForm with the given name.
*
* @param name The name.
* @return A DataEntryForm with the given name.
*/
DataEntryForm getDataEntryFormByName( String name );
-
- /**
- * Get all DataEntryForms.
- *
- * @return A collection containing all DataEntryForms.
- */
- Collection<DataEntryForm> getAllDataEntryForms();
Collection<DataEntryForm> listDistinctDataEntryFormByProgramStageIds( List<Integer> programStageIds );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2015-03-29 20:32:18 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2015-05-03 14:12:07 +0000
@@ -112,25 +112,30 @@
@Override
public int addDataEntryForm( DataEntryForm dataEntryForm )
{
- return dataEntryFormStore.addDataEntryForm( dataEntryForm );
+ if ( dataEntryForm != null )
+ {
+ dataEntryForm.setFormat( DataEntryForm.CURRENT_FORMAT );
+ }
+
+ return dataEntryFormStore.save( dataEntryForm );
}
@Override
public void updateDataEntryForm( DataEntryForm dataEntryForm )
{
- dataEntryFormStore.updateDataEntryForm( dataEntryForm );
+ dataEntryFormStore.update( dataEntryForm );
}
@Override
public void deleteDataEntryForm( DataEntryForm dataEntryForm )
{
- dataEntryFormStore.deleteDataEntryForm( dataEntryForm );
+ dataEntryFormStore.delete( dataEntryForm );
}
@Override
public DataEntryForm getDataEntryForm( int id )
{
- return dataEntryFormStore.getDataEntryForm( id );
+ return dataEntryFormStore.get( id );
}
@Override
@@ -142,7 +147,7 @@
@Override
public Collection<DataEntryForm> getAllDataEntryForms()
{
- return dataEntryFormStore.getAllDataEntryForms();
+ return dataEntryFormStore.getAll();
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/hibernate/HibernateDataEntryFormStore.java 2015-05-03 14:12:07 +0000
@@ -33,12 +33,12 @@
import org.hibernate.Criteria;
import org.hibernate.Session;
-import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormStore;
import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.hibernate.HibernateGenericStore;
import org.hisp.dhis.program.ProgramStage;
/**
@@ -46,59 +46,12 @@
* @version $Id$
*/
public class HibernateDataEntryFormStore
+ extends HibernateGenericStore<DataEntryForm>
implements DataEntryFormStore
{
- // ------------------------------------------------------------------------
- // Dependencies
- // ------------------------------------------------------------------------
-
- private SessionFactory sessionFactory;
-
- public void setSessionFactory( SessionFactory sessionFactory )
- {
- this.sessionFactory = sessionFactory;
- }
-
- // ------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
// DataEntryFormStore implementation
- // ------------------------------------------------------------------------
-
- @Override
- public int addDataEntryForm( DataEntryForm dataEntryForm )
- {
- if ( dataEntryForm != null )
- {
- dataEntryForm.setFormat( DataEntryForm.CURRENT_FORMAT );
- }
-
- Session session = sessionFactory.getCurrentSession();
-
- return (Integer) session.save( dataEntryForm );
- }
-
- @Override
- public void updateDataEntryForm( DataEntryForm dataEntryForm )
- {
- Session session = sessionFactory.getCurrentSession();
-
- session.update( dataEntryForm );
- }
-
- @Override
- public void deleteDataEntryForm( DataEntryForm dataEntryForm )
- {
- Session session = sessionFactory.getCurrentSession();
-
- session.delete( dataEntryForm );
- }
-
- @Override
- public DataEntryForm getDataEntryForm( int id )
- {
- Session session = sessionFactory.getCurrentSession();
-
- return (DataEntryForm) session.get( DataEntryForm.class, id );
- }
+ // -------------------------------------------------------------------------
@Override
public DataEntryForm getDataEntryFormByName( String name )
@@ -123,17 +76,6 @@
@Override
@SuppressWarnings( "unchecked" )
- public Collection<DataEntryForm> getAllDataEntryForms()
- {
- Session session = sessionFactory.getCurrentSession();
-
- Criteria criteria = session.createCriteria( DataEntryForm.class );
-
- return criteria.list();
- }
-
- @Override
- @SuppressWarnings( "unchecked" )
public Collection<DataEntryForm> listDistinctDataEntryFormByProgramStageIds( List<Integer> programStageIds )
{
Session session = sessionFactory.getCurrentSession();
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2015-04-08 13:53:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2015-05-03 14:12:07 +0000
@@ -28,7 +28,9 @@
<!-- Store definitions -->
<bean id="org.hisp.dhis.dataentryform.DataEntryFormStore" class="org.hisp.dhis.dataentryform.hibernate.HibernateDataEntryFormStore">
+ <property name="clazz" value="org.hisp.dhis.dataentryform.DataEntryForm" />
<property name="sessionFactory" ref="sessionFactory" />
+ <property name="cacheable" value="true" />
</bean>
<bean id="org.hisp.dhis.dataelement.DataElementStore" class="org.hisp.dhis.dataelement.hibernate.HibernateDataElementStore">
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataentryform/hibernate/DataEntryForm.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataentryform/hibernate/DataEntryForm.hbm.xml 2013-01-01 19:53:04 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataentryform/hibernate/DataEntryForm.hbm.xml 2015-05-03 14:12:07 +0000
@@ -6,6 +6,8 @@
<hibernate-mapping>
<class name="org.hisp.dhis.dataentryform.DataEntryForm" table="dataentryform">
+ <cache usage="read-write" />
+
<id name="id" column="dataentryformid">
<generator class="native" />
</id>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.java 2015-05-03 14:12:07 +0000
@@ -47,7 +47,6 @@
/**
* @author Bharath
- * @version $Id$
*/
public class DataEntryFormStoreTest
extends DhisSpringTest
@@ -83,9 +82,9 @@
DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
- int dataEntryFormAid = dataEntryFormStore.addDataEntryForm(dataEntryFormA );
+ int dataEntryFormAid = dataEntryFormStore.save(dataEntryFormA );
- dataEntryFormA = dataEntryFormStore.getDataEntryForm( dataEntryFormAid );
+ dataEntryFormA = dataEntryFormStore.get( dataEntryFormAid );
assertEquals( dataEntryFormAid, dataEntryFormA.getId() );
assertEquals( "DataEntryForm-A", dataEntryFormA.getName() );
@@ -97,17 +96,17 @@
DataEntryForm dataEntryForm = new DataEntryForm( "DataEntryForm-A" );
- int id = dataEntryFormStore.addDataEntryForm( dataEntryForm );
+ int id = dataEntryFormStore.save( dataEntryForm );
- dataEntryForm = dataEntryFormStore.getDataEntryForm( id );
+ dataEntryForm = dataEntryFormStore.get( id );
assertEquals( "DataEntryForm-A", dataEntryForm.getName() );
dataEntryForm.setName( "DataEntryForm-X" );
- dataEntryFormStore.updateDataEntryForm( dataEntryForm );
+ dataEntryFormStore.update( dataEntryForm );
- dataEntryForm = dataEntryFormStore.getDataEntryForm( id );
+ dataEntryForm = dataEntryFormStore.get( id );
assertEquals( dataEntryForm.getName(), "DataEntryForm-X" );
}
@@ -118,15 +117,15 @@
DataEntryForm dataEntryForm = new DataEntryForm( "DataEntryForm-A" );
- int id = dataEntryFormStore.addDataEntryForm( dataEntryForm );
-
- dataEntryForm = dataEntryFormStore.getDataEntryForm( id );
-
- assertNotNull( dataEntryFormStore.getDataEntryForm( id ) );
-
- dataEntryFormStore.deleteDataEntryForm( dataEntryFormStore.getDataEntryForm( id ) );
-
- assertNull( dataEntryFormStore.getDataEntryForm( id ) );
+ int id = dataEntryFormStore.save( dataEntryForm );
+
+ dataEntryForm = dataEntryFormStore.get( id );
+
+ assertNotNull( dataEntryFormStore.get( id ) );
+
+ dataEntryFormStore.delete( dataEntryFormStore.get( id ) );
+
+ assertNull( dataEntryFormStore.get( id ) );
}
@Test
@@ -136,9 +135,9 @@
DataEntryForm dataEntryForm = new DataEntryForm( "DataEntryForm-A" );
- int id = dataEntryFormStore.addDataEntryForm( dataEntryForm );
+ int id = dataEntryFormStore.save( dataEntryForm );
- dataEntryForm = dataEntryFormStore.getDataEntryForm( id );
+ dataEntryForm = dataEntryFormStore.get( id );
assertEquals( dataEntryFormStore.getDataEntryFormByName( "DataEntryForm-A" ), dataEntryForm );
assertNull( dataEntryFormStore.getDataEntryFormByName( "DataEntryForm-X" ) );
@@ -151,10 +150,10 @@
DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
DataEntryForm dataEntryFormB = new DataEntryForm( "DataEntryForm-B" );
- dataEntryFormStore.addDataEntryForm( dataEntryFormA );
- dataEntryFormStore.addDataEntryForm( dataEntryFormB );
+ dataEntryFormStore.save( dataEntryFormA );
+ dataEntryFormStore.save( dataEntryFormB );
- Collection<DataEntryForm> dataEntryForms = dataEntryFormStore.getAllDataEntryForms();
+ Collection<DataEntryForm> dataEntryForms = dataEntryFormStore.getAll();
assertEquals( dataEntryForms.size(), 2 );
assertTrue( dataEntryForms.contains( dataEntryFormA ) );