------------------------------------------------------------ revno: 1120 committer: Lars Helge Oeverland larshe...@gmail.com branch nick: trunk timestamp: Wed 2009-11-25 10:08:11 +0100 message: Improved performance in validation modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.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/datavalue/DataValueService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java 2009-11-25 08:19:22 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java 2009-11-25 09:08:11 +0000 @@ -116,7 +116,7 @@ */ DataValue getDataValue( Source source, DataElement dataElement, Period period, DataElementCategoryOptionCombo optionCombo ); - String getValue( DataElement dataElement, Period period, Source source, DataElementCategoryOptionCombo optionCombo ); + String getValue( int dataElementId, int periodId, int sourceId, int categoryOptionComboId ); // ------------------------------------------------------------------------- // Collections of DataValues === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java 2009-11-25 08:19:22 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java 2009-11-25 09:08:11 +0000 @@ -107,7 +107,7 @@ */ DataValue getDataValue( Source source, DataElement dataElement, Period period, DataElementCategoryOptionCombo optionCombo ); - String getValue( DataElement dataElement, Period period, Source source, DataElementCategoryOptionCombo optionCombo ); + String getValue( int dataElementId, int periodId, int sourceId, int categoryOptionComboId ); // ------------------------------------------------------------------------- // Collections of DataValues === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2009-11-25 08:19:22 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2009-11-25 09:08:11 +0000 @@ -105,9 +105,9 @@ return dataValueStore.getDataValue( source, dataElement, period, optionCombo ); } - public String getValue( DataElement dataElement, Period period, Source source, DataElementCategoryOptionCombo optionCombo ) + public String getValue( int dataElementId, int periodId, int sourceId, int categoryOptionComboId ) { - return dataValueStore.getValue( dataElement, period, source, optionCombo ); + return dataValueStore.getValue( dataElementId, periodId, sourceId, categoryOptionComboId ); } // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java 2009-11-25 08:19:22 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java 2009-11-25 09:08:11 +0000 @@ -27,14 +27,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import org.amplecode.quick.StatementHolder; import org.amplecode.quick.StatementManager; import org.hibernate.Criteria; import org.hibernate.Query; @@ -200,32 +197,17 @@ return (DataValue) criteria.uniqueResult(); } - public String getValue( DataElement dataElement, Period period, Source source, DataElementCategoryOptionCombo optionCombo ) + public String getValue( int dataElementId, int periodId, int sourceId, int categoryOptionComboId ) { - StatementHolder holder = statementManager.getHolder(); - final String sql = "SELECT value " + "FROM datavalue " + - "WHERE dataelementid='" + dataElement.getId() + "' " + - "AND periodid='" + period.getId() + "' " + - "AND sourceid='" + source.getId() + "' " + - "AND categoryoptioncomboid='" + optionCombo.getId() + "'"; + "WHERE dataelementid='" + dataElementId + "' " + + "AND periodid='" + periodId + "' " + + "AND sourceid='" + sourceId + "' " + + "AND categoryoptioncomboid='" + categoryOptionComboId + "'"; - try - { - ResultSet resultSet = holder.getStatement().executeQuery( sql ); - - return resultSet.next() ? resultSet.getString( 1 ) : null; - } - catch ( SQLException ex ) - { - throw new RuntimeException( ex ); - } - finally - { - holder.close(); - } + return statementManager.getHolder().queryForString( sql ); } // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2009-10-18 22:44:41 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java 2009-11-25 09:08:11 +0000 @@ -67,6 +67,9 @@ private static final String NULL_REPLACEMENT = "0"; private static final String FORMULA_EXPRESSION = "(\\[\\d+\\" + SEPARATOR + "\\d+\\])"; private static final String DESCRIPTION_EXPRESSION = "\\[.+?\\" + SEPARATOR + ".+?\\]"; + + private final Pattern FORMULA_PATTERN = Pattern.compile( FORMULA_EXPRESSION ); + private final Pattern DESCRIPTION_PATTERN = Pattern.compile( DESCRIPTION_EXPRESSION ); // ------------------------------------------------------------------------- // Dependencies @@ -160,8 +163,8 @@ { dataElementsInExpression = new HashSet<DataElement>(); - final Matcher matcher = getMatcher( "(\\[\\d+\\" + SEPARATOR + "\\d+\\])", expression ); - + final Matcher matcher = FORMULA_PATTERN.matcher( expression ); + while ( matcher.find() ) { final DataElement dataElement = dataElementService.getDataElement( getOperand( matcher.group() ).getDataElementId() ); @@ -182,7 +185,7 @@ if ( expression != null ) { - final Matcher matcher = getMatcher( FORMULA_EXPRESSION, expression ); + final Matcher matcher = FORMULA_PATTERN.matcher( expression ); while ( matcher.find() ) { @@ -227,7 +230,7 @@ { operandsInExpression = new HashSet<Operand>(); - final Matcher matcher = getMatcher( FORMULA_EXPRESSION, expression ); + final Matcher matcher = FORMULA_PATTERN.matcher( expression ); while ( matcher.find() ) { @@ -242,7 +245,7 @@ { StringBuffer buffer = new StringBuffer(); - final Matcher matcher = getMatcher( DESCRIPTION_EXPRESSION, formula ); + final Matcher matcher = DESCRIPTION_PATTERN.matcher( formula ); int dataElementId = -1; int categoryOptionComboId = -1; @@ -310,7 +313,7 @@ { buffer = new StringBuffer(); - final Matcher matcher = getMatcher( DESCRIPTION_EXPRESSION, formula ); + final Matcher matcher = DESCRIPTION_PATTERN.matcher( formula ); while ( matcher.find() ) { @@ -370,7 +373,7 @@ } } - final Matcher matcher = getMatcher( FORMULA_EXPRESSION, expression ); + final Matcher matcher = FORMULA_PATTERN.matcher( expression ); while ( matcher.find() ) { @@ -401,7 +404,7 @@ if ( expression != null ) { - final Matcher matcher = getMatcher( FORMULA_EXPRESSION, expression ); + final Matcher matcher = FORMULA_PATTERN.matcher( expression ); buffer = new StringBuffer(); @@ -411,11 +414,7 @@ final Operand operand = getOperand( replaceString ); - final DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); - final DataElementCategoryOptionCombo categoryOptionCombo = - categoryService.getDataElementCategoryOptionCombo( operand.getOptionComboId() ); - - final String value = dataValueService.getValue( dataElement, period, source, categoryOptionCombo ); + final String value = dataValueService.getValue( operand.getDataElementId(), period.getId(), source.getId(), operand.getOptionComboId() ); if ( value == null && nullIfNoValues ) { @@ -436,13 +435,6 @@ // ------------------------------------------------------------------------- // Supportive methods // ------------------------------------------------------------------------- - - private Matcher getMatcher( String regex, String expression ) - { - final Pattern pattern = Pattern.compile( regex ); - - return pattern.matcher( expression ); - } private Operand getOperand( String formula ) { === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.java 2009-11-25 08:30:25 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patient/ShowAddPatientFormAction.java 2009-11-25 09:08:11 +0000 @@ -44,10 +44,6 @@ // Dependencies // ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - private OrganisationUnitSelectionManager selectionManager; public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp