RESOLVED - issue BATCH-1530: Let job-repository assign id to itself by default.

This commit is contained in:
dsyer
2010-03-24 07:57:45 +00:00
parent 2468a51eab
commit 0cab069165
3 changed files with 107 additions and 29 deletions

View File

@@ -15,8 +15,10 @@
*/
package org.springframework.batch.core.configuration.xml;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
@@ -38,46 +40,60 @@ public class JobRepositoryParser extends AbstractSingleBeanDefinitionParser {
return "org.springframework.batch.core.repository.support.JobRepositoryFactoryBean";
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String id = element.getAttribute(ID_ATTRIBUTE);
if (!StringUtils.hasText(id)) {
id = "jobRepository";
}
return id;
}
/**
* Parse and create a bean definition for a
* {@link org.springframework.batch.core.repository.support.JobRepositoryFactoryBean}
* .
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
CoreNamespaceUtils.autoregisterBeansForNamespace(parserContext, element);
String dataSource = element.getAttribute("data-source");
String dataSource = element.getAttribute("data-source");
String transactionManager = element.getAttribute("transaction-manager");
String transactionManager = element.getAttribute("transaction-manager");
String isolationLevelForCreate = element.getAttribute("isolation-level-for-create");
String tablePrefix = element.getAttribute("table-prefix");
String maxVarCharLength = element.getAttribute("max-varchar-length");
String lobHandler = element.getAttribute("lob-handler");
RuntimeBeanReference ds = new RuntimeBeanReference(dataSource);
builder.addPropertyValue("dataSource", ds);
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
builder.addPropertyValue("transactionManager", tx);
if (StringUtils.hasText(isolationLevelForCreate)) {
builder.addPropertyValue("isolationLevelForCreate", DefaultTransactionDefinition.PREFIX_ISOLATION+isolationLevelForCreate);
}
if (StringUtils.hasText(tablePrefix)) {
builder.addPropertyValue("tablePrefix", tablePrefix);
}
if (StringUtils.hasText(lobHandler)) {
builder.addPropertyReference("lobHandler", lobHandler);
}
if (StringUtils.hasText(maxVarCharLength)) {
builder.addPropertyValue("maxVarCharLength", maxVarCharLength);
}
String isolationLevelForCreate = element.getAttribute("isolation-level-for-create");
builder.setRole(BeanDefinition.ROLE_SUPPORT);
String tablePrefix = element.getAttribute("table-prefix");
}
String maxVarCharLength = element.getAttribute("max-varchar-length");
String lobHandler = element.getAttribute("lob-handler");
RuntimeBeanReference ds = new RuntimeBeanReference(dataSource);
builder.addPropertyValue("dataSource", ds);
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
builder.addPropertyValue("transactionManager", tx);
if (StringUtils.hasText(isolationLevelForCreate)) {
builder.addPropertyValue("isolationLevelForCreate", DefaultTransactionDefinition.PREFIX_ISOLATION
+ isolationLevelForCreate);
}
if (StringUtils.hasText(tablePrefix)) {
builder.addPropertyValue("tablePrefix", tablePrefix);
}
if (StringUtils.hasText(lobHandler)) {
builder.addPropertyReference("lobHandler", lobHandler);
}
if (StringUtils.hasText(maxVarCharLength)) {
builder.addPropertyValue("maxVarCharLength", maxVarCharLength);
}
builder.setRole(BeanDefinition.ROLE_SUPPORT);
}
}

View File

@@ -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 JobRepositoryDefaultParserTests {
@Autowired
@Qualifier("jobRepository")
private JobRepository jobRepository;
@Test
public void testOneStep() throws Exception {
assertNotNull(jobRepository);
}
}

View File

@@ -0,0 +1,16 @@
<?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/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">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<job-repository xmlns="http://www.springframework.org/schema/batch" />
</beans>