diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProviderFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProviderFactory.java index 39a660845a2..528176097bd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProviderFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProviderFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -63,12 +63,12 @@ public class CallMetaDataProviderFactory { /** - * Create a CallMetaDataProvider based on the database metadata + * Create a {@link CallMetaDataProvider} based on the database metadata * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @return instance of the CallMetaDataProvider implementation to be used */ - static public CallMetaDataProvider createMetaDataProvider(DataSource dataSource, final CallMetaDataContext context) { + public static CallMetaDataProvider createMetaDataProvider(DataSource dataSource, final CallMetaDataContext context) { try { return (CallMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() { @Override @@ -104,27 +104,28 @@ public class CallMetaDataProviderFactory { if ("Oracle".equals(databaseProductName)) { provider = new OracleCallMetaDataProvider(databaseMetaData); } - else if ("DB2".equals(databaseProductName)) { - provider = new Db2CallMetaDataProvider((databaseMetaData)); + else if ("PostgreSQL".equals(databaseProductName)) { + provider = new PostgresCallMetaDataProvider((databaseMetaData)); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyCallMetaDataProvider((databaseMetaData)); } - else if ("PostgreSQL".equals(databaseProductName)) { - provider = new PostgresCallMetaDataProvider((databaseMetaData)); + else if ("DB2".equals(databaseProductName)) { + provider = new Db2CallMetaDataProvider((databaseMetaData)); } - else if ("Sybase".equals(databaseProductName)) { - provider = new SybaseCallMetaDataProvider((databaseMetaData)); + else if ("HDB".equals(databaseProductName)) { + provider = new HanaCallMetaDataProvider((databaseMetaData)); } else if ("Microsoft SQL Server".equals(databaseProductName)) { provider = new SqlServerCallMetaDataProvider((databaseMetaData)); } - else if ("HDB".equals(databaseProductName)) { - provider = new HanaCallMetaDataProvider((databaseMetaData)); + else if ("Sybase".equals(databaseProductName)) { + provider = new SybaseCallMetaDataProvider((databaseMetaData)); } else { provider = new GenericCallMetaDataProvider(databaseMetaData); } + if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getName()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java index 821a1ff64ae..49c5754be28 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -39,26 +39,26 @@ public class Db2CallMetaDataProvider extends GenericCallMetaDataProvider { try { setSupportsCatalogsInProcedureCalls(databaseMetaData.supportsCatalogsInProcedureCalls()); } - catch (SQLException se) { - logger.debug("Error retrieving 'DatabaseMetaData.supportsCatalogsInProcedureCalls' - " + se.getMessage()); + catch (SQLException ex) { + logger.debug("Error retrieving 'DatabaseMetaData.supportsCatalogsInProcedureCalls' - " + ex.getMessage()); } try { setSupportsSchemasInProcedureCalls(databaseMetaData.supportsSchemasInProcedureCalls()); } - catch (SQLException se) { - logger.debug("Error retrieving 'DatabaseMetaData.supportsSchemasInProcedureCalls' - " + se.getMessage()); + catch (SQLException ex) { + logger.debug("Error retrieving 'DatabaseMetaData.supportsSchemasInProcedureCalls' - " + ex.getMessage()); } try { setStoresUpperCaseIdentifiers(databaseMetaData.storesUpperCaseIdentifiers()); } - catch (SQLException se) { - logger.debug("Error retrieving 'DatabaseMetaData.storesUpperCaseIdentifiers' - " + se.getMessage()); + catch (SQLException ex) { + logger.debug("Error retrieving 'DatabaseMetaData.storesUpperCaseIdentifiers' - " + ex.getMessage()); } try { setStoresLowerCaseIdentifiers(databaseMetaData.storesLowerCaseIdentifiers()); } - catch (SQLException se) { - logger.debug("Error retrieving 'DatabaseMetaData.storesLowerCaseIdentifiers' - " + se.getMessage()); + catch (SQLException ex) { + logger.debug("Error retrieving 'DatabaseMetaData.storesLowerCaseIdentifiers' - " + ex.getMessage()); } } @@ -67,6 +67,7 @@ public class Db2CallMetaDataProvider extends GenericCallMetaDataProvider { if (schemaName != null) { return super.metaDataSchemaNameToUse(schemaName); } + // Use current user schema if no schema specified... String userName = getUserName(); return (userName != null ? userName.toUpperCase() : null); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java index ef08f8fdea4..477674ba785 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2018 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. @@ -33,11 +33,13 @@ public class DerbyCallMetaDataProvider extends GenericCallMetaDataProvider { super(databaseMetaData); } + @Override public String metaDataSchemaNameToUse(String schemaName) { if (schemaName != null) { return super.metaDataSchemaNameToUse(schemaName); } + // Use current user schema if no schema specified... String userName = getUserName(); return (userName != null ? userName.toUpperCase() : null); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyTableMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyTableMetaDataProvider.java index 53702005522..8ea0bdfffb6 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyTableMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyTableMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -20,9 +20,8 @@ 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 retrieving generated keys. It seems to work OK so not sure why - * they claim it's not supported. + * The Derby specific implementation of {@link TableMetaDataProvider}. + * Overrides the Derby metadata info regarding retrieving generated keys. * * @author Thomas Risberg * @since 3.0 @@ -53,4 +52,5 @@ public class DerbyTableMetaDataProvider extends GenericTableMetaDataProvider { public boolean isGetGeneratedKeysSupported() { return (super.isGetGeneratedKeysSupported() || this.supportsGeneratedKeysOverride); } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java index d427b80784e..c580fde6d0a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java @@ -33,7 +33,7 @@ import org.springframework.jdbc.core.SqlParameter; import org.springframework.util.StringUtils; /** - * Generic implementation for the {@link CallMetaDataProvider} interface. + * A generic implementation of the {@link CallMetaDataProvider} interface. * This class can be extended to provide database specific behavior. * * @author Thomas Risberg diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java index 53a330158d5..a86338237c7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -34,8 +34,8 @@ import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; /** - * A generic implementation of the {@link TableMetaDataProvider} that should provide - * enough features for all supported databases. + * A generic implementation of the {@link TableMetaDataProvider} interface + * which should provide enough features for all supported databases. * * @author Thomas Risberg * @author Juergen Hoeller @@ -221,7 +221,6 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider { logger.warn("Error retrieving 'DatabaseMetaData.storesLowerCaseIdentifiers': " + ex.getMessage()); } } - } @Override diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HanaCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HanaCallMetaDataProvider.java index b853c1e4875..d8dbf2111b3 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HanaCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HanaCallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -33,6 +33,7 @@ public class HanaCallMetaDataProvider extends GenericCallMetaDataProvider { super(databaseMetaData); } + @Override public void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException { super.initializeWithMetaData(databaseMetaData); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java index 1ef669a904b..77c85070521 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/HsqlTableMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -33,6 +33,7 @@ public class HsqlTableMetaDataProvider extends GenericTableMetaDataProvider { super(databaseMetaData); } + @Override public boolean isGetGeneratedKeysSimulated() { return true; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java index ef8d77b803d..d916a83a058 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java @@ -42,7 +42,7 @@ public class TableMetaDataProviderFactory { /** - * Create a TableMetaDataProvider based on the database metadata. + * Create a {@link TableMetaDataProvider} based on the database metadata. * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @return instance of the TableMetaDataProvider implementation to be used @@ -52,7 +52,7 @@ public class TableMetaDataProviderFactory { } /** - * Create a TableMetaDataProvider based on the database metadata. + * Create a {@link TableMetaDataProvider} based on the database metadata. * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @param nativeJdbcExtractor the NativeJdbcExtractor to be used @@ -68,13 +68,11 @@ public class TableMetaDataProviderFactory { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); + TableMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { - provider = new OracleTableMetaDataProvider(databaseMetaData, - context.isOverrideIncludeSynonymsDefault()); - } - else if ("HSQL Database Engine".equals(databaseProductName)) { - provider = new HsqlTableMetaDataProvider(databaseMetaData); + provider = new OracleTableMetaDataProvider( + databaseMetaData, context.isOverrideIncludeSynonymsDefault()); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresTableMetaDataProvider(databaseMetaData); @@ -82,12 +80,16 @@ public class TableMetaDataProviderFactory { else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyTableMetaDataProvider(databaseMetaData); } + else if ("HSQL Database Engine".equals(databaseProductName)) { + provider = new HsqlTableMetaDataProvider(databaseMetaData); + } else { provider = new GenericTableMetaDataProvider(databaseMetaData); } if (nativeJdbcExtractor != null) { provider.setNativeJdbcExtractor(nativeJdbcExtractor); } + if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getSimpleName()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java index 6fc983f19c8..ce40da25a13 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/AbstractEmbeddedDatabaseConfigurer.java @@ -24,7 +24,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** - * Base class for {@link EmbeddedDatabaseConfigurer} implementations providing common shutdown behavior. + * Base class for {@link EmbeddedDatabaseConfigurer} implementations + * providing common shutdown behavior through a "SHUTDOWN" statement. * * @author Oliver Gierke * @author Juergen Hoeller diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java index 9c0a0a196ab..1548eaa872c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -24,7 +24,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.derby.jdbc.EmbeddedDriver; /** - * {@link EmbeddedDatabaseConfigurer} for the Apache Derby database 10.6+. + * {@link EmbeddedDatabaseConfigurer} for the Apache Derby database. + * *
Call {@link #getInstance()} to get the singleton instance of this class. * * @author Oliver Gierke @@ -40,10 +41,9 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure /** * Get the singleton {@link DerbyEmbeddedDatabaseConfigurer} instance. - * @return the configurer - * @throws ClassNotFoundException if Derby is not on the classpath + * @return the configurer instance */ - public static synchronized DerbyEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException { + public static synchronized DerbyEmbeddedDatabaseConfigurer getInstance() { if (instance == null) { // disable log file System.setProperty("derby.stream.error.method", diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurer.java index c461aa6a8f5..8f83729b84e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -30,8 +30,7 @@ import javax.sql.DataSource; public interface EmbeddedDatabaseConfigurer { /** - * Configure the properties required to create and connect to the embedded - * database instance. + * Configure the properties required to create and connect to the embedded database. * @param properties connection properties to configure * @param databaseName the name of the embedded database */ @@ -39,7 +38,7 @@ public interface EmbeddedDatabaseConfigurer { /** * Shut down the embedded database instance that backs the supplied {@link DataSource}. - * @param dataSource the data source + * @param dataSource the corresponding {@link DataSource} * @param databaseName the name of the database being shut down */ void shutdown(DataSource dataSource, String databaseName); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurerFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurerFactory.java index 1ceda5b4470..31819a330b2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurerFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseConfigurerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -19,8 +19,8 @@ package org.springframework.jdbc.datasource.embedded; import org.springframework.util.Assert; /** - * Maps well-known {@linkplain EmbeddedDatabaseType embedded database types} to - * {@link EmbeddedDatabaseConfigurer} strategies. + * Maps well-known {@linkplain EmbeddedDatabaseType embedded database types} + * to {@link EmbeddedDatabaseConfigurer} strategies. * * @author Keith Donald * @author Oliver Gierke @@ -29,6 +29,12 @@ import org.springframework.util.Assert; */ final class EmbeddedDatabaseConfigurerFactory { + /** + * Return a configurer instance for the given embedded database type. + * @param type HSQL, H2 or Derby + * @return the configurer instance + * @throws IllegalStateException if the driver for the specified database type is not available + */ public static EmbeddedDatabaseConfigurer getConfigurer(EmbeddedDatabaseType type) throws IllegalStateException { Assert.notNull(type, "EmbeddedDatabaseType is required"); try { @@ -44,13 +50,11 @@ final class EmbeddedDatabaseConfigurerFactory { } } catch (ClassNotFoundException ex) { - throw new IllegalStateException("Driver for test database type [" + type + - "] is not available in the classpath", ex); + throw new IllegalStateException("Driver for test database type [" + type + "] is not available", ex); + } + catch (NoClassDefFoundError err) { + throw new IllegalStateException("Driver for test database type [" + type + "] is not available", err); } - } - - private EmbeddedDatabaseConfigurerFactory() { - /* no-op */ } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java index 57c6000a6df..e409ce1f0b1 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -22,6 +22,7 @@ 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 @@ -38,7 +39,7 @@ final class H2EmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigu /** * Get the singleton {@code H2EmbeddedDatabaseConfigurer} instance. - * @return the configurer + * @return the configurer instance * @throws ClassNotFoundException if H2 is not on the classpath */ @SuppressWarnings("unchecked") diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java index 89f37f2d3d2..5f2422ee918 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -22,6 +22,7 @@ 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 @@ -37,7 +38,7 @@ final class HsqlEmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfi /** * Get the singleton {@link HsqlEmbeddedDatabaseConfigurer} instance. - * @return the configurer + * @return the configurer instance * @throws ClassNotFoundException if HSQL is not on the classpath */ @SuppressWarnings("unchecked") diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java index 6d9f919ac1e..2cd2c450450 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java @@ -17,7 +17,6 @@ package org.springframework.jdbc.support; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.Blob; import java.sql.Clob; @@ -420,9 +419,10 @@ public abstract class JdbcUtils { } /** - * Extract a common name for the database in use even if various drivers/platforms provide varying names. + * Extract a common name for the target database in use even if + * various drivers/platforms provide varying names at runtime. * @param source the name as provided in database metadata - * @return the common name to be used + * @return the common name to be used (e.g. "DB2" or "Sybase") */ public static String commonDatabaseName(String source) { String name = source; @@ -444,10 +444,10 @@ public abstract class JdbcUtils { * @return whether the type is numeric */ public static boolean isNumeric(int sqlType) { - return Types.BIT == sqlType || Types.BIGINT == sqlType || Types.DECIMAL == sqlType || + return (Types.BIT == sqlType || Types.BIGINT == sqlType || Types.DECIMAL == sqlType || Types.DOUBLE == sqlType || Types.FLOAT == sqlType || Types.INTEGER == sqlType || Types.NUMERIC == sqlType || Types.REAL == sqlType || Types.SMALLINT == sqlType || - Types.TINYINT == sqlType; + Types.TINYINT == sqlType); } /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2MainframeSequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2MainframeSequenceMaxValueIncrementer.java index c7a08e25463..7bb160e8971 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2MainframeSequenceMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2MainframeSequenceMaxValueIncrementer.java @@ -19,13 +19,16 @@ package org.springframework.jdbc.support.incrementer; import javax.sql.DataSource; /** - * {@link DataFieldMaxValueIncrementer} that retrieves the next value of a given sequence - * on DB2/390 or DB2/400. Thanks to Jens Eickmeyer for the suggestion! + * {@link DataFieldMaxValueIncrementer} that retrieves the next value + * of a given sequence on DB2 for the mainframe (z/OS, DB2/390, DB2/400). + * + *
Thanks to Jens Eickmeyer for the suggestion! * * @author Juergen Hoeller * @since 2.5.3 - * @see DB2SequenceMaxValueIncrementer + * @deprecated in favor of the differently named {@link Db2MainframeMaxValueIncrementer} */ +@Deprecated public class DB2MainframeSequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer { /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2SequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2SequenceMaxValueIncrementer.java index ab725db4206..6125fb2ffbd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2SequenceMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/DB2SequenceMaxValueIncrementer.java @@ -19,14 +19,17 @@ package org.springframework.jdbc.support.incrementer; import javax.sql.DataSource; /** - * {@link DataFieldMaxValueIncrementer} that retrieves the next value of a given sequence - * on DB2 UDB (for Unix and Windows). Thanks to Mark MacMahon for the suggestion! + * {@link DataFieldMaxValueIncrementer} that retrieves the next value + * of a given sequence on DB2 LUW (for Linux, Unix and Windows). + * + *
Thanks to Mark MacMahon for the suggestion! * * @author Juergen Hoeller * @since 1.1.3 - * @see DB2MainframeSequenceMaxValueIncrementer + * @deprecated in favor of the specifically named {@link Db2LuwMaxValueIncrementer} */ -public class DB2SequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer { +@Deprecated +public class DB2SequenceMaxValueIncrementer extends Db2LuwMaxValueIncrementer { /** * Default constructor for bean property style usage. @@ -45,10 +48,4 @@ public class DB2SequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncr super(dataSource, incrementerName); } - - @Override - protected String getSequenceQuery() { - return "values nextval for " + getIncrementerName(); - } - } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/Db2LuwMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/Db2LuwMaxValueIncrementer.java new file mode 100644 index 00000000000..ad0102c7d0f --- /dev/null +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/Db2LuwMaxValueIncrementer.java @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2018 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 retrieves the next value + * of a given sequence on DB2 LUW (for Linux, Unix and Windows). + * + *
Thanks to Mark MacMahon for the suggestion! + * + * @author Juergen Hoeller + * @since 4.3.15 + * @see Db2MainframeMaxValueIncrementer + */ +public class Db2LuwMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer { + + /** + * Default constructor for bean property style usage. + * @see #setDataSource + * @see #setIncrementerName + */ + public Db2LuwMaxValueIncrementer() { + } + + /** + * Convenience constructor. + * @param dataSource the DataSource to use + * @param incrementerName the name of the sequence/table to use + */ + public Db2LuwMaxValueIncrementer(DataSource dataSource, String incrementerName) { + super(dataSource, incrementerName); + } + + + @Override + protected String getSequenceQuery() { + return "values nextval for " + getIncrementerName(); + } + +} diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/Db2MainframeMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/Db2MainframeMaxValueIncrementer.java new file mode 100644 index 00000000000..f3d30f0185e --- /dev/null +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/Db2MainframeMaxValueIncrementer.java @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2018 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 retrieves the next value + * of a given sequence on DB2 for the mainframe (z/OS, DB2/390, DB2/400). + * + *
Thanks to Jens Eickmeyer for the suggestion! + * + * @author Juergen Hoeller + * @since 4.3.15 + * @see Db2LuwMaxValueIncrementer + */ +public class Db2MainframeMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer { + + /** + * Default constructor for bean property style usage. + * @see #setDataSource + * @see #setIncrementerName + */ + public Db2MainframeMaxValueIncrementer() { + } + + /** + * Convenience constructor. + * @param dataSource the DataSource to use + * @param incrementerName the name of the sequence/table to use + */ + public Db2MainframeMaxValueIncrementer(DataSource dataSource, String incrementerName) { + super(dataSource, incrementerName); + } + + + @Override + protected String getSequenceQuery() { + return "select next value for " + getIncrementerName() + " from sysibm.sysdummy1"; + } + +} diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java index 7c5bf6c5629..568c1517eb5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/H2SequenceMaxValueIncrementer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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. @@ -19,7 +19,8 @@ package org.springframework.jdbc.support.incrementer; import javax.sql.DataSource; /** - * {@link DataFieldMaxValueIncrementer} that retrieves the next value of a given H2 Database sequence. + * {@link DataFieldMaxValueIncrementer} that retrieves the next value + * of a given H2 sequence. * * @author Thomas Risberg * @since 2.5 diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/HanaSequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/HanaSequenceMaxValueIncrementer.java new file mode 100644 index 00000000000..b590e30d588 --- /dev/null +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/HanaSequenceMaxValueIncrementer.java @@ -0,0 +1,54 @@ +/* + * Copyright 2002-2018 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 retrieves the next value + * of a given SAP HANA sequence. + * + * @author Jonathan Bregler + * @author Juergen Hoeller + * @since 4.3.15 + */ +public class HanaSequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer { + + /** + * Default constructor for bean property style usage. + * @see #setDataSource + * @see #setIncrementerName + */ + public HanaSequenceMaxValueIncrementer() { + } + + /** + * Convenience constructor. + * @param dataSource the DataSource to use + * @param incrementerName the name of the sequence/table to use + */ + public HanaSequenceMaxValueIncrementer(DataSource dataSource, String incrementerName) { + super(dataSource, incrementerName); + } + + + @Override + protected String getSequenceQuery() { + return "select " + getIncrementerName() + ".nextval from dummy"; + } + +} diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/HsqlSequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/HsqlSequenceMaxValueIncrementer.java index 0d589dabf9f..73b624df712 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/HsqlSequenceMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/HsqlSequenceMaxValueIncrementer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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. @@ -19,11 +19,13 @@ package org.springframework.jdbc.support.incrementer; import javax.sql.DataSource; /** - * {@link DataFieldMaxValueIncrementer} that retrieves the next value of a given HSQL sequence. - * Thanks to Guillaume Bilodeau for the suggestion! + * {@link DataFieldMaxValueIncrementer} that retrieves the next value + * of a given HSQL sequence. * - *
NOTE: This is an alternative to using a regular table to support generating - * unique keys that was necessary in previous versions of HSQL. + *
Thanks to Guillaume Bilodeau for the suggestion! + * + *
NOTE: This is an alternative to using a regular table to support + * generating unique keys that was necessary in previous versions of HSQL. * * @author Thomas Risberg * @since 2.5 diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/OracleSequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/OracleSequenceMaxValueIncrementer.java index ea1bcc9c0a2..7efaf6d19a8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/OracleSequenceMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/OracleSequenceMaxValueIncrementer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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. @@ -19,7 +19,8 @@ package org.springframework.jdbc.support.incrementer; import javax.sql.DataSource; /** - * {@link DataFieldMaxValueIncrementer} that retrieves the next value of a given Oracle sequence. + * {@link DataFieldMaxValueIncrementer} that retrieves the next value + * of a given Oracle sequence. * * @author Dmitriy Kopylenko * @author Thomas Risberg diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/PostgreSQLSequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/PostgreSQLSequenceMaxValueIncrementer.java index 7af3fa69eb2..1aac29ed866 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/PostgreSQLSequenceMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/PostgreSQLSequenceMaxValueIncrementer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2018 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. @@ -19,12 +19,16 @@ package org.springframework.jdbc.support.incrementer; import javax.sql.DataSource; /** - * {@link DataFieldMaxValueIncrementer} that retrieves the next value of a given PostgreSQL sequence. - * Thanks to Tomislav Urban for the suggestion! + * {@link DataFieldMaxValueIncrementer} that retrieves the next value + * of a given PostgreSQL sequence. + * + *
Thanks to Tomislav Urban for the suggestion! * * @author Juergen Hoeller + * @deprecated in favor of the differently named {@link PostgresSequenceMaxValueIncrementer} */ -public class PostgreSQLSequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer { +@Deprecated +public class PostgreSQLSequenceMaxValueIncrementer extends PostgresSequenceMaxValueIncrementer { /** * Default constructor for bean property style usage. @@ -43,10 +47,4 @@ public class PostgreSQLSequenceMaxValueIncrementer extends AbstractSequenceMaxVa super(dataSource, incrementerName); } - - @Override - protected String getSequenceQuery() { - return "select nextval('" + getIncrementerName() + "')"; - } - } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/PostgresSequenceMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/PostgresSequenceMaxValueIncrementer.java new file mode 100644 index 00000000000..7901649649e --- /dev/null +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/PostgresSequenceMaxValueIncrementer.java @@ -0,0 +1,55 @@ +/* + * Copyright 2002-2018 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 retrieves the next value + * of a given PostgreSQL sequence. + * + *
Thanks to Tomislav Urban for the suggestion!
+ *
+ * @author Juergen Hoeller
+ * @since 4.3.15
+ */
+public class PostgresSequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer {
+
+ /**
+ * Default constructor for bean property style usage.
+ * @see #setDataSource
+ * @see #setIncrementerName
+ */
+ public PostgresSequenceMaxValueIncrementer() {
+ }
+
+ /**
+ * Convenience constructor.
+ * @param dataSource the DataSource to use
+ * @param incrementerName the name of the sequence/table to use
+ */
+ public PostgresSequenceMaxValueIncrementer(DataSource dataSource, String incrementerName) {
+ super(dataSource, incrementerName);
+ }
+
+
+ @Override
+ protected String getSequenceQuery() {
+ return "select nextval('" + getIncrementerName() + "')";
+ }
+
+}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseAnywhereMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseAnywhereMaxValueIncrementer.java
index 8f6a6ec0b5f..2bd36b4686f 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseAnywhereMaxValueIncrementer.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseAnywhereMaxValueIncrementer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2018 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.
@@ -19,8 +19,7 @@ package org.springframework.jdbc.support.incrementer;
import javax.sql.DataSource;
/**
- * {@link DataFieldMaxValueIncrementer} that increments
- * the maximum value of a given Sybase SQL Anywhere table
+ * {@link DataFieldMaxValueIncrementer} that increments the maximum value of a given Sybase 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.
*
@@ -40,9 +39,9 @@ import javax.sql.DataSource;
* 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
+ * 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}.
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseMaxValueIncrementer.java
index 5131b2945db..82272b2933b 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseMaxValueIncrementer.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/SybaseMaxValueIncrementer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2018 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.
@@ -39,9 +39,9 @@ import javax.sql.DataSource;
* 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 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
+ * HINT: Since Sybase Adaptive Server 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}.
diff --git a/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml b/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml
index c0278d5919e..5e3cd6f840d 100644
--- a/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml
+++ b/spring-jdbc/src/main/resources/org/springframework/jdbc/support/sql-error-codes.xml
@@ -14,7 +14,7 @@
-->
+
+
-
-