Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/BadSqlGrammarException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/CannotGetJdbcConnectionException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/IncorrectResultSetColumnCountException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/InvalidResultSetAccessException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/JdbcUpdateAffectedIncorrectNumberOfRowsException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/LobRetrievalFailureException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/SQLWarningException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/UncategorizedSQLException.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/config/DatabasePopulatorConfigUtils.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/config/DatabasePopulatorConfigUtils.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/config/DatabasePopulatorConfigUtils.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,82 @@ +/* + * Copyright 2002-2011 the original author or authors. + * + * 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 org.springframework.jdbc.config; + +import java.util.List; + +import org.springframework.beans.BeanMetadataElement; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.TypedStringValue; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedList; +import org.springframework.jdbc.datasource.init.CompositeDatabasePopulator; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +/** + * @author Juergen Hoeller + * @since 3.1 + */ +class DatabasePopulatorConfigUtils { + + public static void setDatabasePopulator(Element element, BeanDefinitionBuilder builder) { + List scripts = DomUtils.getChildElementsByTagName(element, "script"); + if (scripts.size() > 0) { + builder.addPropertyValue("databasePopulator", createDatabasePopulator(element, scripts, "INIT")); + builder.addPropertyValue("databaseCleaner", createDatabasePopulator(element, scripts, "DESTROY")); + } + } + + static private BeanDefinition createDatabasePopulator(Element element, List scripts, String execution) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class); + + boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS"); + boolean continueOnError = element.getAttribute("ignore-failures").equals("ALL"); + + ManagedList delegates = new ManagedList(); + for (Element scriptElement : scripts) { + String executionAttr = scriptElement.getAttribute("execution"); + if (!StringUtils.hasText(executionAttr)) { + executionAttr = "INIT"; + } + if (!execution.equals(executionAttr)) { + continue; + } + BeanDefinitionBuilder delegate = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class); + delegate.addPropertyValue("ignoreFailedDrops", ignoreFailedDrops); + delegate.addPropertyValue("continueOnError", continueOnError); + + // Use a factory bean for the resources so they can be given an order if a pattern is used + BeanDefinitionBuilder resourcesFactory = BeanDefinitionBuilder.genericBeanDefinition(SortedResourcesFactoryBean.class); + resourcesFactory.addConstructorArgValue(new TypedStringValue(scriptElement.getAttribute("location"))); + delegate.addPropertyValue("scripts", resourcesFactory.getBeanDefinition()); + if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) { + delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding"))); + } + if (StringUtils.hasLength(scriptElement.getAttribute("separator"))) { + delegate.addPropertyValue("separator", new TypedStringValue(scriptElement.getAttribute("separator"))); + } + delegates.add(delegate.getBeanDefinition()); + } + builder.addPropertyValue("populators", delegates); + + return builder.getBeanDefinition(); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/config/EmbeddedDatabaseBeanDefinitionParser.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/config/EmbeddedDatabaseBeanDefinitionParser.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/config/EmbeddedDatabaseBeanDefinitionParser.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,65 @@ +/* + * Copyright 2002-2011 the original author or authors. + * + * 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 org.springframework.jdbc.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.util.StringUtils; + +/** + * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses an {@code embedded-database} + * element and creates a {@link BeanDefinition} for {@link EmbeddedDatabaseFactoryBean}. Picks up nested + * {@code script} elements and configures a {@link ResourceDatabasePopulator} for them. + * + * @author Oliver Gierke + * @author Juergen Hoeller + * @since 3.0 + */ +class EmbeddedDatabaseBeanDefinitionParser extends AbstractBeanDefinitionParser { + + @Override + protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(EmbeddedDatabaseFactoryBean.class); + setDatabaseType(element, builder); + DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder); + useIdAsDatabaseNameIfGiven(element, builder); + builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); + return builder.getBeanDefinition(); + } + + private void useIdAsDatabaseNameIfGiven(Element element, BeanDefinitionBuilder builder) { + String id = element.getAttribute(ID_ATTRIBUTE); + if (StringUtils.hasText(id)) { + builder.addPropertyValue("databaseName", id); + } + } + + private void setDatabaseType(Element element, BeanDefinitionBuilder builder) { + String type = element.getAttribute("type"); + if (StringUtils.hasText(type)) { + builder.addPropertyValue("databaseType", type); + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/config/InitializeDatabaseBeanDefinitionParser.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/config/InitializeDatabaseBeanDefinitionParser.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/config/InitializeDatabaseBeanDefinitionParser.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,55 @@ +/* + * Copyright 2002-2011 the original author or authors. + * + * 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 org.springframework.jdbc.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.jdbc.datasource.init.DataSourceInitializer; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; + +/** + * {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses an {@code initialize-database} + * element and creates a {@link BeanDefinition} of type {@link DataSourceInitializer}. Picks up nested + * {@code script} elements and configures a {@link ResourceDatabasePopulator} for them. + * + * @author Dave Syer + * @author Juergen Hoeller + * @since 3.0 + */ +class InitializeDatabaseBeanDefinitionParser extends AbstractBeanDefinitionParser { + + @Override + protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DataSourceInitializer.class); + builder.addPropertyReference("dataSource", element.getAttribute("data-source")); + builder.addPropertyValue("enabled", element.getAttribute("enabled")); + DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder); + builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); + return builder.getBeanDefinition(); + } + + @Override + protected boolean shouldGenerateId() { + return true; + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/config/JdbcNamespaceHandler.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/config/JdbcNamespaceHandler.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/config/JdbcNamespaceHandler.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,34 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.config; + +import org.springframework.beans.factory.xml.NamespaceHandler; +import org.springframework.beans.factory.xml.NamespaceHandlerSupport; + +/** + * {@link NamespaceHandler} for JDBC configuration namespace. + * @author Oliver Gierke + * @author Dave Syer + */ +public class JdbcNamespaceHandler extends NamespaceHandlerSupport { + + @Override + public void init() { + registerBeanDefinitionParser("embedded-database", new EmbeddedDatabaseBeanDefinitionParser()); + registerBeanDefinitionParser("initialize-database", new InitializeDatabaseBeanDefinitionParser()); + } +} Index: 3rdParty_sources/spring/org/springframework/jdbc/config/SortedResourcesFactoryBean.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/config/SortedResourcesFactoryBean.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/config/SortedResourcesFactoryBean.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,97 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.config; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.springframework.context.ResourceLoaderAware; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternUtils; + +/** + * {@link FactoryBean} implementation that takes a list of location Strings + * and creates a sorted array of {@link Resource} instances. + * + * @author Dave Syer + * @author Juergen Hoeller + * @author Christian Dupuis + * @since 3.0 + */ +public class SortedResourcesFactoryBean extends AbstractFactoryBean implements ResourceLoaderAware { + + private final List locations; + + private ResourcePatternResolver resourcePatternResolver; + + + public SortedResourcesFactoryBean(List locations) { + this.locations = locations; + this.resourcePatternResolver = new PathMatchingResourcePatternResolver(); + } + + public SortedResourcesFactoryBean(ResourceLoader resourceLoader, List locations) { + this.locations = locations; + this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader); + } + + + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader); + } + + + @Override + public Class getObjectType() { + return Resource[].class; + } + + @Override + protected Resource[] createInstance() throws Exception { + List scripts = new ArrayList(); + for (String location : this.locations) { + List resources = new ArrayList( + Arrays.asList(this.resourcePatternResolver.getResources(location))); + Collections.sort(resources, new Comparator() { + @Override + public int compare(Resource r1, Resource r2) { + try { + return r1.getURL().toString().compareTo(r2.getURL().toString()); + } + catch (IOException ex) { + return 0; + } + } + }); + for (Resource resource : resources) { + scripts.add(resource); + } + } + return scripts.toArray(new Resource[scripts.size()]); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/config/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/config/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/config/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,6 @@ + +/** + * Defines the Spring JDBC configuration namespace. + */ +package org.springframework.jdbc.config; + Index: 3rdParty_sources/spring/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,75 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * 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 org.springframework.jdbc.core; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +/** + * Simple adapter for {@link PreparedStatementSetter} that applies a given array of arguments. + * + * @author Juergen Hoeller + * @since 3.2.3 + */ +public class ArgumentPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer { + + private final Object[] args; + + + /** + * Create a new ArgPreparedStatementSetter for the given arguments. + * @param args the arguments to set + */ + public ArgumentPreparedStatementSetter(Object[] args) { + this.args = args; + } + + + @Override + public void setValues(PreparedStatement ps) throws SQLException { + if (this.args != null) { + for (int i = 0; i < this.args.length; i++) { + Object arg = this.args[i]; + doSetValue(ps, i + 1, arg); + } + } + } + + /** + * Set the value for prepared statements specified parameter index using the passed in value. + * This method can be overridden by sub-classes if needed. + * @param ps the PreparedStatement + * @param parameterPosition index of the parameter position + * @param argValue the value to set + * @throws SQLException + */ + protected void doSetValue(PreparedStatement ps, int parameterPosition, Object argValue) throws SQLException { + if (argValue instanceof SqlParameterValue) { + SqlParameterValue paramValue = (SqlParameterValue) argValue; + StatementCreatorUtils.setParameterValue(ps, parameterPosition, paramValue, paramValue.getValue()); + } + else { + StatementCreatorUtils.setParameterValue(ps, parameterPosition, SqlTypeValue.TYPE_UNKNOWN, argValue); + } + } + + @Override + public void cleanupParameters() { + StatementCreatorUtils.cleanupParameters(this.args); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,105 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * 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 org.springframework.jdbc.core; + +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Collection; + +import org.springframework.dao.InvalidDataAccessApiUsageException; + +/** + * Simple adapter for {@link PreparedStatementSetter} that applies + * given arrays of arguments and JDBC argument types. + * + * @author Juergen Hoeller + * @since 3.2.3 + */ +public class ArgumentTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer { + + private final Object[] args; + + private final int[] argTypes; + + + /** + * Create a new ArgTypePreparedStatementSetter for the given arguments. + * @param args the arguments to set + * @param argTypes the corresponding SQL types of the arguments + */ + public ArgumentTypePreparedStatementSetter(Object[] args, int[] argTypes) { + if ((args != null && argTypes == null) || (args == null && argTypes != null) || + (args != null && args.length != argTypes.length)) { + throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match"); + } + this.args = args; + this.argTypes = argTypes; + } + + + @Override + public void setValues(PreparedStatement ps) throws SQLException { + int parameterPosition = 1; + if (this.args != null) { + for (int i = 0; i < this.args.length; i++) { + Object arg = this.args[i]; + if (arg instanceof Collection && this.argTypes[i] != Types.ARRAY) { + Collection entries = (Collection) arg; + for (Object entry : entries) { + if (entry instanceof Object[]) { + Object[] valueArray = ((Object[]) entry); + for (Object argValue : valueArray) { + doSetValue(ps, parameterPosition, this.argTypes[i], argValue); + parameterPosition++; + } + } + else { + doSetValue(ps, parameterPosition, this.argTypes[i], entry); + parameterPosition++; + } + } + } + else { + doSetValue(ps, parameterPosition, this.argTypes[i], arg); + parameterPosition++; + } + } + } + } + + /** + * Set the value for the prepared statement's specified parameter position using the passed in + * value and type. This method can be overridden by sub-classes if needed. + * @param ps the PreparedStatement + * @param parameterPosition index of the parameter position + * @param argType the argument type + * @param argValue the argument value + * @throws SQLException + */ + protected void doSetValue(PreparedStatement ps, int parameterPosition, int argType, Object argValue) + throws SQLException { + + StatementCreatorUtils.setParameterValue(ps, parameterPosition, argType, argValue); + } + + @Override + public void cleanupParameters() { + StatementCreatorUtils.cleanupParameters(this.args); + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/BatchPreparedStatementSetter.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/BatchUpdateUtils.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/BatchUpdateUtils.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/BatchUpdateUtils.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,70 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.core; + +import java.util.List; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +/** + * Generic utility methods for working with JDBC batch statements. Mainly for internal use + * within the framework. + * + * @author Thomas Risberg + */ +public abstract class BatchUpdateUtils { + + public static int[] executeBatchUpdate(String sql, final List batchValues, final int[] columnTypes, JdbcOperations jdbcOperations) { + return jdbcOperations.batchUpdate( + sql, + new BatchPreparedStatementSetter() { + + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + Object[] values = batchValues.get(i); + setStatementParameters(values, ps, columnTypes); + } + + @Override + public int getBatchSize() { + return batchValues.size(); + } + }); + } + + protected static void setStatementParameters(Object[] values, PreparedStatement ps, int[] columnTypes) throws SQLException { + int colIndex = 0; + for (Object value : values) { + colIndex++; + if (value instanceof SqlParameterValue) { + SqlParameterValue paramValue = (SqlParameterValue) value; + StatementCreatorUtils.setParameterValue(ps, colIndex, paramValue, paramValue.getValue()); + } + else { + int colType; + if (columnTypes == null || columnTypes.length < colIndex) { + colType = SqlTypeValue.TYPE_UNKNOWN; + } + else { + colType = columnTypes[colIndex - 1]; + } + StatementCreatorUtils.setParameterValue(ps, colIndex, colType, value); + } + } + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/BeanPropertyRowMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/CallableStatementCallback.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/CallableStatementCreator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/CallableStatementCreatorFactory.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/ColumnMapRowMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/ConnectionCallback.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/DisposableSqlTypeValue.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/InterruptibleBatchPreparedStatementSetter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/JdbcOperations.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/JdbcTemplate.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/ParameterDisposer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/ParameterMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/ParameterizedPreparedStatementSetter.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/ParameterizedPreparedStatementSetter.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/ParameterizedPreparedStatementSetter.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,50 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.core; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +/** + * Parameterized callback interface used by the {@link JdbcTemplate} class for + * batch updates. + * + *

This interface sets values on a {@link java.sql.PreparedStatement} provided + * by the JdbcTemplate class, for each of a number of updates in a batch using the + * same SQL. Implementations are responsible for setting any necessary parameters. + * SQL with placeholders will already have been supplied. + * + *

Implementations do not need to concern themselves with SQLExceptions + * that may be thrown from operations they attempt. The JdbcTemplate class will + * catch and handle SQLExceptions appropriately. + * + * @author Nicolas Fabre + * @author Thomas Risberg + * @since 3.1 + * @see JdbcTemplate#batchUpdate(String, java.util.Collection, int, ParameterizedPreparedStatementSetter) + */ +public interface ParameterizedPreparedStatementSetter { + + /** + * Set parameter values on the given PreparedStatement. + * @param ps the PreparedStatement to invoke setter methods on + * @param argument the object containing the values to be set + * @throws SQLException if a SQLException is encountered (i.e. there is no need to catch SQLException) + */ + void setValues(PreparedStatement ps, T argument) throws SQLException; + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/PreparedStatementCallback.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/PreparedStatementCreator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/PreparedStatementSetter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/ResultSetExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/ResultSetSupportingSqlParameter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/RowCallbackHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/RowCountCallbackHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/RowMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/RowMapperResultSetExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SingleColumnRowMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlInOutParameter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlOutParameter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlParameter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlParameterValue.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlReturnResultSet.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlReturnType.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlReturnUpdateCount.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/SqlTypeValue.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/StatementCallback.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/StatementCreatorUtils.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/CallMetaDataContext.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/CallMetaDataProviderFactory.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/CallParameterMetaData.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/DerbyTableMetaDataProvider.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/DerbyTableMetaDataProvider.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/DerbyTableMetaDataProvider.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2007 the original author or authors. + * + * 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 org.springframework.jdbc.core.metadata; + +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + +/** + * The Derby specific implementation of the {@link org.springframework.jdbc.core.metadata.TableMetaDataProvider}. + * Overrides the Derby metadata info regarding retreiving generated keys. It seems to work OK so not sure why they + * claim it's not supported. + * + * @author Thomas Risberg + * @since 3.0 + */ +public class DerbyTableMetaDataProvider extends GenericTableMetaDataProvider { + + private boolean supportsGeneratedKeysOverride = false; + + public DerbyTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException { + super(databaseMetaData); + } + + @Override + public void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException { + super.initializeWithMetaData(databaseMetaData); + if (!databaseMetaData.supportsGetGeneratedKeys()) { + logger.warn("Overriding supportsGetGeneratedKeys from DatabaseMetaData to 'true'; it was reported as " + + "'false' by " + databaseMetaData.getDriverName() + " " + databaseMetaData.getDriverVersion()); + supportsGeneratedKeysOverride = true; + } + } + + @Override + public boolean isGetGeneratedKeysSupported() { + boolean derbysAnswer = super.isGetGeneratedKeysSupported(); + if (!derbysAnswer) { + return supportsGeneratedKeysOverride; + } + return derbysAnswer; + } +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/OracleCallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,151 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.core.metadata; + +import java.lang.reflect.Method; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; +import java.sql.Types; + +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; +import org.springframework.util.ReflectionUtils; + +/** + * Oracle-specific implementation of the {@link org.springframework.jdbc.core.metadata.TableMetaDataProvider}. + * Supports a feature for including synonyms in the metadata lookup. Also supports lookup of current schema + * using the sys_context. + * + *

Thanks to Mike Youngstrom and Bruce Campbell for submitting the original suggestion for the Oracle + * current schema lookup implementation. + * + * @author Thomas Risberg + * @author Juergen Hoeller + * @since 3.0 + */ +public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider { + + private final boolean includeSynonyms; + + private String defaultSchema; + + + public OracleTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException { + this(databaseMetaData, false); + } + + public OracleTableMetaDataProvider(DatabaseMetaData databaseMetaData, boolean includeSynonyms) throws SQLException { + super(databaseMetaData); + this.includeSynonyms = includeSynonyms; + lookupDefaultSchema(databaseMetaData); + } + + + @Override + protected String getDefaultSchema() { + if (this.defaultSchema != null) { + return defaultSchema; + } + return super.getDefaultSchema(); + } + + @Override + public void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, + String catalogName, String schemaName, String tableName) throws SQLException { + + if (!this.includeSynonyms) { + logger.debug("Defaulting to no synonyms in table metadata lookup"); + super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName); + return; + } + + Connection con = databaseMetaData.getConnection(); + NativeJdbcExtractor nativeJdbcExtractor = getNativeJdbcExtractor(); + if (nativeJdbcExtractor != null) { + con = nativeJdbcExtractor.getNativeConnection(con); + } + boolean isOracleCon; + try { + Class oracleConClass = con.getClass().getClassLoader().loadClass("oracle.jdbc.OracleConnection"); + isOracleCon = oracleConClass.isInstance(con); + } + catch (ClassNotFoundException ex) { + if (logger.isInfoEnabled()) { + logger.info("Couldn't find Oracle JDBC API: " + ex); + } + isOracleCon = false; + } + + if (!isOracleCon) { + logger.warn("Unable to include synonyms in table metadata lookup. Connection used for " + + "DatabaseMetaData is not recognized as an Oracle connection: " + con); + super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName); + return; + } + + logger.debug("Including synonyms in table metadata lookup"); + Method setIncludeSynonyms; + Boolean originalValueForIncludeSynonyms; + + try { + Method getIncludeSynonyms = con.getClass().getMethod("getIncludeSynonyms", (Class[]) null); + ReflectionUtils.makeAccessible(getIncludeSynonyms); + originalValueForIncludeSynonyms = (Boolean) getIncludeSynonyms.invoke(con); + + setIncludeSynonyms = con.getClass().getMethod("setIncludeSynonyms", boolean.class); + ReflectionUtils.makeAccessible(setIncludeSynonyms); + setIncludeSynonyms.invoke(con, Boolean.TRUE); + } + catch (Exception ex) { + throw new InvalidDataAccessApiUsageException("Couldn't prepare Oracle Connection", ex); + } + + super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName); + + try { + setIncludeSynonyms.invoke(con, originalValueForIncludeSynonyms); + } + catch (Exception ex) { + throw new InvalidDataAccessApiUsageException("Couldn't reset Oracle Connection", ex); + } + } + + /* + * Oracle-based implementation for detecting the current schema. + */ + private void lookupDefaultSchema(DatabaseMetaData databaseMetaData) { + try { + CallableStatement cstmt = null; + try { + cstmt = databaseMetaData.getConnection().prepareCall("{? = call sys_context('USERENV', 'CURRENT_SCHEMA')}"); + cstmt.registerOutParameter(1, Types.VARCHAR); + cstmt.execute(); + this.defaultSchema = cstmt.getString(1); + } + finally { + if (cstmt != null) { + cstmt.close(); + } + } + } + catch (Exception ignore) { + } + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/PostgresCallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/PostgresTableMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/TableMetaDataContext.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/TableMetaDataProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/metadata/TableParameterMetaData.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/metadata/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,8 @@ + +/** + * + * Context metadata abstraction for the configuration and execution of a stored procedure call. + * + */ +package org.springframework.jdbc.core.metadata; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/AbstractSqlParameterSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/EmptySqlParameterSource.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/EmptySqlParameterSource.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/EmptySqlParameterSource.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,53 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * 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 org.springframework.jdbc.core.namedparam; + +/** + * A simple empty implementation of the {@link SqlParameterSource} interface. + * + * @author Juergen Hoeller + * @since 3.2.2 + */ +public class EmptySqlParameterSource implements SqlParameterSource { + + /** + * A shared instance of {@link EmptySqlParameterSource}. + */ + public static final EmptySqlParameterSource INSTANCE = new EmptySqlParameterSource(); + + + @Override + public boolean hasValue(String paramName) { + return false; + } + + @Override + public Object getValue(String paramName) throws IllegalArgumentException { + throw new IllegalArgumentException("This SqlParameterSource is empty"); + } + + @Override + public int getSqlType(String paramName) { + return TYPE_UNKNOWN; + } + + @Override + public String getTypeName(String paramName) { + return null; + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/MapSqlParameterSource.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,58 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.core.namedparam; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +import org.springframework.jdbc.core.BatchUpdateUtils; +import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; + +/** + * Generic utility methods for working with JDBC batch statements using named parameters. Mainly for internal use + * within the framework. + * + * @author Thomas Risberg + */ +public class NamedParameterBatchUpdateUtils extends BatchUpdateUtils { + + public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql, + final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) { + if (batchArgs.length <= 0) { + return new int[] {0}; + } + String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]); + return jdbcOperations.batchUpdate( + sqlToUse, + new BatchPreparedStatementSetter() { + + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); + int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]); + setStatementParameters(values, ps, columnTypes); + } + + @Override + public int getBatchSize() { + return batchArgs.length; + } + }); + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/NamedParameterJdbcDaoSupport.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/ParsedSql.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/SqlParameterSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/SqlParameterSourceUtils.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/namedparam/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,16 @@ +/** + * + * JdbcTemplate variant with named parameter support. + * + *

NamedParameterJdbcTemplate is a wrapper around JdbcTemplate that adds + * support for named parameter parsing. It does not implement the JdbcOperations + * interface or extend JdbcTemplate, but implements the dedicated + * NamedParameterJdbcOperations interface. + * + *

If you need the full power of Spring JDBC for less common operations, use + * the {@code getJdbcOperations()} method of NamedParameterJdbcTemplate and + * work with the returned classic template, or use a JdbcTemplate instance directly. + * + */ +package org.springframework.jdbc.core.namedparam; + Index: 3rdParty_sources/spring/org/springframework/jdbc/core/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,9 @@ + +/** + * + * Provides the core JDBC framework, based on JdbcTemplate + * and its associated callback interfaces and helper objects. + * + */ +package org.springframework.jdbc.core; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/AbstractJdbcCall.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/ParameterizedBeanPropertyRowMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/ParameterizedRowMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/ParameterizedSingleColumnRowMapper.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/SimpleJdbcCall.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/SimpleJdbcCallOperations.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/SimpleJdbcDaoSupport.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/SimpleJdbcInsertOperations.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/SimpleJdbcOperations.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/simple/SimpleJdbcTemplate.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/simple/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/simple/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/simple/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,16 @@ +/** + * + * Simplification layer over JdbcTemplate for Java 5 and above. + * + *

{@code SimpleJdbcInsert} and {@code SimpleJdbcCall} are classes that takes advantage + * of database metadata provided by the JDBC driver to simplify the application code. Much of the + * parameter specification becomes unnecessary since it can be looked up in the metadata. + * + * Note: The {@code SimpleJdbcOperations} and {@code SimpleJdbcTemplate}, which provides a wrapper + * around JdbcTemplate to take advantage of Java 5 features like generics, varargs and autoboxing, is now deprecated + * since Spring 3.1. All functionality is now available in the {@code JdbcOperations} and + * {@code NamedParametersOperations} respectively. + * + */ +package org.springframework.jdbc.core.simple; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/support/AbstractInterruptibleBatchPreparedStatementSetter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/support/AbstractLobCreatingPreparedStatementCallback.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/support/AbstractSqlTypeValue.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/support/JdbcDaoSupport.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/core/support/SqlLobValue.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/core/support/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/core/support/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/core/support/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,8 @@ +/** + * + * Classes supporting the {@code org.springframework.jdbc.core} package. + * Contains a DAO base class for JdbcTemplate usage. + * + */ +package org.springframework.jdbc.core.support; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/AbstractDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/AbstractDriverBasedDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/ConnectionHandle.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/ConnectionHolder.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/ConnectionProxy.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/DataSourceTransactionManager.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/DataSourceUtils.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/DelegatingDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/DriverManagerDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/JdbcTransactionObjectSupport.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/SimpleConnectionHandle.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/SimpleDriverDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/SingleConnectionDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/SmartDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/WebSphereDataSourceAdapter.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,52 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import javax.sql.DataSource; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Base class for {@link EmbeddedDatabaseConfigurer} implementations providing common shutdown behavior. + * + * @author Oliver Gierke + * @author Juergen Hoeller + * @since 3.0 + */ +abstract class AbstractEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigurer { + + protected final Log logger = LogFactory.getLog(getClass()); + + @Override + public void shutdown(DataSource dataSource, String databaseName) { + try { + Connection connection = dataSource.getConnection(); + Statement stmt = connection.createStatement(); + stmt.execute("SHUTDOWN"); + } + catch (SQLException ex) { + if (logger.isWarnEnabled()) { + logger.warn("Could not shutdown embedded database", ex); + } + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/ConnectionProperties.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/ConnectionProperties.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/ConnectionProperties.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,58 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.sql.Driver; + +/** + * {@code ConnectionProperties} serves as a simple data container that allows + * essential JDBC connection properties to be configured consistently, + * independent of the actual {@link javax.sql.DataSource DataSource} + * implementation. + * + * @author Keith Donald + * @author Sam Brannen + * @since 3.0 + * @see DataSourceFactory + */ +public interface ConnectionProperties { + + /** + * Set the JDBC driver class to use to connect to the database. + * @param driverClass the jdbc driver class + */ + void setDriverClass(Class driverClass); + + /** + * Set the JDBC connection URL for the database. + * @param url the connection url + */ + void setUrl(String url); + + /** + * Set the username to use to connect to the database. + * @param username the username + */ + void setUsername(String username); + + /** + * Set the password to use to connect to the database. + * @param password the password + */ + void setPassword(String password); + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/DataSourceFactory.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/DataSourceFactory.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/DataSourceFactory.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,49 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import javax.sql.DataSource; + +/** + * {@code DataSourceFactory} encapsulates the creation of a particular + * {@link DataSource} implementation such as a + * {@link org.springframework.jdbc.datasource.SimpleDriverDataSource + * SimpleDriverDataSource} or a connection pool such as Apache DBCP or C3P0. + * + *

Call {@link #getConnectionProperties()} to configure normalized + * {@code DataSource} properties before calling {@link #getDataSource()} to + * actually get the configured {@code DataSource} instance. + * + * @author Keith Donald + * @author Sam Brannen + * @since 3.0 + */ +public interface DataSourceFactory { + + /** + * Get the {@linkplain ConnectionProperties connection properties} of the + * {@link #getDataSource DataSource} to be configured. + */ + ConnectionProperties getConnectionProperties(); + + /** + * Get the {@link DataSource} with the {@linkplain #getConnectionProperties + * connection properties} applied. + */ + DataSource getDataSource(); + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,82 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.sql.SQLException; +import java.util.Properties; +import javax.sql.DataSource; + +import org.apache.commons.logging.LogFactory; +import org.apache.derby.jdbc.EmbeddedDriver; + +/** + * {@link EmbeddedDatabaseConfigurer} for the Apache Derby database 10.6+. + *

Call {@link #getInstance()} to get the singleton instance of this class. + * + * @author Oliver Gierke + * @author Juergen Hoeller + * @since 3.0 + */ +final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigurer { + + private static final String URL_TEMPLATE = "jdbc:derby:memory:%s;%s"; + + private static DerbyEmbeddedDatabaseConfigurer instance; + + + /** + * Get the singleton {@link DerbyEmbeddedDatabaseConfigurer} instance. + * @return the configurer + * @throws ClassNotFoundException if Derby is not on the classpath + */ + public static synchronized DerbyEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException { + if (instance == null) { + // disable log file + System.setProperty("derby.stream.error.method", + OutputStreamFactory.class.getName() + ".getNoopOutputStream"); + instance = new DerbyEmbeddedDatabaseConfigurer(); + } + return instance; + } + + + private DerbyEmbeddedDatabaseConfigurer() { + } + + @Override + public void configureConnectionProperties(ConnectionProperties properties, String databaseName) { + properties.setDriverClass(EmbeddedDriver.class); + properties.setUrl(String.format(URL_TEMPLATE, databaseName, "create=true")); + properties.setUsername("sa"); + properties.setPassword(""); + } + + @Override + public void shutdown(DataSource dataSource, String databaseName) { + try { + new EmbeddedDriver().connect( + String.format(URL_TEMPLATE, databaseName, "drop=true"), new Properties()); + } + catch (SQLException ex) { + // Error code that indicates successful shutdown + if (!"08006".equals(ex.getSQLState())) { + LogFactory.getLog(getClass()).warn("Could not shutdown in-memory Derby database", ex); + } + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabase.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabase.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabase.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import javax.sql.DataSource; + +/** + * {@code EmbeddedDatabase} serves as a handle to an embedded database instance. + * + *

An {@code EmbeddedDatabase} is also a {@link DataSource} and adds a + * {@link #shutdown} operation so that the embedded database instance can be + * shutdown. + * + * @author Keith Donald + * @author Sam Brannen + * @since 3.0 + */ +public interface EmbeddedDatabase extends DataSource { + + /** + * Shutdown this embedded database. + */ + void shutdown(); + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilder.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilder.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseBuilder.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,254 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import javax.sql.DataSource; + +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.ResourceLoader; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.jdbc.datasource.init.ScriptUtils; +import org.springframework.util.Assert; + +/** + * A builder that provides a convenient API for constructing an embedded database. + * + *

Usage Example

+ *
+ * EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
+ *     .setType(H2)
+ *     .setScriptEncoding("UTF-8")
+ *     .ignoreFailedDrops(true)
+ *     .addScript("schema.sql")
+ *     .addScripts("user_data.sql", "country_data.sql")
+ *     .build();
+ *
+ * // ...
+ *
+ * db.shutdown();
+ * 
+ * + * @author Keith Donald + * @author Juergen Hoeller + * @author Dave Syer + * @author Sam Brannen + * @since 3.0 + * @see org.springframework.jdbc.datasource.init.ScriptUtils + * @see org.springframework.jdbc.datasource.init.ResourceDatabasePopulator + * @see org.springframework.jdbc.datasource.init.DatabasePopulatorUtils + */ +public class EmbeddedDatabaseBuilder { + + private final EmbeddedDatabaseFactory databaseFactory; + + private final ResourceDatabasePopulator databasePopulator; + + private final ResourceLoader resourceLoader; + + + /** + * Create a new embedded database builder with a {@link DefaultResourceLoader}. + */ + public EmbeddedDatabaseBuilder() { + this(new DefaultResourceLoader()); + } + + /** + * Create a new embedded database builder with the given {@link ResourceLoader}. + * @param resourceLoader the {@code ResourceLoader} to delegate to + */ + public EmbeddedDatabaseBuilder(ResourceLoader resourceLoader) { + this.databaseFactory = new EmbeddedDatabaseFactory(); + this.databasePopulator = new ResourceDatabasePopulator(); + this.databaseFactory.setDatabasePopulator(this.databasePopulator); + this.resourceLoader = resourceLoader; + } + + /** + * Set the name of the embedded database. + *

Defaults to {@link EmbeddedDatabaseFactory#DEFAULT_DATABASE_NAME} if + * not called. + * @param databaseName the name of the embedded database to build + * @return {@code this}, to facilitate method chaining + */ + public EmbeddedDatabaseBuilder setName(String databaseName) { + this.databaseFactory.setDatabaseName(databaseName); + return this; + } + + /** + * Set the type of embedded database. + *

Defaults to HSQL if not called. + * @param databaseType the type of embedded database to build + * @return {@code this}, to facilitate method chaining + */ + public EmbeddedDatabaseBuilder setType(EmbeddedDatabaseType databaseType) { + this.databaseFactory.setDatabaseType(databaseType); + return this; + } + + /** + * Set the factory to use to create the {@link DataSource} instance that + * connects to the embedded database. + *

Defaults to {@link SimpleDriverDataSourceFactory} but can be overridden, + * for example to introduce connection pooling. + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder setDataSourceFactory(DataSourceFactory dataSourceFactory) { + Assert.notNull(dataSourceFactory, "DataSourceFactory is required"); + this.databaseFactory.setDataSourceFactory(dataSourceFactory); + return this; + } + + /** + * Add default SQL scripts to execute to populate the database. + *

The default scripts are {@code "schema.sql"} to create the database + * schema and {@code "data.sql"} to populate the database with data. + * @return {@code this}, to facilitate method chaining + */ + public EmbeddedDatabaseBuilder addDefaultScripts() { + return addScripts("schema.sql", "data.sql"); + } + + /** + * Add an SQL script to execute to initialize or populate the database. + * @param script the script to execute + * @return {@code this}, to facilitate method chaining + */ + public EmbeddedDatabaseBuilder addScript(String script) { + this.databasePopulator.addScript(this.resourceLoader.getResource(script)); + return this; + } + + /** + * Add multiple SQL scripts to execute to initialize or populate the database. + * @param scripts the scripts to execute + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder addScripts(String... scripts) { + for (String script : scripts) { + addScript(script); + } + return this; + } + + /** + * Specify the character encoding used in all SQL scripts, if different from + * the platform encoding. + * @param scriptEncoding the encoding used in scripts + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder setScriptEncoding(String scriptEncoding) { + this.databasePopulator.setSqlScriptEncoding(scriptEncoding); + return this; + } + + /** + * Specify the statement separator used in all SQL scripts, if a custom one. + *

Defaults to {@code ";"} if not specified and falls back to {@code "\n"} + * as a last resort; may be set to {@link ScriptUtils#EOF_STATEMENT_SEPARATOR} + * to signal that each script contains a single statement without a separator. + * @param separator the statement separator + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder setSeparator(String separator) { + this.databasePopulator.setSeparator(separator); + return this; + } + + /** + * Specify the single-line comment prefix used in all SQL scripts. + *

Defaults to {@code "--"}. + * @param commentPrefix the prefix for single-line comments + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder setCommentPrefix(String commentPrefix) { + this.databasePopulator.setCommentPrefix(commentPrefix); + return this; + } + + /** + * Specify the start delimiter for block comments in all SQL scripts. + *

Defaults to {@code "/*"}. + * @param blockCommentStartDelimiter the start delimiter for block comments + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + * @see #setBlockCommentEndDelimiter + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder setBlockCommentStartDelimiter(String blockCommentStartDelimiter) { + this.databasePopulator.setBlockCommentStartDelimiter(blockCommentStartDelimiter); + return this; + } + + /** + * Specify the end delimiter for block comments in all SQL scripts. + *

Defaults to "*/". + * @param blockCommentEndDelimiter the end delimiter for block comments + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + * @see #setBlockCommentStartDelimiter + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder setBlockCommentEndDelimiter(String blockCommentEndDelimiter) { + this.databasePopulator.setBlockCommentEndDelimiter(blockCommentEndDelimiter); + return this; + } + + /** + * Specify that all failures which occur while executing SQL scripts should + * be logged but should not cause a failure. + *

Defaults to {@code false}. + * @param flag {@code true} if script execution should continue on error + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder continueOnError(boolean flag) { + this.databasePopulator.setContinueOnError(flag); + return this; + } + + /** + * Specify that a failed SQL {@code DROP} statement within an executed + * script can be ignored. + *

This is useful for a database whose SQL dialect does not support an + * {@code IF EXISTS} clause in a {@code DROP} statement. + *

The default is {@code false} so that {@link #build building} will fail + * fast if a script starts with a {@code DROP} statement. + * @param flag {@code true} if failed drop statements should be ignored + * @return {@code this}, to facilitate method chaining + * @since 4.0.3 + */ + public EmbeddedDatabaseBuilder ignoreFailedDrops(boolean flag) { + this.databasePopulator.setIgnoreFailedDrops(flag); + return this; + } + + /** + * Build the embedded database. + * @return the embedded database + */ + public EmbeddedDatabase build() { + return this.databaseFactory.getDatabase(); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurer.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurer.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurer.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,49 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import javax.sql.DataSource; + +/** + * {@code EmbeddedDatabaseConfigurer} encapsulates the configuration required to + * create, connect to, and shutdown a specific type of embedded database such as + * HSQL or H2. + *

Create an implementation for each database type you wish to support; for + * example HSQL, H2, or some other type. + * + * @author Keith Donald + * @author Sam Brannen + * @since 3.0 + */ +public interface EmbeddedDatabaseConfigurer { + + /** + * Configure the properties required to create and connect to the embedded + * database instance. + * @param properties connection properties to configure + * @param databaseName the name of the embedded database + */ + void configureConnectionProperties(ConnectionProperties properties, String databaseName); + + /** + * Shutdown the embedded database instance that backs the supplied {@link DataSource}. + * @param dataSource the data source + * @param databaseName the name of the database being shutdown + */ + void shutdown(DataSource dataSource, String databaseName); + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurerFactory.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurerFactory.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurerFactory.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import org.springframework.util.Assert; + +/** + * Maps well-known {@linkplain EmbeddedDatabaseType embedded database types} to + * {@link EmbeddedDatabaseConfigurer} strategies. + * + * @author Keith Donald + * @author Oliver Gierke + * @author Sam Brannen + * @since 3.0 + */ +final class EmbeddedDatabaseConfigurerFactory { + + public static EmbeddedDatabaseConfigurer getConfigurer(EmbeddedDatabaseType type) throws IllegalStateException { + Assert.notNull(type, "EmbeddedDatabaseType is required"); + try { + switch (type) { + case HSQL: + return HsqlEmbeddedDatabaseConfigurer.getInstance(); + case H2: + return H2EmbeddedDatabaseConfigurer.getInstance(); + case DERBY: + return DerbyEmbeddedDatabaseConfigurer.getInstance(); + default: + throw new UnsupportedOperationException("Embedded database type [" + type + "] is not supported"); + } + } + catch (ClassNotFoundException ex) { + throw new IllegalStateException("Driver for test database type [" + type + + "] is not available in the classpath", ex); + } + } + + private EmbeddedDatabaseConfigurerFactory() { + /* no-op */ + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactory.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,254 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.logging.Logger; +import javax.sql.DataSource; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.jdbc.datasource.init.DatabasePopulator; +import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; +import org.springframework.util.Assert; + +/** + * Factory for creating {@link EmbeddedDatabase} instances. + * + *

Callers are guaranteed that a returned database has been fully initialized + * and populated. + * + *

Can be configured: + *

    + *
  • Call {@link #setDatabaseName(String)} to change the name of the database. + *
  • Call {@link #setDatabaseType(EmbeddedDatabaseType)} to set the database + * type if you wish to use one of the supported types. + *
  • Call {@link #setDatabaseConfigurer(EmbeddedDatabaseConfigurer)} to + * configure support for your own embedded database type. + *
  • Call {@link #setDatabasePopulator(DatabasePopulator)} to change the + * algorithm used to populate the database. + *
  • Call {@link #setDataSourceFactory(DataSourceFactory)} to change the type + * of {@link DataSource} used to connect to the database. + *
+ * + *

Call {@link #getDatabase()} to get the {@link EmbeddedDatabase} instance. + * + * @author Keith Donald + * @author Juergen Hoeller + * @author Sam Brannen + * @since 3.0 + */ +public class EmbeddedDatabaseFactory { + + /** + * Default name for an embedded database: "testdb". + */ + public static final String DEFAULT_DATABASE_NAME = "testdb"; + + + private static final Log logger = LogFactory.getLog(EmbeddedDatabaseFactory.class); + + private String databaseName = DEFAULT_DATABASE_NAME; + + private DataSourceFactory dataSourceFactory = new SimpleDriverDataSourceFactory(); + + private EmbeddedDatabaseConfigurer databaseConfigurer; + + private DatabasePopulator databasePopulator; + + private DataSource dataSource; + + + /** + * Set the name of the database. + *

Defaults to {@value #DEFAULT_DATABASE_NAME}. + * @param databaseName name of the embedded database + */ + public void setDatabaseName(String databaseName) { + Assert.hasText(databaseName, "Database name is required"); + this.databaseName = databaseName; + } + + /** + * Set the factory to use to create the {@link DataSource} instance that + * connects to the embedded database. + *

Defaults to {@link SimpleDriverDataSourceFactory}. + */ + public void setDataSourceFactory(DataSourceFactory dataSourceFactory) { + Assert.notNull(dataSourceFactory, "DataSourceFactory is required"); + this.dataSourceFactory = dataSourceFactory; + } + + /** + * Set the type of embedded database to use. + *

Call this when you wish to configure one of the pre-supported types. + *

Defaults to HSQL. + * @param type the database type + */ + public void setDatabaseType(EmbeddedDatabaseType type) { + this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(type); + } + + /** + * Set the strategy that will be used to configure the embedded database instance. + *

Call this when you wish to use an embedded database type not already supported. + */ + public void setDatabaseConfigurer(EmbeddedDatabaseConfigurer configurer) { + this.databaseConfigurer = configurer; + } + + /** + * Set the strategy that will be used to initialize or populate the embedded + * database. + *

Defaults to {@code null}. + */ + public void setDatabasePopulator(DatabasePopulator populator) { + this.databasePopulator = populator; + } + + /** + * Factory method that returns the {@link EmbeddedDatabase embedded database} + * instance, which is also a {@link DataSource}. + */ + public EmbeddedDatabase getDatabase() { + if (this.dataSource == null) { + initDatabase(); + } + return new EmbeddedDataSourceProxy(this.dataSource); + } + + + /** + * Hook to initialize the embedded database. Subclasses may call this method + * to force initialization. + *

After calling this method, {@link #getDataSource()} returns the + * {@link DataSource} providing connectivity to the database. + */ + protected void initDatabase() { + // Create the embedded database source first + if (logger.isInfoEnabled()) { + logger.info("Creating embedded database '" + this.databaseName + "'"); + } + if (this.databaseConfigurer == null) { + this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseType.HSQL); + } + this.databaseConfigurer.configureConnectionProperties( + this.dataSourceFactory.getConnectionProperties(), this.databaseName); + this.dataSource = this.dataSourceFactory.getDataSource(); + + // Now populate the database + if (this.databasePopulator != null) { + try { + DatabasePopulatorUtils.execute(this.databasePopulator, this.dataSource); + } + catch (RuntimeException ex) { + // failed to populate, so leave it as not initialized + shutdownDatabase(); + throw ex; + } + } + } + + /** + * Hook to shutdown the embedded database. Subclasses may call this method + * to force shutdown. + *

After calling, {@link #getDataSource()} returns {@code null}. + *

Does nothing if no embedded database has been initialized. + */ + protected void shutdownDatabase() { + if (this.dataSource != null) { + this.databaseConfigurer.shutdown(this.dataSource, this.databaseName); + this.dataSource = null; + } + } + + /** + * Hook that gets the {@link DataSource} that provides the connectivity to the + * embedded database. + *

Returns {@code null} if the {@code DataSource} has not been initialized + * or if the database has been shut down. Subclasses may call this method to + * access the {@code DataSource} instance directly. + */ + protected final DataSource getDataSource() { + return this.dataSource; + } + + + private class EmbeddedDataSourceProxy implements EmbeddedDatabase { + + private final DataSource dataSource; + + public EmbeddedDataSourceProxy(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public Connection getConnection() throws SQLException { + return this.dataSource.getConnection(); + } + + @Override + public Connection getConnection(String username, String password) throws SQLException { + return this.dataSource.getConnection(username, password); + } + + @Override + public PrintWriter getLogWriter() throws SQLException { + return this.dataSource.getLogWriter(); + } + + @Override + public void setLogWriter(PrintWriter out) throws SQLException { + this.dataSource.setLogWriter(out); + } + + @Override + public int getLoginTimeout() throws SQLException { + return this.dataSource.getLoginTimeout(); + } + + @Override + public void setLoginTimeout(int seconds) throws SQLException { + this.dataSource.setLoginTimeout(seconds); + } + + @Override + public T unwrap(Class iface) throws SQLException { + return this.dataSource.unwrap(iface); + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return this.dataSource.isWrapperFor(iface); + } + + // getParentLogger() is required for JDBC 4.1 compatibility + @Override + public Logger getParentLogger() { + return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); + } + + @Override + public void shutdown() { + shutdownDatabase(); + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBean.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBean.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBean.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,90 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.jdbc.datasource.init.DatabasePopulator; +import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; + +/** + * A subclass of {@link EmbeddedDatabaseFactory} that implements {@link FactoryBean} + * for registration as a Spring bean. Returns the actual {@link DataSource} that + * provides connectivity to the embedded database to Spring. + * + *

The target {@link DataSource} is returned instead of an {@link EmbeddedDatabase} + * proxy since the {@link FactoryBean} will manage the initialization and destruction + * lifecycle of the embedded database instance. + * + *

Implements {@link DisposableBean} to shutdown the embedded database when the + * managing Spring container is being closed. + * + * @author Keith Donald + * @author Juergen Hoeller + * @since 3.0 + */ +public class EmbeddedDatabaseFactoryBean extends EmbeddedDatabaseFactory + implements FactoryBean, InitializingBean, DisposableBean { + + private DatabasePopulator databaseCleaner; + + + /** + * Set a script execution to be run in the bean destruction callback, + * cleaning up the database and leaving it in a known state for others. + * @param databaseCleaner the database script executor to run on destroy + * @see #setDatabasePopulator + * @see org.springframework.jdbc.datasource.init.DataSourceInitializer#setDatabaseCleaner + */ + public void setDatabaseCleaner(DatabasePopulator databaseCleaner) { + this.databaseCleaner = databaseCleaner; + } + + @Override + public void afterPropertiesSet() { + initDatabase(); + } + + + @Override + public DataSource getObject() { + return getDataSource(); + } + + @Override + public Class getObjectType() { + return DataSource.class; + } + + @Override + public boolean isSingleton() { + return true; + } + + + @Override + public void destroy() { + if (this.databaseCleaner != null) { + DatabasePopulatorUtils.execute(this.databaseCleaner, getDataSource()); + } + shutdownDatabase(); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,37 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +/** + * A supported embedded database type. + * + * @author Keith Donald + * @author Oliver Gierke + * @since 3.0 + */ +public enum EmbeddedDatabaseType { + + /** The Hypersonic Embedded Java SQL Database (http://hsqldb.org) */ + HSQL, + + /** The H2 Embedded Java SQL Database Engine (http://h2database.com) */ + H2, + + /** The Apache Derby Embedded SQL Database (http://db.apache.org/derby) */ + DERBY + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,66 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.sql.Driver; + +import org.springframework.util.ClassUtils; + +/** + * {@link EmbeddedDatabaseConfigurer} for an H2 embedded database instance. + *

Call {@link #getInstance()} to get the singleton instance of this class. + * + * @author Oliver Gierke + * @author Juergen Hoeller + * @author Sam Brannen + * @since 3.0 + */ +final class H2EmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer { + + private static H2EmbeddedDatabaseConfigurer instance; + + private final Class driverClass; + + + /** + * Get the singleton {@code H2EmbeddedDatabaseConfigurer} instance. + * @return the configurer + * @throws ClassNotFoundException if H2 is not on the classpath + */ + @SuppressWarnings("unchecked") + public static synchronized H2EmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException { + if (instance == null) { + instance = new H2EmbeddedDatabaseConfigurer( (Class) + ClassUtils.forName("org.h2.Driver", H2EmbeddedDatabaseConfigurer.class.getClassLoader())); + } + return instance; + } + + + private H2EmbeddedDatabaseConfigurer(Class driverClass) { + this.driverClass = driverClass; + } + + @Override + public void configureConnectionProperties(ConnectionProperties properties, String databaseName) { + properties.setDriverClass(this.driverClass); + properties.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false", databaseName)); + properties.setUsername("sa"); + properties.setPassword(""); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,65 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.sql.Driver; + +import org.springframework.util.ClassUtils; + +/** + * {@link EmbeddedDatabaseConfigurer} for an HSQL embedded database instance. + *

Call {@link #getInstance()} to get the singleton instance of this class. + * + * @author Keith Donald + * @author Oliver Gierke + * @since 3.0 + */ +final class HsqlEmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer { + + private static HsqlEmbeddedDatabaseConfigurer instance; + + private final Class driverClass; + + + /** + * Get the singleton {@link HsqlEmbeddedDatabaseConfigurer} instance. + * @return the configurer + * @throws ClassNotFoundException if HSQL is not on the classpath + */ + @SuppressWarnings("unchecked") + public static synchronized HsqlEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException { + if (instance == null) { + instance = new HsqlEmbeddedDatabaseConfigurer( (Class) + ClassUtils.forName("org.hsqldb.jdbcDriver", HsqlEmbeddedDatabaseConfigurer.class.getClassLoader())); + } + return instance; + } + + + private HsqlEmbeddedDatabaseConfigurer(Class driverClass) { + this.driverClass = driverClass; + } + + @Override + public void configureConnectionProperties(ConnectionProperties properties, String databaseName) { + properties.setDriverClass(this.driverClass); + properties.setUrl("jdbc:hsqldb:mem:" + databaseName); + properties.setUsername("sa"); + properties.setPassword(""); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/OutputStreamFactory.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/OutputStreamFactory.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/OutputStreamFactory.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,43 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * Internal helper for exposing dummy OutputStreams to embedded databases + * such as Derby, preventing the creation of a log file. + * + * @author Juergen Hoeller + * @since 3.0 + */ +public class OutputStreamFactory { + + /** + * Returns an {@link java.io.OutputStream} that ignores all data given to it. + */ + public static OutputStream getNoopOutputStream() { + return new OutputStream() { + @Override + public void write(int b) throws IOException { + // ignore the output + } + }; + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/SimpleDriverDataSourceFactory.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/SimpleDriverDataSourceFactory.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/SimpleDriverDataSourceFactory.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,66 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.embedded; + +import java.sql.Driver; + +import javax.sql.DataSource; + +import org.springframework.jdbc.datasource.SimpleDriverDataSource; + +/** + * Creates a {@link SimpleDriverDataSource}. + * + * @author Keith Donald + * @author Juergen Hoeller + * @since 3.0 + */ +final class SimpleDriverDataSourceFactory implements DataSourceFactory { + + private final SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); + + @Override + public ConnectionProperties getConnectionProperties() { + return new ConnectionProperties() { + @Override + public void setDriverClass(Class driverClass) { + dataSource.setDriverClass(driverClass); + } + + @Override + public void setUrl(String url) { + dataSource.setUrl(url); + } + + @Override + public void setUsername(String username) { + dataSource.setUsername(username); + } + + @Override + public void setPassword(String password) { + dataSource.setPassword(password); + } + }; + } + + @Override + public DataSource getDataSource() { + return this.dataSource; + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/embedded/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,8 @@ + +/** + * + * Provides extensible support for creating embedded database instances. + * + */ +package org.springframework.jdbc.datasource.embedded; + Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/CannotReadScriptException.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/CannotReadScriptException.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/CannotReadScriptException.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,40 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import org.springframework.core.io.support.EncodedResource; + +/** + * Thrown by {@link ScriptUtils} if an SQL script cannot be read. + * + * @author Keith Donald + * @author Sam Brannen + * @since 3.0 + */ +@SuppressWarnings("serial") +public class CannotReadScriptException extends ScriptException { + + /** + * Construct a new {@code CannotReadScriptException}. + * @param resource the resource that cannot be read from + * @param cause the underlying cause of the resource access failure + */ + public CannotReadScriptException(EncodedResource resource, Throwable cause) { + super("Cannot read SQL script from " + resource, cause); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/CompositeDatabasePopulator.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/CompositeDatabasePopulator.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/CompositeDatabasePopulator.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,65 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import java.sql.Connection; +import java.sql.SQLException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * {@link DatabasePopulator} implementation that delegates to a list of other + * {@code DatabasePopulator} implementations, executing all scripts. + * + * @author Dave Syer + * @author Juergen Hoeller + * @author Sam Brannen + * @since 3.1 + */ +public class CompositeDatabasePopulator implements DatabasePopulator { + + private List populators = new ArrayList(); + + + /** + * Specify a list of populators to delegate to. + */ + public void setPopulators(DatabasePopulator... populators) { + this.populators.clear(); + this.populators.addAll(Arrays.asList(populators)); + } + + /** + * Add one or more populators to the list of delegates. + */ + public void addPopulators(DatabasePopulator... populators) { + this.populators.addAll(Arrays.asList(populators)); + } + + /** + * {@inheritDoc} + */ + @Override + public void populate(Connection connection) throws SQLException, ScriptException { + for (DatabasePopulator populator : this.populators) { + populator.populate(connection); + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DataSourceInitializer.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DataSourceInitializer.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DataSourceInitializer.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,112 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; + +/** + * Used to {@linkplain #setDatabasePopulator set up} a database during + * initialization and {@link #setDatabaseCleaner clean up} a database during + * destruction. + * + * @author Dave Syer + * @author Sam Brannen + * @since 3.0 + * @see DatabasePopulator + */ +public class DataSourceInitializer implements InitializingBean, DisposableBean { + + private DataSource dataSource; + + private DatabasePopulator databasePopulator; + + private DatabasePopulator databaseCleaner; + + private boolean enabled = true; + + + /** + * The {@link DataSource} for the database to populate when this component + * is initialized and to clean up when this component is shut down. + *

This property is mandatory with no default provided. + * @param dataSource the DataSource + */ + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + /** + * Set the {@link DatabasePopulator} to execute during the bean initialization + * phase. + * @param databasePopulator the {@code DatabasePopulator} to use during + * initialization + * @see #setDatabaseCleaner + */ + public void setDatabasePopulator(DatabasePopulator databasePopulator) { + this.databasePopulator = databasePopulator; + } + + /** + * Set the {@link DatabasePopulator} to execute during the bean destruction + * phase, cleaning up the database and leaving it in a known state for others. + * @param databaseCleaner the {@code DatabasePopulator} to use during destruction + * @see #setDatabasePopulator + */ + public void setDatabaseCleaner(DatabasePopulator databaseCleaner) { + this.databaseCleaner = databaseCleaner; + } + + /** + * Flag to explicitly enable or disable the {@linkplain #setDatabasePopulator + * database populator} and {@linkplain #setDatabaseCleaner database cleaner}. + * @param enabled {@code true} if the database populator and database cleaner + * should be called on startup and shutdown, respectively + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + /** + * Use the {@linkplain #setDatabasePopulator database populator} to set up + * the database. + */ + @Override + public void afterPropertiesSet() { + execute(this.databasePopulator); + } + + /** + * Use the {@linkplain #setDatabaseCleaner database cleaner} to clean up the + * database. + */ + @Override + public void destroy() { + execute(this.databaseCleaner); + } + + private void execute(DatabasePopulator populator) { + Assert.state(dataSource != null, "DataSource must be set"); + if (this.enabled && populator != null) { + DatabasePopulatorUtils.execute(populator, this.dataSource); + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DatabasePopulator.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DatabasePopulator.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DatabasePopulator.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,51 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import java.sql.Connection; +import java.sql.SQLException; + +/** + * Strategy used to populate, initialize, or clean up a database. + * + * @author Keith Donald + * @author Sam Brannen + * @since 3.0 + * @see ResourceDatabasePopulator + * @see DatabasePopulatorUtils + * @see DataSourceInitializer + */ +public interface DatabasePopulator { + + /** + * Populate, initialize, or clean up the database using the provided JDBC + * connection. + *

Concrete implementations may throw an {@link SQLException} if + * an error is encountered but are strongly encouraged to throw a + * specific {@link ScriptException} instead. For example, Spring's + * {@link ResourceDatabasePopulator} and {@link DatabasePopulatorUtils} wrap + * all {@code SQLExceptions} in {@code ScriptExceptions}. + * @param connection the JDBC connection to use to populate the db; already + * configured and ready to use + * @throws SQLException if an unrecoverable data access exception occurs + * during database population + * @throws ScriptException in all other error cases + * @see DatabasePopulatorUtils#execute + */ + void populate(Connection connection) throws SQLException, ScriptException; + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,66 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import java.sql.Connection; + +import javax.sql.DataSource; + +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.datasource.DataSourceUtils; +import org.springframework.util.Assert; + +/** + * Utility methods for executing a {@link DatabasePopulator}. + * + * @author Juergen Hoeller + * @author Oliver Gierke + * @author Sam Brannen + * @since 3.1 + */ +public abstract class DatabasePopulatorUtils { + + /** + * Execute the given {@link DatabasePopulator} against the given {@link DataSource}. + * @param populator the {@code DatabasePopulator} to execute + * @param dataSource the {@code DataSource} to execute against + * @throws DataAccessException if an error occurs, specifically a {@link ScriptException} + */ + public static void execute(DatabasePopulator populator, DataSource dataSource) throws DataAccessException { + Assert.notNull(populator, "DatabasePopulator must be provided"); + Assert.notNull(dataSource, "DataSource must be provided"); + try { + Connection connection = DataSourceUtils.getConnection(dataSource); + try { + populator.populate(connection); + } + finally { + if (connection != null) { + DataSourceUtils.releaseConnection(connection, dataSource); + } + } + } + catch (Exception ex) { + if (ex instanceof ScriptException) { + throw (ScriptException) ex; + } + + throw new UncategorizedScriptException("Failed to execute database script", ex); + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,222 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.EncodedResource; + +/** + * Populates or initializes a database from SQL scripts defined in external + * resources. + * + *

Call {@link #addScript(Resource)} to add a single SQL script location. + * Call {@link #addScripts(Resource...)} to add multiple SQL script locations. + * Call {@link #setSqlScriptEncoding(String)} to set the encoding for all added + * scripts. + * + * @author Keith Donald + * @author Dave Syer + * @author Juergen Hoeller + * @author Chris Beams + * @author Oliver Gierke + * @author Sam Brannen + * @author Chris Baldwin + * @since 3.0 + * @see DatabasePopulatorUtils + */ +public class ResourceDatabasePopulator implements DatabasePopulator { + + private List scripts = new ArrayList(); + + private String sqlScriptEncoding; + + private String separator = ScriptUtils.DEFAULT_STATEMENT_SEPARATOR; + + private String commentPrefix = ScriptUtils.DEFAULT_COMMENT_PREFIX; + + private String blockCommentStartDelimiter = ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER; + + private String blockCommentEndDelimiter = ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER; + + private boolean continueOnError = false; + + private boolean ignoreFailedDrops = false; + + + /** + * Construct a new {@code ResourceDatabasePopulator} with default settings. + * @since 4.0.3 + */ + public ResourceDatabasePopulator() { + /* no-op */ + } + + /** + * Construct a new {@code ResourceDatabasePopulator} with default settings + * for the supplied scripts. + * @param scripts the scripts to execute to initialize or populate the database + * @since 4.0.3 + */ + public ResourceDatabasePopulator(Resource... scripts) { + this(); + this.scripts = Arrays.asList(scripts); + } + + /** + * Construct a new {@code ResourceDatabasePopulator} with the supplied values. + * @param continueOnError flag to indicate that all failures in SQL should be + * logged but not cause a failure + * @param ignoreFailedDrops flag to indicate that a failed SQL {@code DROP} + * statement can be ignored + * @param sqlScriptEncoding the encoding for the supplied SQL scripts, if + * different from the platform encoding; may be {@code null} + * @param scripts the scripts to execute to initialize or populate the database + * @since 4.0.3 + */ + public ResourceDatabasePopulator(boolean continueOnError, boolean ignoreFailedDrops, String sqlScriptEncoding, + Resource... scripts) { + this(scripts); + this.continueOnError = continueOnError; + this.ignoreFailedDrops = ignoreFailedDrops; + this.sqlScriptEncoding = sqlScriptEncoding; + } + + /** + * Add a script to execute to initialize or populate the database. + * @param script the path to an SQL script + */ + public void addScript(Resource script) { + this.scripts.add(script); + } + + /** + * Add multiple scripts to execute to initialize or populate the database. + * @param scripts the scripts to execute + */ + public void addScripts(Resource... scripts) { + this.scripts.addAll(Arrays.asList(scripts)); + } + + /** + * Set the scripts to execute to initialize or populate the database, + * replacing any previously added scripts. + * @param scripts the scripts to execute + */ + public void setScripts(Resource... scripts) { + this.scripts = Arrays.asList(scripts); + } + + /** + * Specify the encoding for SQL scripts, if different from the platform encoding. + * @param sqlScriptEncoding the encoding used in scripts + * @see #addScript(Resource) + */ + public void setSqlScriptEncoding(String sqlScriptEncoding) { + this.sqlScriptEncoding = sqlScriptEncoding; + } + + /** + * Specify the statement separator, if a custom one. + *

Defaults to {@code ";"} if not specified and falls back to {@code "\n"} + * as a last resort; may be set to {@link ScriptUtils#EOF_STATEMENT_SEPARATOR} + * to signal that each script contains a single statement without a separator. + * @param separator the script statement separator + */ + public void setSeparator(String separator) { + this.separator = separator; + } + + /** + * Set the prefix that identifies single-line comments within the SQL scripts. + *

Defaults to {@code "--"}. + * @param commentPrefix the prefix for single-line comments + */ + public void setCommentPrefix(String commentPrefix) { + this.commentPrefix = commentPrefix; + } + + /** + * Set the start delimiter that identifies block comments within the SQL + * scripts. + *

Defaults to {@code "/*"}. + * @param blockCommentStartDelimiter the start delimiter for block comments + * @since 4.0.3 + * @see #setBlockCommentEndDelimiter + */ + public void setBlockCommentStartDelimiter(String blockCommentStartDelimiter) { + this.blockCommentStartDelimiter = blockCommentStartDelimiter; + } + + /** + * Set the end delimiter that identifies block comments within the SQL + * scripts. + *

Defaults to "*/". + * @param blockCommentEndDelimiter the end delimiter for block comments + * @since 4.0.3 + * @see #setBlockCommentStartDelimiter + */ + public void setBlockCommentEndDelimiter(String blockCommentEndDelimiter) { + this.blockCommentEndDelimiter = blockCommentEndDelimiter; + } + + /** + * Flag to indicate that all failures in SQL should be logged but not cause a failure. + *

Defaults to {@code false}. + * @param continueOnError {@code true} if script execution should continue on error + */ + public void setContinueOnError(boolean continueOnError) { + this.continueOnError = continueOnError; + } + + /** + * Flag to indicate that a failed SQL {@code DROP} statement can be ignored. + *

This is useful for non-embedded databases whose SQL dialect does not support an + * {@code IF EXISTS} clause in a {@code DROP} statement. + *

The default is {@code false} so that if the populator runs accidentally, it will + * fail fast if the script starts with a {@code DROP} statement. + * @param ignoreFailedDrops {@code true} if failed drop statements should be ignored + */ + public void setIgnoreFailedDrops(boolean ignoreFailedDrops) { + this.ignoreFailedDrops = ignoreFailedDrops; + } + + /** + * {@inheritDoc} + */ + @Override + public void populate(Connection connection) throws ScriptException { + for (Resource script : this.scripts) { + ScriptUtils.executeSqlScript(connection, encodeScript(script), this.continueOnError, + this.ignoreFailedDrops, this.commentPrefix, this.separator, this.blockCommentStartDelimiter, + this.blockCommentEndDelimiter); + } + } + + /** + * {@link EncodedResource} is not a sub-type of {@link Resource}. Thus we + * always need to wrap each script resource in an encoded resource. + */ + private EncodedResource encodeScript(Resource script) { + return new EncodedResource(script, this.sqlScriptEncoding); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptException.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptException.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptException.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import org.springframework.dao.DataAccessException; + +/** + * Root of the hierarchy of data access exceptions that are related to processing + * of SQL scripts. + * + * @author Sam Brannen + * @since 4.0.3 + */ +@SuppressWarnings("serial") +public abstract class ScriptException extends DataAccessException { + + /** + * Constructor for {@code ScriptException}. + * @param message the detail message + */ + public ScriptException(String message) { + super(message); + } + + /** + * Constructor for {@code ScriptException}. + * @param message the detail message + * @param cause the root cause + */ + public ScriptException(String message, Throwable cause) { + super(message, cause); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptParseException.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptParseException.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptParseException.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,54 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import org.springframework.core.io.support.EncodedResource; + +/** + * Thrown by {@link ScriptUtils} if an SQL script cannot be properly parsed. + * + * @author Sam Brannen + * @since 4.0.3 + */ +@SuppressWarnings("serial") +public class ScriptParseException extends ScriptException { + + /** + * Construct a new {@code ScriptParseException}. + * @param message detailed message + * @param resource the resource from which the SQL script was read + */ + public ScriptParseException(String message, EncodedResource resource) { + super(buildMessage(message, resource)); + } + + /** + * Construct a new {@code ScriptParseException}. + * @param message detailed message + * @param resource the resource from which the SQL script was read + * @param cause the underlying cause of the failure + */ + public ScriptParseException(String message, EncodedResource resource, Throwable cause) { + super(buildMessage(message, resource), cause); + } + + private static String buildMessage(String message, EncodedResource resource) { + return String.format("Failed to parse SQL script from resource [%s]: %s", (resource == null ? "" + : resource), message); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptStatementFailedException.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptStatementFailedException.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptStatementFailedException.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,44 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import org.springframework.core.io.support.EncodedResource; + +/** + * Thrown by {@link ScriptUtils} if a statement in an SQL script failed when + * executing it against the target database. + * + * @author Juergen Hoeller + * @author Sam Brannen + * @since 3.0.5 + */ +@SuppressWarnings("serial") +public class ScriptStatementFailedException extends ScriptException { + + /** + * Construct a new {@code ScriptStatementFailedException}. + * @param statement the actual SQL statement that failed + * @param lineNumber the line number in the SQL script + * @param resource the resource from which the SQL statement was read + * @param cause the underlying cause of the failure + */ + public ScriptStatementFailedException(String statement, int lineNumber, EncodedResource resource, Throwable cause) { + super("Failed to execute SQL script statement at line " + lineNumber + " of resource " + resource + ": " + + statement, cause); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptUtils.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptUtils.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/ScriptUtils.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,503 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +import java.io.IOException; +import java.io.LineNumberReader; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.EncodedResource; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +/** + * Generic utility methods for working with SQL scripts. Mainly for internal use + * within the framework. + * + * @author Thomas Risberg + * @author Sam Brannen + * @author Juergen Hoeller + * @author Keith Donald + * @author Dave Syer + * @author Chris Beams + * @author Oliver Gierke + * @author Chris Baldwin + * @since 4.0.3 + */ +public abstract class ScriptUtils { + + private static final Log logger = LogFactory.getLog(ScriptUtils.class); + + /** + * Default statement separator within SQL scripts. + */ + public static final String DEFAULT_STATEMENT_SEPARATOR = ";"; + + /** + * Fallback statement separator within SQL scripts. + *

Used if neither a custom defined separator nor the + * {@link #DEFAULT_STATEMENT_SEPARATOR} is present in a given script. + */ + public static final String FALLBACK_STATEMENT_SEPARATOR = "\n"; + + /** + * End of file (EOF) SQL statement separator. + *

This value may be supplied as the {@code separator} to {@link + * #executeSqlScript(Connection, EncodedResource, boolean, boolean, String, String, String, String)} + * to denote that an SQL script contains a single statement (potentially + * spanning multiple lines) with no explicit statement separator. Note that + * such a script should not actually contain this value; it is merely a + * virtual statement separator. + */ + public static final String EOF_STATEMENT_SEPARATOR = "^^^ END OF SCRIPT ^^^"; + + /** + * Default prefix for line comments within SQL scripts. + */ + public static final String DEFAULT_COMMENT_PREFIX = "--"; + + /** + * Default start delimiter for block comments within SQL scripts. + */ + public static final String DEFAULT_BLOCK_COMMENT_START_DELIMITER = "/*"; + + /** + * Default end delimiter for block comments within SQL scripts. + */ + public static final String DEFAULT_BLOCK_COMMENT_END_DELIMITER = "*/"; + + + /** + * Prevent instantiation of this utility class. + */ + private ScriptUtils() { + /* no-op */ + } + + /** + * Split an SQL script into separate statements delimited by the provided + * separator character. Each individual statement will be added to the + * provided {@code List}. + *

Within the script, {@value #DEFAULT_COMMENT_PREFIX} will be used as the + * comment prefix; any text beginning with the comment prefix and extending to + * the end of the line will be omitted from the output. Similarly, + * {@value #DEFAULT_BLOCK_COMMENT_START_DELIMITER} and + * {@value #DEFAULT_BLOCK_COMMENT_END_DELIMITER} will be used as the + * start and end block comment delimiters: any text enclosed + * in a block comment will be omitted from the output. In addition, multiple + * adjacent whitespace characters will be collapsed into a single space. + * @param script the SQL script + * @param separator character separating each statement — typically a ';' + * @param statements the list that will contain the individual statements + * @throws ScriptException if an error occurred while splitting the SQL script + * @see #splitSqlScript(String, String, List) + * @see #splitSqlScript(EncodedResource, String, String, String, String, String, List) + */ + public static void splitSqlScript(String script, char separator, List statements) throws ScriptException { + splitSqlScript(script, String.valueOf(separator), statements); + } + + /** + * Split an SQL script into separate statements delimited by the provided + * separator string. Each individual statement will be added to the + * provided {@code List}. + *

Within the script, {@value #DEFAULT_COMMENT_PREFIX} will be used as the + * comment prefix; any text beginning with the comment prefix and extending to + * the end of the line will be omitted from the output. Similarly, + * {@value #DEFAULT_BLOCK_COMMENT_START_DELIMITER} and + * {@value #DEFAULT_BLOCK_COMMENT_END_DELIMITER} will be used as the + * start and end block comment delimiters: any text enclosed + * in a block comment will be omitted from the output. In addition, multiple + * adjacent whitespace characters will be collapsed into a single space. + * @param script the SQL script + * @param separator text separating each statement — typically a ';' or newline character + * @param statements the list that will contain the individual statements + * @throws ScriptException if an error occurred while splitting the SQL script + * @see #splitSqlScript(String, char, List) + * @see #splitSqlScript(EncodedResource, String, String, String, String, String, List) + */ + public static void splitSqlScript(String script, String separator, List statements) throws ScriptException { + splitSqlScript(null, script, separator, DEFAULT_COMMENT_PREFIX, DEFAULT_BLOCK_COMMENT_START_DELIMITER, + DEFAULT_BLOCK_COMMENT_END_DELIMITER, statements); + } + + /** + * Split an SQL script into separate statements delimited by the provided + * separator string. Each individual statement will be added to the provided + * {@code List}. + *

Within the script, the provided {@code commentPrefix} will be honored: + * any text beginning with the comment prefix and extending to the end of the + * line will be omitted from the output. Similarly, the provided + * {@code blockCommentStartDelimiter} and {@code blockCommentEndDelimiter} + * delimiters will be honored: any text enclosed in a block comment will be + * omitted from the output. In addition, multiple adjacent whitespace characters + * will be collapsed into a single space. + * @param resource the resource from which the script was read + * @param script the SQL script; never {@code null} or empty + * @param separator text separating each statement — typically a ';' or + * newline character; never {@code null} + * @param commentPrefix the prefix that identifies SQL line comments — + * typically "--"; never {@code null} or empty + * @param blockCommentStartDelimiter the start block comment delimiter; + * never {@code null} or empty + * @param blockCommentEndDelimiter the end block comment delimiter; + * never {@code null} or empty + * @param statements the list that will contain the individual statements + * @throws ScriptException if an error occurred while splitting the SQL script + */ + public static void splitSqlScript(EncodedResource resource, String script, String separator, String commentPrefix, + String blockCommentStartDelimiter, String blockCommentEndDelimiter, List statements) + throws ScriptException { + + Assert.hasText(script, "script must not be null or empty"); + Assert.notNull(separator, "separator must not be null"); + Assert.hasText(commentPrefix, "commentPrefix must not be null or empty"); + Assert.hasText(blockCommentStartDelimiter, "blockCommentStartDelimiter must not be null or empty"); + Assert.hasText(blockCommentEndDelimiter, "blockCommentEndDelimiter must not be null or empty"); + + StringBuilder sb = new StringBuilder(); + boolean inLiteral = false; + boolean inEscape = false; + char[] content = script.toCharArray(); + for (int i = 0; i < script.length(); i++) { + char c = content[i]; + if (inEscape) { + inEscape = false; + sb.append(c); + continue; + } + // MySQL style escapes + if (c == '\\') { + inEscape = true; + sb.append(c); + continue; + } + if (c == '\'') { + inLiteral = !inLiteral; + } + if (!inLiteral) { + if (script.startsWith(separator, i)) { + // we've reached the end of the current statement + if (sb.length() > 0) { + statements.add(sb.toString()); + sb = new StringBuilder(); + } + i += separator.length() - 1; + continue; + } + else if (script.startsWith(commentPrefix, i)) { + // skip over any content from the start of the comment to the EOL + int indexOfNextNewline = script.indexOf("\n", i); + if (indexOfNextNewline > i) { + i = indexOfNextNewline; + continue; + } + else { + // if there's no EOL, we must be at the end + // of the script, so stop here. + break; + } + } + else if (script.startsWith(blockCommentStartDelimiter, i)) { + // skip over any block comments + int indexOfCommentEnd = script.indexOf(blockCommentEndDelimiter, i); + if (indexOfCommentEnd > i) { + i = indexOfCommentEnd + blockCommentEndDelimiter.length() - 1; + continue; + } + else { + throw new ScriptParseException(String.format("Missing block comment end delimiter [%s].", + blockCommentEndDelimiter), resource); + } + } + else if (c == ' ' || c == '\n' || c == '\t') { + // avoid multiple adjacent whitespace characters + if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') { + c = ' '; + } + else { + continue; + } + } + } + sb.append(c); + } + if (StringUtils.hasText(sb)) { + statements.add(sb.toString()); + } + } + + /** + * Read a script from the given resource, using "{@code --}" as the comment prefix + * and "{@code ;}" as the statement separator, and build a String containing the lines. + * @param resource the {@code EncodedResource} to be read + * @return {@code String} containing the script lines + * @throws IOException in case of I/O errors + */ + static String readScript(EncodedResource resource) throws IOException { + return readScript(resource, DEFAULT_COMMENT_PREFIX, DEFAULT_STATEMENT_SEPARATOR); + } + + /** + * Read a script from the provided resource, using the supplied comment prefix + * and statement separator, and build a {@code String} containing the lines. + *

Lines beginning with the comment prefix are excluded from the + * results; however, line comments anywhere else — for example, within + * a statement — will be included in the results. + * @param resource the {@code EncodedResource} containing the script + * to be processed + * @param commentPrefix the prefix that identifies comments in the SQL script — + * typically "--" + * @param separator the statement separator in the SQL script — typically ";" + * @return a {@code String} containing the script lines + * @throws IOException in case of I/O errors + */ + private static String readScript(EncodedResource resource, String commentPrefix, String separator) + throws IOException { + LineNumberReader lnr = new LineNumberReader(resource.getReader()); + try { + return readScript(lnr, commentPrefix, separator); + } + finally { + lnr.close(); + } + } + + /** + * Read a script from the provided {@code LineNumberReader}, using the supplied + * comment prefix and statement separator, and build a {@code String} containing + * the lines. + *

Lines beginning with the comment prefix are excluded from the + * results; however, line comments anywhere else — for example, within + * a statement — will be included in the results. + * @param lineNumberReader the {@code LineNumberReader} containing the script + * to be processed + * @param commentPrefix the prefix that identifies comments in the SQL script — + * typically "--" + * @param separator the statement separator in the SQL script — typically ";" + * @return a {@code String} containing the script lines + * @throws IOException in case of I/O errors + */ + public static String readScript(LineNumberReader lineNumberReader, String commentPrefix, String separator) + throws IOException { + String currentStatement = lineNumberReader.readLine(); + StringBuilder scriptBuilder = new StringBuilder(); + while (currentStatement != null) { + if (commentPrefix != null && !currentStatement.startsWith(commentPrefix)) { + if (scriptBuilder.length() > 0) { + scriptBuilder.append('\n'); + } + scriptBuilder.append(currentStatement); + } + currentStatement = lineNumberReader.readLine(); + } + appendSeparatorToScriptIfNecessary(scriptBuilder, separator); + return scriptBuilder.toString(); + } + + private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuilder, String separator) { + if (separator == null) { + return; + } + String trimmed = separator.trim(); + if (trimmed.length() == separator.length()) { + return; + } + // separator ends in whitespace, so we might want to see if the script is trying + // to end the same way + if (scriptBuilder.lastIndexOf(trimmed) == scriptBuilder.length() - trimmed.length()) { + scriptBuilder.append(separator.substring(trimmed.length())); + } + } + + /** + * Does the provided SQL script contain the specified delimiter? + * @param script the SQL script + * @param delim String delimiting each statement - typically a ';' character + */ + public static boolean containsSqlScriptDelimiters(String script, String delim) { + boolean inLiteral = false; + char[] content = script.toCharArray(); + for (int i = 0; i < script.length(); i++) { + if (content[i] == '\'') { + inLiteral = !inLiteral; + } + if (!inLiteral && script.startsWith(delim, i)) { + return true; + } + } + return false; + } + + /** + * Execute the given SQL script using default settings for separator separators, + * comment delimiters, and exception handling flags. + *

Statement separators and comments will be removed before executing + * individual statements within the supplied script. + *

Do not use this method to execute DDL if you expect rollback. + * @param connection the JDBC connection to use to execute the script; already + * configured and ready to use + * @param resource the resource to load the SQL script from; encoded with the + * current platform's default encoding + * @throws ScriptException if an error occurred while executing the SQL script + * @see #executeSqlScript(Connection, EncodedResource, boolean, boolean, String, String, String, String) + * @see #DEFAULT_COMMENT_PREFIX + * @see #DEFAULT_STATEMENT_SEPARATOR + * @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER + * @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER + */ + public static void executeSqlScript(Connection connection, Resource resource) throws ScriptException { + executeSqlScript(connection, new EncodedResource(resource)); + } + + /** + * Execute the given SQL script using default settings for separator separators, + * comment delimiters, and exception handling flags. + *

Statement separators and comments will be removed before executing + * individual statements within the supplied script. + *

Do not use this method to execute DDL if you expect rollback. + * @param connection the JDBC connection to use to execute the script; already + * configured and ready to use + * @param resource the resource (potentially associated with a specific encoding) + * to load the SQL script from + * @throws ScriptException if an error occurred while executing the SQL script + * @see #executeSqlScript(Connection, EncodedResource, boolean, boolean, String, String, String, String) + * @see #DEFAULT_COMMENT_PREFIX + * @see #DEFAULT_STATEMENT_SEPARATOR + * @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER + * @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER + */ + public static void executeSqlScript(Connection connection, EncodedResource resource) throws ScriptException { + executeSqlScript(connection, resource, false, false, DEFAULT_COMMENT_PREFIX, DEFAULT_STATEMENT_SEPARATOR, + DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER); + } + + /** + * Execute the given SQL script. + *

Statement separators and comments will be removed before executing + * individual statements within the supplied script. + *

Do not use this method to execute DDL if you expect rollback. + * @param connection the JDBC connection to use to execute the script; already + * configured and ready to use + * @param resource the resource (potentially associated with a specific encoding) + * to load the SQL script from + * @param continueOnError whether or not to continue without throwing an exception + * in the event of an error + * @param ignoreFailedDrops whether or not to continue in the event of specifically + * an error on a {@code DROP} statement + * @param commentPrefix the prefix that identifies comments in the SQL script — + * typically "--" + * @param separator the script statement separator; defaults to + * {@value #DEFAULT_STATEMENT_SEPARATOR} if not specified and falls back to + * {@value #FALLBACK_STATEMENT_SEPARATOR} as a last resort; may be set to + * {@value #EOF_STATEMENT_SEPARATOR} to signal that the script contains a + * single statement without a separator + * @param blockCommentStartDelimiter the start block comment delimiter; never + * {@code null} or empty + * @param blockCommentEndDelimiter the end block comment delimiter; never + * {@code null} or empty + * @throws ScriptException if an error occurred while executing the SQL script + * @see #DEFAULT_STATEMENT_SEPARATOR + * @see #FALLBACK_STATEMENT_SEPARATOR + * @see #EOF_STATEMENT_SEPARATOR + */ + public static void executeSqlScript(Connection connection, EncodedResource resource, boolean continueOnError, + boolean ignoreFailedDrops, String commentPrefix, String separator, String blockCommentStartDelimiter, + String blockCommentEndDelimiter) throws ScriptException { + + try { + if (logger.isInfoEnabled()) { + logger.info("Executing SQL script from " + resource); + } + + long startTime = System.currentTimeMillis(); + List statements = new LinkedList(); + String script; + try { + script = readScript(resource, commentPrefix, separator); + } + catch (IOException ex) { + throw new CannotReadScriptException(resource, ex); + } + + if (separator == null) { + separator = DEFAULT_STATEMENT_SEPARATOR; + } + if (!EOF_STATEMENT_SEPARATOR.equals(separator) && !containsSqlScriptDelimiters(script, separator)) { + separator = FALLBACK_STATEMENT_SEPARATOR; + } + + splitSqlScript(resource, script, separator, commentPrefix, blockCommentStartDelimiter, + blockCommentEndDelimiter, statements); + int lineNumber = 0; + Statement stmt = connection.createStatement(); + try { + for (String statement : statements) { + lineNumber++; + try { + stmt.execute(statement); + int rowsAffected = stmt.getUpdateCount(); + if (logger.isDebugEnabled()) { + logger.debug(rowsAffected + " returned as updateCount for SQL: " + statement); + } + } + catch (SQLException ex) { + boolean dropStatement = StringUtils.startsWithIgnoreCase(statement.trim(), "drop"); + if (continueOnError || (dropStatement && ignoreFailedDrops)) { + if (logger.isDebugEnabled()) { + logger.debug("Failed to execute SQL script statement at line " + lineNumber + + " of resource " + resource + ": " + statement, ex); + } + } + else { + throw new ScriptStatementFailedException(statement, lineNumber, resource, ex); + } + } + } + } + finally { + try { + stmt.close(); + } + catch (Throwable ex) { + logger.debug("Could not close JDBC Statement", ex); + } + } + + long elapsedTime = System.currentTimeMillis() - startTime; + if (logger.isInfoEnabled()) { + logger.info("Executed SQL script from " + resource + " in " + elapsedTime + " ms."); + } + } + catch (Exception ex) { + if (ex instanceof ScriptException) { + throw (ScriptException) ex; + } + + throw new UncategorizedScriptException( + "Failed to execute database script from resource [" + resource + "]", ex); + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/UncategorizedScriptException.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/UncategorizedScriptException.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/UncategorizedScriptException.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,47 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.datasource.init; + +/** + * Thrown when we cannot determine anything more specific than "something went + * wrong while processing an SQL script": for example, a {@link java.sql.SQLException} + * from JDBC that we cannot pinpoint more precisely. + * + * @author Sam Brannen + * @since 4.0.3 + */ +@SuppressWarnings("serial") +public class UncategorizedScriptException extends ScriptException { + + /** + * Construct a new {@code UncategorizedScriptException}. + * @param message detailed message + */ + public UncategorizedScriptException(String message) { + super(message); + } + + /** + * Construct a new {@code UncategorizedScriptException}. + * @param message detailed message + * @param cause the root cause + */ + public UncategorizedScriptException(String message, Throwable cause) { + super(message, cause); + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/init/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,6 @@ + +/** + * Provides extensible support for initializing databases through scripts. + */ +package org.springframework.jdbc.datasource.init; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookup.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/DataSourceLookup.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/DataSourceLookupFailureException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/JndiDataSourceLookup.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/MapDataSourceLookup.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/SingleDataSourceLookup.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/lookup/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,8 @@ + +/** + * + * Provides a strategy for looking up JDBC DataSources by name. + * + */ +package org.springframework.jdbc.datasource.lookup; + Index: 3rdParty_sources/spring/org/springframework/jdbc/datasource/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/datasource/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/datasource/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,10 @@ + +/** + * + * Provides a utility class for easy DataSource access, + * a PlatformTransactionManager for a single DataSource, + * and various simple DataSource implementations. + * + */ +package org.springframework.jdbc.datasource; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/BatchSqlUpdate.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/object/GenericSqlQuery.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/object/GenericSqlQuery.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/object/GenericSqlQuery.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,60 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.object; + +import java.util.Map; + +import org.springframework.jdbc.core.RowMapper; +import org.springframework.util.Assert; +import org.springframework.dao.InvalidDataAccessResourceUsageException; + +public class GenericSqlQuery extends SqlQuery { + + Class rowMapperClass; + + RowMapper rowMapper; + + @SuppressWarnings("rawtypes") + public void setRowMapperClass(Class rowMapperClass) + throws IllegalAccessException, InstantiationException { + this.rowMapperClass = rowMapperClass; + if (!RowMapper.class.isAssignableFrom(rowMapperClass)) + throw new IllegalStateException("The specified class '" + + rowMapperClass.getName() + " is not a sub class of " + + "'org.springframework.jdbc.core.RowMapper'"); + } + + @Override + public void afterPropertiesSet() { + super.afterPropertiesSet(); + Assert.notNull(rowMapperClass, "The 'rowMapperClass' property is required"); + } + + @Override + @SuppressWarnings("unchecked") + protected RowMapper newRowMapper(Object[] parameters, Map context) { + try { + return (RowMapper) rowMapperClass.newInstance(); + } + catch (InstantiationException e) { + throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e); + } + catch (IllegalAccessException e) { + throw new InvalidDataAccessResourceUsageException("Unable to instantiate RowMapper", e); + } + } +} Index: 3rdParty_sources/spring/org/springframework/jdbc/object/GenericStoredProcedure.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/object/GenericStoredProcedure.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/object/GenericStoredProcedure.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,32 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.object; + +/** + * Concrete implementation making it possible to define the RDBMS stored procedures + * in an application context without writing a custom Java implementation class. + *

+ * This implementation does not provide a typed method for invocation so executions + * must use one of the generic {@link StoredProcedure#execute(java.util.Map)} or + * {@link StoredProcedure#execute(org.springframework.jdbc.core.ParameterMapper)} methods. + * + * @author Thomas Risberg + * @see org.springframework.jdbc.object.StoredProcedure + */ +public class GenericStoredProcedure extends StoredProcedure { + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/MappingSqlQuery.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/RdbmsOperation.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/SqlCall.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/SqlFunction.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/SqlOperation.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/SqlQuery.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/SqlUpdate.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/StoredProcedure.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/object/UpdatableSqlQuery.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/object/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/object/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/object/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,20 @@ +/** + * + * The classes in this package represent RDBMS queries, updates, + * and stored procedures as threadsafe, reusable objects. This approach + * is modelled by JDO, although of course objects returned by queries + * are "disconnected" from the database. + * + *

This higher level of JDBC abstraction depends on the lower-level + * abstraction in the {@code org.springframework.jdbc.core} package. + * Exceptions thrown are as in the {@code org.springframework.dao} package, + * meaning that code using this package does not need to implement JDBC or + * RDBMS-specific error handling. + * + *

This package and related packages are discussed in Chapter 9 of + * Expert One-On-One J2EE Design and Development + * by Rod Johnson (Wrox, 2002). + * + */ +package org.springframework.jdbc.object; + Index: 3rdParty_sources/spring/org/springframework/jdbc/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,24 @@ + +/** + * + * The classes in this package make JDBC easier to use and + * reduce the likelihood of common errors. In particular, they: + *

    + *
  • Simplify error handling, avoiding the need for try/catch/finally + * blocks in application code. + *
  • Present exceptions to application code in a generic hierarchy of + * unchecked exceptions, enabling applications to catch data access + * exceptions without being dependent on JDBC, and to ignore fatal + * exceptions there is no value in catching. + *
  • Allow the implementation of error handling to be modified + * to target different RDBMSes without introducing proprietary + * dependencies into application code. + *
+ * + *

This package and related packages are discussed in Chapter 9 of + * Expert One-On-One J2EE Design and Development + * by Rod Johnson (Wrox, 2002). + * + */ +package org.springframework.jdbc; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/AbstractFallbackSQLExceptionTranslator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/CustomSQLErrorCodesTranslation.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistrar.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistrar.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistrar.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,58 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.support; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.beans.factory.InitializingBean; + +/** + * Registry for registering custom {@link org.springframework.jdbc.support.SQLExceptionTranslator} + * instances for specific databases. + * + * @author Thomas Risberg + * @since 3.1.1 + */ +public class CustomSQLExceptionTranslatorRegistrar implements InitializingBean { + + /** + * Map registry to hold custom translators specific databases. + * Key is the database product name as defined in the + * {@link org.springframework.jdbc.support.SQLErrorCodesFactory}. + */ + private final Map translators = new HashMap(); + + + /** + * Setter for a Map of {@link SQLExceptionTranslator} references where the key must + * be the database name as defined in the {@code sql-error-codes.xml} file. + *

Note that any existing translators will remain unless there is a match in the + * database name, at which point the new translator will replace the existing one. + */ + public void setTranslators(Map translators) { + this.translators.putAll(translators); + } + + @Override + public void afterPropertiesSet() { + for (String dbName : this.translators.keySet()) { + CustomSQLExceptionTranslatorRegistry.getInstance().registerTranslator(dbName, this.translators.get(dbName)); + } + } + +} Index: 3rdParty_sources/spring/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/CustomSQLExceptionTranslatorRegistry.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,93 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.support; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Registry for custom {@link org.springframework.jdbc.support.SQLExceptionTranslator} instances associated with + * specific databases allowing for overriding translation based on values contained in the configuration file + * named "sql-error-codes.xml". + * + * @author Thomas Risberg + * @since 3.1.1 + * @see SQLErrorCodesFactory + */ +public class CustomSQLExceptionTranslatorRegistry { + + private static final Log logger = LogFactory.getLog(CustomSQLExceptionTranslatorRegistry.class); + + /** + * Keep track of a single instance so we can return it to classes that request it. + */ + private static final CustomSQLExceptionTranslatorRegistry instance = new CustomSQLExceptionTranslatorRegistry(); + + + /** + * Return the singleton instance. + */ + public static CustomSQLExceptionTranslatorRegistry getInstance() { + return instance; + } + + + /** + * Map registry to hold custom translators specific databases. + * Key is the database product name as defined in the + * {@link org.springframework.jdbc.support.SQLErrorCodesFactory}. + */ + private final Map translatorMap = new HashMap(); + + + /** + * Create a new instance of the {@link CustomSQLExceptionTranslatorRegistry} class. + *

Not public to enforce Singleton design pattern. + */ + private CustomSQLExceptionTranslatorRegistry() { + } + + /** + * Register a new custom translator for the specified database name. + * @param dbName the database name + * @param translator the custom translator + */ + public void registerTranslator(String dbName, SQLExceptionTranslator translator) { + SQLExceptionTranslator replaced = translatorMap.put(dbName, translator); + if (replaced != null) { + logger.warn("Replacing custom translator [" + replaced + "] for database '" + dbName + + "' with [" + translator + "]"); + } + else { + logger.info("Adding custom translator of type [" + translator.getClass().getName() + + "] for database '" + dbName + "'"); + } + } + + /** + * Find a custom translator for the specified database. + * @param dbName the database name + * @return the custom translator, or {@code null} if none found + */ + public SQLExceptionTranslator findTranslatorForDatabase(String dbName) { + return this.translatorMap.get(dbName); + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/DatabaseMetaDataCallback.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/DatabaseStartupValidator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/GeneratedKeyHolder.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/JdbcAccessor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/JdbcUtils.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/KeyHolder.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/MetaDataAccessException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/SQLErrorCodes.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/SQLErrorCodesFactory.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/SQLExceptionTranslator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/SqlValue.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/AbstractColumnMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/AbstractSequenceMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/DB2MainframeSequenceMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/DB2SequenceMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/DataFieldMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/DerbyMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/HsqlMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/HsqlSequenceMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/MySQLMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/OracleSequenceMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/PostgreSQLSequenceMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/SqlServerMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/SybaseAnywhereMaxValueIncrementer.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/SybaseAnywhereMaxValueIncrementer.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/SybaseAnywhereMaxValueIncrementer.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,81 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * 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 org.springframework.jdbc.support.incrementer; + +import javax.sql.DataSource; + +/** + * {@link DataFieldMaxValueIncrementer} that increments + * the maximum value of a given Sybase SQL Anywhere table + * with the equivalent of an auto-increment column. Note: If you use this class, your table key + * column should NOT be defined as an IDENTITY column, as the sequence table does the job. + * + *

This class is intended to be used with Sybase Anywhere. + * + *

The sequence is kept in a table. There should be one sequence table per + * table that needs an auto-generated key. + * + *

Example: + * + *

 create table tab (id int not null primary key, text varchar(100))
+ * create table tab_sequence (id bigint identity)
+ * insert into tab_sequence values(DEFAULT)
+ * + * If "cacheSize" is set, the intermediate values are served without querying the + * database. If the server or your application is stopped or crashes or a transaction + * is rolled back, the unused values will never be served. The maximum hole size in + * numbering is consequently the value of cacheSize. + * + * HINT: Since Sybase Anywhere supports the JDBC 3.0 {@code getGeneratedKeys} method, + * it is recommended to use IDENTITY columns directly in the tables and then using a + * {@link org.springframework.jdbc.core.simple.SimpleJdbcInsert} or utilizing + * a {@link org.springframework.jdbc.support.KeyHolder} when calling the with the + * {@code update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder)} + * method of the {@link org.springframework.jdbc.core.JdbcTemplate}. + * + *

Thanks to Tarald Saxi Stormark for the suggestion! + * + * @author Thomas Risberg + * @since 3.0.5 + */ +public class SybaseAnywhereMaxValueIncrementer extends SybaseMaxValueIncrementer { + + /** + * Default constructor for bean property style usage. + * @see #setDataSource + * @see #setIncrementerName + * @see #setColumnName + */ + public SybaseAnywhereMaxValueIncrementer() { + } + + /** + * Convenience constructor. + * @param dataSource the DataSource to use + * @param incrementerName the name of the sequence/table to use + * @param columnName the name of the column in the sequence table to use + */ + public SybaseAnywhereMaxValueIncrementer(DataSource dataSource, String incrementerName, String columnName) { + super(dataSource, incrementerName, columnName); + } + + @Override + protected String getIncrementStatement() { + return "insert into " + getIncrementerName() + " values(DEFAULT)"; + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/SybaseMaxValueIncrementer.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/incrementer/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,11 @@ + +/** + * + * Provides a support framework for incrementing database table values + * via sequences, with implementations for various databases. + * + *

Can be used independently, for example in custom JDBC access code. + * + */ +package org.springframework.jdbc.support.incrementer; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/AbstractLobHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/DefaultLobHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/JtaLobCreatorSynchronization.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/LobCreator.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/LobCreatorUtils.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/LobHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/OracleLobHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/PassThroughBlob.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/PassThroughClob.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/lob/SpringLobCreatorSynchronization.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/lob/TemporaryLobCreator.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/lob/TemporaryLobCreator.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/lob/TemporaryLobCreator.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,173 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * 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 org.springframework.jdbc.support.lob; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.util.FileCopyUtils; + +/** + * {@link LobCreator} implementation based on temporary LOBs, + * using JDBC 4.0's {@link java.sql.Connection#createBlob()} / + * {@link java.sql.Connection#createClob()} mechanism. + * + *

Used by DefaultLobHandler's {@link DefaultLobHandler#setCreateTemporaryLob} mode. + * Can also be used directly to reuse the tracking and freeing of temporary LOBs. + * + * @author Juergen Hoeller + * @since 3.2.2 + * @see DefaultLobHandler#setCreateTemporaryLob + * @see java.sql.Connection#createBlob() + * @see java.sql.Connection#createClob() + */ +public class TemporaryLobCreator implements LobCreator { + + protected static final Log logger = LogFactory.getLog(TemporaryLobCreator.class); + + private final Set temporaryBlobs = new LinkedHashSet(1); + + private final Set temporaryClobs = new LinkedHashSet(1); + + + @Override + public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content) + throws SQLException { + + Blob blob = ps.getConnection().createBlob(); + blob.setBytes(1, content); + + this.temporaryBlobs.add(blob); + ps.setBlob(paramIndex, blob); + + if (logger.isDebugEnabled()) { + logger.debug(content != null ? "Copied bytes into temporary BLOB with length " + content.length : + "Set BLOB to null"); + } + } + + @Override + public void setBlobAsBinaryStream( + PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength) + throws SQLException { + + Blob blob = ps.getConnection().createBlob(); + try { + FileCopyUtils.copy(binaryStream, blob.setBinaryStream(1)); + } + catch (IOException ex) { + throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex); + } + + this.temporaryBlobs.add(blob); + ps.setBlob(paramIndex, blob); + + if (logger.isDebugEnabled()) { + logger.debug(binaryStream != null ? + "Copied binary stream into temporary BLOB with length " + contentLength : + "Set BLOB to null"); + } + } + + @Override + public void setClobAsString(PreparedStatement ps, int paramIndex, String content) + throws SQLException { + + Clob clob = ps.getConnection().createClob(); + clob.setString(1, content); + + this.temporaryClobs.add(clob); + ps.setClob(paramIndex, clob); + + if (logger.isDebugEnabled()) { + logger.debug(content != null ? "Copied string into temporary CLOB with length " + content.length() : + "Set CLOB to null"); + } + } + + @Override + public void setClobAsAsciiStream( + PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength) + throws SQLException { + + Clob clob = ps.getConnection().createClob(); + try { + FileCopyUtils.copy(asciiStream, clob.setAsciiStream(1)); + } + catch (IOException ex) { + throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex); + } + + this.temporaryClobs.add(clob); + ps.setClob(paramIndex, clob); + + if (logger.isDebugEnabled()) { + logger.debug(asciiStream != null ? + "Copied ASCII stream into temporary CLOB with length " + contentLength : + "Set CLOB to null"); + } + } + + @Override + public void setClobAsCharacterStream( + PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength) + throws SQLException { + + Clob clob = ps.getConnection().createClob(); + try { + FileCopyUtils.copy(characterStream, clob.setCharacterStream(1)); + } + catch (IOException ex) { + throw new DataAccessResourceFailureException("Could not copy into LOB stream", ex); + } + + this.temporaryClobs.add(clob); + ps.setClob(paramIndex, clob); + + if (logger.isDebugEnabled()) { + logger.debug(characterStream != null ? + "Copied character stream into temporary CLOB with length " + contentLength : + "Set CLOB to null"); + } + } + + @Override + public void close() { + try { + for (Blob blob : this.temporaryBlobs) { + blob.free(); + } + for (Clob clob : this.temporaryClobs) { + clob.free(); + } + } + catch (SQLException ex) { + logger.error("Could not free LOB", ex); + } + } +} Index: 3rdParty_sources/spring/org/springframework/jdbc/support/lob/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/lob/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/lob/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,12 @@ + +/** + * + * Provides a stategy interface for Large OBject handling, + * with implementations for various databases. + * + *

Can be used independently from jdbc.core and jdbc.object, + * for example in custom JDBC access code. + * + */ +package org.springframework.jdbc.support.lob; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/C3P0NativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/CommonsDbcpNativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/JBossNativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/Jdbc4NativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractorAdapter.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/OracleJdbc4NativeJdbcExtractor.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/OracleJdbc4NativeJdbcExtractor.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/OracleJdbc4NativeJdbcExtractor.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,60 @@ +/* + * Copyright 2002-2012 the original author or authors. + * + * 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 org.springframework.jdbc.support.nativejdbc; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; + +/** + * A {@link Jdbc4NativeJdbcExtractor} which comes pre-configured for Oracle's JDBC driver, + * specifying the following vendor-specific API types for unwrapping: + *

    + *
  • {@code oracle.jdbc.OracleConnection} + *
  • {@code oracle.jdbc.OracleStatement} + *
  • {@code oracle.jdbc.OraclePreparedStatement} + *
  • {@code oracle.jdbc.OracleCallableStatement} + *
  • {@code oracle.jdbc.OracleResultSet} + *
+ * + *

Note: This will work with any JDBC 4.0 compliant connection pool, without a need for + * connection pool specific setup. In other words, as of JDBC 4.0, NativeJdbcExtractors + * will typically be implemented for specific drivers instead of for specific pools. + * + * @author Juergen Hoeller + * @since 3.0.5 + */ +public class OracleJdbc4NativeJdbcExtractor extends Jdbc4NativeJdbcExtractor { + + @SuppressWarnings("unchecked") + public OracleJdbc4NativeJdbcExtractor() { + try { + setConnectionType((Class) getClass().getClassLoader().loadClass("oracle.jdbc.OracleConnection")); + setStatementType((Class) getClass().getClassLoader().loadClass("oracle.jdbc.OracleStatement")); + setPreparedStatementType((Class) getClass().getClassLoader().loadClass("oracle.jdbc.OraclePreparedStatement")); + setCallableStatementType((Class) getClass().getClassLoader().loadClass("oracle.jdbc.OracleCallableStatement")); + setResultSetType((Class) getClass().getClassLoader().loadClass("oracle.jdbc.OracleResultSet")); + } + catch (Exception ex) { + throw new IllegalStateException( + "Could not initialize OracleJdbc4NativeJdbcExtractor because Oracle API classes are not available: " + ex); + } + } + +} Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/SimpleNativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/WebLogicNativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/WebSphereNativeJdbcExtractor.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/nativejdbc/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,11 @@ + +/** + * + * Provides a mechanism for extracting native implementations of JDBC + * interfaces from wrapper objects that got returned from connection pools. + * + *

Can be used independently, for example in custom JDBC access code. + * + */ +package org.springframework.jdbc.support.nativejdbc; + Index: 3rdParty_sources/spring/org/springframework/jdbc/support/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,13 @@ + +/** + * + * Support classes for the JDBC framework, used by the classes in the + * jdbc.core and jdbc.object packages. Provides a translator from + * SQLExceptions Spring's generic DataAccessExceptions. + * + *

Can be used independently, for example in custom JDBC access code, + * or in JDBC-based O/R mapping layers. + * + */ +package org.springframework.jdbc.support; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSetMetaData.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/rowset/SqlRowSet.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/rowset/SqlRowSetMetaData.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/rowset/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/rowset/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/rowset/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,9 @@ + +/** + * + * Provides a convenient holder for disconnected result sets. + * Supported by JdbcTemplate, but can be used independently too. + * + */ +package org.springframework.jdbc.support.rowset; + Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/Jdbc4SqlXmlHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/SqlXmlFeatureNotImplementedException.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/SqlXmlHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/SqlXmlValue.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/XmlBinaryStreamProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/XmlCharacterStreamProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 2b6774d5449fee3258575f0164adf4a2056aff5a refers to a dead (removed) revision in file `3rdParty_sources/spring/org/springframework/jdbc/support/xml/XmlResultProvider.java'. Fisheye: No comparison available. Pass `N' to diff? Index: 3rdParty_sources/spring/org/springframework/jdbc/support/xml/package-info.java =================================================================== diff -u --- 3rdParty_sources/spring/org/springframework/jdbc/support/xml/package-info.java (revision 0) +++ 3rdParty_sources/spring/org/springframework/jdbc/support/xml/package-info.java (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -0,0 +1,8 @@ + +/** + * + * Abstraction for handling fields of SQLXML data type. + * + */ +package org.springframework.jdbc.support.xml; + Index: lams_build/lib/spring/spring-jdbc-4.0.6.RELEASE.jar =================================================================== diff -u Binary files differ Index: lams_build/lib/spring/spring.module.xml =================================================================== diff -u -r5ae237e4a0128296396d4be27e32f54d1304c2ef -rc0ff6b441af3e25ef2eebc07a1f19a766372c6d9 --- lams_build/lib/spring/spring.module.xml (.../spring.module.xml) (revision 5ae237e4a0128296396d4be27e32f54d1304c2ef) +++ lams_build/lib/spring/spring.module.xml (.../spring.module.xml) (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -30,6 +30,7 @@ + @@ -40,12 +41,16 @@ - + + + + + \ No newline at end of file Index: lams_build/liblist.txt =================================================================== diff -u -r5ae237e4a0128296396d4be27e32f54d1304c2ef -rc0ff6b441af3e25ef2eebc07a1f19a766372c6d9 --- lams_build/liblist.txt (.../liblist.txt) (revision 5ae237e4a0128296396d4be27e32f54d1304c2ef) +++ lams_build/liblist.txt (.../liblist.txt) (revision c0ff6b441af3e25ef2eebc07a1f19a766372c6d9) @@ -60,6 +60,7 @@ spring-context-4.0.6.RELEASE.jar spring-context-support-4.0.6.RELEASE.jar spring-expression-4.0.6.RELEASE.jar + spring-jdbc-4.0.6.RELEASE.jar spring-orm-4.0.6.RELEASE.jar spring-tx-4.0.6.RELEASE.jar spring-web-4.0.6.RELEASE.jar