dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30063
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15254: Use HibernateGenericStore in HibernateProgramStageDataElementStore.
------------------------------------------------------------
revno: 15254
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-05-13 18:43:52 +0800
message:
Use HibernateGenericStore in HibernateProgramStageDataElementStore.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementStore.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java
dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml
--
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/program/ProgramStageDataElementStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementStore.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageDataElementStore.java 2014-05-13 10:43:52 +0000
@@ -30,6 +30,7 @@
import java.util.Collection;
+import org.hisp.dhis.common.GenericStore;
import org.hisp.dhis.dataelement.DataElement;
/**
@@ -38,34 +39,11 @@
* @version $Id$
*/
public interface ProgramStageDataElementStore
+ extends GenericStore<ProgramStageDataElement>
{
String ID = ProgramStageInstanceStore.class.getName();
/**
- * Adds an {@link ProgramStageDataElement}
- *
- * @param programStageDataElement The to ProgramStageDataElement add.
- *
- * @return A generated unique id of the added
- * {@link ProgramStageDataElement}.
- */
- void save( ProgramStageDataElement programStageDataElement );
-
- /**
- * Updates an {@link ProgramStageDataElement}.
- *
- * @param programStageDataElement the ProgramStageDataElement to update.
- */
- void update( ProgramStageDataElement programStageDataElement );
-
- /**
- * Deletes a {@link ProgramStageDataElement}.
- *
- * @param programStageDataElement the ProgramStageDataElement to delete.
- */
- void delete( ProgramStageDataElement programStageDataElement );
-
- /**
* Retrieve ProgramStageDataElement list on a program stage and a data
* element
*
@@ -77,14 +55,6 @@
ProgramStageDataElement get( ProgramStage programStage, DataElement dataElement );
/**
- * Returns all {@link ProgramStageDataElement}
- *
- * @return a collection of all ProgramStageDataElement, or an empty
- * collection if there are no ProgramStageDataElements.
- */
- Collection<ProgramStageDataElement> getAll();
-
- /**
* Retrieve ProgramStageDataElement list on a program stage
*
* @param programStage ProgramStage
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java 2014-05-09 15:49:36 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageDataElementStore.java 2014-05-13 10:43:52 +0000
@@ -28,109 +28,51 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Collection;
+
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.dataelement.DataElement;
+import org.hisp.dhis.hibernate.HibernateGenericStore;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramStageDataElementStore;
-import java.util.Collection;
-
/**
* @author Viet Nguyen
*/
public class HibernateProgramStageDataElementStore
+ extends HibernateGenericStore<ProgramStageDataElement>
implements ProgramStageDataElementStore
{
// -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private SessionFactory sessionFactory;
-
- public void setSessionFactory( SessionFactory sessionFactory )
- {
- this.sessionFactory = sessionFactory;
- }
-
- // -------------------------------------------------------------------------
// Implemented methods
// -------------------------------------------------------------------------
- public void save( ProgramStageDataElement programStageDataElement )
- {
- Session session = sessionFactory.getCurrentSession();
-
- session.save( programStageDataElement );
- }
-
- public void update( ProgramStageDataElement programStageDataElement )
- {
- Session session = sessionFactory.getCurrentSession();
-
- session.update( programStageDataElement );
- }
-
- public void delete( ProgramStageDataElement programStageDataElement )
- {
- Session session = sessionFactory.getCurrentSession();
-
- session.delete( programStageDataElement );
- }
-
- @SuppressWarnings( "unchecked" )
- public Collection<ProgramStageDataElement> getAll()
- {
- Session session = sessionFactory.getCurrentSession();
-
- Criteria criteria = session.createCriteria( ProgramStageDataElement.class );
-
- return criteria.list();
- }
-
@SuppressWarnings( "unchecked" )
public Collection<ProgramStageDataElement> get( ProgramStage programStage )
{
- Session session = sessionFactory.getCurrentSession();
-
- Criteria criteria = session.createCriteria( ProgramStageDataElement.class );
-
- return criteria.add( Restrictions.eq( "programStage", programStage ) ).list();
+ return getCriteria( Restrictions.eq( "programStage", programStage ) ).list();
}
@SuppressWarnings( "unchecked" )
public Collection<ProgramStageDataElement> get( ProgramStage programStage, boolean compulsory )
{
- Session session = sessionFactory.getCurrentSession();
-
- Criteria criteria = session.createCriteria( ProgramStageDataElement.class );
- criteria.add( Restrictions.eq( "programStage", programStage ) );
- criteria.add( Restrictions.eq( "compulsory", compulsory ) );
-
- return criteria.list();
+ return getCriteria( Restrictions.eq( "programStage", programStage ), Restrictions.eq( "compulsory", compulsory ) )
+ .list();
}
public ProgramStageDataElement get( ProgramStage programStage, DataElement dataElement )
{
- Session session = sessionFactory.getCurrentSession();
-
- Criteria criteria = session.createCriteria( ProgramStageDataElement.class );
- criteria.add( Restrictions.eq( "programStage", programStage ) );
- criteria.add( Restrictions.eq( "dataElement", dataElement ) );
-
- return (ProgramStageDataElement) criteria.uniqueResult();
+ return (ProgramStageDataElement) getCriteria( Restrictions.eq( "programStage", programStage ),
+ Restrictions.eq( "dataElement", dataElement ) ).uniqueResult();
}
@SuppressWarnings( "unchecked" )
public Collection<DataElement> getListDataElement( ProgramStage programStage )
{
- Session session = sessionFactory.getCurrentSession();
- Criteria criteria = session.createCriteria( ProgramStageDataElement.class );
- criteria.add( Restrictions.eq( "programStage", programStage ) );
+ Criteria criteria = getCriteria( Restrictions.eq( "programStage", programStage ) );
criteria.setProjection( Projections.property( "dataElement" ) );
return criteria.list();
}
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml 2014-05-13 09:42:58 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/META-INF/dhis/beans.xml 2014-05-13 10:43:52 +0000
@@ -113,6 +113,8 @@
<bean id="org.hisp.dhis.program.ProgramStageDataElementStore"
class="org.hisp.dhis.program.hibernate.HibernateProgramStageDataElementStore">
+ <property name="clazz"
+ value="org.hisp.dhis.program.ProgramStageDataElement" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>