← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1484: Improve startup routine for remove dataset column from dataentryform table.

 

------------------------------------------------------------
revno: 1484
committer: Viet <Viet@Viet-Laptop>
branch nick: trunk
timestamp: Wed 2010-02-24 17:47:43 +0530
message:
  Improve startup routine for remove dataset column from dataentryform table.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormPopulator.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientForm.vm


--
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/dataentryform/DataEntryFormPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormPopulator.java	2010-02-23 14:38:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormPopulator.java	2010-02-24 12:17:43 +0000
@@ -1,44 +1,60 @@
 package org.hisp.dhis.dataentryform;
 
+import java.sql.Statement;
+
 import org.amplecode.quick.StatementManager;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.dataelement.OptionsCategoriesDefaultSortOrderPopulator;
+import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
-
-public class DataEntryFormPopulator extends AbstractStartupRoutine {
-	private static final Log log = LogFactory
-			.getLog(OptionsCategoriesDefaultSortOrderPopulator.class);
-	private StatementManager statementManager;
-
-	public void setStatementManager(StatementManager statementManager) {
-		this.statementManager = statementManager;
-	}
-
-
-	public void execute() throws Exception {
-		
-		log.info("Update association between DataEntryForm table  and DataEntryFormAssociation table");
-		//      For mysql
-		//executeSql("alter table dataentryform drop foreign key fk_dataentryform_datasetid;");
-		
-		// 		For postgres
-		executeSql("alter table dataentryform drop constraint fk_dataentryform_datasetid;");
-
-		executeSql("insert into dataentryformassociation  select 'dataset', datasetid, dataentryformid from dataentryform ; ");
-		executeSql("alter table dataentryform drop column datasetid;");
-		
-		log.info("Finished Update association between DataEntryForm table  and DataEntryFormAssociation table");
-
-	}
-
-	private int executeSql(String sql) {
-		try {
-			return statementManager.getHolder().getStatement().executeUpdate(sql);
-		} catch (Exception ex) {
-			log.debug(ex);
-			return -1;
-		}
-	}
+import org.springframework.transaction.annotation.Transactional;
+
+public class DataEntryFormPopulator
+    extends AbstractStartupRoutine
+{
+    private static final Log log = LogFactory.getLog( DataEntryFormPopulator.class );
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private StatementManager statementManager;
+
+    public void setStatementManager( StatementManager statementManager )
+    {
+        this.statementManager = statementManager;
+    }
+    
+    private StatementBuilder statementBuilder;
+    
+    public void setStatementBuilder( StatementBuilder statementBuilder )
+    {
+        this.statementBuilder = statementBuilder;
+    }
+
+    // -------------------------------------------------------------------------
+    // Execute
+    // -------------------------------------------------------------------------
+    
+    @Transactional
+    public void execute()
+        throws Exception
+    {
+        log.info( "Remove datasetid column from dataentryform table" );
+        Statement stmnt = statementManager.getHolder().getStatement();
+        try
+        {
+            stmnt.executeUpdate(  statementBuilder.getDropDatasetForeignKeyForDataEntryFormTable() );
+            stmnt.executeUpdate( "INSERT INTO dataentryformassociation  SELECT 'dataset', datasetid, dataentryformid FROM dataentryform;" );
+            stmnt.executeUpdate( "ALTER TABLE dataentryform DROP COLUMN datasetid;" );
+        }
+        catch ( Exception ex )
+        {
+            log.error( ex );
+        }
+    }
+
+
+    
 
 }

=== 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	2010-02-23 17:10:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2010-02-24 12:17:43 +0000
@@ -398,6 +398,7 @@
   <bean id="org.hisp.dhis.dataentryform.DataEntryFormPopulator"
     class="org.hisp.dhis.dataentryform.DataEntryFormPopulator">
   	<property name="statementManager" ref="statementManager"/>
+  	<property name="statementBuilder" ref="statementBuilder"/>
     <property name="runlevel" value="1"/>
   </bean>
 	

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java	2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java	2010-02-24 12:17:43 +0000
@@ -91,4 +91,12 @@
      * @return the maximum number of columns in a table.
      */
     int getMaximumNumberOfColumns();
+    
+    /**
+     *  
+     *  Drop Dataset foreign key for DataEntryForm table
+     *  
+     * @return
+     */
+    String getDropDatasetForeignKeyForDataEntryFormTable();
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/DerbyStatementBuilder.java	2010-02-24 12:17:43 +0000
@@ -128,4 +128,9 @@
     {
         return 1200; //TODO verify
     }
+
+    public String getDropDatasetForeignKeyForDataEntryFormTable()
+    {
+        return "ALTER TABLE dataentryform DROP FOREIGN KEY fk_dataentryform_datasetid;" ;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java	2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java	2010-02-24 12:17:43 +0000
@@ -126,4 +126,9 @@
     {
         return 1580; // TODO verify
     }
+
+    public String getDropDatasetForeignKeyForDataEntryFormTable()
+    {
+        return  "ALTER TABLE dataentryform DROP CONSTRAINT fk_dataentryform_datasetid;";
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java	2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java	2010-02-24 12:17:43 +0000
@@ -128,4 +128,9 @@
     {
         return 720;
     }
+
+    public String getDropDatasetForeignKeyForDataEntryFormTable()
+    {
+        return  "ALTER TABLE dataentryform DROP FOREIGN KEY fk_dataentryform_datasetid;" ;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java	2010-02-24 12:17:43 +0000
@@ -128,4 +128,9 @@
     {
         return 1580; // TODO verify
     }
+
+    public String getDropDatasetForeignKeyForDataEntryFormTable()
+    {
+        return  "ALTER TABLE dataentryform DROP CONSTRAINT fk_dataentryform_datasetid;" ;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientForm.vm	2010-02-23 14:38:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/addPatientForm.vm	2010-02-24 12:17:43 +0000
@@ -53,8 +53,9 @@
 	<tr>
 		<td><label for="gender">$i18n.getString( "gender" )<em title="$i18n.getString( "required" )" class="required">*</em></label></td>
 		<td>
-			<select id="gender" name="gender" style="min-width:20em">
-				<option value="M" selected="selected">$i18n.getString( "male" )</option>
+			<select id="gender" name="gender" style="min-width:20em" class="{validate:{required:true}}">
+				<option value="" selected="selected">[$i18n.getString( "please_select" )]</option>
+				<option value="M" >$i18n.getString( "male" )</option>
 				<option value="F">$i18n.getString( "female" )</option>
 			</select>
 		</td>