dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22918
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11140: Fixed bug with IdentityPopulator
------------------------------------------------------------
revno: 11140
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-06-05 14:02:23 +0200
message:
Fixed bug with IdentityPopulator
modified:
dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.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/org/hisp/dhis/validation/hibernate/ValidationRuleGroup.hbm.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-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml 2013-02-07 10:25:34 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml 2013-06-05 12:02:23 +0000
@@ -8,7 +8,7 @@
<hibernate-mapping>
<class name="org.hisp.dhis.sqlview.SqlView" table="sqlview">
- <id name="id" column="viewid">
+ <id name="id" column="sqlviewid">
<generator class="native" />
</id>
&identifiableProperties;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2013-04-18 13:39:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2013-06-05 12:02:23 +0000
@@ -27,7 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.sql.SQLException;
+import java.util.Map;
import java.util.UUID;
import org.apache.commons.logging.Log;
@@ -47,13 +47,17 @@
{
private static final Log log = LogFactory.getLog( IdentityPopulator.class );
- private static String[] tables = { "chart", "constant", "concept", "attribute", "indicatortype", "indicatorgroupset", "indicator",
+ private static final String[] tables = { "chart", "constant", "concept", "attribute", "indicatortype", "indicatorgroupset", "indicator",
"indicatorgroup", "datadictionary", "validationrulegroup", "validationrule", "dataset", "orgunitlevel", "document",
"organisationunit", "orgunitgroup", "orgunitgroupset", "dataelementcategoryoption", "dataelementgroup", "sqlview",
"dataelement", "dataelementgroupset", "dataelementcategory", "categorycombo", "categoryoptioncombo", "map", "mapview",
"reporttable", "report", "messageconversation", "message", "userinfo", "usergroup", "userrole", "maplegend",
"maplegendset", "maplayer", "section", "optionset", "program", "programstage"
};
+
+ private static final Map<String, String> TABLE_ID_MAP = DimensionalObjectUtils.asMap(
+ "dataelementcategoryoption", "categoryoptionid",
+ "dataelementcategory", "categoryid" );
// -------------------------------------------------------------------------
// Dependencies
@@ -67,7 +71,7 @@
// -------------------------------------------------------------------------
public void execute()
- throws SQLException
+ throws Exception
{
for ( String table : tables )
{
@@ -82,7 +86,7 @@
while ( resultSet.next() )
{
++count;
- String idColumn = table + "id";
+ String idColumn = getIdColumn( table );
int id = resultSet.getInt( idColumn );
String sql = "update " + table + " set uid = '" + CodeGenerator.generateCode() + "' where " + idColumn + " = " + id;
jdbcTemplate.update( sql );
@@ -102,7 +106,7 @@
while ( resultSet.next() )
{
++count;
- String idColumn = table + "id";
+ String idColumn = getIdColumn( table );
int id = resultSet.getInt( idColumn );
String sql = "update " + table + " set lastupdated = '" + timestamp + "' where " + idColumn + " = " + id;
jdbcTemplate.update( sql );
@@ -120,7 +124,7 @@
while ( resultSet.next() )
{
++count;
- String idColumn = table + "id";
+ String idColumn = getIdColumn( table );
int id = resultSet.getInt( idColumn );
String sql = "update " + table + " set created = '" + timestamp + "' where " + idColumn + " = " + id;
jdbcTemplate.update( sql );
@@ -131,9 +135,11 @@
log.info( count + " timestamps set on " + table );
}
}
- catch ( BadSqlGrammarException ex )
+ catch ( Exception ex )
{
- log.error( "Problem updating " + table + ": ", ex );
+ log.error( "Problem updating: " + table + ", id column: " + getIdColumn( table ), ex );
+
+ throw ex;
}
}
@@ -148,6 +154,11 @@
log.debug( "Organisation unit uuids updated" );
}
+ private String getIdColumn( String table )
+ {
+ return TABLE_ID_MAP.containsKey( table ) ? TABLE_ID_MAP.get( table ) : ( table + "id" );
+ }
+
private void createUidConstraints()
{
for ( String table : tables )
=== 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 2013-05-23 12:00:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-06-05 12:02:23 +0000
@@ -576,6 +576,9 @@
executeSql( "ALTER TABLE dataelement ALTER COLUMN domaintype SET NOT NULL" );
executeSql( "update dataelementcategory set datadimension = false where datadimension is null" );
+ executeSql( "alter table validationrulegroup rename column validationgroupid to validationrulegroupid" );
+ executeSql( "alter table sqlview rename column viewid to sqlviewid" );
+
log.info( "Tables updated" );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/validation/hibernate/ValidationRuleGroup.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/validation/hibernate/ValidationRuleGroup.hbm.xml 2013-02-07 10:25:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/validation/hibernate/ValidationRuleGroup.hbm.xml 2013-06-05 12:02:23 +0000
@@ -10,7 +10,7 @@
<cache usage="read-write" />
- <id name="id" column="validationgroupid">
+ <id name="id" column="validationrulegroupid">
<generator class="native" />
</id>
&identifiableProperties;