dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06864
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1915: Persits and regenerate Views - Improving - working in process...
------------------------------------------------------------
revno: 1915
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-08-11 15:38:22 +0700
message:
Persits and regenerate Views - Improving - working in process...
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.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/hibernate/HibernateSqlViewExpandStore.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addSqlViewForm.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/sqlView.js
--
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 2010-07-16 08:26:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java 2010-08-11 08:38:22 +0000
@@ -156,7 +156,7 @@
@Override
public String toString()
{
- return "[ Name: " + name + ", sqlQuery: " + sqlQuery + " ]";
+ return "[ Name: " + name + ",\n\n sqlQuery: " + sqlQuery + " ]";
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.java 2010-08-09 03:57:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.java 2010-08-11 08:38:22 +0000
@@ -21,4 +21,6 @@
void setUpDataSqlViewTable( SqlViewTable sqlViewTable, String viewTableName );
Collection<String> getAllResourceProperties( String resourceTableName );
+
+ String testSqlGrammar( String sql );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java 2010-08-09 03:57:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java 2010-08-11 08:38:22 +0000
@@ -64,8 +64,10 @@
Collection<String> getAllSqlViewNames();
boolean isViewTableExists( String viewTableName );
-
+
SqlViewTable getDataSqlViewTable( String viewTableName );
-
+
Collection<String> getAllResourceProperties( String resourceTableName );
+
+ String testSqlGrammar( String sql );
}
=== 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 2010-08-09 03:57:18 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java 2010-08-11 08:38:22 +0000
@@ -157,4 +157,10 @@
return sqlViewExpandStore.getAllResourceProperties( resourceTableName );
}
+ @Override
+ public String testSqlGrammar( String sql )
+ {
+ return sqlViewExpandStore.testSqlGrammar( sql );
+ }
+
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/hibernate/HibernateSqlViewExpandStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/hibernate/HibernateSqlViewExpandStore.java 2010-08-09 03:57:18 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/hibernate/HibernateSqlViewExpandStore.java 2010-08-11 08:38:22 +0000
@@ -42,6 +42,8 @@
import org.hisp.dhis.sqlview.SqlViewExpandStore;
import org.hisp.dhis.sqlview.SqlViewTable;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.BadSqlGrammarException;
+import org.springframework.jdbc.core.JdbcTemplate;
/**
* @author Dang Duy Hieu
@@ -64,6 +66,9 @@
@Autowired
private StatementManager statementManager;
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
// -------------------------------------------------------------------------
// Implementing methods
// -------------------------------------------------------------------------
@@ -152,7 +157,7 @@
try
{
- ResultSet rs = holder.getStatement().executeQuery( "SELECT * FROM " + resourceTableName + " LIMIT 1");
+ ResultSet rs = holder.getStatement().executeQuery( "SELECT * FROM " + resourceTableName + " LIMIT 1" );
ResultSetMetaData rsmd = rs.getMetaData();
int countCols = rsmd.getColumnCount();
@@ -175,6 +180,24 @@
return propertiesName;
}
+ @Override
+ public String testSqlGrammar( String sql )
+ {
+ String errorMessage = "";
+
+ try
+ {
+ jdbcTemplate.queryForList( sql );
+ }
+ catch ( BadSqlGrammarException bge )
+ {
+ errorMessage = setUpMessage( bge.getRootCause().toString() );
+ return errorMessage;
+ }
+
+ return errorMessage;
+ }
+
// -------------------------------------------------------------------------
// Supporting methods
// -------------------------------------------------------------------------
@@ -196,4 +219,14 @@
return stm.getResultSet();
}
+ private String setUpMessage( String input )
+ {
+ input = "<span style='color:red;font-size:13px;font-weight:bold;font-style:italic;'>"
+ + input.replaceFirst( "(?i)\\s*error:", "</span><br/><br/><b>ERROR:</b>" )
+ .replaceFirst( "(?i)\\s*hint:", "<br/><b>HINT:</b>" )
+ .replaceFirst( "(?i)\\s*Position:", "<br/><b>POSITION:</b>" );
+
+ return input;
+ }
+
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java 2010-07-19 15:20:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java 2010-08-11 08:38:22 +0000
@@ -42,8 +42,7 @@
* Updates a existing sqlview to the database.
*
* @author Dang Duy Hieu
- * @version $Id$
- * @since 2010-07-06
+ * @version $Id ExecuteSqlViewQueryAction.java July 06, 2010$
*/
public class ExecuteSqlViewQueryAction
extends ActionSupport
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.java 2010-07-19 15:20:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ValidateAddUpdateSqlViewAction.java 2010-08-11 08:38:22 +0000
@@ -138,13 +138,20 @@
if ( !s.matches( REGEX_SELECT_QUERY ) || s.toLowerCase().contains( REGEX_SELECT_INTO_QUERY ) )
{
message = i18n.getString( "sqlquery_is_invalid" )
- + "<br/><span style=\"color:blue;font-weight:bold;font-style:italic;\">"
+ + "<br/><span style='color:blue;font-weight:bold;font-style:italic;'>"
+ i18n.getString( "sqlquery_is_welformed" ) + "</span>";
return INPUT;
}
}
+ message = sqlViewService.testSqlGrammar( sqlquery );
+
+ if ( !message.equals( "" ) )
+ {
+ return INPUT;
+ }
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml 2010-08-09 03:57:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml 2010-08-11 08:38:22 +0000
@@ -467,8 +467,9 @@
<param name="page">
/dhis-web-maintenance-dataadmin/showDataSqlViewForm.vm</param>
<param name="javascripts">javascript/sqlView.js
- ,../dhis-web-commons/util/validate/jquery.validate.js,../dhis-web-commons/util/jquery.metadata.js
- ,../dhis-web-commons/util/validate/additional-methods.js,../dhis-web-commons/validationMessages.action</param>
+ ,../dhis-web-commons/util/validate/jquery.validate.js
+ ,../dhis-web-commons/util/validate/additional-methods.js
+ ,../dhis-web-commons/validationMessages.action</param>
<param name="requiredAuthorities">F_SQLVIEW_MANAGEMENT</param>
</action>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addSqlViewForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addSqlViewForm.vm 2010-08-09 03:57:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addSqlViewForm.vm 2010-08-11 08:38:22 +0000
@@ -16,11 +16,12 @@
jQuery.validator.setMessages( validationMessage );
jQuery("#name").focus();
+ hideById("mainDesignQueryDiv");
initHtml(i18n_resourcetables, i18n_sorttypes);
initField("resource-table-combo1", "sort-property-combo1");
applyAutocompleteSupporting(jQuery.merge(criteria_clone, keywords), "sqlquery", $("#sqlquery").width() );
- applyAutocompleteSupporting(criteria_operators, "criteria_and_property1", $("#criteria_and_property1").width()+50 );
- applyAutocompleteSupporting(criteria_operators, "criteria_or_property1", $("#criteria_or_property1").width()+50 );
+ applyAutocompleteSupporting(criteria_operators, "criteria_and_property1", 225 );
+ applyAutocompleteSupporting(criteria_operators, "criteria_or_property1", 225 );
});
</script>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/sqlView.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/sqlView.js 2010-08-09 03:57:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/sqlView.js 2010-08-11 08:38:22 +0000
@@ -528,9 +528,9 @@
var curValue = $("#sqlquery").val().trim();
var result = selectQuery + "\n" + fromQuery + "\n";
result += (whereQuery == "WHERE ") == true ? "" : whereQuery + "\n";
+ result += (groupbyQuery == "GROUP BY ") == true ? "" : groupbyQuery + "\n";
+ result += (havingbyQuery == "HAVING ") == true ? "" : havingbyQuery + "\n";
result += (sortQuery == "ORDER BY ") == true ? "" : sortQuery + "\n";
- result += (havingbyQuery == "HAVING ") == true ? "" : havingbyQuery + "\n";
- result += (groupbyQuery == "GROUP BY ") == true ? "" : groupbyQuery + "\n";
if ( curValue != "SELECT" )
{
@@ -590,8 +590,8 @@
}
initField( resourceComboId+columnIndex, sortComboId+columnIndex );
- applyAutocompleteSupporting( criteria_operators, criteriaANDFieldId+columnIndex, $("#"+criteriaANDFieldId+columnIndex).width()+50 );
- applyAutocompleteSupporting( criteria_operators, criteriaORFieldId+columnIndex, $("#"+criteriaORFieldId+columnIndex).width()+50 );
+ applyAutocompleteSupporting( criteria_operators, criteriaANDFieldId+columnIndex, 225 );
+ applyAutocompleteSupporting( criteria_operators, criteriaORFieldId+columnIndex, 225 );
}
function getIndexById( elementId )