dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31919
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16307: Option set, fixed a range of issues
------------------------------------------------------------
revno: 16307
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-08-04 16:27:32 +0200
message:
Option set, fixed a range of issues
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.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/option/hibernate/Option.hbm.xml
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.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-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java 2014-08-03 07:05:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java 2014-08-04 14:27:32 +0000
@@ -32,7 +32,6 @@
import java.util.List;
import org.hibernate.Query;
-import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.option.Option;
import org.hisp.dhis.option.OptionSet;
@@ -40,8 +39,6 @@
/**
* @author Chau Thu Tran
- *
- * @version $HibernateOptionStore.java Jun 15, 2012 9:45:48 AM$
*/
public class HibernateOptionStore
extends HibernateIdentifiableObjectStore<OptionSet>
@@ -55,15 +52,20 @@
@Override
public List<Option> getOptions( int optionSetId, String key, Integer max )
{
- String hql = "select option from OptionSet as optionset join optionset.options as option where optionset.id = :optionSetId ";
+ String hql =
+ "select option from OptionSet as optionset " +
+ "join optionset.options as option where optionset.id = :optionSetId ";
+
if ( key != null )
{
- hql += " and lower(option.name) like lower('%" + key + "%') ";
+ hql += "and lower(option.name) like lower('%" + key + "%') ";
}
- hql += " order by index(option)";
+ hql += "order by index(option)";
+
Query query = getQuery( hql );
query.setInteger( "optionSetId", optionSetId );
+
if ( max != null )
{
query.setMaxResults( max );
@@ -74,7 +76,9 @@
public Option getOptionValueByName( OptionSet optionSet, String name )
{
- String hql = "select option from OptionSet as optionset join optionset.options as option where optionset = :optionSet and lower(option.name) = :name";
+ String hql =
+ "select option from OptionSet as optionset " +
+ "join optionset.options as option where optionset = :optionSet and lower(option.name) = :name";
Query query = getQuery( hql );
query.setEntity( "optionSet", optionSet );
@@ -86,13 +90,17 @@
@SuppressWarnings( "unchecked" )
public Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max )
{
- String hql = "select option from OptionSet as optionset join optionset.options as option where optionset = :optionSet ";
+ String hql =
+ "select option from OptionSet as optionset " +
+ "join optionset.options as option where optionset = :optionSet ";
if ( option != null )
{
- hql += " and lower(option.name) like ('%" + option + "%') ";
+ hql += "and lower(option.name) like ('%" + option + "%') ";
}
+ hql += "order by index(option)";
+
Query query = getQuery( hql );
query.setEntity( "optionSet", optionSet );
@@ -102,8 +110,6 @@
query.setMaxResults( max );
}
- hql += " order by index(option)";
-
return query.list();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2014-08-04 13:40:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2014-08-04 14:27:32 +0000
@@ -41,8 +41,6 @@
import org.amplecode.quick.StatementManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
-import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.jdbc.batchhandler.RelativePeriodsBatchHandler;
@@ -731,7 +729,7 @@
executeSql( "ALTER TABLE dataelement DROP COLUMN active" );
- updateOptionTbl();
+ updateOptions();
log.info( "Tables updated" );
}
@@ -1164,10 +1162,21 @@
return statementManager.getHolder().queryForInteger( sql );
}
- private void updateOptionTbl()
+ private void updateOptions()
{
- executeSql( "INSERT INTO option( optionid, code, created, lastupdated, name, optionsetid, sort_order) "
- + " select " + statementBuilder.getAutoIncrementValue() + ", optionvalue, now(), now(), optionvalue, optionsetid, ( sort_order + 1 ) "
- + " from optionsetmembers " );
+ String sql = "insert into optionvalue(optionid, code, name, optionsetid, sort_order) "
+ + "select " + statementBuilder.getAutoIncrementValue() + ", optionvalue, optionvalue, optionsetid, ( sort_order + 1 ) "
+ + "from optionsetmembers";
+
+ int result = executeSql( sql );
+
+ if ( result != -1 )
+ {
+ executeSql( "drop table optionsetmembers" );
+ }
+ else
+ {
+ log.info( "Updated optionvalue table, SQL: " + sql );
+ }
}
}
=== 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 2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-08-04 14:27:32 +0000
@@ -1011,6 +1011,7 @@
<value>usergroup</value>
<value>userrole</value>
<value>optionset</value>
+ <value>optionvalue</value>
<value>validationcriteria</value>
</list>
</property>
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml 2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml 2014-08-04 14:27:32 +0000
@@ -6,14 +6,18 @@
>
<hibernate-mapping>
- <class name="org.hisp.dhis.option.Option" table="option">
+ <class name="org.hisp.dhis.option.Option" table="optionvalue">
<cache usage="read-write" />
- <id name="id" column="optionid">
+ <id name="id" column="optionvalueid">
<generator class="native" />
</id>
- &identifiableProperties;
+
+ <property name="uid" column="uid" unique="true" length="11" />
+ <property name="code" column="code" not-null="false" unique="true" length="230" /> <!-- Length for legacy support -->
+ <property name="created" type="timestamp"/>
+ <property name="lastUpdated" type="timestamp"/>
<property name="name" column="name" not-null="true" length="230" />
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2014-07-29 07:52:47 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2014-08-04 14:27:32 +0000
@@ -193,7 +193,7 @@
emptyTable( "dataelementcategory" );
emptyTable( "dataelementcategoryoption" );
- emptyTable( "option" );
+ emptyTable( "optionvalue" );
emptyTable( "optionset" );
dropTable( "aggregateddatavalue" );