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 8a3b50e83c..3be899388b 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-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. @@ -67,7 +67,7 @@ public class CallMetaDataProviderFactory { */ static public CallMetaDataProvider createMetaDataProvider(DataSource dataSource, final CallMetaDataContext context) { try { - CallMetaDataProvider result = (CallMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { + return (CallMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessProcedureColumnMetaData = context.isAccessCallParameterMetaData(); if (context.isFunction()) { @@ -94,31 +94,33 @@ public class CallMetaDataProviderFactory { } } } + CallMetaDataProvider provider; 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 ("Sybase".equals(databaseProductName)) { - provider = new SybaseCallMetaDataProvider((databaseMetaData)); - } - else if ("Microsoft SQL Server".equals(databaseProductName)) { - provider = new SqlServerCallMetaDataProvider((databaseMetaData)); + else if ("DB2".equals(databaseProductName)) { + provider = new Db2CallMetaDataProvider((databaseMetaData)); } else if ("HDB".equals(databaseProductName)) { provider = new HanaCallMetaDataProvider((databaseMetaData)); } + else if ("Microsoft SQL Server".equals(databaseProductName)) { + provider = new SqlServerCallMetaDataProvider((databaseMetaData)); + } + else if ("Sybase".equals(databaseProductName)) { + provider = new SybaseCallMetaDataProvider((databaseMetaData)); + } else { provider = new GenericCallMetaDataProvider(databaseMetaData); } + if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getName()); } @@ -129,7 +131,6 @@ public class CallMetaDataProviderFactory { } return provider; }); - return result; } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); 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 ca4a4bd1f3..5411f33127 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-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. @@ -70,6 +70,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 ceed04db89..629823cb61 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-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. @@ -35,12 +35,14 @@ public class DerbyCallMetaDataProvider extends GenericCallMetaDataProvider { super(databaseMetaData); } + @Override @Nullable public String metaDataSchemaNameToUse(@Nullable 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 5370200552..8ea0bdfffb 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 5cfc325c85..6d8137019a 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 @@ -34,7 +34,7 @@ import org.springframework.lang.Nullable; 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 f72d7fd00e..946d9b5349 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.lang.Nullable; /** - * 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 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 b853c1e487..d8dbf2111b 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 1ef669a904..77c8507052 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 51b3b09428..d376b1c25c 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 @@ -50,12 +50,10 @@ public class TableMetaDataProviderFactory { 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); @@ -63,9 +61,13 @@ 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 (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 a78b819350..2f512fc03b 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 @@ -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. @@ -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 081218e967..25bcfed906 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-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. @@ -26,7 +26,8 @@ import org.apache.derby.jdbc.EmbeddedDriver; import org.springframework.lang.Nullable; /** - * {@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 @@ -43,10 +44,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 c461aa6a8f..8f83729b84 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 1ceda5b447..75e54c62a9 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 { @@ -43,14 +49,9 @@ final class EmbeddedDatabaseConfigurerFactory { 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); + catch (ClassNotFoundException | NoClassDefFoundError ex) { + throw new IllegalStateException("Driver for test database type [" + type + "] is not available", ex); } } - 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 540bbf7233..5a013903d2 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-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. @@ -23,6 +23,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 @@ -40,7 +41,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 acf8d61ecb..f8ba882c6e 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-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. @@ -23,6 +23,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 @@ -39,7 +40,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 1540ffd8e5..8470126f43 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 @@ -406,9 +406,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") */ @Nullable public static String commonDatabaseName(@Nullable String source) { @@ -431,10 +432,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 c7a08e2546..7bb160e897 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 ab725db420..6125fb2ffb 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 0000000000..ad0102c7d0 --- /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 0000000000..f3d30f0185 --- /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 7c5bf6c562..568c1517eb 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 0000000000..b590e30d58 --- /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 0d589dabf9..73b624df71 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 ea1bcc9c0a..7efaf6d19a 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 7af3fa69eb..1aac29ed86 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 0000000000..7901649649 --- /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 8f6a6ec0b5..2bd36b4686 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 5131b2945d..82272b2933 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 c0278d5919..5e3cd6f840 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 @@ --> - + DB2* @@ -83,7 +83,49 @@ - + + + + + SAP HANA + SAP DB + + + + + 257,259,260,261,262,263,264,267,268,269,270,271,272,273,275,276,277,278, + 278,279,280,281,282,283,284,285,286,288,289,290,294,295,296,297,299,308,309, + 313,315,316,318,319,320,321,322,323,324,328,329,330,333,335,336,337,338,340, + 343,350,351,352,362,368 + + + + 10,258 + + + 301 + + + 461,462 + + + -813,-709,-708,1024,1025,1026,1027,1029,1030,1031 + + + -11210,582,587,588,594 + + + 131 + + + 138,143 + + + 133 + + + + HSQL Database Engine @@ -116,7 +158,7 @@ - + Microsoft SQL Server @@ -191,7 +233,7 @@ - + true @@ -222,10 +264,10 @@ Sybase SQL Server - SQL Server Adaptive Server Enterprise - ASE - sql server + ASE + SQL Server + sql server @@ -248,47 +290,4 @@ - - - - - SAP DB - HDB - - - - - 257,259,260,261,262,263,264,267,268,269,270,271,272,273,275,276,277,278, - 278,279,280,281,282,283,284,285,286,288,289,290,294,295,296,297,299,308,309, - 313,315,316,318,319,320,321,322,323,324,328,329,330,333,335,336,337,338,340, - 343,350,351,352,362,368 - - - - 10,258 - - - 301 - - - 461,462 - - - -813,-709,-708,1024,1025,1026,1027,1029,1030,1031 - - - -11210,582,587,588,594 - - - 131 - - - 138,143 - - - 133 - - - - diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/DataFieldMaxValueIncrementerTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/DataFieldMaxValueIncrementerTests.java index f493a74366..25bb14b510 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/DataFieldMaxValueIncrementerTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/DataFieldMaxValueIncrementerTests.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. @@ -24,10 +24,11 @@ import javax.sql.DataSource; import org.junit.Test; +import org.springframework.jdbc.support.incrementer.HanaSequenceMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer; -import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer; +import org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer; import static org.junit.Assert.*; import static org.mockito.BDDMockito.*; @@ -38,15 +39,37 @@ import static org.mockito.BDDMockito.*; */ public class DataFieldMaxValueIncrementerTests { - private DataSource dataSource = mock(DataSource.class); + private final DataSource dataSource = mock(DataSource.class); - private Connection connection = mock(Connection.class); + private final Connection connection = mock(Connection.class); - private Statement statement = mock(Statement.class); + private final Statement statement = mock(Statement.class); - private ResultSet resultSet = mock(ResultSet.class); + private final ResultSet resultSet = mock(ResultSet.class); + @Test + public void testHanaSequenceMaxValueIncrementer() throws SQLException { + given(dataSource.getConnection()).willReturn(connection); + given(connection.createStatement()).willReturn(statement); + given(statement.executeQuery("select myseq.nextval from dummy")).willReturn(resultSet); + given(resultSet.next()).willReturn(true); + given(resultSet.getLong(1)).willReturn(10L, 12L); + + HanaSequenceMaxValueIncrementer incrementer = new HanaSequenceMaxValueIncrementer(); + incrementer.setDataSource(dataSource); + incrementer.setIncrementerName("myseq"); + incrementer.setPaddingLength(2); + incrementer.afterPropertiesSet(); + + assertEquals(10, incrementer.nextLongValue()); + assertEquals("12", incrementer.nextStringValue()); + + verify(resultSet, times(2)).close(); + verify(statement, times(2)).close(); + verify(connection, times(2)).close(); + } + @Test public void testHsqlMaxValueIncrementer() throws SQLException { given(dataSource.getConnection()).willReturn(connection); @@ -135,28 +158,6 @@ public class DataFieldMaxValueIncrementerTests { verify(connection, times(2)).close(); } - @Test - public void testPostgreSQLSequenceMaxValueIncrementer() throws SQLException { - given(dataSource.getConnection()).willReturn(connection); - given(connection.createStatement()).willReturn(statement); - given(statement.executeQuery("select nextval('myseq')")).willReturn(resultSet); - given(resultSet.next()).willReturn(true); - given(resultSet.getLong(1)).willReturn(10L, 12L); - - PostgreSQLSequenceMaxValueIncrementer incrementer = new PostgreSQLSequenceMaxValueIncrementer(); - incrementer.setDataSource(dataSource); - incrementer.setIncrementerName("myseq"); - incrementer.setPaddingLength(5); - incrementer.afterPropertiesSet(); - - assertEquals("00010", incrementer.nextStringValue()); - assertEquals(12, incrementer.nextIntValue()); - - verify(resultSet, times(2)).close(); - verify(statement, times(2)).close(); - verify(connection, times(2)).close(); - } - @Test public void testOracleSequenceMaxValueIncrementer() throws SQLException { given(dataSource.getConnection()).willReturn(connection); @@ -179,4 +180,26 @@ public class DataFieldMaxValueIncrementerTests { verify(connection, times(2)).close(); } + @Test + public void testPostgresSequenceMaxValueIncrementer() throws SQLException { + given(dataSource.getConnection()).willReturn(connection); + given(connection.createStatement()).willReturn(statement); + given(statement.executeQuery("select nextval('myseq')")).willReturn(resultSet); + given(resultSet.next()).willReturn(true); + given(resultSet.getLong(1)).willReturn(10L, 12L); + + PostgresSequenceMaxValueIncrementer incrementer = new PostgresSequenceMaxValueIncrementer(); + incrementer.setDataSource(dataSource); + incrementer.setIncrementerName("myseq"); + incrementer.setPaddingLength(5); + incrementer.afterPropertiesSet(); + + assertEquals("00010", incrementer.nextStringValue()); + assertEquals(12, incrementer.nextIntValue()); + + verify(resultSet, times(2)).close(); + verify(statement, times(2)).close(); + verify(connection, times(2)).close(); + } + }