INTSAMPLE-33 Changes

This commit is contained in:
Amol Nayak
2011-12-15 22:47:52 +05:30
parent 7c43e23308
commit 6b6abd92e4
11 changed files with 110 additions and 192 deletions

View File

@@ -15,6 +15,10 @@
*/
package org.springframework.integration.samples.jdbc;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* Represents the gender of the person
* @author Amol Nayak
@@ -23,6 +27,7 @@ package org.springframework.integration.samples.jdbc;
public enum Gender {
MALE("M"),FEMALE("F");
private static Map<String, Gender> map;
private String identifier;
@@ -33,4 +38,15 @@ public enum Gender {
public String getIdentifier() {
return identifier;
}
public static Gender getGenderByIdentifier(String identifier) {
return map.get(identifier);
}
static {
map = new HashMap<String, Gender>();
for(Gender gender:EnumSet.allOf(Gender.class)) {
map.put(gender.getIdentifier(), gender);
}
}
}

View File

@@ -24,11 +24,28 @@ import java.util.Date;
*/
public class Person {
private int personId;
private String name;
private Gender gender;
private Date dateOfBirth;
/**
* Sets the person id
* @return
*/
public int getPersonId() {
return personId;
}
/**
* Get the person Id
* @param personId
*/
public void setPersonId(int personId) {
this.personId = personId;
}
/**
* Gets the name of the person
* @return

View File

@@ -13,7 +13,7 @@
<int:channel id="replyChannel"/>
<jdbc:embedded-database id="datasource" type="H2">
<jdbc:script location="classpath:setup-tables.sql"/>
<jdbc:script location="classpath:setup-tables.sql"/>
</jdbc:embedded-database>
<!-- See also:
@@ -34,5 +34,49 @@
</int-jdbc:outbound-gateway>
<bean id="rowMapper" class="org.springframework.integration.samples.jdbc.UserMapper"/>
<!-- ====================Config for Person Service ========================= -->
<int:channel id="outboundJdbcRequestChannel"/>
<int:channel id="outboundJdbcResponseChannel"/>
<int:gateway id="personService" service-interface="org.springframework.integration.samples.jdbc.service.PersonService">
<int:method name="createPerson"
request-channel="outboundJdbcRequestChannel"
request-timeout="5000"
reply-channel="outboundJdbcResponseChannel"
reply-timeout="5000"/>
</int:gateway>
<bean id="personResultMapper" class="org.springframework.integration.samples.jdbc.PersonMapper"/>
<int-jdbc:outbound-gateway data-source="datasource"
request-channel="outboundJdbcRequestChannel"
reply-channel="outboundJdbcResponseChannel"
update="insert into Person (name,gender,dateOfBirth)
values
(:name,:gender,:dateOfBirth)"
query="select * from Person where id = :id"
request-sql-parameter-source-factory="requestSource"
reply-sql-parameter-source-factory="replySource"
row-mapper="personResultMapper"
keys-generated="true"/>
<bean id="replySource" class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
<property name="parameterExpressions">
<map>
<entry key="id" value="#this['SCOPE_IDENTITY()']"/>
</map>
</property>
</bean>
<bean id="requestSource" 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>

View File

@@ -1,6 +0,0 @@
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
);

View File

@@ -1,5 +1,6 @@
create table IF NOT EXISTS USERS(USERNAME varchar(100),PASSWORD varchar(100), EMAIL varchar(100));
create table IF NOT EXISTS DUMMY(DUMMY_VALUE varchar(10));
create table IF NOT EXISTS Person(id integer identity primary key , name varchar(100), gender varchar(1), dateOfBirth date);
INSERT INTO USERS(USERNAME, PASSWORD, EMAIL) VALUES ('a', 'secret', 'spring-integration@awesome.com');
INSERT INTO USERS(USERNAME, PASSWORD, EMAIL) VALUES ('b', 's3cr3t', 'spring@rocks.com');
INSERT INTO USERS(USERNAME, PASSWORD, EMAIL) VALUES ('foo', 'bar', 'foo@bar.de');