dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20199
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9123: Minor fix for option-set.
------------------------------------------------------------
revno: 9123
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-11-26 11:43:39 +0700
message:
Minor fix for option-set.
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.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 2012-11-20 08:44:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java 2012-11-26 04:43:39 +0000
@@ -32,6 +32,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.hibernate.Query;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.option.OptionSet;
import org.hisp.dhis.option.OptionStore;
@@ -62,38 +63,21 @@
// Implementation methods
// -------------------------------------------------------------------------
+ @SuppressWarnings( "unchecked" )
@Override
public List<String> getOptions( int optionSetId, String key, Integer max )
{
- //TODO Should ideally be cached and go through Hibernate
-
- String sql =
- "select optionvalue from optionset os " +
- "inner join optionsetmembers as om on os.optionsetid=om.optionsetid " +
- "where os.optionsetid=" + optionSetId;
-
- if ( key != null )
- {
- sql += " and lower(om.optionvalue) like lower('%" + key + "%')";
- }
-
- sql += " order by sort_order";
-
- if ( max != null )
- {
- sql += " limit " + max;
- }
-
- List<String> optionValues = new ArrayList<String>();
-
- optionValues = jdbcTemplate.query( sql, new RowMapper<String>()
- {
- public String mapRow( ResultSet rs, int rowNum ) throws SQLException
- {
- return rs.getString( 1 );
- }
- } );
-
- return optionValues;
+ String hql = "select option from OptionSet as optionset inner join optionset.options as option where optionset.id = :optionSetId ";
+ if( key != null )
+ {
+ hql += " and lower(option) like lower('%" + key + "%') ";
+ }
+
+ hql += " order by index(option)";
+ Query query = getQuery( hql );
+ query.setInteger( "optionSetId", optionSetId );
+ query.setMaxResults( max );
+
+ return query.list();
}
}