Refactor tests in spring-batch-infrastructure

- Remove unused resources
- Fix logging libraries conflicts
- Merge duplicate data source configuration
- Merge scattered DDL scripts
- Replace usage of DataSourceInitializer with Spring JDBC test utilities
This commit is contained in:
Mahmoud Ben Hassine
2023-06-23 08:52:08 +02:00
parent e6e9c4e7a2
commit 8aea17f21d
47 changed files with 156 additions and 785 deletions

View File

@@ -103,6 +103,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
@@ -146,18 +150,36 @@
<artifactId>spring-data-commons</artifactId>
<version>${spring-data-commons.version}</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring-data-mongodb.version}</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
@@ -170,6 +192,12 @@
<artifactId>spring-ldap-core</artifactId>
<version>${spring-ldap.version}</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
@@ -355,12 +383,6 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 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.
@@ -52,7 +52,7 @@ public abstract class AbstractDatabaseItemStreamItemReaderTests extends Abstract
* Sub-classes can override this and create their own context.
*/
protected void initializeContext() throws Exception {
ctx = new ClassPathXmlApplicationContext("org/springframework/batch/item/database/data-source-context.xml");
ctx = new ClassPathXmlApplicationContext("data-source-context.xml");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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,8 +23,9 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
* from database. Uses a common test context and HSQLDB database.
*
* @author Thomas Risberg
* @author Mahmoud Ben Hassine
*/
@SpringJUnitConfig(locations = "data-source-context.xml")
@SpringJUnitConfig(locations = "classpath:data-source-context.xml")
abstract class AbstractGenericDataSourceItemReaderIntegrationTests
extends AbstractDataSourceItemReaderIntegrationTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-2023 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,8 +35,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
* Tests for {@link HibernateCursorItemReader} using {@link StatelessSession}.
*
* @author Robert Kasanicky
* @author Mahmoud Ben Hassine
*/
@SpringJUnitConfig(locations = "data-source-context.xml")
@SpringJUnitConfig(locations = "classpath:data-source-context.xml")
class HibernateCursorProjectionItemReaderIntegrationTests {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-2023 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,7 +30,7 @@ public class JpaCursorItemReaderCommonTests extends AbstractDatabaseItemStreamIt
protected ItemReader<Foo> getItemReader() throws Exception {
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(getDataSource());
factoryBean.setPersistenceUnitName("bar");
factoryBean.setPersistenceUnitName("foo");
factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
factoryBean.afterPropertiesSet();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2021 the original author or authors.
* Copyright 2008-2023 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.
@@ -37,7 +37,7 @@ public class JpaPagingItemReaderIntegrationTests extends AbstractGenericDataSour
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(dataSource);
factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
factoryBean.setPersistenceUnitName("bar");
factoryBean.setPersistenceUnitName("foo");
factoryBean.afterPropertiesSet();
EntityManagerFactory entityManagerFactory = factoryBean.getObject();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
@@ -75,7 +75,7 @@ public class JpaPagingItemReaderNativeQueryIntegrationTests extends AbstractPagi
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("org/springframework/batch/item/database/init-foo-schema-hsqldb.sql")
.addScript("org/springframework/batch/item/database/init-foo-schema.sql")
.generateUniqueName(true)
.build();
}

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.item.database;
import org.hsqldb.types.Types;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
@@ -26,6 +27,7 @@ import org.springframework.jdbc.core.SqlParameter;
import static org.junit.jupiter.api.Assertions.assertThrows;
@Disabled("see FIXME in init-foo-schema.sql")
class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
@Override
@@ -41,8 +43,7 @@ class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemStreamIte
@Override
protected void initializeContext() {
ctx = new ClassPathXmlApplicationContext(
"org/springframework/batch/item/database/stored-procedure-context.xml");
ctx = new ClassPathXmlApplicationContext("data-source-context.xml");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
@@ -15,15 +15,18 @@
*/
package org.springframework.batch.item.database;
import org.junit.jupiter.api.Disabled;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.sample.Foo;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@SpringJUnitConfig(locations = "stored-procedure-context.xml")
@Disabled("see FIXME in init-foo-schema.sql")
@SpringJUnitConfig(locations = "classpath:data-source-context.xml")
public class StoredProcedureItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
@Override
protected ItemReader<Foo> createItemReader() throws Exception {
protected ItemReader<Foo> createItemReader() {
StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReader<>();
reader.setDataSource(dataSource);
reader.setProcedureName("read_foos");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-2023 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.
@@ -45,6 +45,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
class HibernateCursorItemReaderBuilderTests {
@@ -219,8 +220,7 @@ class HibernateCursorItemReaderBuilderTests {
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
dataSourceInitializer.setDataSource(dataSource);
Resource create = new ClassPathResource(
"org/springframework/batch/item/database/init-foo-schema-hsqldb.sql");
Resource create = new ClassPathResource("org/springframework/batch/item/database/init-foo-schema.sql");
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(create));
return dataSourceInitializer;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-2023 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.
@@ -206,8 +206,7 @@ class HibernatePagingItemReaderBuilderTests {
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
dataSourceInitializer.setDataSource(dataSource);
Resource create = new ClassPathResource(
"org/springframework/batch/item/database/init-foo-schema-hsqldb.sql");
Resource create = new ClassPathResource("org/springframework/batch/item/database/init-foo-schema.sql");
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(create));
return dataSourceInitializer;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 the original author or authors.
* Copyright 2020-2023 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.
@@ -223,8 +223,7 @@ class JpaCursorItemReaderBuilderTests {
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
dataSourceInitializer.setDataSource(dataSource);
Resource create = new ClassPathResource(
"org/springframework/batch/item/database/init-foo-schema-hsqldb.sql");
Resource create = new ClassPathResource("org/springframework/batch/item/database/init-foo-schema.sql");
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(create));
return dataSourceInitializer;
@@ -235,7 +234,7 @@ class JpaCursorItemReaderBuilderTests {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPersistenceUnitName("bar");
entityManagerFactoryBean.setPersistenceUnitName("foo");
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
return entityManagerFactoryBean;

View File

@@ -235,8 +235,7 @@ class JpaPagingItemReaderBuilderTests {
DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
dataSourceInitializer.setDataSource(dataSource);
Resource create = new ClassPathResource(
"org/springframework/batch/item/database/init-foo-schema-hsqldb.sql");
Resource create = new ClassPathResource("org/springframework/batch/item/database/init-foo-schema.sql");
dataSourceInitializer.setDatabasePopulator(new ResourceDatabasePopulator(create));
return dataSourceInitializer;
@@ -247,7 +246,7 @@ class JpaPagingItemReaderBuilderTests {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPersistenceUnitName("bar");
entityManagerFactoryBean.setPersistenceUnitName("foo");
entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
return entityManagerFactoryBean;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2022 the original author or authors.
* Copyright 2017-2023 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.
@@ -17,27 +17,15 @@ package org.springframework.batch.item.database.builder;
import javax.sql.DataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import test.jdbc.datasource.DataSourceInitializer;
import test.jdbc.datasource.DerbyDataSourceFactoryBean;
import test.jdbc.datasource.DerbyShutdownBean;
import org.mockito.Mockito;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.database.FooRowMapper;
import org.springframework.batch.item.database.StoredProcedureItemReader;
import org.springframework.batch.item.sample.Foo;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -50,39 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
class StoredProcedureItemReaderBuilderTests {
private DataSource dataSource;
private ConfigurableApplicationContext context;
@BeforeEach
void setUp() {
this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class);
this.dataSource = (DataSource) this.context.getBean("dataSource");
}
@AfterEach
void tearDown() {
this.context.close();
}
@Test
void testSunnyScenario() throws Exception {
StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReaderBuilder<Foo>().name("foo_reader")
.dataSource(this.dataSource)
.procedureName("read_foos")
.rowMapper(new FooRowMapper())
.verifyCursorPosition(false)
.build();
reader.open(new ExecutionContext());
Foo item1 = reader.read();
assertEquals(1, item1.getId());
assertEquals("bar1", item1.getName());
assertEquals(1, item1.getValue());
reader.close();
}
private final DataSource dataSource = Mockito.mock(DataSource.class);
@Test
void testConfiguration() {
@@ -123,28 +79,6 @@ class StoredProcedureItemReaderBuilderTests {
assertFalse((Boolean) ReflectionTestUtils.getField(reader, "ignoreWarnings"));
}
@Test
void testNoSaveState() throws Exception {
StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReaderBuilder<Foo>().dataSource(this.dataSource)
.procedureName("read_foos")
.rowMapper(new FooRowMapper())
.verifyCursorPosition(false)
.saveState(false)
.build();
ExecutionContext executionContext = new ExecutionContext();
reader.open(executionContext);
reader.read();
reader.read();
reader.update(executionContext);
assertEquals(0, executionContext.size());
reader.close();
}
@Test
void testValidation() {
var builder = new StoredProcedureItemReaderBuilder<Foo>();
@@ -166,49 +100,4 @@ class StoredProcedureItemReaderBuilderTests {
assertEquals("A rowmapper is required", exception.getMessage());
}
@Configuration
public static class TestDataSourceConfiguration {
@Bean
public DerbyDataSourceFactoryBean dataSource() {
DerbyDataSourceFactoryBean derbyDataSourceFactoryBean = new DerbyDataSourceFactoryBean();
derbyDataSourceFactoryBean.setDataDirectory("target/derby-home");
return derbyDataSourceFactoryBean;
}
@Bean
public DerbyShutdownBean dbShutdown(DataSource dataSource) {
DerbyShutdownBean shutdownBean = new DerbyShutdownBean();
shutdownBean.setDataSource(dataSource);
return shutdownBean;
}
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
JdbcTransactionManager transactionManager = new JdbcTransactionManager();
transactionManager.setDataSource(dataSource);
return transactionManager;
}
@Bean
public DataSourceInitializer initializer(DataSource dataSource) {
DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
initializer.setInitScripts(new ClassPathResource[] {
new ClassPathResource("org/springframework/batch/item/database/init-foo-schema-derby.sql") });
initializer.setDestroyScripts(new ClassPathResource[] {
new ClassPathResource("org/springframework/batch/item/database/drop-foo-schema-derby.sql") });
return initializer;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 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,8 +39,9 @@ import org.springframework.transaction.annotation.Transactional;
/**
* @author Anatoly Polinsky
* @author Dave Syer
* @author Mahmoud Ben Hassine
*/
@SpringJUnitConfig(locations = "../data-source-context.xml")
@SpringJUnitConfig(locations = "classpath:data-source-context.xml")
class HibernateNativeQueryProviderIntegrationTests {
@Autowired

View File

@@ -18,21 +18,11 @@ package org.springframework.batch.repeat.exception;
import java.io.StringWriter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.WriterAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.classify.ClassifierSupport;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.exception.LogOrRethrowExceptionHandler.Level;
import org.springframework.classify.ClassifierSupport;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -46,19 +36,6 @@ class LogOrRethrowExceptionHandlerTests {
private final RepeatContext context = null;
@BeforeEach
void setUp() {
Logger logger = LoggerFactory.getLogger(LogOrRethrowExceptionHandler.class);
LoggerContext loggerContext = (LoggerContext) LogManager.getContext();
Configuration configuration = loggerContext.getConfiguration();
LoggerConfig rootLoggerConfig = configuration.getLoggerConfig(logger.getName());
rootLoggerConfig.getAppenders().forEach((name, appender) -> rootLoggerConfig.removeAppender(name));
Appender appender = WriterAppender.createAppender(PatternLayout.createDefaultLayout(), null, writer,
"TESTWriter", false, false);
rootLoggerConfig.addAppender(appender, org.apache.logging.log4j.Level.DEBUG, null);
}
@Test
void testRuntimeException() {
Exception exception = assertThrows(RuntimeException.class,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 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.
@@ -16,30 +16,36 @@
package org.springframework.batch.support;
import javax.sql.DataSource;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
class DatabaseTypeIntegrationTests {
@Test
void testH2() throws Exception {
DataSource dataSource = DatabaseTypeTestUtils.getDataSource(org.h2.Driver.class,
"jdbc:h2:file:./target/data/sample");
DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
.generateUniqueName(true)
.build();
assertEquals(DatabaseType.H2, DatabaseType.fromMetaData(dataSource));
dataSource.getConnection();
}
@Test
void testDerby() throws Exception {
DataSource dataSource = DatabaseTypeTestUtils.getDataSource(org.apache.derby.jdbc.EmbeddedDriver.class,
"jdbc:derby:./target/derby-home/test;create=true", "sa", "");
DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
.generateUniqueName(true)
.build();
assertEquals(DatabaseType.DERBY, DatabaseType.fromMetaData(dataSource));
dataSource.getConnection();
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright 2010-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
*
* https://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 test.jdbc.datasource;
import java.io.File;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.springframework.beans.factory.config.AbstractFactoryBean;
public class DerbyDataSourceFactoryBean extends AbstractFactoryBean<DataSource> {
private static Log logger = LogFactory.getLog(DerbyDataSourceFactoryBean.class);
private String dataDirectory = "target/derby-home";
public void setDataDirectory(String dataDirectory) {
this.dataDirectory = dataDirectory;
}
@Override
protected DataSource createInstance() throws Exception {
File directory = new File(dataDirectory);
System.setProperty("derby.system.home", directory.getCanonicalPath());
System.setProperty("derby.storage.fileSyncTransactionLog", "true");
System.setProperty("derby.storage.pageCacheSize", "100");
final EmbeddedDataSource ds = new EmbeddedDataSource();
ds.setDatabaseName("target/derbydb");
ds.setCreateDatabase("create");
logger.info("Created instance of " + ds.toString());
return ds;
}
@Override
public Class<DataSource> getObjectType() {
return DataSource.class;
}
}

View File

@@ -1,60 +0,0 @@
/*
* Copyright 2010-2023 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
*
* https://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 test.jdbc.datasource;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.springframework.beans.factory.DisposableBean;
public class DerbyShutdownBean implements DisposableBean {
private static Log logger = LogFactory.getLog(DerbyShutdownBean.class);
private DataSource dataSource;
private boolean isShutdown = false;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void destroy() throws Exception {
logger.info("Attempting Derby database shut down on: " + dataSource);
if (!isShutdown && dataSource != null && dataSource instanceof EmbeddedDataSource ds) {
try {
ds.setShutdownDatabase("shutdown");
ds.getConnection();
}
catch (SQLException except) {
if (except.getSQLState().equals("08006")) {
// SQLState derby throws when shutting down the database
logger.info("Derby database is now shut down.");
isShutdown = true;
}
else {
logger.error("Problem shutting down Derby " + except.getMessage());
}
}
}
}
}

View File

@@ -1,50 +0,0 @@
/*
* Copyright 2010 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
*
* https://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 test.jdbc.proc.derby;
import java.sql.*;
/**
* @author trisberg
*
* CALL SQLJ.install_jar('testproc.jar', 'APP.TESTPROC', 0); CALL
* SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.classpath', 'APP.TESTPROC');
*
* CALL SQLJ.replace_jar('testproc.jar', 'APP.TESTPROC');
*
* CALL SQLJ.remove_jar('APP.TESTPROC', 0)
*
*/
public class TestProcedures {
public static void readFoos(ResultSet[] rs) throws SQLException {
String SQL = "SELECT id, name, value FROM T_FOOS";
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps1 = conn.prepareStatement(SQL);
rs[0] = ps1.executeQuery();
}
public static void readSomeFoos(int fromId, int toId, ResultSet[] rs) throws SQLException {
String SQL = "SELECT id, name, value FROM T_FOOS WHERE id between ? and ?";
Connection conn = DriverManager.getConnection("jdbc:default:connection");
PreparedStatement ps2 = conn.prepareStatement(SQL);
ps2.setInt(1, fromId);
ps2.setInt(2, toId);
rs[0] = ps2.executeQuery();
}
}

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence https://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="bar" transaction-type="RESOURCE_LOCAL">
<persistence-unit name="foo" transaction-type="RESOURCE_LOCAL">
<class>org.springframework.batch.item.sample.Foo</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>

View File

@@ -1,15 +0,0 @@
# Placeholders batch.*
# for Derby:
batch.jdbc.driver=org.apache.derby.jdbc.EmbeddedDriver
batch.jdbc.url=jdbc:derby:target/derby-home/test;create=true
batch.jdbc.user=app
batch.jdbc.password=
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-derby.sql
batch.schema.script=classpath:org/springframework/batch/item/database/init-foo-schema-derby.sql
batch.business.schema.script=classpath:/org/springframework/batch/jms/init.sql
batch.data.source.init=true
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer
batch.database.incrementer.parent=columnIncrementerParent
batch.verify.cursor.position=false

View File

@@ -1,14 +0,0 @@
# Placeholders batch.*
# for SAP HANA:
batch.jdbc.driver=com.sap.db.jdbc.Driver
batch.jdbc.url=jdbc:sap://localhost:39015/
batch.jdbc.user=SPRING_TEST
batch.jdbc.password=Spr1ng_test
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.schema.script=classpath:org/springframework/batch/item/database/init-foo-schema-hana.sql
batch.business.schema.script=classpath:/org/springframework/batch/jms/init.sql
batch.data.source.init=true
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HanaSequenceMaxValueIncrementer
batch.database.incrementer.parent=sequenceIncrementerParent
batch.verify.cursor.position=true

View File

@@ -1,17 +0,0 @@
# Placeholders batch.*
# for HSQLDB:
batch.jdbc.driver=org.hsqldb.jdbcDriver
batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true;hsqldb.tx=mvcc
# use this one for a separate server process so you can inspect the results
# (or add it to system properties with -D to override at run time).
# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples
batch.jdbc.user=sa
batch.jdbc.password=
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.schema.script=classpath:org/springframework/batch/item/database/init-foo-schema-hsqldb.sql
batch.business.schema.script=classpath:/org/springframework/batch/jms/init.sql
batch.data.source.init=true
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer
batch.database.incrementer.parent=columnIncrementerParent
batch.verify.cursor.position=true

View File

@@ -1,14 +0,0 @@
# Placeholders batch.*
# for Oracle:
batch.jdbc.driver=oracle.jdbc.OracleDriver
batch.jdbc.url=jdbc:oracle:thin:@oracle:1521:xe
batch.jdbc.user=spring
batch.jdbc.password=spring
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.schema.script=classpath:org/springframework/batch/item/database/init-foo-schema-oracle.sql
batch.business.schema.script=classpath:/org/springframework/batch/jms/init.sql
batch.data.source.init=true
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer
batch.database.incrementer.parent=sequenceIncrementerParent
batch.verify.cursor.position=true

View File

@@ -1,14 +0,0 @@
# Placeholders batch.*
# for Oracle:
batch.jdbc.driver=org.postgresql.Driver
batch.jdbc.url=jdbc:postgresql://localhost:9432/test
batch.jdbc.user=test
batch.jdbc.password=test
batch.jdbc.testWhileIdle=false
batch.jdbc.validationQuery=
batch.schema.script=classpath:org/springframework/batch/item/database/init-foo-schema-postgres.sql
batch.business.schema.script=classpath:/org/springframework/batch/jms/init.sql
batch.data.source.init=true
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer
batch.database.incrementer.parent=sequenceIncrementerParent
batch.verify.cursor.position=true

View File

@@ -1,65 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<!-- Initialise the database before every test case: -->
<bean id="dataSourceInitializer" class="test.jdbc.datasource.DataSourceInitializer">
<property name="dataSource" ref="dataSource"/>
<property name="initScripts">
<list>
<value>${batch.business.schema.script}</value>
</list>
</property>
</bean>
<jdbc:embedded-database id="dataSource" generate-name="true">
<jdbc:script location="org/springframework/batch/item/database/init-foo-schema.sql"/>
</jdbc:embedded-database>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${batch.jdbc.driver}" />
<property name="url" value="${batch.jdbc.url}" />
<property name="username" value="${batch.jdbc.user}" />
<property name="password" value="${batch.jdbc.password}" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager" lazy-init="true">
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- Set up or detect a System property called "ENVIRONMENT" used to construct a properties file on the classpath. The default is "hsql". -->
<bean id="environment"
class="org.springframework.batch.support.SystemPropertyInitializer">
<property name="defaultValue" value="hsql"/>
<property name="keyName" value="ENVIRONMENT"/>
</bean>
<!-- Use this to set additional properties on beans at run time -->
<bean id="overrideProperties" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer"
depends-on="environment">
<property name="location" value="classpath:batch-${ENVIRONMENT}.properties" />
<!-- Allow system properties (-D) to override those from file -->
<property name="localOverride" value="true" />
<property name="properties">
<bean class="java.lang.System" factory-method="getProperties" />
</property>
<property name="ignoreInvalidKeys" value="true" />
<property name="order" value="2" />
</bean>
<bean id="placeholderProperties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
depends-on="environment">
<property name="location" value="classpath:batch-${ENVIRONMENT}.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
</bean>
<bean id="sequenceIncrementerParent" class="${batch.database.incrementer.class}" abstract="true">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="columnIncrementerParent" class="${batch.database.incrementer.class}" abstract="true" parent="sequenceIncrementerParent">
<property name="columnName" value="ID" />
</bean>
<bean id="incrementerParent" parent="${batch.database.incrementer.parent}">
<property name="incrementerName" value="DUMMY"/>
</bean>
</beans>

View File

@@ -1,10 +0,0 @@
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.logging.log4j.core.appender.ConsoleAppender
log4j.appender.stdout.layout=org.apache.logging.log4j.core.layout.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p %t [%c] - <%m>%n
#log4j.category.org.springframework.batch=DEBUG
log4j.category.org.springframework.transaction=INFO
log4j.category.org.springframework.batch.support.transaction.ResourcelessTransactionManager=INFO
log4j.category.org.springframework.jdbc.datasource=INFO

View File

@@ -1,21 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<jdbc:embedded-database id="dataSource" generate-name="true">
<jdbc:script location="org/springframework/batch/item/database/init-foo-schema-hsqldb.sql"/>
</jdbc:embedded-database>
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="incrementerParent" class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer"
abstract="true">
<property name="dataSource" ref="dataSource" />
<property name="columnName" value="ID" />
</bean>
<import resource="classpath:/data-source-context.xml" />
</beans>

View File

@@ -1,17 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:testdb" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<import resource="classpath:/data-source-context.xml" />
<bean id="jdbcPagingItemReader" class="org.springframework.batch.item.database.JdbcPagingItemReader">
<property name="dataSource" ref="dataSource"/>
@@ -19,7 +10,7 @@
<property name="fetchSize" value="100"/>
<property name="queryProvider">
<bean class="org.springframework.batch.item.database.support.HsqlPagingQueryProvider">
<property name="selectClause" value="select id, bar"/>
<property name="selectClause" value="select id"/>
<property name="fromClause" value="foo"/>
<property name="sortKeys">
<map>

View File

@@ -1,26 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="test.jdbc.datasource.DataSourceInitializer">
<property name="dataSource" ref="dataSource"/>
<property name="initScripts" value="org/springframework/batch/item/database/init-foo-schema-hsqldb.sql" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:testdb" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="xincrementerParent" class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer"
abstract="true">
<property name="dataSource" ref="dataSource" />
<property name="columnName" value="ID" />
</bean>
<import resource="classpath:/data-source-context.xml" />
</beans>

View File

@@ -1,20 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<jdbc:embedded-database id="dataSource" generate-name="true">
<jdbc:script location="org/springframework/batch/item/database/init-foo-schema-hsqldb.sql"/>
</jdbc:embedded-database>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<import resource="classpath:/data-source-context.xml" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="bar"/>
<property name="persistenceUnitName" value="foo"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false"/>
@@ -22,11 +14,4 @@
</property>
</bean>
<bean id="incrementerParent" class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer"
abstract="true">
<property name="dataSource" ref="dataSource" />
<property name="columnName" value="ID" />
</bean>
</beans>

View File

@@ -2,29 +2,21 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:testjpamydb" />
</bean>
<!-- Initialise the database -->
<bean id="dataSourceInitializer" class="test.jdbc.datasource.DataSourceInitializer">
<property name="dataSource" ref="dataSource"/>
<property name="initScripts">
<list>
<value>classpath:org/springframework/batch/item/database/init-books-schema.sql</value>
</list>
</property>
</bean>
<jdbc:embedded-database id="dataSource" generate-name="true">
<jdbc:script location="org/springframework/batch/item/database/init-books-schema.sql"/>
</jdbc:embedded-database>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<tx:annotation-driven/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>

View File

@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc https://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd">
<jdbc:embedded-database id="dataSource" generate-name="true">
<jdbc:script location="org/springframework/batch/item/database/init-foo-schema-hsqldb.sql"/>
</jdbc:embedded-database>
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="incrementerParent" class="org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer"
abstract="true">
<property name="dataSource" ref="dataSource" />
<property name="columnName" value="ID" />
</bean>
</beans>

View File

@@ -1,3 +0,0 @@
DROP PROCEDURE read_foos;
DROP PROCEDURE read_some_foos;
DROP TABLE T_FOOS;

View File

@@ -1,27 +0,0 @@
CREATE TABLE T_FOOS (
ID BIGINT NOT NULL,
NAME VARCHAR(45),
VALUE INTEGER
);
ALTER TABLE T_FOOS ADD PRIMARY KEY (ID);
INSERT INTO t_foos (id, name, value) VALUES (1, 'bar1', 1);
INSERT INTO t_foos (id, name, value) VALUES (2, 'bar2', 2);
INSERT INTO t_foos (id, name, value) VALUES (3, 'bar3', 3);
INSERT INTO t_foos (id, name, value) VALUES (4, 'bar4', 4);
INSERT INTO t_foos (id, name, value) VALUES (5, 'bar5', 5);
CREATE PROCEDURE read_foos ()
PARAMETER STYLE JAVA
LANGUAGE JAVA
READS SQL DATA
DYNAMIC RESULT SETS 1
EXTERNAL NAME 'test.jdbc.proc.derby.TestProcedures.readFoos';
CREATE PROCEDURE read_some_foos (from_id INTEGER, to_id INTEGER)
PARAMETER STYLE JAVA
LANGUAGE JAVA
READS SQL DATA
DYNAMIC RESULT SETS 1
EXTERNAL NAME 'test.jdbc.proc.derby.TestProcedures.readSomeFoos';

View File

@@ -1,25 +0,0 @@
DROP TABLE T_FOOS;
DROP TABLE T_WRITE_FOOS;
CREATE TABLE T_FOOS (
ID BIGINT NOT NULL,
NAME VARCHAR(45),
CODE VARCHAR(10),
VALUE BIGINT
);
ALTER TABLE T_FOOS ADD PRIMARY KEY (ID);
INSERT INTO t_foos (id, name, value) VALUES (1, 'bar2', 2);
INSERT INTO t_foos (id, name, value) VALUES (2, 'bar4', 4);
INSERT INTO t_foos (id, name, value) VALUES (3, 'bar1', 1);
INSERT INTO t_foos (id, name, value) VALUES (4, 'bar5', 5);
INSERT INTO t_foos (id, name, value) VALUES (5, 'bar3', 3);
CREATE TABLE T_WRITE_FOOS (
ID BIGINT NOT NULL,
NAME VARCHAR(45),
VALUE BIGINT
);
ALTER TABLE T_WRITE_FOOS ADD PRIMARY KEY (ID);

View File

@@ -1,25 +0,0 @@
DROP TABLE T_FOOS if exists;
DROP TABLE T_WRITE_FOOS if exists;
CREATE TABLE T_FOOS (
ID BIGINT NOT NULL,
NAME VARCHAR(45),
CODE VARCHAR(10),
VALUE INTEGER
);
ALTER TABLE T_FOOS ADD PRIMARY KEY (ID);
INSERT INTO t_foos (id, name, value) VALUES (1, 'bar1', 1);
INSERT INTO t_foos (id, name, value) VALUES (2, 'bar2', 2);
INSERT INTO t_foos (id, name, value) VALUES (3, 'bar3', 3);
INSERT INTO t_foos (id, name, value) VALUES (4, 'bar4', 4);
INSERT INTO t_foos (id, name, value) VALUES (5, 'bar5', 5);
CREATE TABLE T_WRITE_FOOS (
ID BIGINT NOT NULL,
NAME VARCHAR(45),
VALUE INTEGER
);
ALTER TABLE T_WRITE_FOOS ADD PRIMARY KEY (ID);

View File

@@ -1,25 +0,0 @@
DROP TABLE T_FOOS;
DROP TABLE T_WRITE_FOOS;
CREATE TABLE T_FOOS (
ID NUMBER(19) NOT NULL,
NAME VARCHAR(45),
CODE VARCHAR(10),
VALUE NUMBER(19)
);
ALTER TABLE T_FOOS ADD PRIMARY KEY (ID);
INSERT INTO t_foos (id, name, value) VALUES (1, 'bar2', 2);
INSERT INTO t_foos (id, name, value) VALUES (2, 'bar4', 4);
INSERT INTO t_foos (id, name, value) VALUES (3, 'bar1', 1);
INSERT INTO t_foos (id, name, value) VALUES (4, 'bar5', 5);
INSERT INTO t_foos (id, name, value) VALUES (5, 'bar3', 3);
CREATE TABLE T_WRITE_FOOS (
ID NUMBER(19) NOT NULL,
NAME VARCHAR(45),
VALUE NUMBER(19)
);
ALTER TABLE T_WRITE_FOOS ADD PRIMARY KEY (ID);

View File

@@ -1,25 +0,0 @@
DROP TABLE T_FOOS;
DROP TABLE T_WRITE_FOOS;
CREATE TABLE T_FOOS (
ID BIGINT NOT NULL,
NAME VARCHAR(45),
CODE VARCHAR(10),
VALUE BIGINT
);
ALTER TABLE T_FOOS ADD PRIMARY KEY (ID);
INSERT INTO t_foos (id, name, value) VALUES (1, 'bar2', 2);
INSERT INTO t_foos (id, name, value) VALUES (2, 'bar4', 4);
INSERT INTO t_foos (id, name, value) VALUES (3, 'bar1', 1);
INSERT INTO t_foos (id, name, value) VALUES (4, 'bar5', 5);
INSERT INTO t_foos (id, name, value) VALUES (5, 'bar3', 3);
CREATE TABLE T_WRITE_FOOS (
ID BIGINT NOT NULL,
NAME VARCHAR(45),
VALUE BIGINT
);
ALTER TABLE T_WRITE_FOOS ADD PRIMARY KEY (ID);

View File

@@ -0,0 +1,49 @@
DROP TABLE T_FOOS if exists;
DROP TABLE T_BARS if exists;
DROP TABLE T_WRITE_FOOS if exists;
CREATE TABLE T_FOOS (
ID INT NOT NULL,
NAME VARCHAR(45),
CODE VARCHAR(10),
VALUE INTEGER
);
create table T_BARS (
id int not null primary key,
name varchar(80),
foo_date timestamp
);
CREATE TABLE T_WRITE_FOOS (
ID INT NOT NULL,
NAME VARCHAR(45),
VALUE INTEGER
);
ALTER TABLE T_FOOS ADD PRIMARY KEY (ID);
INSERT INTO t_foos (id, name, value) VALUES (1, 'bar1', 1);
INSERT INTO t_foos (id, name, value) VALUES (2, 'bar2', 2);
INSERT INTO t_foos (id, name, value) VALUES (3, 'bar3', 3);
INSERT INTO t_foos (id, name, value) VALUES (4, 'bar4', 4);
INSERT INTO t_foos (id, name, value) VALUES (5, 'bar5', 5);
ALTER TABLE T_WRITE_FOOS ADD PRIMARY KEY (ID);
-- FIXME: syntax error with the following even though it is taken from the official docs of HSQLDB 2.7.1
-- http://hsqldb.org/doc/guide/sqlroutines-chapt.html#src_returning_data
-- CREATE PROCEDURE read_foos()
-- READS SQL DATA DYNAMIC RESULT SETS 1
-- BEGIN ATOMIC
-- DECLARE result CURSOR WITH RETURN FOR SELECT * FROM T_FOOS FOR READ ONLY;
-- OPEN result;
-- END;
--
-- CREATE PROCEDURE read_some_foos(IN from_id INTEGER, IN to_id INTEGER)
-- READS SQL DATA DYNAMIC RESULT SETS 1
-- BEGIN ATOMIC
-- DECLARE result CURSOR WITH RETURN FOR SELECT * FROM T_FOOS WHERE ID >= from_id and ID <= to_id FOR READ ONLY;
-- OPEN result;
-- END;

View File

@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dbShutdown" class="test.jdbc.datasource.DerbyShutdownBean">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean class="test.jdbc.datasource.DataSourceInitializer" depends-on="dbShutdown">
<property name="dataSource" ref="dataSource"/>
<property name="initScripts" value="org/springframework/batch/item/database/init-foo-schema-derby.sql" />
<property name="destroyScripts" value="org/springframework/batch/item/database/drop-foo-schema-derby.sql"/>
</bean>
<bean id="dataSource" class="test.jdbc.datasource.DerbyDataSourceFactoryBean">
<property name="dataDirectory" value="target/derby-home"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.support.JdbcTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>

View File

@@ -1,23 +0,0 @@
<mapping>
<class name="org.springframework.batch.item.xml.domain.Trade">
<map-to xml="trade" />
<field name="isin">
<bind-xml name="isin" node="element" />
</field>
<field name="quantity">
<bind-xml name="quantity" node="element" />
</field>
<field name="price">
<bind-xml name="price" node="element" />
</field>
<field name="customer">
<bind-xml name="customer" node="element" />
</field>
</class>
</mapping>

View File

@@ -1,7 +0,0 @@
DROP TABLE T_BARS;
create table T_BARS (
id integer not null primary key,
name varchar(80),
foo_date timestamp
);

View File

@@ -89,7 +89,7 @@
<bean id="brokerService" class="org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ"
init-method="start" destroy-method="stop">
<property name="configResourcePath" value="broker.xml"/>
<property name="configResourcePath" value="message-broker-configuration.xml"/>
</bean>
</beans>