diff --git a/symmetric-client/src/main/java/org/jumpmind/symmetric/DbFill.java b/symmetric-client/src/main/java/org/jumpmind/symmetric/DbFill.java index 432982f5f8..1a11078e24 100644 --- a/symmetric-client/src/main/java/org/jumpmind/symmetric/DbFill.java +++ b/symmetric-client/src/main/java/org/jumpmind/symmetric/DbFill.java @@ -1,7 +1,6 @@ package org.jumpmind.symmetric; import java.math.BigDecimal; -import java.math.BigInteger; import java.sql.Types; import java.util.ArrayList; import java.util.Date; @@ -94,14 +93,22 @@ private void fillTables(Table... tables) { for (int i = 0; i < inputLength; i++) { for (Table table : tables) { + DmlStatement statement = platform.createDmlStatement(DmlType.INSERT, table); + Column[] tableColumns = table.getColumns(); Object[] columnValues = generateRandomValues(insertedColumns, table); for (int j = 0; j < tableColumns.length; j++) { - insertedColumns.put(table.getName() + "." + tableColumns[j].getName(), + insertedColumns.put(table.getQualifiedColumnName(tableColumns[j]), columnValues[j]); } - DmlStatement statement = platform.createDmlStatement(DmlType.INSERT, table); - sqlTemplate.update(statement.getSql(), columnValues); + + Column[] statementColumns = statement.getMetaData(); + Object[] statementValues = new Object[statementColumns.length]; + for (int j = 0; j < statementColumns.length; j++) { + statementValues[j] = insertedColumns.get(table + .getQualifiedColumnName(statementColumns[j])); + } + sqlTemplate.update(statement.getSql(), statementValues); } insertedColumns.clear(); diff --git a/symmetric-core/src/main/java/org/jumpmind/symmetric/AbstractSymmetricEngine.java b/symmetric-core/src/main/java/org/jumpmind/symmetric/AbstractSymmetricEngine.java index e60c604b1c..2f4ee884de 100644 --- a/symmetric-core/src/main/java/org/jumpmind/symmetric/AbstractSymmetricEngine.java +++ b/symmetric-core/src/main/java/org/jumpmind/symmetric/AbstractSymmetricEngine.java @@ -18,6 +18,7 @@ import org.jumpmind.db.platform.IDatabasePlatform; import org.jumpmind.db.sql.ISqlTemplate; import org.jumpmind.db.sql.SqlScript; +import org.jumpmind.db.sql.SqlScriptReader; import org.jumpmind.properties.TypedProperties; import org.jumpmind.symmetric.common.Constants; import org.jumpmind.symmetric.common.ParameterConstants; @@ -441,7 +442,7 @@ protected boolean loadFromScriptIfProvided() { if (fileUrl != null) { new SqlScript(fileUrl, symmetricDialect.getPlatform().getSqlTemplate(), - true, SqlScript.QUERY_ENDS, getSymmetricDialect().getPlatform() + true, SqlScriptReader.QUERY_ENDS, getSymmetricDialect().getPlatform() .getSqlScriptReplacementTokens()).execute(); loaded = true; } else { diff --git a/symmetric-core/src/test/resources/test-data-drop-all.sql b/symmetric-core/src/test/resources/test-data-drop-all.sql index fc97a3572b..a1b16405f7 100644 --- a/symmetric-core/src/test/resources/test-data-drop-all.sql +++ b/symmetric-core/src/test/resources/test-data-drop-all.sql @@ -1,32 +1,32 @@ ---drop table sym_transform_column; ---drop table sym_transform_table; ---drop table sym_data_gap; ---drop table sym_node_channel_ctl; ---drop table sym_node_group_channel_window; ---drop table sym_data_event; ---drop table sym_trigger_hist; ---drop table sym_trigger_router; ---drop table sym_trigger; ---drop table sym_router; ---drop table sym_node_security; ---drop table sym_node_identity; ---drop table sym_lock; ---drop table sym_node_communication; ---drop table sym_node_host; ---drop table sym_node; ---drop table sym_conflict; ---drop table sym_node_group_link; ---drop table sym_node_group; ---drop table sym_incoming_batch; ---drop table sym_channel; ---drop table sym_outgoing_batch; ---drop table sym_parameter; ---drop table sym_node_host_channel_stats; ---drop table sym_node_host_stats; ---drop table sym_node_host_job_stats; ---drop table sym_registration_redirect; ---drop table sym_registration_request; ---drop table sym_data; ---drop table sym_incoming_error; ---drop table sym_sequence; ---drop table sym_load_filter; \ No newline at end of file +drop table sym_transform_column; +drop table sym_transform_table; +drop table sym_data_gap; +drop table sym_node_channel_ctl; +drop table sym_node_group_channel_window; +drop table sym_data_event; +drop table sym_trigger_hist; +drop table sym_trigger_router; +drop table sym_trigger; +drop table sym_router; +drop table sym_node_security; +drop table sym_node_identity; +drop table sym_lock; +drop table sym_node_communication; +drop table sym_node_host; +drop table sym_node; +drop table sym_conflict; +drop table sym_node_group_link; +drop table sym_node_group; +drop table sym_incoming_batch; +drop table sym_channel; +drop table sym_outgoing_batch; +drop table sym_parameter; +drop table sym_node_host_channel_stats; +drop table sym_node_host_stats; +drop table sym_node_host_job_stats; +drop table sym_registration_redirect; +drop table sym_registration_request; +drop table sym_data; +drop table sym_incoming_error; +drop table sym_sequence; +drop table sym_load_filter; \ No newline at end of file diff --git a/symmetric-db/src/main/java/org/jumpmind/db/sql/ISqlStatementSource.java b/symmetric-db/src/main/java/org/jumpmind/db/sql/ISqlStatementSource.java new file mode 100644 index 0000000000..08c4cef1da --- /dev/null +++ b/symmetric-db/src/main/java/org/jumpmind/db/sql/ISqlStatementSource.java @@ -0,0 +1,6 @@ +package org.jumpmind.db.sql; + +public interface ISqlStatementSource { + + public String readSqlStatement(); +} diff --git a/symmetric-db/src/main/java/org/jumpmind/db/sql/ISqlTemplate.java b/symmetric-db/src/main/java/org/jumpmind/db/sql/ISqlTemplate.java index 722cc24c11..65c0be01ea 100644 --- a/symmetric-db/src/main/java/org/jumpmind/db/sql/ISqlTemplate.java +++ b/symmetric-db/src/main/java/org/jumpmind/db/sql/ISqlTemplate.java @@ -61,6 +61,8 @@ public Map query(String sql, String keyCol, String valueCol, Object public int update(boolean autoCommit, boolean failOnError, int commitRate, ISqlResultsListener listener, String... sql); + public int update(boolean autoCommit, boolean failOnError, int commitRate, ISqlResultsListener listener, ISqlStatementSource source); + public int update(boolean autoCommit, boolean failOnError, int commitRate, String... sql); public int update(String sql, Object[] values, int[] types); diff --git a/symmetric-db/src/main/java/org/jumpmind/db/sql/ListSqlStatementSource.java b/symmetric-db/src/main/java/org/jumpmind/db/sql/ListSqlStatementSource.java new file mode 100644 index 0000000000..a2647330a8 --- /dev/null +++ b/symmetric-db/src/main/java/org/jumpmind/db/sql/ListSqlStatementSource.java @@ -0,0 +1,25 @@ +package org.jumpmind.db.sql; + +import java.util.ArrayList; +import java.util.List; + +public class ListSqlStatementSource implements ISqlStatementSource { + + protected List statements; + + public ListSqlStatementSource(String... statements) { + this.statements = new ArrayList(); + for (String sql : statements) { + this.statements.add(sql); + } + } + + public ListSqlStatementSource(List statements) { + this.statements = new ArrayList(statements); + } + + public String readSqlStatement() { + return statements.size() > 0 ? statements.remove(0) : null; + } + +} diff --git a/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScript.java b/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScript.java index 56160d3a8e..5bc5a63772 100644 --- a/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScript.java +++ b/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScript.java @@ -22,15 +22,12 @@ import java.io.IOException; import java.io.InputStreamReader; +import java.io.Reader; import java.io.StringReader; import java.net.URL; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; -import org.jumpmind.util.FormatUtils; /** * This class parses and runs SQL from an input file or buffer using the @@ -38,31 +35,22 @@ */ public class SqlScript { - static final String COMMENT_CHARS_1 = "--"; - static final String COMMENT_CHARS_2 = "#"; - - public final static String QUERY_ENDS = ";"; - - private String delimiter = QUERY_ENDS; - - private List statements; - private ISqlTemplate sqlTemplate; private int commitRate = 10000; private boolean failOnError = true; - private String lineDeliminator; - private ISqlResultsListener resultsListener; + private SqlScriptReader scriptReader; + public SqlScript(URL url, ISqlTemplate sqlTemplate) { - this(url, sqlTemplate, true, QUERY_ENDS, null); + this(url, sqlTemplate, true, SqlScriptReader.QUERY_ENDS, null); } public SqlScript(URL url, ISqlTemplate sqlTemplate, boolean failOnError) { - this(url, sqlTemplate, failOnError, QUERY_ENDS, null); + this(url, sqlTemplate, failOnError, SqlScriptReader.QUERY_ENDS, null); } public SqlScript(URL url, ISqlTemplate sqlTemplate, String delimiter) { @@ -74,67 +62,34 @@ public SqlScript(URL url, ISqlTemplate sqlTemplate, boolean failOnError, String try { String fileName = url.getFile(); fileName = fileName.substring(fileName.lastIndexOf("/") + 1); - init(IOUtils.readLines(new InputStreamReader(url.openStream(), "UTF-8")), sqlTemplate, - failOnError, delimiter, replacementTokens); + init(new InputStreamReader(url.openStream(), "UTF-8"), sqlTemplate, failOnError, + delimiter, replacementTokens); } catch (IOException ex) { throw new RuntimeException(ex); } } public SqlScript(String sqlScript, ISqlTemplate sqlTemplate, boolean failOnError) { - this(sqlScript, sqlTemplate, failOnError, QUERY_ENDS, null); + this(sqlScript, sqlTemplate, failOnError, SqlScriptReader.QUERY_ENDS, null); } public SqlScript(String sqlScript, ISqlTemplate sqlTemplate, boolean failOnError, String delimiter, Map replacementTokens) { - try { - init(IOUtils.readLines(new StringReader(sqlScript)), sqlTemplate, failOnError, - delimiter, replacementTokens); - } catch (IOException ex) { - throw new RuntimeException(ex); - } + init(new StringReader(sqlScript), sqlTemplate, failOnError, delimiter, replacementTokens); } - public SqlScript(List sqlScript, ISqlTemplate sqlTemplate, boolean failOnError, + public SqlScript(Reader reader, ISqlTemplate sqlTemplate, boolean failOnError, String delimiter, Map replacementTokens) { - init(sqlScript, sqlTemplate, failOnError, delimiter, replacementTokens); + init(reader, sqlTemplate, failOnError, delimiter, replacementTokens); } - private void init(List sqlScript, ISqlTemplate sqlTemplate, boolean failOnError, + private void init(Reader reader, ISqlTemplate sqlTemplate, boolean failOnError, String delimiter, Map replacementTokens) { - this.statements = parseLines(sqlScript, replacementTokens); + this.scriptReader = new SqlScriptReader(reader); + this.scriptReader.setDelimiter(delimiter); + this.scriptReader.setReplacementTokens(replacementTokens); this.sqlTemplate = sqlTemplate; this.failOnError = failOnError; - this.delimiter = delimiter; - } - - protected List parseLines(List script, Map replacementTokens) { - List statements = new ArrayList(); - StringBuilder sql = new StringBuilder(); - for (String line : script) { - line = trimComments(line); - if (line.trim().length() > 0) { - if (checkStatementEnds(line)) { - if (sql.length() > 0) { - sql.append("\n"); - } - sql.append(line.substring(0, line.lastIndexOf(delimiter)).trim()); - String toExecute = sql.toString(); - if (StringUtils.isNotBlank(lineDeliminator)) { - toExecute = toExecute.replaceAll(lineDeliminator, "\n"); - } - toExecute = FormatUtils.replaceTokens(toExecute, replacementTokens, false); - if (StringUtils.isNotBlank(toExecute)) { - statements.add(toExecute.trim()); - } - sql.setLength(0); - } else { - sql.append("\n"); - sql.append(line); - } - } - } - return statements; } public long execute() { @@ -142,24 +97,14 @@ public long execute() { } public long execute(final boolean autoCommit) { - return sqlTemplate.update(autoCommit, failOnError, commitRate, resultsListener, - statements.toArray(new String[statements.size()])); - } - - private String trimComments(String line) { - int index = line.indexOf(COMMENT_CHARS_1); - if (index >= 0) { - line = line.substring(0, index); - } - index = line.indexOf(COMMENT_CHARS_2); - if (index >= 0) { - line = line.substring(0, index); + try { + long count = this.sqlTemplate.update(autoCommit, failOnError, commitRate, + this.resultsListener, this.scriptReader); + return count; + } finally { + IOUtils.closeQuietly(this.scriptReader); } - return line; - } - private boolean checkStatementEnds(String s) { - return s.trim().endsWith("" + delimiter); } public int getCommitRate() { @@ -171,7 +116,7 @@ public void setCommitRate(int commitRate) { } public void setLineDeliminator(String lineDeliminator) { - this.lineDeliminator = lineDeliminator; + this.scriptReader.setDelimiter(lineDeliminator); } public void setListener(ISqlResultsListener listener) { diff --git a/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScriptReader.java b/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScriptReader.java index 97e723741a..d1a06ec789 100644 --- a/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScriptReader.java +++ b/symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScriptReader.java @@ -1,3 +1,23 @@ +/* + * Licensed to JumpMind Inc under one or more contributor + * license agreements. See the NOTICE file distributed + * with this work for additional information regarding + * copyright ownership. JumpMind Inc licenses this file + * to you under the GNU Lesser General Public License (the + * "License"); you may not use this file except in compliance + * with the License. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + * . + * + * 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 org.jumpmind.db.sql; import java.io.IOException; @@ -9,9 +29,12 @@ import org.jumpmind.exception.IoException; import org.jumpmind.util.FormatUtils; -public class SqlScriptReader extends LineNumberReader { +/** + * Provides an interface to read each SQL statement in a SQL script. + */ +public class SqlScriptReader extends LineNumberReader implements ISqlStatementSource { - static final String COMMENT_CHARS[] = { "--", "#", "//" }; + static final char COMMENT_CHARS[] = { '-', '#', '/' }; public final static String QUERY_ENDS = ";"; @@ -68,7 +91,7 @@ public String readSqlStatement() { } line = readLine(); } while (line != null); - + if (sql != null) { return sql.toString(); } else { @@ -85,9 +108,41 @@ public String readSqlStatement() { } protected String trimComments(String line) { - for (String commmentChar : COMMENT_CHARS) { - if (line.startsWith(commmentChar)) { - return null; + int inLiteralStart = -1; + int inLiteralEnd = -1; + char[] content = line.toCharArray(); + for (int i = 0; i < line.length(); i++) { + if (inLiteralStart == -1 && content[i] == '\'') { + inLiteralStart = i; + for (int j = inLiteralStart + 1; j < line.length(); j++) { + if (content[j] == '\'') { + if (j + 1 < content.length && content[j + 1] == '\'') { + j++; + } else { + inLiteralEnd = j + 1; + break; + } + } + } + } + + if (inLiteralEnd == i) { + inLiteralEnd = -1; + inLiteralStart = -1; + } + + if (inLiteralStart == -1) { + for (char c : COMMENT_CHARS) { + if (c == content[i]) { + if (i + 1 < content.length && content[i + 1] == c) { + return line.substring(0, i); + } + + if (i > 0 && content[i - 1] == c) { + return line.substring(0, i - 1); + } + } + } } } return line; diff --git a/symmetric-db/src/test/java/org/jumpmind/db/sql/SqlScriptReaderTest.java b/symmetric-db/src/test/java/org/jumpmind/db/sql/SqlScriptReaderTest.java index 0b2067186c..2faa739a20 100644 --- a/symmetric-db/src/test/java/org/jumpmind/db/sql/SqlScriptReaderTest.java +++ b/symmetric-db/src/test/java/org/jumpmind/db/sql/SqlScriptReaderTest.java @@ -1,3 +1,23 @@ +/* + * Licensed to JumpMind Inc under one or more contributor + * license agreements. See the NOTICE file distributed + * with this work for additional information regarding + * copyright ownership. JumpMind Inc licenses this file + * to you under the GNU Lesser General Public License (the + * "License"); you may not use this file except in compliance + * with the License. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + * . + * + * 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 org.jumpmind.db.sql; import java.io.InputStreamReader; @@ -10,14 +30,16 @@ public class SqlScriptReaderTest { @Test public void testReadScript() throws Exception { - SqlScriptReader reader = new SqlScriptReader(new InputStreamReader(getClass().getResourceAsStream("/test-script-1.sql"))); + SqlScriptReader reader = new SqlScriptReader(new InputStreamReader(getClass().getResourceAsStream("/test-script-1.sql"))); + Assert.assertEquals("select * from \n TEST where\nid = 'someid'", reader.readSqlStatement()); Assert.assertEquals("select * from test", reader.readSqlStatement()); Assert.assertEquals("insert into test (one, two, three) values('1','1','2')", reader.readSqlStatement()); for (int i = 0; i < 4; i++) { Assert.assertEquals("delete from test where one='1'", reader.readSqlStatement()); } Assert.assertEquals("update sym_node set sync_url='http://localhost:8080/test' where node_id='test'", reader.readSqlStatement()); - Assert.assertEquals("update something set oops=';' where whoops='test'", reader.readSqlStatement()); + Assert.assertEquals("update something set oops=';' where whoops='test'", reader.readSqlStatement()); + Assert.assertEquals("update test set one = '''', two='\\\\##--''' where one is null", reader.readSqlStatement()); Assert.assertEquals("update test\n set one = '1', two = '2'\nwhere one = 'one'", reader.readSqlStatement()); Assert.assertNull(reader.readSqlStatement()); reader.close(); diff --git a/symmetric-db/src/test/resources/test-script-1.sql b/symmetric-db/src/test/resources/test-script-1.sql index 09ddde8c01..01aa287323 100644 --- a/symmetric-db/src/test/resources/test-script-1.sql +++ b/symmetric-db/src/test/resources/test-script-1.sql @@ -1,4 +1,8 @@ -- This is a comment +select * from + TEST where + -- a = 'b' and + id = 'someid'; ## some note select * from test; insert into test (one, two, three) values('1','1','2'); // Another Comment; @@ -8,6 +12,7 @@ delete from test where one='1'; delete from test where one='1'; update sym_node set sync_url='http://localhost:8080/test' where node_id='test'; update something set oops=';' where whoops='test'; +update test set one = '''', two='\\##--''' where one is null; // comment update test set one = '1', two = '2' where one = 'one'; diff --git a/symmetric-jdbc/src/main/java/org/jumpmind/db/sql/JdbcSqlTemplate.java b/symmetric-jdbc/src/main/java/org/jumpmind/db/sql/JdbcSqlTemplate.java index 61e90dbfc2..6f40fb6f40 100644 --- a/symmetric-jdbc/src/main/java/org/jumpmind/db/sql/JdbcSqlTemplate.java +++ b/symmetric-jdbc/src/main/java/org/jumpmind/db/sql/JdbcSqlTemplate.java @@ -46,11 +46,11 @@ public class JdbcSqlTemplate extends AbstractSqlTemplate implements ISqlTemplate protected int[] primaryKeyViolationCodes; protected String[] primaryKeyViolationSqlStates; - + protected int[] foreignKeyViolationCodes; protected String[] foreignKeyViolationSqlStates; - + protected int isolationLevel; public JdbcSqlTemplate(DataSource dataSource, SqlTemplateSettings settings, @@ -60,7 +60,7 @@ public JdbcSqlTemplate(DataSource dataSource, SqlTemplateSettings settings, this.lobHandler = lobHandler == null ? new DefaultLobHandler() : lobHandler; this.isolationLevel = databaseInfo.getMinIsolationLevelToPreventPhantomReads(); } - + protected Connection getConnection() throws SQLException { return this.dataSource.getConnection(); } @@ -85,21 +85,21 @@ public LobHandler getLobHandler() { return lobHandler; } - public ISqlReadCursor queryForCursor(String sql, ISqlRowMapper mapper, - Object[] args, int[] types) { + public ISqlReadCursor queryForCursor(String sql, ISqlRowMapper mapper, Object[] args, + int[] types) { logSql(sql, args); return new JdbcSqlReadCursor(this, mapper, sql, args, types); } public int getIsolationLevel() { - return isolationLevel; - } + return isolationLevel; + } - public void setIsolationLevel(int isolationLevel) { - this.isolationLevel = isolationLevel; - } + public void setIsolationLevel(int isolationLevel) { + this.isolationLevel = isolationLevel; + } - public T queryForObject(final String sql, final Class clazz, final Object... args) { + public T queryForObject(final String sql, final Class clazz, final Object... args) { logSql(sql, args); return execute(new IConnectionCallback() { public T execute(Connection con) throws SQLException { @@ -271,8 +271,14 @@ public int update(boolean autoCommit, boolean failOnError, int commitRate, Strin return update(autoCommit, failOnError, commitRate, null, sql); } + public int update(boolean autoCommit, boolean failOnError, int commitRate, + ISqlResultsListener resultsListener, String... sql) { + return this.update(autoCommit, failOnError, commitRate, resultsListener, + new ListSqlStatementSource(sql)); + } + public int update(final boolean autoCommit, final boolean failOnError, final int commitRate, - final ISqlResultsListener resultsListener, final String... sql) { + final ISqlResultsListener resultsListener, final ISqlStatementSource source) { return execute(new IConnectionCallback() { public Integer execute(Connection con) throws SQLException { int updateCount = 0; @@ -282,7 +288,8 @@ public Integer execute(Connection con) throws SQLException { con.setAutoCommit(autoCommit); stmt = con.createStatement(); int statementCount = 0; - for (String statement : sql) { + for (String statement = source.readSqlStatement(); statement != null; statement = source + .readSqlStatement()) { logSql(statement, null); try { boolean hasResults = stmt.execute(statement); @@ -312,13 +319,11 @@ public Integer execute(Connection con) throws SQLException { resultsListener.sqlErrored(statement, translate(statement, ex), statementCount); } - + if (statement.toLowerCase().startsWith("drop")) { - log.debug("{}. Failed to execute: {}.", ex.getMessage(), - statement); + log.debug("{}. Failed to execute: {}.", ex.getMessage(), statement); } else { - log.warn("{}. Failed to execute: {}.", ex.getMessage(), - statement); + log.warn("{}. Failed to execute: {}.", ex.getMessage(), statement); } if (failOnError) { @@ -423,7 +428,7 @@ public static Object getResultSetValue(ResultSet rs, int index) throws SQLExcept className = obj.getClass().getName(); } if (obj instanceof Blob) { - Blob blob = (Blob)obj; + Blob blob = (Blob) obj; InputStream is = blob.getBinaryStream(); try { obj = IOUtils.toByteArray(is); @@ -433,7 +438,7 @@ public static Object getResultSetValue(ResultSet rs, int index) throws SQLExcept IOUtils.closeQuietly(is); } } else if (obj instanceof Clob) { - Clob clob = (Clob)obj; + Clob clob = (Clob) obj; Reader reader = clob.getCharacterStream(); try { obj = IOUtils.toString(reader); @@ -499,7 +504,7 @@ public static void close(boolean autoCommitValue, Connection c) { close(c); } } - + public static void close(boolean autoCommitValue, int transactionIsolationLevel, Connection c) { try { if (c != null) { @@ -512,7 +517,7 @@ public static void close(boolean autoCommitValue, int transactionIsolationLevel, } finally { close(c); } - } + } public static void close(Connection c) { try { @@ -562,7 +567,7 @@ public Boolean execute(Connection con) throws SQLException { } }); } - + public boolean isStoresLowerCaseIdentifiers() { return execute(new IConnectionCallback() { public Boolean execute(Connection con) throws SQLException { @@ -653,7 +658,8 @@ protected long insertWithGeneratedKey(Connection conn, String sql, String column ps = conn.prepareStatement(sql); } } else { - String replaceSql = sql.replaceFirst("\\([\"|\\w]*,", "(").replaceFirst("\\(null,", "("); + String replaceSql = sql.replaceFirst("\\([\"|\\w]*,", "(").replaceFirst("\\(null,", + "("); if (supportsGetGeneratedKeys) { ps = conn.prepareStatement(replaceSql, Statement.RETURN_GENERATED_KEYS); } else { @@ -735,7 +741,7 @@ public boolean isUniqueKeyViolation(Exception ex) { return primaryKeyViolation; } - + public boolean isForeignKeyViolation(Exception ex) { boolean foreignKeyViolation = false; if (foreignKeyViolationCodes != null || foreignKeyViolationSqlStates != null) { @@ -769,7 +775,6 @@ public boolean isForeignKeyViolation(Exception ex) { return foreignKeyViolation; } - protected SQLException findSQLException(Throwable ex) { if (ex instanceof SQLException) { return (SQLException) ex; diff --git a/symmetric-jdbc/src/test/java/org/jumpmind/db/sql/SqlScriptUnitTest.java b/symmetric-jdbc/src/test/java/org/jumpmind/db/sql/SqlScriptTest.java similarity index 98% rename from symmetric-jdbc/src/test/java/org/jumpmind/db/sql/SqlScriptUnitTest.java rename to symmetric-jdbc/src/test/java/org/jumpmind/db/sql/SqlScriptTest.java index 7cdf6a2ff6..8152d31d04 100644 --- a/symmetric-jdbc/src/test/java/org/jumpmind/db/sql/SqlScriptUnitTest.java +++ b/symmetric-jdbc/src/test/java/org/jumpmind/db/sql/SqlScriptTest.java @@ -30,7 +30,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.SingleConnectionDataSource; -public class SqlScriptUnitTest { +public class SqlScriptTest { @Test public void testSimpleSqlScript() throws Exception {