commit 052515668c4468251ebdc93f6f70922ccd42b83e
Author: Andreas Müller <a.mueller@bgbm.org>
Date:   Mon Apr 18 14:10:50 2016 +0200

    Remove Autoincrement on AuditEvent.revisionnumber on MySQL #5718
    
     * Not yet tested for H2 and PostGreSQL

diff --git a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v36_40/SchemaUpdater_36_40.java b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v36_40/SchemaUpdater_36_40.java
index aeeec552de..63eb562f76 100644
--- a/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v36_40/SchemaUpdater_36_40.java
+++ b/cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v36_40/SchemaUpdater_36_40.java
@@ -16,9 +16,12 @@ import java.util.List;
 import org.apache.log4j.Logger;
 
 import eu.etaxonomy.cdm.database.update.ColumnAdder;
+import eu.etaxonomy.cdm.database.update.ColumnNameChanger;
+import eu.etaxonomy.cdm.database.update.ColumnRemover;
 import eu.etaxonomy.cdm.database.update.ISchemaUpdater;
 import eu.etaxonomy.cdm.database.update.ISchemaUpdaterStep;
 import eu.etaxonomy.cdm.database.update.SchemaUpdaterBase;
+import eu.etaxonomy.cdm.database.update.SimpleSchemaUpdaterStep;
 import eu.etaxonomy.cdm.database.update.v35_36.SchemaUpdater_35_36;
 
 /**
@@ -78,6 +81,34 @@ public class SchemaUpdater_36_40 extends SchemaUpdaterBase {
         step = ColumnAdder.NewStringInstance(stepName, tableName, newColumnName, INCLUDE_AUDIT);
         stepList.add(step);
 
+        //#5718
+        //Remove autoincrement from AuditEvent.revisionnumber
+        stepName = "Remove autoincrement from AuditEvent.revisionnumber";
+//        String query = "ALTER TABLE @@AuditEvent@@ ALTER revisionnumber DROP DEFAULT";
+//        step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
+//        stepList.add(step);
+        tableName = "AuditEvent";
+        oldColumnName = "revisionnumber";
+        newColumnName = "revisionnumberOld";
+        step = ColumnNameChanger.NewIntegerInstance(stepName, tableName, oldColumnName, newColumnName, ! INCLUDE_AUDIT);
+        stepList.add(step);
+
+        tableName = "AuditEvent";
+        String columnName = oldColumnName;
+        Integer defaultValue = null;
+        boolean notNull = true;
+        step = ColumnAdder.NewIntegerInstance(stepName, tableName, columnName, ! INCLUDE_AUDIT, defaultValue, notNull);
+        stepList.add(step);
+
+        String query = "UPDATE @@AuditEvent@@ SET revisionnumber = revisionnumberOld";
+        step = SimpleSchemaUpdaterStep.NewNonAuditedInstance(stepName, query, -99);
+        stepList.add(step);
+
+        step = ColumnRemover.NewInstance(stepName, tableName, newColumnName, ! INCLUDE_AUDIT);
+        stepList.add(step);
+
+
+
         return stepList;
 	}
 
diff --git a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestModelUpdate.java b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestModelUpdate.java
index 09fe931e22..c54bd8b407 100644
--- a/cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestModelUpdate.java
+++ b/cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestModelUpdate.java
@@ -1,151 +1,151 @@
-/**
-* Copyright (C) 2009 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.cdm.test.function;
-
-import org.apache.log4j.Logger;
-
-import eu.etaxonomy.cdm.api.application.CdmApplicationController;
-import eu.etaxonomy.cdm.common.AccountStore;
-import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
-import eu.etaxonomy.cdm.database.CdmDataSource;
-import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
-import eu.etaxonomy.cdm.database.DbSchemaValidation;
-import eu.etaxonomy.cdm.database.ICdmDataSource;
-import eu.etaxonomy.cdm.database.update.CdmUpdater;
-import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
-
-/**
- * This class is meant for functional testing of model changes. It is not meant
- * for running in maven.
- * @author a.mueller
- * @date 22.05.2015
- *
- */
-public class TestModelUpdate {
-	@SuppressWarnings("unused")
-	private static final Logger logger = Logger.getLogger(TestModelUpdate.class);
-
-
-	private void testSelectedDb(){
-		DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
-
-		DatabaseTypeEnum dbType = DatabaseTypeEnum.PostgreSQL;
-
-
-		String database = (schema == DbSchemaValidation.VALIDATE  ? "cdm35" : "cdm36");
-//		database = "cdm36";
-		CdmDataSource dataSource = getDatasource(dbType, database);
-
-
- 		try {
-			CdmUpdater updater = new CdmUpdater();
-			if (schema == DbSchemaValidation.VALIDATE){
-				updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-
-		CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource,schema);
-
-//		Classification classification = Classification.NewInstance("Me");
-//		Taxon taxon = Taxon.NewInstance(null, null);
-//		Person person = Person.NewInstance();
-//		TaxonNode node = classification.addChildTaxon(taxon, null, null);
-//		DefinedTerm lastScrutiny = (DefinedTerm)appCtr.getTermService().find(DefinedTerm.uuidLastScrutiny);
-//		TaxonNodeAgentRelation rel = node.addAgentRelation(lastScrutiny, person);
-//      appCtr.getClassificationService().save(classification);
-
-//		appCtr.getCommonService().createFullSampleData();
-
-
-
-		appCtr.close();
-	}
-
-
-
-/**
-     * @param dbType
-     * @param database
-     * @return
-     */
-    private CdmDataSource getDatasource(DatabaseTypeEnum dbType, String database) {
-        String server = "localhost";
-        String username = "edit";
-        String serverSql = "130.133.70.26";
-
-        if (dbType == DatabaseTypeEnum.MySQL){
-            return CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
-        }else if (dbType == DatabaseTypeEnum.H2){
-            //H2
-            String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database;
-            username = "sa";
-            CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path,   NomenclaturalCode.ICNAFP);
-            return dataSource;
-        }else if (dbType == DatabaseTypeEnum.SqlServer2005){
-            server = serverSql;
-            username = "cdmupdater";
-            CdmDataSource dataSource = CdmDataSource.NewSqlServer2005Instance(server, database, 1433, username, AccountStore.readOrStorePassword(server, database, username, null));
-            return dataSource;
-        }else if (dbType == DatabaseTypeEnum.PostgreSQL){
-            server = serverSql;
-            username = "postgres";
-            CdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(server, database, 5432, username,  AccountStore.readOrStorePassword(server, database, username, null), null);
-            return dataSource;
-        }else{
-            throw new IllegalArgumentException("dbType not supported:" + dbType);
-        }
-    }
-
-
-
-	/**
-	 * Updates the H2 test database in remote web-app.
-	 * Requires that the local path to the database is adapted
-	 */
-	@SuppressWarnings("unused")  //enable only if needed
-	private void updateRemoteWebappTestH2(){
-		String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
-		ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", "sa", "", path, NomenclaturalCode.ICNAFP);
-
-
- 		try {
-			CdmUpdater updater = new CdmUpdater();
-			updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-
-		//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
-		CdmApplicationController appCtr;
-		appCtr = CdmApplicationController.NewInstance(dataSource,DbSchemaValidation.VALIDATE);
-		appCtr.close();
-	}
-
-
-	private void test(){
-		System.out.println("Start Datasource");
-		testSelectedDb();
-
-//		updateRemoteWebappTestH2();
-
-		System.out.println("\nEnd Datasource");
-	}
-
-	/**
-	 * @param args
-	 */
-	public static void  main(String[] args) {
-		TestModelUpdate cc = new TestModelUpdate();
-    	cc.test();
-	}
-
-}
+/**
+* Copyright (C) 2009 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.test.function;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationController;
+import eu.etaxonomy.cdm.common.AccountStore;
+import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
+import eu.etaxonomy.cdm.database.CdmDataSource;
+import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
+import eu.etaxonomy.cdm.database.DbSchemaValidation;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.database.update.CdmUpdater;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+
+/**
+ * This class is meant for functional testing of model changes. It is not meant
+ * for running in maven.
+ * @author a.mueller
+ * @date 22.05.2015
+ *
+ */
+public class TestModelUpdate {
+	@SuppressWarnings("unused")
+	private static final Logger logger = Logger.getLogger(TestModelUpdate.class);
+
+
+	private void testSelectedDb(){
+		DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
+
+		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
+
+
+		String database = (schema == DbSchemaValidation.VALIDATE  ? "cdm36" : "cdm40");
+//		database = "cdm36";
+		CdmDataSource dataSource = getDatasource(dbType, database);
+
+
+ 		try {
+			CdmUpdater updater = new CdmUpdater();
+			if (schema == DbSchemaValidation.VALIDATE){
+				updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource,schema);
+
+//		Classification classification = Classification.NewInstance("Me");
+//		Taxon taxon = Taxon.NewInstance(null, null);
+//		Person person = Person.NewInstance();
+//		TaxonNode node = classification.addChildTaxon(taxon, null, null);
+//		DefinedTerm lastScrutiny = (DefinedTerm)appCtr.getTermService().find(DefinedTerm.uuidLastScrutiny);
+//		TaxonNodeAgentRelation rel = node.addAgentRelation(lastScrutiny, person);
+//      appCtr.getClassificationService().save(classification);
+
+//		appCtr.getCommonService().createFullSampleData();
+
+
+
+		appCtr.close();
+	}
+
+
+
+/**
+     * @param dbType
+     * @param database
+     * @return
+     */
+    private CdmDataSource getDatasource(DatabaseTypeEnum dbType, String database) {
+        String server = "localhost";
+        String username = "edit";
+        String serverSql = "130.133.70.26";
+
+        if (dbType == DatabaseTypeEnum.MySQL){
+            return CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
+        }else if (dbType == DatabaseTypeEnum.H2){
+            //H2
+            String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database;
+            username = "sa";
+            CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path,   NomenclaturalCode.ICNAFP);
+            return dataSource;
+        }else if (dbType == DatabaseTypeEnum.SqlServer2005){
+            server = serverSql;
+            username = "cdmupdater";
+            CdmDataSource dataSource = CdmDataSource.NewSqlServer2005Instance(server, database, 1433, username, AccountStore.readOrStorePassword(server, database, username, null));
+            return dataSource;
+        }else if (dbType == DatabaseTypeEnum.PostgreSQL){
+            server = serverSql;
+            username = "postgres";
+            CdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(server, database, 5432, username,  AccountStore.readOrStorePassword(server, database, username, null), null);
+            return dataSource;
+        }else{
+            throw new IllegalArgumentException("dbType not supported:" + dbType);
+        }
+    }
+
+
+
+	/**
+	 * Updates the H2 test database in remote web-app.
+	 * Requires that the local path to the database is adapted
+	 */
+	@SuppressWarnings("unused")  //enable only if needed
+	private void updateRemoteWebappTestH2(){
+		String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
+		ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", "sa", "", path, NomenclaturalCode.ICNAFP);
+
+
+ 		try {
+			CdmUpdater updater = new CdmUpdater();
+			updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
+		CdmApplicationController appCtr;
+		appCtr = CdmApplicationController.NewInstance(dataSource,DbSchemaValidation.VALIDATE);
+		appCtr.close();
+	}
+
+
+	private void test(){
+		System.out.println("Start Datasource");
+		testSelectedDb();
+
+//		updateRemoteWebappTestH2();
+
+		System.out.println("\nEnd Datasource");
+	}
+
+	/**
+	 * @param args
+	 */
+	public static void  main(String[] args) {
+		TestModelUpdate cc = new TestModelUpdate();
+    	cc.test();
+	}
+
+}
