dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25135
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12393: fix for sqlview, support mixed case sql view names
------------------------------------------------------------
revno: 12393
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-10-02 15:49:44 +0200
message:
fix for sqlview, support mixed case sql view names
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.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/sqlview/SqlView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java 2013-09-11 16:52:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java 2013-10-02 13:49:44 +0000
@@ -28,16 +28,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-
import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
@@ -45,6 +39,11 @@
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
/**
* @author Dang Duy Hieu
*/
@@ -55,7 +54,7 @@
public static final String PREFIX_VIEWNAME = "_view";
private static final String CRITERIA_SEP = ":";
-
+
// -------------------------------------------------------------------------
// Variables
// -------------------------------------------------------------------------
@@ -88,23 +87,23 @@
final Pattern p = Pattern.compile( "\\W" );
String input = name;
-
+
String[] items = p.split( input.trim().replaceAll( "_", "" ) );
input = "";
for ( String s : items )
{
- input += s.isEmpty() ? "" : ( "_" + s );
+ input += s.isEmpty() ? "" : ("_" + s);
}
return PREFIX_VIEWNAME + input;
}
-
+
public static Map<String, String> getCriteria( Set<String> params )
{
Map<String, String> map = new HashMap<String, String>();
-
+
if ( params != null )
{
for ( String param : params )
@@ -114,7 +113,7 @@
String[] criteria = param.split( CRITERIA_SEP );
String filter = criteria[0];
String value = criteria[1];
-
+
if ( StringUtils.isAlphanumeric( filter ) && StringUtils.isAlphanumeric( value ) )
{
map.put( filter, value );
@@ -122,16 +121,16 @@
}
}
}
-
+
return map;
}
-
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getDescription()
{
@@ -144,7 +143,7 @@
}
@JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
+ @JsonView( { DetailedView.class, ExportView.class } )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public String getSqlQuery()
{
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java 2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java 2013-10-02 13:49:44 +0000
@@ -28,18 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.system.grid.ListGrid;
+import org.springframework.transaction.annotation.Transactional;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
-import org.hisp.dhis.common.Grid;
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.system.grid.ListGrid;
-import org.springframework.transaction.annotation.Transactional;
-
/**
* @author Dang Duy Hieu
* @version $Id DefaultSqlViewService.java July 06, 2010$
@@ -152,9 +152,9 @@
boolean success = true;
List<SqlView> sqlViews = new ArrayList<SqlView>( getAllSqlViews() );
-
+
Collections.sort( sqlViews, IdentifiableObjectNameComparator.INSTANCE );
-
+
for ( SqlView sqlView : sqlViews )
{
if ( createViewTable( sqlView ) != null )
@@ -198,10 +198,10 @@
public void dropAllSqlViewTables()
{
List<SqlView> views = sqlViewStore.getAllOrderedName();
-
+
Collections.sort( views, IdentifiableObjectNameComparator.INSTANCE );
Collections.reverse( views );
-
+
for ( SqlView view : views )
{
dropViewTable( view.getViewName() );
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java 2013-09-11 16:52:21 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java 2013-10-02 13:49:44 +0000
@@ -28,8 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Map;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.Grid;
@@ -41,6 +39,8 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
+import java.util.Map;
+
/**
* @author Dang Duy Hieu
* @version $Id JdbcSqlViewExpandStore.java July 06, 2010$
@@ -49,7 +49,7 @@
implements SqlViewExpandStore
{
private static final Log log = LogFactory.getLog( JdbcSqlViewExpandStore.class );
-
+
private static final String PREFIX_CREATEVIEW_QUERY = "CREATE VIEW ";
private static final String PREFIX_SELECT_QUERY = "SELECT * FROM ";
@@ -63,7 +63,7 @@
{
this.jdbcTemplate = jdbcTemplate;
}
-
+
private StatementBuilder statementBuilder;
public void setStatementBuilder( StatementBuilder statementBuilder )
@@ -80,8 +80,8 @@
{
try
{
- jdbcTemplate.queryForRowSet( "select * from " + statementBuilder.columnQuote( viewTableName.toLowerCase() ) + " limit 1" );
-
+ jdbcTemplate.queryForRowSet( "select * from " + statementBuilder.columnQuote( viewTableName ) + " limit 1" );
+
return true;
}
catch ( BadSqlGrammarException ex )
@@ -98,9 +98,9 @@
dropViewTable( viewName );
final String sql = PREFIX_CREATEVIEW_QUERY + statementBuilder.columnQuote( viewName ) + " AS " + sqlViewInstance.getSqlQuery();
-
+
log.debug( "Create view SQL: " + sql );
-
+
try
{
jdbcTemplate.execute( sql );
@@ -117,21 +117,21 @@
public void setUpDataSqlViewTable( Grid grid, String viewTableName, Map<String, String> criteria )
{
String sql = PREFIX_SELECT_QUERY + statementBuilder.columnQuote( viewTableName );
-
+
if ( criteria != null && !criteria.isEmpty() )
{
SqlHelper helper = new SqlHelper();
-
+
for ( String filter : criteria.keySet() )
{
sql += " " + helper.whereAnd() + " " + filter + "='" + criteria.get( filter ) + "'";
}
}
-
+
log.info( "Get view SQL: " + sql );
-
+
SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
-
+
grid.addHeaders( rs );
grid.addRows( rs );
}
@@ -142,9 +142,9 @@
String viewNameCheck = SqlView.PREFIX_VIEWNAME + System.currentTimeMillis();
sql = PREFIX_CREATEVIEW_QUERY + viewNameCheck + " AS " + sql;
-
+
log.debug( "Test view SQL: " + sql );
-
+
try
{
jdbcTemplate.execute( sql );