OPEN - issue BATCH-1428: Add support for lobhandler in job repository name space / factory bean
http://jira.springframework.org/browse/BATCH-1428
This commit is contained in:
@@ -51,6 +51,8 @@ public class JobRepositoryParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
String tablePrefix = element.getAttribute("table-prefix");
|
||||
|
||||
String lobHandler = element.getAttribute("lob-handler");
|
||||
|
||||
RuntimeBeanReference ds = new RuntimeBeanReference(dataSource);
|
||||
builder.addPropertyValue("dataSource", ds);
|
||||
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
|
||||
@@ -61,6 +63,9 @@ public class JobRepositoryParser extends AbstractSingleBeanDefinitionParser {
|
||||
if (StringUtils.hasText(tablePrefix)) {
|
||||
builder.addPropertyValue("tablePrefix", tablePrefix);
|
||||
}
|
||||
if (StringUtils.hasText(lobHandler)) {
|
||||
builder.addPropertyReference("lobHandler", lobHandler);
|
||||
}
|
||||
|
||||
builder.setRole(BeanDefinition.ROLE_SUPPORT);
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcOperations;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.jdbc.support.lob.OracleLobHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -68,6 +70,21 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i
|
||||
|
||||
private int exitMessageLength = AbstractJdbcBatchMetadataDao.DEFAULT_EXIT_MESSAGE_LENGTH;
|
||||
|
||||
private LobHandler lobHandler;
|
||||
|
||||
/**
|
||||
* A special handler for large objects. The default is usually fine, except
|
||||
* for some (usually older) versions of Oracle. The default is determined
|
||||
* from the data base type.
|
||||
*
|
||||
* @param lobHandler the {@link LobHandler} to set
|
||||
*
|
||||
* @see LobHandler
|
||||
*/
|
||||
public void setLobHandler(LobHandler lobHandler) {
|
||||
this.lobHandler = lobHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the exit message length in database. Do not set this if
|
||||
* you haven't modified the schema. Note this value will be used for both
|
||||
@@ -122,6 +139,10 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i
|
||||
databaseType = DatabaseType.fromMetaData(dataSource).name();
|
||||
logger.info("No database type set, using meta data indicating: " + databaseType);
|
||||
}
|
||||
|
||||
if (lobHandler==null && databaseType.equalsIgnoreCase(DatabaseType.ORACLE.toString())) {
|
||||
lobHandler = new OracleLobHandler();
|
||||
}
|
||||
|
||||
Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType
|
||||
+ "' is an unsupported database type. The supported database types are "
|
||||
@@ -173,6 +194,9 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i
|
||||
dao.setJdbcTemplate(jdbcTemplate);
|
||||
dao.setTablePrefix(tablePrefix);
|
||||
dao.setClobTypeToUse(determineClobTypeToUse(this.databaseType));
|
||||
if (lobHandler != null) {
|
||||
dao.setLobHandler(lobHandler);
|
||||
}
|
||||
dao.afterPropertiesSet();
|
||||
return dao;
|
||||
}
|
||||
|
||||
@@ -190,6 +190,20 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="lob-handler" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
A reference to the lob handler (optional). Only override if using Oracle and
|
||||
the database type is not being detected for some reason.
|
||||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type
|
||||
type="org.springframework.jdbc.support.lob.LobHandler" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class JobRepositoryParserReferenceTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("jobRepo1")
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Test
|
||||
public void testOneStep() throws Exception {
|
||||
assertNotNull(jobRepository);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,22 +15,33 @@
|
||||
*/
|
||||
package org.springframework.batch.core.repository.support;
|
||||
|
||||
import static junit.framework.Assert.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.createNiceMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.lob.DefaultLobHandler;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.jdbc.support.lob.OracleLobHandler;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
@@ -85,6 +96,46 @@ public class JobRepositoryFactoryBeanTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOracleLobHandler() throws Exception {
|
||||
|
||||
factory.setDatabaseType("ORACLE");
|
||||
|
||||
incrementerFactory = createNiceMock(DataFieldMaxValueIncrementerFactory.class);
|
||||
expect(incrementerFactory.isSupportedIncrementerType("ORACLE")).andReturn(true);
|
||||
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer());
|
||||
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).andReturn(new StubIncrementer());
|
||||
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(new StubIncrementer());
|
||||
replay(dataSource,incrementerFactory);
|
||||
factory.setIncrementerFactory(incrementerFactory);
|
||||
|
||||
factory.afterPropertiesSet();
|
||||
LobHandler lobHandler = (LobHandler) ReflectionTestUtils.getField(factory, "lobHandler");
|
||||
assertTrue(lobHandler instanceof OracleLobHandler);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomLobHandler() throws Exception {
|
||||
|
||||
factory.setDatabaseType("ORACLE");
|
||||
|
||||
incrementerFactory = createNiceMock(DataFieldMaxValueIncrementerFactory.class);
|
||||
expect(incrementerFactory.isSupportedIncrementerType("ORACLE")).andReturn(true);
|
||||
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer());
|
||||
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "JOB_EXECUTION_SEQ")).andReturn(new StubIncrementer());
|
||||
expect(incrementerFactory.getIncrementer("ORACLE", tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(new StubIncrementer());
|
||||
replay(dataSource,incrementerFactory);
|
||||
factory.setIncrementerFactory(incrementerFactory);
|
||||
|
||||
LobHandler lobHandler = new DefaultLobHandler();
|
||||
factory.setLobHandler(lobHandler);
|
||||
|
||||
factory.afterPropertiesSet();
|
||||
assertEquals(lobHandler, ReflectionTestUtils.getField(factory, "lobHandler"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingDataSource() throws Exception {
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true">
|
||||
<beans:property name="driverClassName" value="org.hsqldb.jdbcDriver" />
|
||||
<beans:property name="url" value="jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true" />
|
||||
</beans:bean>
|
||||
<beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<beans:property name="dataSource" ref="dataSource"/>
|
||||
</beans:bean>
|
||||
|
||||
<job-repository id="jobRepo1"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true">
|
||||
@@ -11,7 +11,8 @@
|
||||
<beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<beans:property name="dataSource" ref="dataSource"/>
|
||||
</beans:bean>
|
||||
<beans:bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/>
|
||||
|
||||
<job-repository id="jobRepo1"/>
|
||||
<job-repository id="jobRepo1" data-source="dataSource" transaction-manager="transactionManager" lob-handler="lobHandler"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user