Initial commit for the JDBC project
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.integration.samples.jdbc;
|
||||
|
||||
/**
|
||||
* Represents the gender of the person
|
||||
* @author Amol Nayak
|
||||
*
|
||||
*/
|
||||
public enum Gender {
|
||||
|
||||
MALE("M"),FEMALE("F");
|
||||
|
||||
private String identifier;
|
||||
|
||||
private Gender(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.integration.samples.jdbc;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* A simple POJO representing a Person
|
||||
* @author Amol Nayak
|
||||
*
|
||||
*/
|
||||
public class Person {
|
||||
|
||||
private String name;
|
||||
private Gender gender;
|
||||
private Date dateOfBirth;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of the person
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gender of the person
|
||||
* @return
|
||||
*/
|
||||
public Gender getGender() {
|
||||
return gender;
|
||||
}
|
||||
public void setGender(Gender gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date of birth of the person
|
||||
* @return
|
||||
*/
|
||||
public Date getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
public void setDateOfBirth(Date dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
}
|
||||
6
basic/jdbc/src/main/resources/Person_Derby.sql
Normal file
6
basic/jdbc/src/main/resources/Person_Derby.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
create table Person (
|
||||
id integer primary key not null generated always as identity (start with 1, increment by 1),
|
||||
name varchar(100) not null,
|
||||
gender varchar(1) not null,
|
||||
dateOfBirth date
|
||||
);
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.integration.samples.jdbc;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* The test class for jdbc outbound channel adapter
|
||||
* @author Amol Nayak
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration("classpath:jdbcOutboundAdapterConfig.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class OutboundChannelAdapterTest {
|
||||
|
||||
private Logger logger = Logger.getLogger(OutboundChannelAdapterTest.class);
|
||||
@Autowired
|
||||
@Qualifier("outboundJdbcChannelOne")
|
||||
private MessageChannel channel;
|
||||
|
||||
@Test
|
||||
public void insertPersonRecord() {
|
||||
|
||||
logger.info("Creating person Instance");
|
||||
Person person = new Person();
|
||||
Calendar dateOfBirth = Calendar.getInstance();
|
||||
dateOfBirth.set(1980, 0, 1);
|
||||
person.setDateOfBirth(dateOfBirth.getTime());
|
||||
person.setName("Name Of The Person");
|
||||
person.setGender(Gender.MALE);
|
||||
Message<Person> message = MessageBuilder.withPayload(person).build();
|
||||
channel.send(message);
|
||||
logger.info("Sent person Instance");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
basic/jdbc/src/test/resources/jdbcOutboundAdapterConfig.xml
Normal file
38
basic/jdbc/src/test/resources/jdbcOutboundAdapterConfig.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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:integration="http://www.springframework.org/schema/integration"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:task="http://www.springframework.org/schema/task"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc-2.0.xsd">
|
||||
|
||||
|
||||
<integration:channel id="outboundJdbcChannelOne"/>
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="org.apache.derby.client.ClientXAConnection"/>
|
||||
<property name="url" value="jdbc:derby://localhost:1527/TestDatabase"/>
|
||||
</bean>
|
||||
|
||||
<jdbc:outbound-channel-adapter data-source="dataSource"
|
||||
channel="outboundJdbcChannelOne"
|
||||
query="insert into Person (name,gender,dateOfBirth)
|
||||
values
|
||||
(:name,:gender,:dateOfBirth)"
|
||||
sql-parameter-source-factory="spelSource"/>
|
||||
|
||||
|
||||
<bean id="spelSource" class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
|
||||
<property name="parameterExpressions">
|
||||
<map>
|
||||
<entry key="name" value="payload.name.toUpperCase()"/>
|
||||
<entry key="gender" value="payload.gender.identifier"/>
|
||||
<entry key="dateOfBirth" value="payload.dateOfBirth"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
8
basic/jdbc/src/test/resources/log4j.properties
Normal file
8
basic/jdbc/src/test/resources/log4j.properties
Normal file
@@ -0,0 +1,8 @@
|
||||
log4j.rootCategory=DEBUG, stdout
|
||||
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
|
||||
|
||||
|
||||
log4j.category.org.springframework=DEBUG
|
||||
Reference in New Issue
Block a user