From f526d050946c14eeb678348075576932a857c9d6 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Thu, 24 Nov 2011 12:38:24 +0000 Subject: [PATCH] ALF-11370: ExportDbTest expects particular/PostgreSQL schema * Refactored to allow easier addition of DBMS-specific test implementation. * Added MySQL test implementation. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32271 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../Schema-Reference.xml | 472 +++++++++--------- .../alfresco/util/schemacomp/ExportDb.java | 47 +- .../util/schemacomp/ExportDbTest.java | 309 +----------- .../test/exportdb/AbstractExportTester.java | 97 ++++ .../exportdb/MySQLDialectExportTester.java | 283 +++++++++++ .../PostgreSQLDialectExportTester.java | 299 +++++++++++ 6 files changed, 952 insertions(+), 555 deletions(-) create mode 100644 source/java/org/alfresco/util/schemacomp/test/exportdb/AbstractExportTester.java create mode 100644 source/java/org/alfresco/util/schemacomp/test/exportdb/MySQLDialectExportTester.java create mode 100644 source/java/org/alfresco/util/schemacomp/test/exportdb/PostgreSQLDialectExportTester.java diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/Schema-Reference.xml b/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/Schema-Reference.xml index 8fd0cacdb7..9660d79af0 100644 --- a/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/Schema-Reference.xml +++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/Schema-Reference.xml @@ -4,31 +4,31 @@ - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIT + bit false - INT + int false - BIGINT + bigint true @@ -83,51 +83,51 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(36) false - BIT + bit false - BIGINT + bigint false - BIT + bit false - BIGINT + bigint true - INT + int false - BIGINT + bigint true - BIT + bit false - BIT + bit false - BIGINT + bigint true @@ -167,23 +167,23 @@
- BIGINT + bigint false - BIGINT + bigint false - TEXT + text true - TEXT + text true - TEXT + text true @@ -198,11 +198,11 @@
- BIGINT + bigint false - BIGINT + bigint true @@ -223,23 +223,23 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - INT + int false @@ -283,47 +283,47 @@
- BIGINT + bigint false - BIGINT + bigint true - DATETIME + datetime false - TEXT + text true - VARCHAR + varchar(255) true - VARCHAR + varchar(255) false - VARCHAR + varchar(10) true - VARCHAR + varchar(255) true - VARCHAR + varchar(36) true - VARCHAR + varchar(255) false - DATETIME + datetime false @@ -364,23 +364,23 @@
- BIGINT + bigint false - VARCHAR + varchar(255) false - VARCHAR + varchar(255) true - VARCHAR + varchar(36) true - DATETIME + datetime false @@ -401,43 +401,43 @@
- BIGINT + bigint false - DATETIME + datetime false - VARCHAR + varchar(10) false - TEXT + text false - VARCHAR + varchar(255) false - INT + int false - VARCHAR + varchar(255) true - VARCHAR + varchar(36) true - VARCHAR + varchar(255) false - DATETIME + datetime false @@ -463,47 +463,47 @@
- VARCHAR + varchar(64) false - TEXT + text true - INT + int true - INT + int true - INT + int true - INT + int true - DATETIME + datetime true - VARCHAR + varchar(64) true - BIT + bit true - BIT + bit true - TEXT + text true @@ -518,23 +518,23 @@
- BIGINT + bigint false - SMALLINT + smallint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false @@ -581,23 +581,23 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint true - BIGINT + bigint true @@ -649,15 +649,15 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false @@ -689,19 +689,19 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(100) true - BIGINT + bigint true @@ -728,19 +728,19 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false @@ -783,51 +783,51 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(50) false - BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(255) false - BIGINT + bigint false - BIT + bit true - INT + int true @@ -906,27 +906,27 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint true - BIGINT + bigint true - BIGINT + bigint true - BIGINT + bigint true @@ -983,27 +983,27 @@
- BIGINT + bigint false - VARCHAR + varchar(255) false - VARCHAR + varchar(12) false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint true @@ -1030,15 +1030,15 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(100) false @@ -1059,15 +1059,15 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(20) false @@ -1088,31 +1088,31 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(36) false - BIGINT + bigint false - BIGINT + bigint false @@ -1150,19 +1150,19 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(255) false @@ -1190,15 +1190,15 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(100) false @@ -1219,15 +1219,15 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(100) false @@ -1248,59 +1248,59 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(36) false - BIGINT + bigint false - BIT + bit false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint true - VARCHAR + varchar(255) true - VARCHAR + varchar(30) true - VARCHAR + varchar(255) true - VARCHAR + varchar(30) true - VARCHAR + varchar(30) true @@ -1378,11 +1378,11 @@
- BIGINT + bigint false - BIGINT + bigint false @@ -1420,27 +1420,27 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false @@ -1497,51 +1497,51 @@
- BIGINT + bigint false - INT + int false - INT + int false - BIT + bit true - BIGINT + bigint true - FLOAT + float true - DOUBLE + double true - TEXT + text true - BLOB + blob true - BIGINT + bigint false - INT + int false - BIGINT + bigint false @@ -1591,19 +1591,19 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(100) false @@ -1636,19 +1636,19 @@
- BIGINT + bigint false - VARCHAR + varchar(255) false - VARCHAR + varchar(32) false - BIGINT + bigint false @@ -1675,43 +1675,43 @@
- BIGINT + bigint false - SMALLINT + smallint false - TINYINT + tinyint false - TINYINT + tinyint false - TINYINT + tinyint false - TINYINT + tinyint false - TINYINT + tinyint false - SMALLINT + smallint false - TINYINT + tinyint false - TINYINT + tinyint false @@ -1734,11 +1734,11 @@
- BIGINT + bigint false - DOUBLE + double false @@ -1759,23 +1759,23 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false @@ -1826,11 +1826,11 @@
- BIGINT + bigint false - SMALLINT + smallint false @@ -1845,11 +1845,11 @@
- BIGINT + bigint false - BLOB + blob false @@ -1864,19 +1864,19 @@
- BIGINT + bigint false - TEXT + text false - VARCHAR + varchar(16) false - BIGINT + bigint false @@ -1903,27 +1903,27 @@
- BIGINT + bigint false - SMALLINT + smallint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint true @@ -1982,19 +1982,19 @@
- BIGINT + bigint false - BIGINT + bigint false - TINYINT + tinyint false - BIGINT + bigint false @@ -2022,19 +2022,19 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(200) false @@ -2067,15 +2067,15 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(39) false @@ -2096,23 +2096,23 @@
- BIGINT + bigint false - BIGINT + bigint false - VARCHAR + varchar(50) false - VARCHAR + varchar(100) false - BIGINT + bigint true @@ -2145,11 +2145,11 @@
- BIGINT + bigint false - BIGINT + bigint false @@ -2182,23 +2182,23 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint true - VARCHAR + varchar(56) false - BIGINT + bigint true @@ -2230,19 +2230,19 @@
- BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false - BIGINT + bigint false diff --git a/source/java/org/alfresco/util/schemacomp/ExportDb.java b/source/java/org/alfresco/util/schemacomp/ExportDb.java index 0925f776f1..1eec1b5641 100644 --- a/source/java/org/alfresco/util/schemacomp/ExportDb.java +++ b/source/java/org/alfresco/util/schemacomp/ExportDb.java @@ -37,7 +37,6 @@ import org.alfresco.util.schemacomp.model.Schema; import org.alfresco.util.schemacomp.model.Sequence; import org.alfresco.util.schemacomp.model.Table; import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.dialect.TypeNames; import org.springframework.context.ApplicationContext; @@ -130,7 +129,7 @@ public class ExportDb final Map forwardMap2 = (Map) defaultsField.get(typeNames); for (final Map.Entry e : forwardMap2.entrySet()) { - this.reverseTypeMap.put(e.getValue(), e.getKey()); + this.reverseTypeMap.put(e.getValue().toLowerCase(), e.getKey()); } final Field weightedField = TypeNames.class.getDeclaredField("weighted"); @@ -141,7 +140,7 @@ public class ExportDb { for (final String type : e.getValue().values()) { - this.reverseTypeMap.put(type, e.getKey()); + this.reverseTypeMap.put(type.toLowerCase(), e.getKey()); } } } @@ -378,27 +377,26 @@ public class ExportDb } - protected String generateType(final String dbType, int size, final int digits, int sqlType) + protected String generateType(final String dbTypeRaw, int size, final int digits, int sqlType) throws IllegalArgumentException, IllegalAccessException { - String dbName = dbType.toLowerCase() + "(" + size + ")"; - if (this.reverseTypeMap.containsKey(dbName)) + final String dbType = dbTypeRaw.toLowerCase(); + + final String sizeType = dbType + "(" + size + ")"; + if (this.reverseTypeMap.containsKey(sizeType)) { // the map may contain an exact match, e.g. "char(1)" - return dbName; + return sizeType; } - dbName = dbType.toLowerCase() + "(" + size + ", " + digits + ")"; - if (this.reverseTypeMap.containsKey(dbName)) + final String precisionScaleType = dbType + "(" + size + ", " + digits + ")"; + if (this.reverseTypeMap.containsKey(precisionScaleType)) { // the map may contain an exact match, e.g. "numeric(3, 1)" - return dbName; + return precisionScaleType; } else { - String precisionScaleType = dbType + "(" + size + ", " + digits + ")"; - String sizeType = dbType + "(" + size + ")"; - for (String key : reverseTypeMap.keySet()) { // Populate the placeholders, examples: @@ -451,27 +449,4 @@ public class ExportDb { this.namePrefix = namePrefix; } - - - public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException - { - ExportDb exportDb = null; - try - { - exportDb = new ExportDb(null, new PostgreSQLDialect()); - } - catch (Exception error) - { - throw new RuntimeException(error); - } - - if (exportDb != null) - { - String varchar = exportDb.generateType("varchar", 20, 0, 12); - System.out.println("varchar: " + varchar); - - String int4 = exportDb.generateType("int4", 20, 0, 4); - System.out.println("int4: " + int4); - } - } } diff --git a/source/java/org/alfresco/util/schemacomp/ExportDbTest.java b/source/java/org/alfresco/util/schemacomp/ExportDbTest.java index 814da82957..281a01540b 100644 --- a/source/java/org/alfresco/util/schemacomp/ExportDbTest.java +++ b/source/java/org/alfresco/util/schemacomp/ExportDbTest.java @@ -19,38 +19,30 @@ package org.alfresco.util.schemacomp; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; - -import java.util.Iterator; - import javax.sql.DataSource; import org.alfresco.util.ApplicationContextHelper; -import org.alfresco.util.schemacomp.model.Column; -import org.alfresco.util.schemacomp.model.DbObject; -import org.alfresco.util.schemacomp.model.ForeignKey; -import org.alfresco.util.schemacomp.model.Index; -import org.alfresco.util.schemacomp.model.PrimaryKey; import org.alfresco.util.schemacomp.model.Schema; -import org.alfresco.util.schemacomp.model.Sequence; -import org.alfresco.util.schemacomp.model.Table; +import org.alfresco.util.schemacomp.test.exportdb.AbstractExportTester; +import org.alfresco.util.schemacomp.test.exportdb.MySQLDialectExportTester; +import org.alfresco.util.schemacomp.test.exportdb.PostgreSQLDialectExportTester; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.PostgreSQLDialect; import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.TransactionCallbackWithoutResult; -import org.springframework.transaction.support.TransactionTemplate; /** - * Tests for the ExportDb class. + * Tests for the ExportDb class. Loads the database into an in-memory {@link Schema} representation. + *

+ * This test is DBMS specific, if the test is run on a system configured against MySQL for example, + * it will run MySQL specific tests. If there is no test available for the configured DBMS then + * the test will pass - this allows addition of new DBMS-specific tests when available. * * @author Matt Ward */ @@ -62,6 +54,9 @@ public class ExportDbTest private DataSource dataSource; private SimpleJdbcTemplate jdbcTemplate; private PlatformTransactionManager tx; + private AbstractExportTester exportTester; + private static final Log logger = LogFactory.getLog(ExportDbTest.class); + @Before public void setUp() throws Exception @@ -79,275 +74,23 @@ public class ExportDbTest @Test public void exportDb() throws Exception { - if (dialect.getClass().equals(PostgreSQLDialect.class)) + Class dialectClass = dialect.getClass(); + + if (logger.isInfoEnabled()) { - exportPostgreSQL(); + logger.info("Using dialect class " + dialectClass.getName()); } - } - - - private void exportPostgreSQL() throws Exception - { - setupPostgreSQL(); - - exporter.execute(); - - Schema schema = exporter.getSchema(); - - assertNull("Schema shouldn't have a parent", schema.getParent()); - System.out.println(schema); - - Table exampleTable = null; - Table otherTable = null; - Sequence exampleSeq = null; - - for (DbObject dbo : schema) - { - if (dbo.getName().equals("export_test_example")) - { - exampleTable = (Table) dbo; - } - if (dbo.getName().equals("export_test_other")) - { - otherTable = (Table) dbo; - } - if (dbo.getName().equals("export_test_example_seq")) - { - exampleSeq = (Sequence) dbo; - } - } - - checkResultsFiltered(schema, "export_test_"); - checkExampleTable(schema, exampleTable); - checkOtherTable(schema, otherTable); - checkExampleSequence(schema, exampleSeq); - } - - - private void setupPostgreSQL() - { - // Create database objects: this decouples test code from the actual schema which is - // free to change without breaking these tests. - final String[] createStatements = new String[] + if (PostgreSQLDialect.class.isAssignableFrom(dialectClass)) { - "DROP TABLE IF EXISTS export_test_example CASCADE", - "CREATE TABLE export_test_example" + - " (" + - " id INT8 NOT NULL," + - " description VARCHAR(1024)," + - " fixes_from_schema INT4," + - " fixes_to_schema INT4," + - " applied_to_schema INT4," + - " target_schema INT4," + - " applied_on_date TIMESTAMP," + - " applied_to_server VARCHAR(64)," + - " was_executed BOOL," + - " succeeded BOOL," + - " report VARCHAR(1024)," + - " PRIMARY KEY (id)" + - " )", - - "DROP TABLE IF EXISTS export_test_other CASCADE", - "CREATE TABLE export_test_other" + - " (" + - " id INT8 NOT NULL," + - " version INT8 NOT NULL," + - " ex_id INT8 NOT NULL," + - " local_name VARCHAR(200) NOT NULL," + - " CONSTRAINT export_test_fk_example FOREIGN KEY (ex_id) REFERENCES export_test_example (id)," + - " PRIMARY KEY (id)" + - " )", - - "DROP INDEX IF EXISTS export_test_idx_other_1", - "CREATE UNIQUE INDEX export_test_idx_other_1 ON export_test_other (ex_id, local_name)", - - "DROP INDEX IF EXISTS export_test_idx_other_2", - "CREATE INDEX export_test_idx_other_2 ON export_test_other (ex_id)", - - "DROP SEQUENCE IF EXISTS export_test_example_seq", - "CREATE SEQUENCE export_test_example_seq START WITH 1 INCREMENT BY 1" - }; - - TransactionTemplate tt = new TransactionTemplate(tx); - tt.execute(new TransactionCallbackWithoutResult() - { - @Override - protected void doInTransactionWithoutResult(TransactionStatus status) - { - for (String sql : createStatements) - { - jdbcTemplate.update(sql); - } - } - }); - } - - - /** - * Check that all top level database objects are prefixed as expected - * (no other objects should have been retrieved) - * - * @param schema - * @param prefix - */ - private void checkResultsFiltered(Schema schema, String prefix) - { - for (DbObject dbo : schema) - { - if (!dbo.getName().startsWith(prefix)) - { - fail("Database object's name does not start with '" + prefix + "': " + dbo); - } + exportTester = new PostgreSQLDialectExportTester(exporter, tx, jdbcTemplate); + } + else if (MySQLDialect.class.isAssignableFrom(dialectClass)) + { + exportTester = new MySQLDialectExportTester(exporter, tx, jdbcTemplate); } - } - - - private void checkOtherTable(Schema schema, Table otherTable) - { - assertNotNull("Couldn't find table export_test_other", otherTable); - assertSame("Incorrect parent or no parent set", schema, otherTable.getParent()); - Iterator colIt = otherTable.getColumns().iterator(); - Column col = colIt.next(); - assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); - assertEquals("id", col.getName()); - assertEquals("int8", col.getType()); - assertEquals(false, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); - assertEquals("version", col.getName()); - assertEquals("int8", col.getType()); - assertEquals(false, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); - assertEquals("ex_id", col.getName()); - assertEquals("int8", col.getType()); - assertEquals(false, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); - assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); - assertEquals("local_name", col.getName()); - assertEquals("varchar(200)", col.getType()); - assertEquals(false, col.isNullable()); - - assertEquals(2, otherTable.getIndexes().size()); - Iterator indexIt = otherTable.getIndexes().iterator(); - - Index index = indexIt.next(); - assertSame("Incorrect parent or no parent set", otherTable, index.getParent()); - assertEquals("export_test_idx_other_1", index.getName()); - assertEquals(true, index.isUnique()); - assertEquals(2, index.getColumnNames().size()); - assertEquals("ex_id", index.getColumnNames().get(0)); - assertEquals("local_name", index.getColumnNames().get(1)); - - index = indexIt.next(); - assertSame("Incorrect parent or no parent set", otherTable, index.getParent()); - assertEquals("export_test_idx_other_2", index.getName()); - assertEquals(1, index.getColumnNames().size()); - assertEquals("ex_id", index.getColumnNames().get(0)); - - PrimaryKey pk = otherTable.getPrimaryKey(); - assertSame("Incorrect parent or no parent set", otherTable, pk.getParent()); - assertEquals("id", pk.getColumnNames().get(0)); - - assertEquals(1, otherTable.getForeignKeys().size()); - ForeignKey fk = otherTable.getForeignKeys().get(0); - assertSame("Incorrect parent or no parent set", otherTable, fk.getParent()); - assertEquals("export_test_fk_example", fk.getName()); - assertEquals("ex_id", fk.getLocalColumn()); - assertEquals("export_test_example", fk.getTargetTable()); - assertEquals("id", fk.getTargetColumn()); - } - - - private void checkExampleTable(Schema schema, Table exampleTable) - { - assertNotNull("Couldn't find export_test_example", exampleTable); - - assertSame("Incorrect parent or no parent set", schema, exampleTable.getParent()); - assertEquals("export_test_example", exampleTable.getName()); - Iterator colIt = exampleTable.getColumns().iterator(); - Column col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("id", col.getName()); - assertEquals("int8", col.getType()); - assertEquals(false, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("description", col.getName()); - assertEquals("varchar(1024)", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("fixes_from_schema", col.getName()); - assertEquals("int4", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("fixes_to_schema", col.getName()); - assertEquals("int4", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("applied_to_schema", col.getName()); - assertEquals("int4", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("target_schema", col.getName()); - assertEquals("int4", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("applied_on_date", col.getName()); - assertEquals("timestamp", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("applied_to_server", col.getName()); - assertEquals("varchar(64)", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("was_executed", col.getName()); - assertEquals("bool", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("succeeded", col.getName()); - assertEquals("bool", col.getType()); - assertEquals(true, col.isNullable()); - - col = colIt.next(); - assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); - assertEquals("report", col.getName()); - assertEquals("varchar(1024)", col.getType()); - assertEquals(true, col.isNullable()); - - PrimaryKey pk = exampleTable.getPrimaryKey(); - assertSame("Incorrect parent or no parent set", exampleTable, pk.getParent()); - assertEquals("id", pk.getColumnNames().get(0)); - } - - - public void checkExampleSequence(Schema schema, Sequence seq) - { - assertNotNull("Couldn't find sequence", seq); - assertSame("Incorrect parent or no parent set", schema, seq.getParent()); - assertEquals("export_test_example_seq", seq.getName()); + // Run the DBMS specific tests. + exportTester.runExportTest(); } } diff --git a/source/java/org/alfresco/util/schemacomp/test/exportdb/AbstractExportTester.java b/source/java/org/alfresco/util/schemacomp/test/exportdb/AbstractExportTester.java new file mode 100644 index 0000000000..8c8b76ba80 --- /dev/null +++ b/source/java/org/alfresco/util/schemacomp/test/exportdb/AbstractExportTester.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.util.schemacomp.test.exportdb; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import org.alfresco.util.schemacomp.ExportDb; +import org.alfresco.util.schemacomp.model.DbObject; +import org.alfresco.util.schemacomp.model.Schema; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.transaction.PlatformTransactionManager; + +/** + * Base class for DBMS-specific ExportDb tests. + * + * @author Matt Ward + */ +public abstract class AbstractExportTester +{ + protected ExportDb exporter; + protected PlatformTransactionManager tx; + protected SimpleJdbcTemplate jdbcTemplate; + + + public AbstractExportTester(ExportDb exporter, PlatformTransactionManager tx, SimpleJdbcTemplate jdbcTemplate) + { + this.exporter = exporter; + this.tx = tx; + this.jdbcTemplate = jdbcTemplate; + } + + protected abstract void doExportTest() throws Exception; + + protected abstract void doDatabaseSetup(); + + public void runExportTest() throws Exception + { + doDatabaseSetup(); + exporter.execute(); + // Dump the schema for diagnostics + System.out.println(getSchema()); + commonPostExportChecks(); + doExportTest(); + } + + + /** + * Common checks that do not need to be coded into every test implementation. + * May be overridden if required. + */ + protected void commonPostExportChecks() + { + Schema schema = getSchema(); + assertNull("Schema shouldn't have a parent", getSchema().getParent()); + checkResultsFiltered(schema, "export_test_"); + } + + public Schema getSchema() + { + return exporter.getSchema(); + } + + /** + * Check that all top level database objects are prefixed as expected + * (no other objects should have been retrieved) + * + * @param schema + * @param prefix + */ + protected void checkResultsFiltered(Schema schema, String prefix) + { + for (DbObject dbo : schema) + { + if (!dbo.getName().startsWith(prefix)) + { + fail("Database object's name does not start with '" + prefix + "': " + dbo); + } + } + } +} diff --git a/source/java/org/alfresco/util/schemacomp/test/exportdb/MySQLDialectExportTester.java b/source/java/org/alfresco/util/schemacomp/test/exportdb/MySQLDialectExportTester.java new file mode 100644 index 0000000000..158a177847 --- /dev/null +++ b/source/java/org/alfresco/util/schemacomp/test/exportdb/MySQLDialectExportTester.java @@ -0,0 +1,283 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.util.schemacomp.test.exportdb; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; + +import java.util.Iterator; + +import org.alfresco.util.schemacomp.ExportDb; +import org.alfresco.util.schemacomp.model.Column; +import org.alfresco.util.schemacomp.model.DbObject; +import org.alfresco.util.schemacomp.model.ForeignKey; +import org.alfresco.util.schemacomp.model.Index; +import org.alfresco.util.schemacomp.model.PrimaryKey; +import org.alfresco.util.schemacomp.model.Schema; +import org.alfresco.util.schemacomp.model.Table; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.TransactionCallbackWithoutResult; +import org.springframework.transaction.support.TransactionTemplate; + +/** + * MySQL specific test for the ExportDb class. + * + * @author Matt Ward + */ +public class MySQLDialectExportTester extends AbstractExportTester +{ + /** + * Constructor. + * + * @param exporter + * @param tx + * @param jdbcTemplate + */ + public MySQLDialectExportTester(ExportDb exporter, PlatformTransactionManager tx, + SimpleJdbcTemplate jdbcTemplate) + { + super(exporter, tx, jdbcTemplate); + } + + + @Override + protected void doExportTest() throws Exception + { + Schema schema = getSchema(); + Table exampleTable = null; + Table otherTable = null; + + for (DbObject dbo : schema) + { + if (dbo.getName().equals("export_test_example")) + { + exampleTable = (Table) dbo; + } + if (dbo.getName().equals("export_test_other")) + { + otherTable = (Table) dbo; + } + } + + checkExampleTable(schema, exampleTable); + checkOtherTable(schema, otherTable); + } + + + + private void checkOtherTable(Schema schema, Table otherTable) + { + assertNotNull("Couldn't find table export_test_other", otherTable); + assertSame("Incorrect parent or no parent set", schema, otherTable.getParent()); + + Iterator colIt = otherTable.getColumns().iterator(); + Column col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("id", col.getName()); + assertEquals("bigint", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("version", col.getName()); + assertEquals("bigint", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("ex_id", col.getName()); + assertEquals("bigint", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("local_name", col.getName()); + assertEquals("varchar(200)", col.getType()); + assertEquals(false, col.isNullable()); + + assertEquals(2, otherTable.getIndexes().size()); + Iterator indexIt = otherTable.getIndexes().iterator(); + + Index index = indexIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, index.getParent()); + assertEquals("export_test_idx_other_1", index.getName()); + assertEquals(true, index.isUnique()); + assertEquals(2, index.getColumnNames().size()); + assertEquals("ex_id", index.getColumnNames().get(0)); + assertEquals("local_name", index.getColumnNames().get(1)); + + index = indexIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, index.getParent()); + assertEquals("export_test_idx_other_2", index.getName()); + assertEquals(1, index.getColumnNames().size()); + assertEquals("ex_id", index.getColumnNames().get(0)); + + PrimaryKey pk = otherTable.getPrimaryKey(); + assertSame("Incorrect parent or no parent set", otherTable, pk.getParent()); + assertEquals("id", pk.getColumnNames().get(0)); + + assertEquals(1, otherTable.getForeignKeys().size()); + ForeignKey fk = otherTable.getForeignKeys().get(0); + assertSame("Incorrect parent or no parent set", otherTable, fk.getParent()); + assertEquals("export_test_fk_example", fk.getName()); + assertEquals("ex_id", fk.getLocalColumn()); + assertEquals("export_test_example", fk.getTargetTable()); + assertEquals("id", fk.getTargetColumn()); + } + + + private void checkExampleTable(Schema schema, Table exampleTable) + { + assertNotNull("Couldn't find export_test_example", exampleTable); + + assertSame("Incorrect parent or no parent set", schema, exampleTable.getParent()); + assertEquals("export_test_example", exampleTable.getName()); + Iterator colIt = exampleTable.getColumns().iterator(); + Column col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("id", col.getName()); + assertEquals("bigint", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("description", col.getName()); + assertEquals("text", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("fixes_from_schema", col.getName()); + assertEquals("int", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("fixes_to_schema", col.getName()); + assertEquals("int", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("applied_to_schema", col.getName()); + assertEquals("int", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("target_schema", col.getName()); + assertEquals("int", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("applied_on_date", col.getName()); + assertEquals("datetime", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("applied_to_server", col.getName()); + assertEquals("varchar(64)", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("was_executed", col.getName()); + assertEquals("bit", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("succeeded", col.getName()); + assertEquals("bit", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("report", col.getName()); + assertEquals("text", col.getType()); + assertEquals(true, col.isNullable()); + + PrimaryKey pk = exampleTable.getPrimaryKey(); + assertSame("Incorrect parent or no parent set", exampleTable, pk.getParent()); + assertEquals("id", pk.getColumnNames().get(0)); + } + + + @Override + protected void doDatabaseSetup() + { + // Create database objects: this decouples test code from the actual schema which is + // free to change without breaking these tests. + + final String[] createStatements = new String[] + { + "DROP TABLE IF EXISTS export_test_other CASCADE", + "DROP TABLE IF EXISTS export_test_example CASCADE", + + "CREATE TABLE export_test_example" + + " (" + + " id BIGINT NOT NULL AUTO_INCREMENT," + + " description TEXT," + + " fixes_from_schema INTEGER," + + " fixes_to_schema INTEGER," + + " applied_to_schema INTEGER," + + " target_schema INTEGER," + + " applied_on_date DATETIME," + + " applied_to_server VARCHAR(64)," + + " was_executed BIT," + + " succeeded BIT," + + " report TEXT," + + " PRIMARY KEY (id)" + + " ) ENGINE=InnoDB", + + "CREATE TABLE export_test_other" + + " (" + + " id BIGINT NOT NULL AUTO_INCREMENT," + + " version BIGINT NOT NULL," + + " ex_id BIGINT NOT NULL," + + " local_name VARCHAR(200) NOT NULL," + + " CONSTRAINT export_test_fk_example FOREIGN KEY (ex_id) REFERENCES export_test_example (id)," + + " PRIMARY KEY (id)" + + " ) ENGINE=InnoDB", + + "CREATE UNIQUE INDEX export_test_idx_other_1 ON export_test_other (ex_id, local_name)", + + "CREATE INDEX export_test_idx_other_2 ON export_test_other (ex_id)" + }; + + TransactionTemplate tt = new TransactionTemplate(tx); + tt.execute(new TransactionCallbackWithoutResult() + { + @Override + protected void doInTransactionWithoutResult(TransactionStatus status) + { + for (String sql : createStatements) + { + jdbcTemplate.update(sql); + } + } + }); + } +} diff --git a/source/java/org/alfresco/util/schemacomp/test/exportdb/PostgreSQLDialectExportTester.java b/source/java/org/alfresco/util/schemacomp/test/exportdb/PostgreSQLDialectExportTester.java new file mode 100644 index 0000000000..d072167d17 --- /dev/null +++ b/source/java/org/alfresco/util/schemacomp/test/exportdb/PostgreSQLDialectExportTester.java @@ -0,0 +1,299 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.util.schemacomp.test.exportdb; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; + +import java.util.Iterator; + +import org.alfresco.util.schemacomp.ExportDb; +import org.alfresco.util.schemacomp.model.Column; +import org.alfresco.util.schemacomp.model.DbObject; +import org.alfresco.util.schemacomp.model.ForeignKey; +import org.alfresco.util.schemacomp.model.Index; +import org.alfresco.util.schemacomp.model.PrimaryKey; +import org.alfresco.util.schemacomp.model.Schema; +import org.alfresco.util.schemacomp.model.Sequence; +import org.alfresco.util.schemacomp.model.Table; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.TransactionCallbackWithoutResult; +import org.springframework.transaction.support.TransactionTemplate; + +/** + * Test implementation for the PostgreSQL database dialect. + * + * @author Matt Ward + */ +public class PostgreSQLDialectExportTester extends AbstractExportTester +{ + /** + * Constructor. + * + * @param exporter + * @param jdbcTemplate + * @param tx + */ + public PostgreSQLDialectExportTester(ExportDb exporter, PlatformTransactionManager tx, SimpleJdbcTemplate jdbcTemplate) + { + super(exporter, tx, jdbcTemplate); + } + + @Override + protected void doExportTest() throws Exception + { + Schema schema = getSchema(); + Table exampleTable = null; + Table otherTable = null; + Sequence exampleSeq = null; + + for (DbObject dbo : schema) + { + if (dbo.getName().equals("export_test_example")) + { + exampleTable = (Table) dbo; + } + if (dbo.getName().equals("export_test_other")) + { + otherTable = (Table) dbo; + } + if (dbo.getName().equals("export_test_example_seq")) + { + exampleSeq = (Sequence) dbo; + } + } + + checkExampleTable(schema, exampleTable); + checkOtherTable(schema, otherTable); + checkExampleSequence(schema, exampleSeq); + } + + + + private void checkOtherTable(Schema schema, Table otherTable) + { + assertNotNull("Couldn't find table export_test_other", otherTable); + assertSame("Incorrect parent or no parent set", schema, otherTable.getParent()); + + Iterator colIt = otherTable.getColumns().iterator(); + Column col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("id", col.getName()); + assertEquals("int8", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("version", col.getName()); + assertEquals("int8", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("ex_id", col.getName()); + assertEquals("int8", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertSame("Incorrect parent or no parent set", otherTable, col.getParent()); + assertEquals("local_name", col.getName()); + assertEquals("varchar(200)", col.getType()); + assertEquals(false, col.isNullable()); + + assertEquals(2, otherTable.getIndexes().size()); + Iterator indexIt = otherTable.getIndexes().iterator(); + + Index index = indexIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, index.getParent()); + assertEquals("export_test_idx_other_1", index.getName()); + assertEquals(true, index.isUnique()); + assertEquals(2, index.getColumnNames().size()); + assertEquals("ex_id", index.getColumnNames().get(0)); + assertEquals("local_name", index.getColumnNames().get(1)); + + index = indexIt.next(); + assertSame("Incorrect parent or no parent set", otherTable, index.getParent()); + assertEquals("export_test_idx_other_2", index.getName()); + assertEquals(1, index.getColumnNames().size()); + assertEquals("ex_id", index.getColumnNames().get(0)); + + PrimaryKey pk = otherTable.getPrimaryKey(); + assertSame("Incorrect parent or no parent set", otherTable, pk.getParent()); + assertEquals("id", pk.getColumnNames().get(0)); + + assertEquals(1, otherTable.getForeignKeys().size()); + ForeignKey fk = otherTable.getForeignKeys().get(0); + assertSame("Incorrect parent or no parent set", otherTable, fk.getParent()); + assertEquals("export_test_fk_example", fk.getName()); + assertEquals("ex_id", fk.getLocalColumn()); + assertEquals("export_test_example", fk.getTargetTable()); + assertEquals("id", fk.getTargetColumn()); + } + + + private void checkExampleTable(Schema schema, Table exampleTable) + { + assertNotNull("Couldn't find export_test_example", exampleTable); + + assertSame("Incorrect parent or no parent set", schema, exampleTable.getParent()); + assertEquals("export_test_example", exampleTable.getName()); + Iterator colIt = exampleTable.getColumns().iterator(); + Column col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("id", col.getName()); + assertEquals("int8", col.getType()); + assertEquals(false, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("description", col.getName()); + assertEquals("varchar(1024)", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("fixes_from_schema", col.getName()); + assertEquals("int4", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("fixes_to_schema", col.getName()); + assertEquals("int4", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("applied_to_schema", col.getName()); + assertEquals("int4", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("target_schema", col.getName()); + assertEquals("int4", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("applied_on_date", col.getName()); + assertEquals("timestamp", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("applied_to_server", col.getName()); + assertEquals("varchar(64)", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("was_executed", col.getName()); + assertEquals("bool", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("succeeded", col.getName()); + assertEquals("bool", col.getType()); + assertEquals(true, col.isNullable()); + + col = colIt.next(); + assertSame("Incorrect parent or no parent set", exampleTable, col.getParent()); + assertEquals("report", col.getName()); + assertEquals("varchar(1024)", col.getType()); + assertEquals(true, col.isNullable()); + + PrimaryKey pk = exampleTable.getPrimaryKey(); + assertSame("Incorrect parent or no parent set", exampleTable, pk.getParent()); + assertEquals("id", pk.getColumnNames().get(0)); + } + + + public void checkExampleSequence(Schema schema, Sequence seq) + { + assertNotNull("Couldn't find sequence", seq); + assertSame("Incorrect parent or no parent set", schema, seq.getParent()); + assertEquals("export_test_example_seq", seq.getName()); + } + + @Override + protected void doDatabaseSetup() + { + // Create database objects: this decouples test code from the actual schema which is + // free to change without breaking these tests. + + final String[] createStatements = new String[] + { + "DROP TABLE IF EXISTS export_test_example CASCADE", + "CREATE TABLE export_test_example" + + " (" + + " id INT8 NOT NULL," + + " description VARCHAR(1024)," + + " fixes_from_schema INT4," + + " fixes_to_schema INT4," + + " applied_to_schema INT4," + + " target_schema INT4," + + " applied_on_date TIMESTAMP," + + " applied_to_server VARCHAR(64)," + + " was_executed BOOL," + + " succeeded BOOL," + + " report VARCHAR(1024)," + + " PRIMARY KEY (id)" + + " )", + + "DROP TABLE IF EXISTS export_test_other CASCADE", + "CREATE TABLE export_test_other" + + " (" + + " id INT8 NOT NULL," + + " version INT8 NOT NULL," + + " ex_id INT8 NOT NULL," + + " local_name VARCHAR(200) NOT NULL," + + " CONSTRAINT export_test_fk_example FOREIGN KEY (ex_id) REFERENCES export_test_example (id)," + + " PRIMARY KEY (id)" + + " )", + + "DROP INDEX IF EXISTS export_test_idx_other_1", + "CREATE UNIQUE INDEX export_test_idx_other_1 ON export_test_other (ex_id, local_name)", + + "DROP INDEX IF EXISTS export_test_idx_other_2", + "CREATE INDEX export_test_idx_other_2 ON export_test_other (ex_id)", + + "DROP SEQUENCE IF EXISTS export_test_example_seq", + "CREATE SEQUENCE export_test_example_seq START WITH 1 INCREMENT BY 1" + }; + + TransactionTemplate tt = new TransactionTemplate(tx); + tt.execute(new TransactionCallbackWithoutResult() + { + @Override + protected void doInTransactionWithoutResult(TransactionStatus status) + { + for (String sql : createStatements) + { + jdbcTemplate.update(sql); + } + } + }); + } +}