=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2010-10-14 08:14:12 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2010-10-22 08:42:25 +0000 @@ -299,13 +299,16 @@ // ------------------------------------------------------------------------- // Logic // ------------------------------------------------------------------------- + + /** * Null-safe check. */ public boolean isZeroIsSignificant() { - return zeroIsSignificant != null && zeroIsSignificant; + return zeroIsSignificant != null && zeroIsSignificant; + } /** === 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 2010-10-22 06:43:14 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-10-22 08:42:25 +0000 @@ -136,7 +136,7 @@ return criteria.list(); } - + public DataElement getDataElementByAlternativeName( String alternativeName ) { Session session = sessionFactory.getCurrentSession(); @@ -175,7 +175,7 @@ Criteria criteria = session.createCriteria( DataElement.class ); criteria.setCacheable( true ); criteria.addOrder( Order.asc( "name" ) ); - + return criteria.list(); } @@ -260,16 +260,29 @@ return query.list(); } - + public void setZeroIsSignificantForDataElements( Collection dataElementIds ) { - String sql = "update dataelement set zeroissignificant=false"; - - statementManager.getHolder().executeUpdate( sql ); - - sql = "update dataelement set zeroissignificant=true where dataelementid in (" + TextUtils.getCommaDelimitedString( dataElementIds ) + ")"; - - statementManager.getHolder().executeUpdate( sql ); + Session session = sessionFactory.getCurrentSession(); + + String sql = "update DataElement set zeroIsSignificant = false"; + + Query query = session.createQuery( sql ); + + query.executeUpdate(); + + if ( !dataElementIds.isEmpty() ) + { + + sql = "update DataElement set zeroIsSignificant=true where id in (:dataElementIds)"; + + query = session.createQuery( sql ); + query.setParameterList( "dataElementIds", dataElementIds ); + + query.executeUpdate(); + + } + } @SuppressWarnings( "unchecked" ) @@ -287,7 +300,7 @@ public Collection getDataElementsWithoutGroups() { String hql = "from DataElement d where d.groups.size = 0"; - + return sessionFactory.getCurrentSession().createQuery( hql ).list(); } @@ -295,21 +308,21 @@ public Collection getDataElementsWithoutDataSets() { String hql = "from DataElement d where d.dataSets.size = 0"; - + return sessionFactory.getCurrentSession().createQuery( hql ).list(); } - + public boolean dataElementExists( int id ) { final String sql = "select count(*) from dataelement where dataelementid=" + id; - + return statementManager.getHolder().queryForInteger( sql ) > 0; } - + public boolean dataElementCategoryOptionComboExists( int id ) { final String sql = "select count(*) from categoryoptioncombo where categoryoptioncomboid=" + id; - + return statementManager.getHolder().queryForInteger( sql ) > 0; } @@ -317,10 +330,11 @@ public Collection getDataElementsByDataSets( Collection dataSets ) { String hql = "select distinct de from DataElement de join de.dataSets ds where ds.id in (:ids)"; - - return sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", ConversionUtils.getIdentifiers( DataSet.class, dataSets ) ).list(); + + return sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", + ConversionUtils.getIdentifiers( DataSet.class, dataSets ) ).list(); } - + // ------------------------------------------------------------------------- // CalculatedDataElement // ------------------------------------------------------------------------- @@ -434,54 +448,53 @@ // ------------------------------------------------------------------------- // DataElementOperand // ------------------------------------------------------------------------- - + public Collection getAllGeneratedOperands() { final ObjectMapper mapper = new ObjectMapper(); - - final String sql = - "SELECT de.dataelementid, de.name, cocn.categoryoptioncomboid, cocn.categoryoptioncomboname " + - "FROM dataelement as de " + - "JOIN categorycombo as cc on de.categorycomboid=cc.categorycomboid " + - "JOIN categorycombos_optioncombos as ccoc on cc.categorycomboid=ccoc.categorycomboid " + - "LEFT JOIN _categoryoptioncomboname as cocn on ccoc.categoryoptioncomboid=cocn.categoryoptioncomboid;"; - + + final String sql = "SELECT de.dataelementid, de.name, cocn.categoryoptioncomboid, cocn.categoryoptioncomboname " + + "FROM dataelement as de " + + "JOIN categorycombo as cc on de.categorycomboid=cc.categorycomboid " + + "JOIN categorycombos_optioncombos as ccoc on cc.categorycomboid=ccoc.categorycomboid " + + "LEFT JOIN _categoryoptioncomboname as cocn on ccoc.categoryoptioncomboid=cocn.categoryoptioncomboid;"; + try { ResultSet resultSet = statementManager.getHolder().getStatement().executeQuery( sql ); - + return mapper.getCollection( resultSet, new DataElementOperandMapper() ); } catch ( SQLException ex ) { throw new RuntimeException( "Failed to get all operands", ex ); - } + } } - + public Collection getAllGeneratedOperands( Collection dataElements ) { - final String dataElementString = TextUtils.getCommaDelimitedString( ConversionUtils.getIdentifiers( DataElement.class, dataElements ) ); - + final String dataElementString = TextUtils.getCommaDelimitedString( ConversionUtils.getIdentifiers( + DataElement.class, dataElements ) ); + final ObjectMapper mapper = new ObjectMapper(); - - final String sql = - "SELECT de.dataelementid, de.name, cocn.categoryoptioncomboid, cocn.categoryoptioncomboname " + - "FROM dataelement as de " + - "JOIN categorycombo as cc on de.categorycomboid=cc.categorycomboid " + - "JOIN categorycombos_optioncombos as ccoc on cc.categorycomboid=ccoc.categorycomboid " + - "LEFT JOIN _categoryoptioncomboname as cocn on ccoc.categoryoptioncomboid=cocn.categoryoptioncomboid " + - "WHERE de.dataelementid IN (" + dataElementString + ");"; - + + final String sql = "SELECT de.dataelementid, de.name, cocn.categoryoptioncomboid, cocn.categoryoptioncomboname " + + "FROM dataelement as de " + + "JOIN categorycombo as cc on de.categorycomboid=cc.categorycomboid " + + "JOIN categorycombos_optioncombos as ccoc on cc.categorycomboid=ccoc.categorycomboid " + + "LEFT JOIN _categoryoptioncomboname as cocn on ccoc.categoryoptioncomboid=cocn.categoryoptioncomboid " + + "WHERE de.dataelementid IN (" + dataElementString + ");"; + try { ResultSet resultSet = statementManager.getHolder().getStatement().executeQuery( sql ); - + return mapper.getCollection( resultSet, new DataElementOperandMapper() ); } catch ( SQLException ex ) { throw new RuntimeException( "Failed to get all operands", ex ); - } + } } public Collection getAllDataElements( int from, int to ) @@ -499,18 +512,18 @@ public int getNumberOfDataElements() { -// Session session = sessionFactory.getCurrentSession(); -// -// Criteria criteria = session.createCriteria( DataElement.class ); -// criteria.setCacheable( true ); -// criteria.setProjection( Projections.rowCount() ).uniqueResult(); -// -// return ((Number) criteria).intValue(); - + // Session session = sessionFactory.getCurrentSession(); + // + // Criteria criteria = session.createCriteria( DataElement.class ); + // criteria.setCacheable( true ); + // criteria.setProjection( Projections.rowCount() ).uniqueResult(); + // + // return ((Number) criteria).intValue(); + String sql = "select count(*) from DataElement"; Query query = sessionFactory.getCurrentSession().createQuery( sql ); Number countResult = (Number) query.uniqueResult(); - + return countResult.intValue(); } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/zerovaluestorage/UpdateZeroIsSignificantForDataElementsAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/zerovaluestorage/UpdateZeroIsSignificantForDataElementsAction.java 2010-09-20 08:49:55 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/zerovaluestorage/UpdateZeroIsSignificantForDataElementsAction.java 2010-10-22 08:42:25 +0000 @@ -69,6 +69,8 @@ throws Exception { dataElementService.setZeroIsSignificantForDataElements( zeroDataValueElements ); + + return SUCCESS; }