dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15134
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5346: Replaced boilerplate code in store layer with HibernateGenericStore
------------------------------------------------------------
revno: 5346
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-12-09 20:44:38 +0100
message:
Replaced boilerplate code in store layer with HibernateGenericStore
removed:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementCategoryOptionComboStore.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.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/validation/ValidationRuleStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java 2011-11-03 01:02:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java 2011-12-09 19:44:38 +0000
@@ -46,22 +46,6 @@
// -------------------------------------------------------------------------
/**
- * Saves a ValidationRule to the database.
- *
- * @param validationRule the ValidationRule to add.
- * @return the generated unique identifier for the ValidationRule.
- */
-
- int saveValidationRule( ValidationRule validationRule );
- /**
- * Update a ValidationRule to the database.
- *
- * @param validationRule the ValidationRule to update.
- * @return the generated unique identifier for the ValidationRule.
- */
- void updateValidationRule( ValidationRule validationRule );
-
- /**
* Returns all ValidationRules which are associated through their left or
* right side Expression with the given collection of DataElements.
*
@@ -69,11 +53,4 @@
* @return a collection of ValidationRules.
*/
Collection<ValidationRule> getValidationRulesByDataElements( Collection<DataElement> dataElements );
-
- /**
- * Returns the number of ValidationRules.
- *
- * @return the number of ValidationRules.
- */
- Integer getNumberOfValidationRules();
}
=== removed file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementCategoryOptionComboStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementCategoryOptionComboStore.java 2011-11-03 01:02:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementCategoryOptionComboStore.java 1970-01-01 00:00:00 +0000
@@ -1,66 +0,0 @@
-package org.hisp.dhis.dataelement.hibernate;
-
-
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.hibernate.HibernateGenericStore;
-
-/*
- * Copyright (c) 2004-2005, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the <ORGANIZATION> nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/**
- *
- * @author bobj
- * @version created 02-Nov-2011
- */
-public class HibernateDataElementCategoryOptionComboStore
- extends HibernateGenericStore<DataElementCategoryOptionCombo>
-{
- @Override
- public final int save( DataElementCategoryOptionCombo catoptcombo )
- {
- catoptcombo.setAutoFields();
-
- return (Integer) sessionFactory.getCurrentSession().save( catoptcombo );
- }
-
- @Override
- public final void update( DataElementCategoryOptionCombo catoptcombo )
- {
- catoptcombo.setAutoFields();
-
- sessionFactory.getCurrentSession().update( catoptcombo );
- }
-
- @Override
- public final void saveOrUpdate( DataElementCategoryOptionCombo catoptcombo )
- {
-
- catoptcombo.setAutoFields();
-
- sessionFactory.getCurrentSession().saveOrUpdate( catoptcombo );
- }
-
-}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java 2011-04-22 18:56:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/minmax/hibernate/HibernateMinMaxDataElementStore.java 2011-12-09 19:44:38 +0000
@@ -40,30 +40,33 @@
/**
* @author Kristian Nordal
- * @version $Id: HibernateMinMaxDataElementStore.java 6216 2008-11-06 18:06:42Z eivindwa $
+ * @version $Id: HibernateMinMaxDataElementStore.java 6216 2008-11-06 18:06:42Z
+ * eivindwa $
*/
public class HibernateMinMaxDataElementStore
- extends HibernateGenericStore<MinMaxDataElement> implements MinMaxDataElementStore
+ extends HibernateGenericStore<MinMaxDataElement>
+ implements MinMaxDataElementStore
{
// -------------------------------------------------------------------------
// MinMaxDataElementStore Implementation
// -------------------------------------------------------------------------
- public MinMaxDataElement get( OrganisationUnit source, DataElement dataElement, DataElementCategoryOptionCombo optionCombo )
+ public MinMaxDataElement get( OrganisationUnit source, DataElement dataElement,
+ DataElementCategoryOptionCombo optionCombo )
{
- return (MinMaxDataElement) getCriteria(
+ return (MinMaxDataElement) getCriteria(
Restrictions.eq( "source", source ),
- Restrictions.eq( "dataElement", dataElement ),
+ Restrictions.eq( "dataElement", dataElement ),
Restrictions.eq( "optionCombo", optionCombo ) ).uniqueResult();
}
@SuppressWarnings( "unchecked" )
public Collection<MinMaxDataElement> get( OrganisationUnit source, DataElement dataElement )
{
- return getCriteria(
- Restrictions.eq( "source", source ),
- Restrictions.eq( "dataElement", dataElement ) ).list();
- }
+ return getCriteria(
+ Restrictions.eq( "source", source ),
+ Restrictions.eq( "dataElement", dataElement ) ).list();
+ }
@SuppressWarnings( "unchecked" )
public Collection<MinMaxDataElement> get( OrganisationUnit source, Collection<DataElement> dataElements )
@@ -73,8 +76,8 @@
return Collections.emptySet();
}
- return getCriteria(
- Restrictions.eq( "source", source ),
- Restrictions.in( "dataElement", dataElements ) ).list();
+ return getCriteria(
+ Restrictions.eq( "source", source ),
+ Restrictions.in( "dataElement", dataElements ) ).list();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2011-09-10 08:40:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2011-12-09 19:44:38 +0000
@@ -117,7 +117,7 @@
public Grid getAggregateValidationResult( Collection<ValidationResult> results, List<Period> periods,
List<OrganisationUnit> sources )
{
- int number = validationRuleStore.getNumberOfValidationRules();
+ int number = validationRuleStore.getCount();
Grid grid = new ListGrid();
@@ -377,12 +377,12 @@
public int saveValidationRule( ValidationRule validationRule )
{
- return validationRuleStore.saveValidationRule( validationRule );
+ return validationRuleStore.save( validationRule );
}
public void updateValidationRule( ValidationRule validationRule )
{
- validationRuleStore.updateValidationRule( validationRule );
+ validationRuleStore.update( validationRule );
}
public void deleteValidationRule( ValidationRule validationRule )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java 2010-12-04 00:17:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java 2011-12-09 19:44:38 +0000
@@ -31,7 +31,6 @@
import java.util.HashSet;
import java.util.Set;
-import org.hibernate.Session;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.hibernate.HibernateGenericStore;
import org.hisp.dhis.period.PeriodStore;
@@ -65,27 +64,23 @@
// -------------------------------------------------------------------------
@Override
- public int saveValidationRule( ValidationRule validationRule )
+ public int save( ValidationRule validationRule )
{
PeriodType periodType = periodStore.getPeriodType( validationRule.getPeriodType().getClass() );
validationRule.setPeriodType( periodType );
- Session session = sessionFactory.getCurrentSession();
-
- return (Integer) session.save( validationRule );
+ return super.save( validationRule );
}
@Override
- public void updateValidationRule( ValidationRule validationRule )
+ public void update( ValidationRule validationRule )
{
PeriodType periodType = periodStore.getPeriodType( validationRule.getPeriodType().getClass() );
validationRule.setPeriodType( periodType );
- Session session = sessionFactory.getCurrentSession();
-
- session.update( validationRule );
+ super.save( validationRule );
}
@Override
@@ -106,10 +101,4 @@
return validationRules;
}
-
- @Override
- public Integer getNumberOfValidationRules()
- {
- return getCount();
- }
}
=== 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 2011-12-09 18:58:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-12-09 19:44:38 +0000
@@ -132,7 +132,7 @@
<property name="cacheable" value="true" />
</bean>
- <bean id="org.hisp.dhis.dataelement.DataElementCategoryOptionComboStore" class="org.hisp.dhis.dataelement.hibernate.HibernateDataElementCategoryOptionComboStore">
+ <bean id="org.hisp.dhis.dataelement.DataElementCategoryOptionComboStore" class="org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore">
<property name="clazz" value="org.hisp.dhis.dataelement.DataElementCategoryOptionCombo" />
<property name="sessionFactory" ref="sessionFactory" />
<property name="cacheable" value="true" />
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java 2011-06-03 13:11:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleStoreTest.java 2011-12-09 19:44:38 +0000
@@ -143,7 +143,7 @@
{
ValidationRule validationRule = createValidationRule( 'A', equal_to, expressionA, expressionB, periodType );
- int id = validationRuleStore.saveValidationRule( validationRule );
+ int id = validationRuleStore.save( validationRule );
validationRule = validationRuleStore.get( id );
@@ -161,7 +161,7 @@
{
ValidationRule validationRule = createValidationRule( 'A', equal_to, expressionA, expressionB, periodType );
- int id = validationRuleStore.saveValidationRule( validationRule );
+ int id = validationRuleStore.save( validationRule );
validationRule = validationRuleStore.get( id );
@@ -175,7 +175,7 @@
validationRule.setType( ValidationRule.TYPE_STATISTICAL );
validationRule.setOperator( greater_than );
- validationRuleStore.updateValidationRule( validationRule );
+ validationRuleStore.update( validationRule );
validationRule = validationRuleStore.get( id );
@@ -191,8 +191,8 @@
ValidationRule validationRuleA = createValidationRule( 'A', equal_to, expressionA, expressionB, periodType );
ValidationRule validationRuleB = createValidationRule( 'B', equal_to, expressionA, expressionB, periodType );
- int idA = validationRuleStore.saveValidationRule( validationRuleA );
- int idB = validationRuleStore.saveValidationRule( validationRuleB );
+ int idA = validationRuleStore.save( validationRuleA );
+ int idB = validationRuleStore.save( validationRuleB );
assertNotNull( validationRuleStore.get( idA ) );
assertNotNull( validationRuleStore.get( idB ) );
@@ -218,8 +218,8 @@
ValidationRule validationRuleA = createValidationRule( 'A', equal_to, expressionA, expressionB, periodType );
ValidationRule validationRuleB = createValidationRule( 'B', equal_to, expressionA, expressionB, periodType );
- validationRuleStore.saveValidationRule( validationRuleA );
- validationRuleStore.saveValidationRule( validationRuleB );
+ validationRuleStore.save( validationRuleA );
+ validationRuleStore.save( validationRuleB );
Collection<ValidationRule> rules = validationRuleStore.getAll();
@@ -234,8 +234,8 @@
ValidationRule validationRuleA = createValidationRule( 'A', equal_to, expressionA, expressionB, periodType );
ValidationRule validationRuleB = createValidationRule( 'B', equal_to, expressionA, expressionB, periodType );
- int id = validationRuleStore.saveValidationRule( validationRuleA );
- validationRuleStore.saveValidationRule( validationRuleB );
+ int id = validationRuleStore.save( validationRuleA );
+ validationRuleStore.save( validationRuleB );
ValidationRule rule = validationRuleStore.getByName( "ValidationRuleA" );
@@ -272,9 +272,9 @@
ValidationRule ruleB = createValidationRule( 'B', equal_to, expression2, expression3, periodType );
ValidationRule ruleC = createValidationRule( 'C', equal_to, expression3, expression3, periodType );
- validationRuleStore.saveValidationRule( ruleA );
- validationRuleStore.saveValidationRule( ruleB );
- validationRuleStore.saveValidationRule( ruleC );
+ validationRuleStore.save( ruleA );
+ validationRuleStore.save( ruleB );
+ validationRuleStore.save( ruleC );
Collection<ValidationRule> rules = validationRuleStore.getValidationRulesByDataElements( dataElementsA );
@@ -325,11 +325,11 @@
ValidationRule ruleB = createValidationRule( 'B', equal_to, expression2, expression3, periodType );
ValidationRule ruleC = createValidationRule( 'C', equal_to, expression3, expression3, periodType );
- validationRuleStore.saveValidationRule( ruleA );
- validationRuleStore.saveValidationRule( ruleB );
- validationRuleStore.saveValidationRule( ruleC );
+ validationRuleStore.save( ruleA );
+ validationRuleStore.save( ruleB );
+ validationRuleStore.save( ruleC );
- assertNotNull( validationRuleStore.getNumberOfValidationRules().intValue() );
- assertEquals( 3, validationRuleStore.getNumberOfValidationRules().intValue() );
+ assertNotNull( validationRuleStore.getCount() );
+ assertEquals( 3, validationRuleStore.getCount() );
}
}