From: <fg...@us...> - 2008-02-11 20:47:50
|
Revision: 611 http://openutils.svn.sourceforge.net/openutils/?rev=611&view=rev Author: fgiust Date: 2008-02-11 12:47:48 -0800 (Mon, 11 Feb 2008) Log Message: ----------- ready for 2.0.2 Modified Paths: -------------- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java Added Paths: ----------- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java trunk/openutils-dbmigration/src/site/changes/ trunk/openutils-dbmigration/src/site/changes/changes.xml Modified: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-11 20:42:17 UTC (rev 610) +++ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcIfColumnExistsConditionalTask.java 2008-02-11 20:47:48 UTC (rev 611) @@ -22,7 +22,29 @@ private String column; + protected String catalog; + + 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 */ @@ -37,8 +59,6 @@ @Override public boolean check(SimpleJdbcTemplate jdbcTemplate) { - final String catalog = null; - final String schema = null; String columnTrim = StringUtils.trim(column); Modified: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-11 20:42:17 UTC (rev 610) +++ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/generic/JdbcObjectCreationTask.java 2008-02-11 20:47:48 UTC (rev 611) @@ -1,3 +1,4 @@ +// temporary patch until a new openutils-dbmigration release is outF /* * Copyright Openmind http://www.openmindonline.it * @@ -44,9 +45,29 @@ protected String catalog; + protected String schema; + abstract String getObjectType(); /** + * 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; + } + + /** * {@inheritDoc} */ @Override @@ -65,7 +86,7 @@ String fqTableName = this.objectNameFromFileName(script); String tmptableName = null; - String tmpschema = null; + String tmpschema = schema; if (StringUtils.contains(fqTableName, ".")) { @@ -88,7 +109,7 @@ { DatabaseMetaData dbMetadata = con.getMetaData(); - ResultSet rs = dbMetadata.getTables(catalog, schema, tableName, new String[]{getObjectType() }); + ResultSet rs = dbMetadata.getTables(catalog, schema, tableName, new String[]{getObjectType()}); boolean tableExists = rs.next(); rs.close(); @@ -132,6 +153,10 @@ } } } + else + { + log.debug("{} {} already existing", getObjectType(), tableName); + } } } } \ No newline at end of file Added: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java =================================================================== --- trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java (rev 0) +++ trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java 2008-02-11 20:47:48 UTC (rev 611) @@ -0,0 +1,134 @@ +/* + * 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.oracle; + +import it.openutils.migration.task.setup.DbTask; + +import java.text.MessageFormat; +import java.util.List; + +import javax.sql.DataSource; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; + + +/** + * Db tasks that handles the initial setup of sequences. + * @author fgiust + * @version $Id$ + */ +public class OracleSequenceCreationTask implements DbTask +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(OracleSequenceCreationTask.class); + + private List<String> sequences; + + private String creationQuery; + + private String selectUserSequences; + + private String selectAllSequences; + + private int startsWith; + + /** + * Sets the sequences. + * @param sequences the sequences to set + */ + public void setSequences(List<String> sequences) + { + this.sequences = sequences; + } + + /** + * Sets the creationQuery. + * @param creationQuery the creationQuery to set + */ + public void setCreationQuery(String creationQuery) + { + this.creationQuery = creationQuery; + } + + /** + * Sets the selectAllSequences. + * @param selectAllSequences the selectAllSequences to set + */ + public void setSelectAllSequences(String selectAllSequences) + { + this.selectAllSequences = selectAllSequences; + } + + /** + * Sets the startsWith. + * @param startsWith the startsWith to set + */ + public void setStartsWith(int startsWith) + { + this.startsWith = startsWith; + } + + /** + * Sets the selectUserSequences. + * @param selectUserSequences the selectUserSequences to set + */ + public void setSelectUserSequences(String selectUserSequences) + { + this.selectUserSequences = selectUserSequences; + } + + /** + * {@inheritDoc} + */ + public String getDescription() + { + return "Checking Sequences"; + } + + /** + * {@inheritDoc} + */ + public void execute(DataSource dataSource) + { + SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource); + for (String sequenceName : sequences) + { + int result = 0; + + if (StringUtils.contains(sequenceName, ".")) + { + String[] tokens = StringUtils.split(sequenceName, "."); + result = jdbcTemplate.queryForInt(selectAllSequences, new Object[]{tokens[1], tokens[0]}); + } + else + { + result = jdbcTemplate.queryForInt(selectUserSequences, sequenceName); + } + + if (result <= 0) + { + log.info("Creating new {}", sequenceName); + jdbcTemplate.update(MessageFormat.format(creationQuery, new Object[]{sequenceName, startsWith})); + } + } + } +} \ No newline at end of file Property changes on: trunk/openutils-dbmigration/src/main/java/it/openutils/migration/oracle/OracleSequenceCreationTask.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/openutils-dbmigration/src/site/changes/changes.xml =================================================================== --- trunk/openutils-dbmigration/src/site/changes/changes.xml (rev 0) +++ trunk/openutils-dbmigration/src/site/changes/changes.xml 2008-02-11 20:47:48 UTC (rev 611) @@ -0,0 +1,19 @@ +<?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.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 Property changes on: trunk/openutils-dbmigration/src/site/changes/changes.xml ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |