dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20155
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9082: Don't sort option-values in entry form.
------------------------------------------------------------
revno: 9082
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-11-20 11:08:23 +0700
message:
Don't sort option-values in entry form.
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/resources/META-INF/dhis/beans.xml
--
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-01 15:15:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java 2012-11-20 04:08:23 +0000
@@ -27,12 +27,16 @@
package org.hisp.dhis.option.hibernate;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+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;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
/**
* @author Chau Thu Tran
@@ -43,27 +47,47 @@
extends HibernateIdentifiableObjectStore<OptionSet>
implements OptionStore
{
- @SuppressWarnings("unchecked")
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private JdbcTemplate jdbcTemplate;
+
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ // -------------------------------------------------------------------------
+ // Implementation methods
+ // -------------------------------------------------------------------------
+
@Override
public List<String> getOptions( int optionSetId, String key, Integer max )
{
- String hql = "select option from OptionSet os inner join os.options as option where os.id = :optionSetId";
-
+ String sql = "select optionvalue from optionset os inner join optionsetmembers as om on os.optionsetid=om.optionsetid "
+ + "where os.optionsetid=" + optionSetId;
if ( key != null )
{
- hql += " and lower(option) like lower('%" + key + "%') ";
+ sql += " and lower(om.optionvalue) like lower('%" + key + "%')";
}
-
- hql += " order by option";
-
- Query query = getQuery( hql );
- query.setInteger( "optionSetId", optionSetId );
-
+ sql += " order by sort_order";
+
if ( max != null )
{
- query.setMaxResults( max );
+ sql += " limit " + max;
}
- return query.list();
+ 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;
}
}
=== 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 2012-11-13 14:54:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2012-11-20 04:08:23 +0000
@@ -285,6 +285,7 @@
<bean id="org.hisp.dhis.option.OptionStore" class="org.hisp.dhis.option.hibernate.HibernateOptionStore">
<property name="clazz" value="org.hisp.dhis.option.OptionSet" />
<property name="sessionFactory" ref="sessionFactory" />
+ <property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.hisp.dhis.mapping.MapStore" class="org.hisp.dhis.mapping.hibernate.HibernateMapStore">