|
From: <fg...@us...> - 2008-06-11 21:26:37
|
Revision: 837
http://openutils.svn.sourceforge.net/openutils/?rev=837&view=rev
Author: fgiust
Date: 2008-06-11 14:25:54 -0700 (Wed, 11 Jun 2008)
Log Message:
-----------
[maven-release-plugin] copy for tag openutils-dbmigration-2.0.4
Added Paths:
-----------
tags/openutils-dbmigration-2.0.4/
tags/openutils-dbmigration-2.0.4/pom.xml
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/site/changes/changes.xml
Removed Paths:
-------------
tags/openutils-dbmigration-2.0.4/pom.xml
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java
tags/openutils-dbmigration-2.0.4/src/site/changes/changes.xml
Copied: tags/openutils-dbmigration-2.0.4 (from rev 824, trunk/openutils-dbmigration)
Deleted: tags/openutils-dbmigration-2.0.4/pom.xml
===================================================================
--- trunk/openutils-dbmigration/pom.xml 2008-05-07 12:57:08 UTC (rev 824)
+++ tags/openutils-dbmigration-2.0.4/pom.xml 2008-06-11 21:25:54 UTC (rev 837)
@@ -1,96 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>net.sourceforge.openutils</groupId>
- <artifactId>openutils</artifactId>
- <version>8</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>openutils-dbmigration</artifactId>
- <name>openutils db migration</name>
- <version>2.0.4-SNAPSHOT</version>
- <description />
- <dependencies>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.3</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>1.3</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>${spring.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>${spring.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${spring.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl104-over-slf4j</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi</artifactId>
- <version>3.0-FINAL</version>
- <optional>true</optional>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <classifier>jdk15</classifier>
- <version>5.1</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- </dependencies>
- <properties>
- <spring.version>2.5.1</spring.version>
- </properties>
-</project>
\ No newline at end of file
Copied: tags/openutils-dbmigration-2.0.4/pom.xml (from rev 836, trunk/openutils-dbmigration/pom.xml)
===================================================================
--- tags/openutils-dbmigration-2.0.4/pom.xml (rev 0)
+++ tags/openutils-dbmigration-2.0.4/pom.xml 2008-06-11 21:25:54 UTC (rev 837)
@@ -0,0 +1,102 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sourceforge.openutils</groupId>
+ <artifactId>openutils</artifactId>
+ <version>8</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>openutils-dbmigration</artifactId>
+ <name>openutils db migration</name>
+ <version>2.0.4</version>
+ <description />
+ <dependencies>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${spring.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${spring.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl104-over-slf4j</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.poi</groupId>
+ <artifactId>poi</artifactId>
+ <version>3.0-FINAL</version>
+ <optional>true</optional>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <classifier>jdk15</classifier>
+ <version>5.1</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <properties>
+ <spring.version>2.5.1</spring.version>
+ </properties>
+
+ <scm>
+ <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.4</connection>
+ <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-dbmigration-2.0.4</developerConnection>
+ <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-dbmigration-2.0.4</url>
+ </scm>
+</project>
\ No newline at end of file
Deleted: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java
===================================================================
--- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java 2008-05-07 12:57:08 UTC (rev 824)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -1,178 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.migration.generic;
-
-import it.openutils.migration.task.setup.BaseConditionalTask;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.ConnectionCallback;
-import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-
-
-/**
- * Base conditional task that operates on conditions related to a specific column. This base task takes care of
- * retrieving the column metadata, so that subclasses only need to override <code>checkColumnMetadata()</code>.
- * @author fgiust
- * @version $Id$
- */
-public abstract class JdbcColumnBasedConditionalTask extends BaseConditionalTask
-{
-
- /**
- * Column name
- */
- protected String column;
-
- /**
- * Catalog name
- */
- protected String catalog;
-
- /**
- * Schema name
- */
- protected String schema;
-
- /**
- * Sets the catalog.
- * @param catalog the catalog to set
- */
- public void setCatalog(String catalog)
- {
- this.catalog = catalog;
- }
-
- /**
- * Sets the schema.
- * @param schema the schema to set
- */
- public void setSchema(String schema)
- {
- this.schema = schema;
- }
-
- /**
- * Sets the column.
- * @param column the column to set
- */
- public void setColumn(String column)
- {
- this.column = column;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean check(SimpleJdbcTemplate jdbcTemplate)
- {
-
- String columnTrim = StringUtils.trim(column);
-
- final String tableName = StringUtils.substringBefore(columnTrim, ".");
- final String columnName = StringUtils.substringAfter(columnTrim, ".");
- return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback()
- {
-
- public Object doInConnection(Connection con) throws SQLException, DataAccessException
- {
- DatabaseMetaData dbMetadata = con.getMetaData();
- ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName);
- boolean conditionMet = rs.next();
- if (conditionMet)
- {
- ResultSetMetaData rsmeta = rs.getMetaData();
- int colcount = rsmeta.getColumnCount();
- Map<String, Object> params = new HashMap<String, Object>();
- for (int j = 1; j <= colcount; j++)
- {
- params.put(rsmeta.getColumnName(j), rs.getObject(j));
- }
- conditionMet = !checkColumnMetadata(params);
- }
- rs.close();
- return conditionMet;
- }
- });
- }
-
- /**
- * <p>
- * Check if a specific condition is met depending on column metadata.
- * </p>
- * Column attributes included in the Map are:
- * <ol>
- * <li><strong>TABLE_CAT</strong> String => table catalog (may be <code>null</code>)</li>
- * <li><strong>TABLE_SCHEM</strong> String => table schema (may be <code>null</code>)</li>
- * <li><strong>TABLE_NAME</strong> String => table name</li>
- * <li><strong>COLUMN_NAME</strong> String => column name</li>
- * <li><strong>DATA_TYPE</strong> int => SQL type from java.sql.Types</li>
- * <li><strong>TYPE_NAME</strong> String => Data source dependent type name, for a UDT the type name is fully
- * qualified</li>
- * <li><strong>COLUMN_SIZE</strong> int => column size.</li>
- * <li><strong>BUFFER_LENGTH</strong> is not used.</li>
- * <li><strong>DECIMAL_DIGITS</strong> int => the number of fractional digits. Null is returned for data types
- * where DECIMAL_DIGITS is not applicable.</li>
- * <li><strong>NUM_PREC_RADIX</strong> int => Radix (typically either 10 or 2)</li>
- * <li><strong>NULLABLE</strong> int => is NULL allowed.</li>
- * <ul>
- * <li> columnNoNulls - might not allow <code>NULL</code> values</li>
- * <li> columnNullable - definitely allows <code>NULL</code> values</li>
- * <li> columnNullableUnknown - nullability unknown</li>
- * </ul>
- * <li><strong>REMARKS</strong> String => comment describing column (may be <code>null</code>)</li>
- * <li><strong>COLUMN_DEF</strong> String => default value for the column, which should be interpreted as a string
- * when the value is enclosed in single quotes (may be <code>null</code>)</li>
- * <li><strong>SQL_DATA_TYPE</strong> int => unused</li>
- * <li><strong>SQL_DATETIME_SUB</strong> int => unused</li>
- * <li><strong>CHAR_OCTET_LENGTH</strong> int => for char types the maximum number of bytes in the column</li>
- * <li><strong>ORDINAL_POSITION</strong> int => index of column in table (starting at 1)</li>
- * <li><strong>IS_NULLABLE</strong> String => ISO rules are used to determine the nullability for a column.</li>
- * <ul>
- * <li> YES --- if the parameter can include NULLs</li>
- * <li> NO --- if the parameter cannot include NULLs</li>
- * <li> empty string --- if the nullability for the parameter is unknown</li>
- * </ul>
- * <li><strong>SCOPE_CATLOG</strong> String => catalog of table that is the scope of a reference attribute (<code>null</code>
- * if DATA_TYPE isn't REF)</li>
- * <li><strong>SCOPE_SCHEMA</strong> String => schema of table that is the scope of a reference attribute (<code>null</code>
- * if the DATA_TYPE isn't REF)</li>
- * <li><strong>SCOPE_TABLE</strong> String => table name that this the scope of a reference attribure (<code>null</code>
- * if the DATA_TYPE isn't REF)</li>
- * <li><strong>SOURCE_DATA_TYPE</strong> short => source type of a distinct type or user-generated Ref type, SQL
- * type from java.sql.Types (<code>null</code> if DATA_TYPE isn't DISTINCT or user-generated REF)</li>
- * <li><strong>IS_AUTOINCREMENT</strong> String => Indicates whether this column is auto incremented</li>
- * <ul>
- * <li> YES --- if the column is auto incremented</li>
- * <li> NO --- if the column is not auto incremented</li>
- * <li> empty string --- if it cannot be determined whether the column is auto incremented parameter is unknown</li>
- * </ul>
- * </ol>
- * @param metadata column metadata
- * @return <code>true</code> if the condition is met
- */
- protected abstract boolean checkColumnMetadata(Map<String, Object> metadata);
-
-}
Copied: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java (from rev 834, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java)
===================================================================
--- tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java (rev 0)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcColumnBasedConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -0,0 +1,178 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.migration.generic;
+
+import it.openutils.migration.task.setup.BaseConditionalTask;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.ConnectionCallback;
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+
+
+/**
+ * Base conditional task that operates on conditions related to a specific column. This base task takes care of
+ * retrieving the column metadata, so that subclasses only need to override <code>checkColumnMetadata()</code>.
+ * @author fgiust
+ * @version $Id$
+ */
+public abstract class JdbcColumnBasedConditionalTask extends BaseConditionalTask
+{
+
+ /**
+ * Column name
+ */
+ protected String column;
+
+ /**
+ * Catalog name
+ */
+ protected String catalog;
+
+ /**
+ * Schema name
+ */
+ protected String schema;
+
+ /**
+ * Sets the catalog.
+ * @param catalog the catalog to set
+ */
+ public void setCatalog(String catalog)
+ {
+ this.catalog = catalog;
+ }
+
+ /**
+ * Sets the schema.
+ * @param schema the schema to set
+ */
+ public void setSchema(String schema)
+ {
+ this.schema = schema;
+ }
+
+ /**
+ * Sets the column.
+ * @param column the column to set
+ */
+ public void setColumn(String column)
+ {
+ this.column = column;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean check(SimpleJdbcTemplate jdbcTemplate)
+ {
+
+ String columnTrim = StringUtils.trim(column);
+
+ final String tableName = StringUtils.substringBefore(columnTrim, ".");
+ final String columnName = StringUtils.substringAfter(columnTrim, ".");
+ return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback()
+ {
+
+ public Object doInConnection(Connection con) throws SQLException, DataAccessException
+ {
+ DatabaseMetaData dbMetadata = con.getMetaData();
+ ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName);
+ boolean conditionMet = rs.next();
+ if (conditionMet)
+ {
+ ResultSetMetaData rsmeta = rs.getMetaData();
+ int colcount = rsmeta.getColumnCount();
+ Map<String, Object> params = new HashMap<String, Object>();
+ for (int j = 1; j <= colcount; j++)
+ {
+ params.put(rsmeta.getColumnName(j), rs.getObject(j));
+ }
+ conditionMet = checkColumnMetadata(params);
+ }
+ rs.close();
+ return conditionMet;
+ }
+ });
+ }
+
+ /**
+ * <p>
+ * Check if a specific condition is met depending on column metadata.
+ * </p>
+ * Column attributes included in the Map are:
+ * <ol>
+ * <li><strong>TABLE_CAT</strong> String => table catalog (may be <code>null</code>)</li>
+ * <li><strong>TABLE_SCHEM</strong> String => table schema (may be <code>null</code>)</li>
+ * <li><strong>TABLE_NAME</strong> String => table name</li>
+ * <li><strong>COLUMN_NAME</strong> String => column name</li>
+ * <li><strong>DATA_TYPE</strong> int => SQL type from java.sql.Types</li>
+ * <li><strong>TYPE_NAME</strong> String => Data source dependent type name, for a UDT the type name is fully
+ * qualified</li>
+ * <li><strong>COLUMN_SIZE</strong> int => column size.</li>
+ * <li><strong>BUFFER_LENGTH</strong> is not used.</li>
+ * <li><strong>DECIMAL_DIGITS</strong> int => the number of fractional digits. Null is returned for data types
+ * where DECIMAL_DIGITS is not applicable.</li>
+ * <li><strong>NUM_PREC_RADIX</strong> int => Radix (typically either 10 or 2)</li>
+ * <li><strong>NULLABLE</strong> int => is NULL allowed.</li>
+ * <ul>
+ * <li> columnNoNulls - might not allow <code>NULL</code> values</li>
+ * <li> columnNullable - definitely allows <code>NULL</code> values</li>
+ * <li> columnNullableUnknown - nullability unknown</li>
+ * </ul>
+ * <li><strong>REMARKS</strong> String => comment describing column (may be <code>null</code>)</li>
+ * <li><strong>COLUMN_DEF</strong> String => default value for the column, which should be interpreted as a string
+ * when the value is enclosed in single quotes (may be <code>null</code>)</li>
+ * <li><strong>SQL_DATA_TYPE</strong> int => unused</li>
+ * <li><strong>SQL_DATETIME_SUB</strong> int => unused</li>
+ * <li><strong>CHAR_OCTET_LENGTH</strong> int => for char types the maximum number of bytes in the column</li>
+ * <li><strong>ORDINAL_POSITION</strong> int => index of column in table (starting at 1)</li>
+ * <li><strong>IS_NULLABLE</strong> String => ISO rules are used to determine the nullability for a column.</li>
+ * <ul>
+ * <li> YES --- if the parameter can include NULLs</li>
+ * <li> NO --- if the parameter cannot include NULLs</li>
+ * <li> empty string --- if the nullability for the parameter is unknown</li>
+ * </ul>
+ * <li><strong>SCOPE_CATLOG</strong> String => catalog of table that is the scope of a reference attribute (<code>null</code>
+ * if DATA_TYPE isn't REF)</li>
+ * <li><strong>SCOPE_SCHEMA</strong> String => schema of table that is the scope of a reference attribute (<code>null</code>
+ * if the DATA_TYPE isn't REF)</li>
+ * <li><strong>SCOPE_TABLE</strong> String => table name that this the scope of a reference attribure (<code>null</code>
+ * if the DATA_TYPE isn't REF)</li>
+ * <li><strong>SOURCE_DATA_TYPE</strong> short => source type of a distinct type or user-generated Ref type, SQL
+ * type from java.sql.Types (<code>null</code> if DATA_TYPE isn't DISTINCT or user-generated REF)</li>
+ * <li><strong>IS_AUTOINCREMENT</strong> String => Indicates whether this column is auto incremented</li>
+ * <ul>
+ * <li> YES --- if the column is auto incremented</li>
+ * <li> NO --- if the column is not auto incremented</li>
+ * <li> empty string --- if it cannot be determined whether the column is auto incremented parameter is unknown</li>
+ * </ul>
+ * </ol>
+ * @param metadata column metadata
+ * @return <code>true</code> if the condition is met
+ */
+ protected abstract boolean checkColumnMetadata(Map<String, Object> metadata);
+
+}
Deleted: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java
===================================================================
--- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-05-07 12:57:08 UTC (rev 824)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -1,108 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.migration.generic;
-
-import it.openutils.migration.task.setup.BaseConditionalTask;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.ConnectionCallback;
-import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-
-
-/**
- * Task that executes if a given column exists.
- * @author fgiust
- * @version $Id: $
- */
-public class JdbcIfColumnExistsConditionalTask extends BaseConditionalTask
-{
-
- /**
- * Column name.
- */
- protected String column;
-
- /**
- * Catalog.
- */
- protected String catalog;
-
- /**
- * Schema.
- */
- protected String schema;
-
- /**
- * Sets the catalog.
- * @param catalog the catalog to set
- */
- public void setCatalog(String catalog)
- {
- this.catalog = catalog;
- }
-
- /**
- * Sets the schema.
- * @param schema the schema to set
- */
- public void setSchema(String schema)
- {
- this.schema = schema;
- }
-
- /**
- * Sets the column.
- * @param column the column to set
- */
- public void setColumn(String column)
- {
- this.column = column;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean check(SimpleJdbcTemplate jdbcTemplate)
- {
-
- String columnTrim = StringUtils.trim(column);
-
- final String tableName = StringUtils.substringBefore(columnTrim, ".");
- final String columnName = StringUtils.substringAfter(columnTrim, ".");
- return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback()
- {
-
- public Object doInConnection(Connection con) throws SQLException, DataAccessException
- {
-
- DatabaseMetaData dbMetadata = con.getMetaData();
- ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName);
- boolean tableExists = rs.next();
- rs.close();
-
- return !tableExists;
- }
- });
- }
-
-}
Copied: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java (from rev 834, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java)
===================================================================
--- tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java (rev 0)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -0,0 +1,108 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.migration.generic;
+
+import it.openutils.migration.task.setup.BaseConditionalTask;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.ConnectionCallback;
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+
+
+/**
+ * Task that executes if a given column exists.
+ * @author fgiust
+ * @version $Id: $
+ */
+public class JdbcIfColumnExistsConditionalTask extends BaseConditionalTask
+{
+
+ /**
+ * Column name.
+ */
+ protected String column;
+
+ /**
+ * Catalog.
+ */
+ protected String catalog;
+
+ /**
+ * Schema.
+ */
+ protected String schema;
+
+ /**
+ * Sets the catalog.
+ * @param catalog the catalog to set
+ */
+ public void setCatalog(String catalog)
+ {
+ this.catalog = catalog;
+ }
+
+ /**
+ * Sets the schema.
+ * @param schema the schema to set
+ */
+ public void setSchema(String schema)
+ {
+ this.schema = schema;
+ }
+
+ /**
+ * Sets the column.
+ * @param column the column to set
+ */
+ public void setColumn(String column)
+ {
+ this.column = column;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean check(SimpleJdbcTemplate jdbcTemplate)
+ {
+
+ String columnTrim = StringUtils.trim(column);
+
+ final String tableName = StringUtils.substringBefore(columnTrim, ".");
+ final String columnName = StringUtils.substringAfter(columnTrim, ".");
+ return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback()
+ {
+
+ public Object doInConnection(Connection con) throws SQLException, DataAccessException
+ {
+
+ DatabaseMetaData dbMetadata = con.getMetaData();
+ ResultSet rs = dbMetadata.getColumns(catalog, schema, tableName, columnName);
+ boolean tableExists = rs.next();
+ rs.close();
+
+ return tableExists;
+ }
+ });
+ }
+
+}
Deleted: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java
===================================================================
--- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java 2008-05-07 12:57:08 UTC (rev 824)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -1,105 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.migration.generic;
-
-import it.openutils.migration.task.setup.BaseConditionalTask;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.ConnectionCallback;
-import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-
-
-/**
- * Task that executes if a named foreign key eists.
- * @author fgiust
- * @version $Id$
- */
-public class JdbcIfForeignKeyExistsConditionalTask extends BaseConditionalTask
-{
-
- private String fkName;
-
- private String catalog;
-
- private String schema;
-
- /**
- * Sets the catalog.
- * @param catalog the catalog to set
- */
- public void setCatalog(String catalog)
- {
- this.catalog = catalog;
- }
-
- /**
- * Sets the schema.
- * @param schema the schema to set
- */
- public void setSchema(String schema)
- {
- this.schema = schema;
- }
-
- /**
- * Sets the fkName (TABLE.FKNAME).
- * @param fkName the fkName to set
- */
- public void setFkName(String fkName)
- {
- this.fkName = fkName;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean check(SimpleJdbcTemplate jdbcTemplate)
- {
-
- String fkNameTrim = StringUtils.trim(fkName);
-
- final String tableName = StringUtils.substringBefore(fkNameTrim, ".");
- final String fkName = StringUtils.substringAfter(fkNameTrim, ".");
- return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback()
- {
-
- public Object doInConnection(Connection con) throws SQLException, DataAccessException
- {
- boolean fkExists = false;
- DatabaseMetaData dbMetadata = con.getMetaData();
- ResultSet rs = dbMetadata.getExportedKeys(catalog, schema, tableName);
- while (rs.next())
- {
- if (StringUtils.equals(fkName, rs.getString("FK_NAME")))
- {
- fkExists = true;
- }
- }
- rs.close();
-
- return !fkExists;
- }
- });
- }
-
-}
Copied: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java (from rev 834, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java)
===================================================================
--- tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java (rev 0)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/generic/JdbcIfForeignKeyExistsConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -0,0 +1,105 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.migration.generic;
+
+import it.openutils.migration.task.setup.BaseConditionalTask;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.ConnectionCallback;
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+
+
+/**
+ * Task that executes if a named foreign key eists.
+ * @author fgiust
+ * @version $Id$
+ */
+public class JdbcIfForeignKeyExistsConditionalTask extends BaseConditionalTask
+{
+
+ private String fkName;
+
+ private String catalog;
+
+ private String schema;
+
+ /**
+ * Sets the catalog.
+ * @param catalog the catalog to set
+ */
+ public void setCatalog(String catalog)
+ {
+ this.catalog = catalog;
+ }
+
+ /**
+ * Sets the schema.
+ * @param schema the schema to set
+ */
+ public void setSchema(String schema)
+ {
+ this.schema = schema;
+ }
+
+ /**
+ * Sets the fkName (TABLE.FKNAME).
+ * @param fkName the fkName to set
+ */
+ public void setFkName(String fkName)
+ {
+ this.fkName = fkName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean check(SimpleJdbcTemplate jdbcTemplate)
+ {
+
+ String fkNameTrim = StringUtils.trim(fkName);
+
+ final String tableName = StringUtils.substringBefore(fkNameTrim, ".");
+ final String fkName = StringUtils.substringAfter(fkNameTrim, ".");
+ return (Boolean) jdbcTemplate.getJdbcOperations().execute(new ConnectionCallback()
+ {
+
+ public Object doInConnection(Connection con) throws SQLException, DataAccessException
+ {
+ boolean fkExists = false;
+ DatabaseMetaData dbMetadata = con.getMetaData();
+ ResultSet rs = dbMetadata.getExportedKeys(catalog, schema, tableName);
+ while (rs.next())
+ {
+ if (StringUtils.equals(fkName, rs.getString("FK_NAME")))
+ {
+ fkExists = true;
+ }
+ }
+ rs.close();
+
+ return fkExists;
+ }
+ });
+ }
+
+}
Deleted: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java
===================================================================
--- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java 2008-05-07 12:57:08 UTC (rev 824)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -1,240 +0,0 @@
-/*
- * Copyright Openmind http://www.openmindonline.it
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package it.openutils.migration.task.setup;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-
-
-/**
- * A base conditional task that executes a task only if an expected condition is met.
- * @author fgiust
- * @version $Id:SqlServerObjCreationTask.java 3143 2007-09-24 19:50:49Z fgiust $
- */
-public abstract class BaseConditionalTask extends BaseDbTask
-{
-
- /**
- * Logger.
- */
- protected Logger log = LoggerFactory.getLogger(getClass());
-
- /**
- * DDL to run when the condition is met.
- */
- protected String ddl;
-
- /**
- * If <code>true</code> executes only if check returned <code>false</code>
- */
- protected boolean not;
-
- /**
- * Map of key-value that will be replaced in ddl.
- */
- protected Map<String, String> variables;
-
- /**
- * Script list to execute
- */
- protected List<Resource> scripts;
-
- /**
- * Sets the scripts.
- * @param scripts the scripts to set
- */
- public void setScripts(List<Resource> scripts)
- {
- this.scripts = scripts;
- }
-
- /**
- * {@inheritDoc}
- */
- public final void setDdl(String ddls)
- {
- this.ddl = ddls;
- }
-
- /**
- * Sets the not.
- * @param not the not to set
- */
- public final void setNot(boolean not)
- {
- this.not = not;
- }
-
- /**
- * Sets the ddlScript.
- * @param ddlScript the ddlScript to set
- * @deprecated use the "scripts" property
- */
- @Deprecated
- public final void setDdlScript(Resource ddlScript)
- {
- log.warn("ddlScript is deprecated, please use \"scripts\"");
- if (scripts == null)
- {
- scripts = new ArrayList<Resource>(1);
- }
- scripts.add(ddlScript);
- }
-
- /**
- * Subclasses need to override this method and provide specific checks.
- * @param jdbcTemplate SimpleJdbcTemplate
- * @return true if the condition is met
- */
- public abstract boolean check(SimpleJdbcTemplate jdbcTemplate);
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getDescription()
- {
-
- if (StringUtils.isNotEmpty(super.getDescription()))
- {
- return super.getDescription();
- }
-
- if (scripts != null && !scripts.isEmpty())
- {
- StringBuffer result = new StringBuffer();
- result.append("Checking :\n");
- for (Resource script : scripts)
- {
- result.append(" - " + objectNameFromFileName(script) + "\n");
- }
- return result.toString();
-
- }
-
- return getClass().getName();
- }
-
- /**
- * @param script The script resource
- * @return The script name
- */
- protected String objectNameFromFileName(Resource script)
- {
- return StringUtils.substringBeforeLast(script.getFilename(), ".");
- }
-
- /**
- * Perform sobstitution in the given string.
- * @param string Original String
- * @return processed string
- */
- protected String performSubstitution(String string)
- {
- if (variables == null || variables.isEmpty())
- {
- return string;
- }
-
- String stringReplaced = string;
- for (String key : variables.keySet())
- {
- stringReplaced = StringUtils.replace(stringReplaced, "${" + key + "}", variables.get(key));
- }
-
- return stringReplaced;
- }
-
- /**
- * {@inheritDoc}
- */
- public void execute(DataSource dataSource)
- {
- SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
-
- if (check(jdbcTemplate) ^ !not)
- {
- log.info("Executing Alter Task: {}", getDescription());
-
- if (StringUtils.isNotBlank(ddl))
- {
- executeSingle(jdbcTemplate, ddl);
- }
- else
- {
- if (scripts == null || scripts.isEmpty())
- {
- log.error("Unable to execute db task \"{}\", no ddl or scripts configured.", getDescription());
- return;
- }
-
- for (Resource script : scripts)
- {
- String scriptContent = ddl;
- InputStream is = null;
- try
- {
- is = script.getInputStream();
- scriptContent = IOUtils.toString(is, "UTF8");
- }
- catch (IOException e)
- {
- log.error(
- "Unable to execute db task \"{}\", script \"{}\" can't be read.",
- getDescription(),
- script);
- return;
- }
- finally
- {
- IOUtils.closeQuietly(is);
- }
- executeSingle(jdbcTemplate, scriptContent);
- }
- }
- }
- }
-
- /**
- * @param jdbcTemplate
- * @param scriptContent
- */
- protected void executeSingle(SimpleJdbcTemplate jdbcTemplate, String scriptContent)
- {
- String[] ddls = StringUtils.split(performSubstitution(scriptContent), ';');
- for (String statement : ddls)
- {
- if (StringUtils.isNotBlank(statement))
- {
- log.debug("Executing:\n{}", statement);
- jdbcTemplate.update(statement);
- }
- }
- }
-
-}
Copied: tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java (from rev 834, trunk/openutils-dbmigration/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java)
===================================================================
--- tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java (rev 0)
+++ tags/openutils-dbmigration-2.0.4/src/main/java/it/openutils/migration/task/setup/BaseConditionalTask.java 2008-06-11 21:25:54 UTC (rev 837)
@@ -0,0 +1,240 @@
+/*
+ * Copyright Openmind http://www.openmindonline.it
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package it.openutils.migration.task.setup;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.Resource;
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+
+
+/**
+ * A base conditional task that executes a task only if an expected condition is met.
+ * @author fgiust
+ * @version $Id:SqlServerObjCreationTask.java 3143 2007-09-24 19:50:49Z fgiust $
+ */
+public abstract class BaseConditionalTask extends BaseDbTask
+{
+
+ /**
+ * Logger.
+ */
+ protected Logger log = LoggerFactory.getLogger(getClass());
+
+ /**
+ * DDL to run when the condition is met.
+ */
+ protected String ddl;
+
+ /**
+ * If <code>true</code> executes only if check returned <code>false</code>
+ */
+ protected boolean not;
+
+ /**
+ * Map of key-value that will be replaced in ddl.
+ */
+ protected Map<String, String> variables;
+
+ /**
+ * Script list to execute
+ */
+ protected List<Resource> scripts;
+
+ /**
+ * Sets the scripts.
+ * @param scripts the scripts to set
+ */
+ public void setScripts(List<Resource> scripts)
+ {
+ this.scripts = scripts;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void setDdl(String ddls)
+ {
+ this.ddl = ddls;
+ }
+
+ /**
+ * Sets the not.
+ * @param not the not to set
+ */
+ public final void setNot(boolean not)
+ {
+ this.not = not;
+ }
+
+ /**
+ * Sets the ddlScript.
+ * @param ddlScript the ddlScript to set
+ * @deprecated use the "scripts" property
+ */
+ @Deprecated
+ public final void setDdlScript(Resource ddlScript)
+ {
+ log.warn("ddlScript is deprecated, please use \"scripts\"");
+ if (scripts == null)
+ {
+ scripts = new ArrayList<Resource>(1);
+ }
+ scripts.add(ddlScript);
+ }
+
+ /**
+ * Subclasses need to override this method and provide specific checks.
+ * @param jdbcTemplate SimpleJdbcTemplate
+ * @return true if the condition is met
+ */
+ public abstract boolean check(SimpleJdbcTemplate jdbcTemplate);
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getDescription()
+ {
+
+ if (StringUtils.isNotEmpty(super.getDescription()))
+ {
+ return super.getDescription();
+ }
+
+ if (scripts != null && !scripts.isEmpty())
+ {
+ StringBuffer result = new StringBuffer();
+ result.append("Checking :\n");
+ for (Resource script : scripts)
+ {
+ result.append(" - " + objectNameFromFileName(script) + "\n");
+ }
+ return result.toString();
+
+ }
+
+ return getClass().getName();
+ }
+
+ /**
+ * @param script The script resource
+ * @return The script name
+ */
+ protected String objectNameFromFileName(Resource script)
+ {
+ return StringUtils.substringBeforeLast(script.getFilename(), ".");
+ }
+
+ /**
+ * Perform sobstitution in the given string.
+ * @param string Original String
+ * @return processed string
+ */
+ protected String performSubstitution(String string)
+ {
+ if (variables == null || variables.isEmpty())
+ {
+ return string;
+ }
+
+ String stringReplaced = string;
+ for (String key : variables.keySet())
+ {
+ stringReplaced = StringUtils.replace(stringReplaced, "${" + key + "}", variables.get(key));
+ }
+
+ return stringReplaced;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute(DataSource dataSource)
+ {
+ SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
+
+ if (check(jdbcTemplate) ^ not)
+ {
+ log.info("Executing Alter Task: {}", getDescription());
+
+ if (StringUtils.isNotBlank(ddl))
+ {
+ executeSingle(jdbcTemplate, ddl);
+ }
+ else
+ {
+ if (scripts == null || scripts.isEmpty())
+ {
+ log.error("Unable to execute db task \"{}\", no ddl or scripts configured.", getDescription());
+ return;
+ }
+
+ for (Resource script : scripts)
+ {
+ String scriptContent = ddl;
+ InputStream is = null;
+ try
+ {
+ is = script.getInputStream();
+ scriptContent = IOUtils.toString(is, "UTF8");
+ }
+ catch (IOException e)
+ {
+ log.error(
+ "Unable to execute db task \"{}\", script \"{}\" can't be read.",
+ getDescription(),
+ script);
+ return;
+ }
+ finally
+ {
+ IOUtils.closeQuietly(is);
+ }
+ executeSingle(jdbcTemplate, scriptContent);
+ }
+ }
+ }
+ }
+
+ /**
+ * @param jdbcTemplate
+ * @param scriptContent
+ */
+ protected void executeSingle(SimpleJdbcTemplate jdbcTemplate, String scriptContent)
+ {
+ String[] ddls = StringUtils.split(performSubstitution(scriptContent), ';');
+ for (String statement : ddls)
+ {
+ if (StringUtils.isNotBlank(statement))
+ {
+ log.debug("Executing:\n{}", statement);
+ jdbcTemplate.update(statement);
+ }
+ }
+ }
+
+}
Deleted: tags/openutils-dbmigration-2.0.4/src/site/changes/changes.xml
===================================================================
--- trunk/openutils-dbmigration/src/site/changes/changes.xml 2008-05-07 12:57:08 UTC (rev 824)
+++ tags/openutils-dbmigration-2.0.4/src/site/changes/changes.xml 2008-06-11 21:25:54 UTC (rev 837)
@@ -1,33 +0,0 @@
-<?xml version="1.0"?>
-<!--
- "type" attribute can be: add, remove, update or fix.
--->
-<document>
- <properties>
- <title>Changes</title>
- <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author>
- </properties>
- <body>
- <release version="2.0.4" date="in svn" description="2.0.4">
- <action type="add" dev="fgiust">New jdbc generic tasks: IfColumnIsNotIdentityConditionalTask,
- JdbcIfColumnIsNotNullableConditionalTask, JdbcIfForeignKeyExistsConditionalTask</action>
- <action type="add" dev="fgiust">New oracle specific tasks: OraclePackageCreationTask,
- OracleStoredProcedureCallTask</action>
- </release>
- <release version="2.0.3" date="2008-02-21" description="2.0.3">
- <action type="add" dev="fgiust">New it.openutils.migration.oracle.OracleViewCreateOrUpdateTask</action>
- <action type="fix" dev="fgiust">Fix handling of empty strings for numeric types in ExcelConfigurationTask
- </action>
- <action type="update" dev="fgiust"> Dates are now always processed using an ISO8601 date format in
- ExcelConfigurationTask (previously the parsing was left to the jdbc driver, leading to different results with
- different drivers)</action>
- <action type="add" dev="fgiust">Added a new "enabled" flag in ExcelConfigurationTask</action>
- </release>
- <release version="2.0.2" date="2008-02-11" description="2.0.2">
- <action type="add" dev="fgiust">New it.openutils.migration.oracle.OracleSequenceCreationTask</action>
- <action type="update" dev="fgiust"> Added ability to set a schema name in
- it.openutils.migration.generic.JdbcObjectCreationTask and
- it.openutils.migration.generic.JdbcIfColumnExistsConditionalTask</action>
- </release>
- </body>
-</document>
\ No newline at end of file
Copied: tags/openutils-dbmigration-2.0.4/src/site/changes/changes.xml (from rev 835, trunk/openutils-dbmigration/src/site/changes/changes.xml)
===================================================================
--- tags/openutils-dbmigration-2.0.4/src/site/changes/changes.xml (rev 0)
+++ tags/openutils-dbmigration-2.0.4/src/site/changes/changes.xml 2008-06-11 21:25:54 UTC (rev 837)
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<!--
+ "type" attribute can be: add, remove, update or fix.
+-->
+<document>
+ <properties>
+ <title>Changes</title>
+ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author>
+ </properties>
+ <body>
+ <release version="2.0.4" date="2008-06-11" description="2.0.4">
+ <action type="fix" dev="fgiust"> Warning: fixed the usage of the "not" condition in
+ it.openutils.migration.task.setup.BaseConditionalTask that previosly caused unexpected (inverted) results. You
+ may need to review your conditional tasks in order to check if the condition is still valid!</action>
+ <action type="add" dev="fgiust">New jdbc generic tasks: IfColumnIsNotIdentityConditionalTask,
+ JdbcIfColumnIsNotNullableConditionalTask, JdbcIfForeignKeyExistsConditionalTask</action>
+ <action type="add" dev="fgiust">New oracle specific tasks: OraclePackageCreationTask,
+ OracleStoredProcedureCallTask</action>
+ </release>
+ <release version="2.0.3" date="2008-02-21" description="2.0.3">
+ <action type="add" dev="fgiust">New it.openutils.migration.oracle.OracleViewCreateOrUpdateTask</action>
+ <action type="fix" dev="fgiust">Fix handling of empty strings for numeric types in ExcelConfigurationTask
+ </action>
+ <action type="update" dev="fgiust"> Dates are now always processed using an ISO8601 date format in
+ ExcelConfigurationTask (previously the parsing was left to the jdbc driver, leading to different results with
+ different drivers)</action>
+ <action type="add" dev="fgiust">Added a new "enabled" flag in ExcelConfigurationTask</action>
+ </release>
+ <release version="2.0.2" date="2008-02-11" description="2.0.2">
+ <action type="add" dev="fgiust">New it.openutils.migration.oracle.OracleSequenceCreationTask</action>
+ <action type="update" dev="fgiust"> Added ability to set a schema name in
+ it.openutils.migration.generic.JdbcObjectCreationTask and
+ it.openutils.migration.generic.JdbcIfColumnExistsConditionalTask</action>
+ </release>
+ </body>
+</document>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|