INTSAMPLES-148: Make JPA Sample as Boot App

JIRA: https://jira.spring.io/browse/INTSAMPLES-148

Upgrade several dependencies, especially OpenJPA-2.4.0 to support Java 8 Class Transformation

Upgrade to DSL-1.1.2 and other polishing

Upgrade to SI-4.3.0.M1
This commit is contained in:
Artem Bilan
2015-12-18 15:34:34 -05:00
parent b52ee9ed9c
commit 6080639682
22 changed files with 234 additions and 250 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2016 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.
@@ -18,8 +18,10 @@ package org.springframework.integration.samples.ftp;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
@@ -33,7 +35,7 @@ import org.springframework.messaging.PollableChannel;
*/
public class FtpInboundChannelAdapterSample {
private static final Logger LOGGER = Logger.getLogger(FtpInboundChannelAdapterSample.class);
private static final Logger LOGGER = LoggerFactory.getLogger(FtpInboundChannelAdapterSample.class);
@Test
public void runDemo() throws Exception{

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2016 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.
@@ -19,10 +19,12 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.InputStream;
import org.apache.log4j.Logger;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
@@ -37,7 +39,7 @@ import org.springframework.integration.support.MessageBuilder;
*/
public class FtpOutboundChannelAdapterSample {
private static final Logger LOGGER = Logger.getLogger(FtpOutboundChannelAdapterSample.class);
private static final Logger LOGGER = LoggerFactory.getLogger(FtpOutboundChannelAdapterSample.class);
private final File baseFolder = new File("target" + File.separator + "toSend");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@@ -24,13 +24,15 @@ import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.listener.ListenerFactory;
import org.apache.log4j.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.samples.ftp.support.TestUserManager;
import org.springframework.integration.test.util.SocketUtils;
@@ -50,7 +52,7 @@ import org.springframework.integration.test.util.SocketUtils;
})
public class TestSuite {
private static final Logger LOGGER = Logger.getLogger(TestSuite.class);
private static final Logger LOGGER = LoggerFactory.getLogger(TestSuite.class);
public static final String FTP_ROOT_DIR = "target" + File.separator + "ftproot";
public static final String LOCAL_FTP_TEMP_DIR = "target" + File.separator + "local-ftp-temp";

View File

@@ -8,7 +8,7 @@ This sample illustrates how the JPA Components can be used. The example presente
* List all people from the database
* Create a new Person record in the database
The first example demonstrates the use of an JPA Outbound gateway to retrieve a list of people. The second example uses an JPA Outbound Gateway in order to create a new Person record and then return the newly created Person record.
The first example demonstrates the use of an JPA Outbound gateway to retrieve a list of people. The second example uses an JPA Outbound Gateway in order to create a new Person record and then return the newly created Person record.
You have the option to choose between the following 3 persistence providers:
@@ -18,18 +18,18 @@ You have the option to choose between the following 3 persistence providers:
# Getting Started
Hibernate works out of the box and there are 2 options on how to execute the sample:
Hibernate works out of the box and there are 2 options on how to execute the sample:
* running the "Main" class from within STS (Right-click on Main class --> Run As --> Java Application)
* or from the command line:
$ gradlew :jpa:run
For **OpenJPA** and **EclipseLink** to work, you must provide a [Java Agent](http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html).
When using the Gradle Application Plugin, this is taken care of for you behind the scenes automatically. However,
For **OpenJPA** and **EclipseLink** to work, you must provide a [Java Agent](http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html).
When using the Gradle Application Plugin, this is taken care of for you behind the scenes automatically. However,
when running the sample from within STS start the Main class with the following JVM flags:
-javaagent:/path/to/.m2/repository/org/springframework/spring-instrument/3.1.1.RELEASE/spring-instrument-3.1.1.RELEASE.jar
-javaagent:/path/to/.m2/repository/org/apache/openjpa/openjpa/2.2.0/openjpa-2.2.0.jar
-javaagent:/path/to/.m2/repository/org/springframework/spring-instrument/4.2.4.RELEASE/spring-instrument-4.2.4.RELEASE.jar
-javaagent:/path/to/.m2/repository/org/apache/openjpa/openjpa/2.4.0/openjpa-2.4.0.jar
With these flags you will be able to use all 3 persistence providers at once.

View File

@@ -0,0 +1,64 @@
package org.springframework.integration.samples.jpa;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.ClassUtils;
/**
* @author Artem Bilan
* @since 4.2
*/
@Configuration
@ConditionalOnClass({LocalContainerEntityManagerFactoryBean.class,
EnableTransactionManagement.class, EntityManager.class})
@Conditional(EclipseLinkAutoConfiguration.EclipseLinkEntityManagerCondition.class)
@AutoConfigureAfter({DataSourceAutoConfiguration.class})
@Profile("eclipseLink")
public class EclipseLinkAutoConfiguration extends JpaBaseConfiguration {
@Override
protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
return new EclipseLinkJpaVendorAdapter();
}
@Override
protected Map<String, Object> getVendorProperties() {
return new HashMap<String, Object>();
}
@Order(Ordered.HIGHEST_PRECEDENCE + 20)
static class EclipseLinkEntityManagerCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
if (ClassUtils.isPresent("org.eclipse.persistence.jpa.JpaEntityManager", context.getClassLoader())) {
return ConditionOutcome.match("found JpaEntityManager class");
}
else {
return ConditionOutcome.noMatch("did not find JpaEntityManager class");
}
}
}
}

View File

@@ -13,13 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.jpa;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Scanner;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.integration.samples.jpa.domain.Person;
import org.springframework.integration.samples.jpa.service.PersonService;
import org.springframework.util.StringUtils;
@@ -30,18 +35,16 @@ import org.springframework.util.StringUtils;
* @author Gunnar Hillert
* @author Amol Nayak
* @author Gary Russell
* @author Artem Bilan
* @version 1.0
*
*/
public final class Main {
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
@ImportResource("spring-integration-context.xml")
public class Main {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss");
/**
* Prevent instantiation.
*/
private Main() {}
/**
* Load the Spring Integration Application Context
*
@@ -68,19 +71,19 @@ public final class Main {
System.out.println("\tq. Quit the application");
System.out.print("Enter you choice: ");
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(Main.class).web(false);
while (true) {
final String input = scanner.nextLine();
if("1".equals(input.trim())) {
context.getEnvironment().setActiveProfiles("hibernate");
springApplicationBuilder.sources(HibernateJpaAutoConfiguration.class);
break;
} else if("2".equals(input.trim())) {
context.getEnvironment().setActiveProfiles("openjpa");
springApplicationBuilder.profiles("openJpa");
break;
} else if("3".equals(input.trim())) {
context.getEnvironment().setActiveProfiles("eclipselink");
springApplicationBuilder.profiles("eclipseLink");
break;
} else if("q".equals(input.trim())) {
System.out.println("Exiting application...bye.");
@@ -91,9 +94,7 @@ public final class Main {
}
}
context.load("classpath:META-INF/spring/integration/*-context.xml");
context.registerShutdownHook();
context.refresh();
ConfigurableApplicationContext context = springApplicationBuilder.run(args);
final PersonService personService = context.getBean(PersonService.class);
@@ -161,10 +162,7 @@ public final class Main {
}
}
}
/**
* @param service
* @param input
*/
private static void findPeople(final PersonService service) {
System.out.println("ID NAME CREATED");
@@ -183,6 +181,6 @@ public final class Main {
}
System.out.println("==================================\n\n");
}
}

View File

@@ -0,0 +1,64 @@
package org.springframework.integration.samples.jpa;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.ClassUtils;
/**
* @author Artem Bilan
* @since 4.2
*/
@Configuration
@ConditionalOnClass({LocalContainerEntityManagerFactoryBean.class,
EnableTransactionManagement.class, EntityManager.class})
@Conditional(OpenJpaAutoConfiguration.OpenJpaEntityManagerCondition.class)
@AutoConfigureAfter({DataSourceAutoConfiguration.class})
@Profile("openJpa")
public class OpenJpaAutoConfiguration extends JpaBaseConfiguration {
@Override
protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
return new OpenJpaVendorAdapter();
}
@Override
protected Map<String, Object> getVendorProperties() {
return new HashMap<String, Object>();
}
@Order(Ordered.HIGHEST_PRECEDENCE + 20)
static class OpenJpaEntityManagerCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
if (ClassUtils.isPresent("org.apache.openjpa.persistence.OpenJPAEntityManager", context.getClassLoader())) {
return ConditionOutcome.match("found OpenJPAEntityManager class");
}
else {
return ConditionOutcome.noMatch("did not find OpenJPAEntityManager class");
}
}
}
}

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.jpa.domain;
import java.util.Date;
@@ -28,32 +29,29 @@ import javax.persistence.TemporalType;
/**
* A simple POJO representing a Person.
*
* @author Amol Nayak
* @author Gunnar Hillert
*
* @author Artem Bilan
*/
@Entity
@Table(name="PEOPLE")
@Table(name = "PEOPLE")
public class Person {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="CREATED_DATE_TIME")
@Column(name = "CREATED_DATE_TIME")
private Date createdDateTime;
public Person() {
super();
this.createdDateTime = new Date();
}
public Person(String name) {
super();
this.name = name;
this.createdDateTime = new Date();
}
@@ -106,7 +104,8 @@ public class Person {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
}
else if (!name.equals(other.name)) {
return false;
}
return true;

View File

@@ -1,2 +0,0 @@
drop table OPENJPA_SEQUENCE_TABLE;
drop table PEOPLE;

View File

@@ -1,2 +0,0 @@
insert into PEOPLE(id, name, CREATED_DATE_TIME)
values ('1001', 'Cartman', NOW());

View File

@@ -1,48 +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:int="http://www.springframework.org/schema/integration"
xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd">
<!-- Setting Up the Database -->
<jdbc:embedded-database id="dataSource" type="H2"/>
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS" >
<jdbc:script location="classpath:H2-DropTables.sql" />
<jdbc:script location="classpath:H2-CreateTables.sql" />
<jdbc:script location="classpath:H2-PopulateData.sql" />
</jdbc:initialize-database>
<!-- Define the JPA transaction manager -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<constructor-arg ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="vendorAdaptor" />
<property name="packagesToScan" value="org.springframework.integration.samples.jpa"/>
</bean>
<bean id="abstractVendorAdaptor" abstract="true">
<property name="generateDdl" value="true" />
<property name="database" value="H2" />
<property name="showSql" value="false"/>
</bean>
<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
</beans>

View File

@@ -1,22 +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:int="http://www.springframework.org/schema/integration"
xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd">
<import resource="classpath:/META-INF/spring/integration/commonJpa-context.xml" />
<bean id="vendorAdaptor" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
parent="abstractVendorAdaptor">
</bean>
</beans>

View File

@@ -1,22 +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:int="http://www.springframework.org/schema/integration"
xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd">
<import resource="classpath:/META-INF/spring/integration/commonJpa-context.xml" />
<bean id="vendorAdaptor" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
parent="abstractVendorAdaptor">
</bean>
</beans>

View File

@@ -1,22 +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:int="http://www.springframework.org/schema/integration"
xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd">
<import resource="classpath:/META-INF/spring/integration/commonJpa-context.xml" />
<bean id="vendorAdaptor" class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"
parent="abstractVendorAdaptor">
</bean>
</beans>

View File

@@ -0,0 +1,8 @@
spring:
jpa:
generate-ddl: false
hibernate:
ddl-auto: false
show-sql: true
main:
banner-mode: "off"

View File

@@ -0,0 +1,3 @@
insert into PEOPLE(id, name, CREATED_DATE_TIME) values ('1001', 'Cartman', NOW());
INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0);

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework.integration">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.samples">
<level value="info" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>

View File

@@ -1,6 +1,8 @@
drop table PEOPLE;
DROP TABLE OPENJPA_SEQUENCE_TABLE;
drop table if EXISTS PEOPLE;
DROP TABLE if EXISTS OPENJPA_SEQUENCE_TABLE;
CREATE TABLE OPENJPA_SEQUENCE_TABLE (ID TINYINT NOT NULL, SEQUENCE_VALUE BIGINT, PRIMARY KEY (ID));
CREATE TABLE PEOPLE (id BIGINT generated by default as identity, name VARCHAR(255), CREATED_DATE_TIME TIMESTAMP, PRIMARY KEY (id));
CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50), SEQ_COUNT DECIMAL(15));
CREATE TABLE PEOPLE (id BIGINT generated by default as identity, name VARCHAR(255), CREATED_DATE_TIME TIMESTAMP, PRIMARY KEY (id));

View File

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

View File

@@ -3,17 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jpa="http://www.springframework.org/schema/integration/jpa"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd">
<int:channel id="createPersonRequestChannel"/>
<int:channel id="listPeopleRequestChannel"/>
<int:gateway id="personService"
@@ -33,15 +28,4 @@
<int-jpa:transactional transaction-manager="transactionManager" />
</int-jpa:updating-outbound-gateway>
<!-- Depending on the selected profile, users can use different JPA Providers -->
<beans profile="default, hibernate">
<import resource="classpath:/META-INF/spring/integration/hibernate-context.xml"/>
</beans>
<beans profile="openjpa">
<import resource="classpath:/META-INF/spring/integration/openjpa-context.xml"/>
</beans>
<beans profile="eclipselink">
<import resource="classpath:/META-INF/spring/integration/eclipselink-context.xml"/>
</beans>
</beans>

View File

@@ -15,44 +15,48 @@
*/
package org.springframework.integration.samples.jpa;
import java.util.Calendar;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Calendar;
import java.util.List;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.integration.samples.jpa.domain.Person;
import org.springframework.integration.samples.jpa.service.PersonService;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
* @author Amol Nayak
* @author Artem Bilan
*
*/
public class OutboundGatewayTest {
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {Main.class, HibernateJpaAutoConfiguration.class})
public class JpaTests {
private static final Logger LOGGER = Logger.getLogger(OutboundGatewayTest.class);
@Autowired
private PersonService personService;
@Test
public void insertPersonRecord() {
final ApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:/META-INF/spring/integration/spring-integration-context.xml");
final PersonService service = context.getBean(PersonService.class);
LOGGER.info("Creating person Instance");
final Person person = new Person();
Person person = new Person();
Calendar createdDateTime = Calendar.getInstance();
createdDateTime.set(1980, 0, 1);
createdDateTime.set(1980, Calendar.JANUARY, 1);
person.setCreatedDateTime(createdDateTime.getTime());
person.setName("Name Of The Person");
final Person persistedPerson = service.createPerson(person);
Assert.assertNotNull("Expected a non null instance of Person, got null", persistedPerson);
LOGGER.info("\n\tGenerated person with id: " + persistedPerson.getId() + ", with name: " + persistedPerson.getName());
this.personService.createPerson(person);
List<Person> people = this.personService.findPeople();
assertNotNull(people);
assertEquals(2, people.size());
assertEquals(person.getName(), people.get(1).getName());
}
}

View File

@@ -29,7 +29,7 @@ allprojects {
// mavenLocal()
maven { url 'http://repo.spring.io/libs-snapshot' }
maven { url 'http://repo.spring.io/libs-milestone' }
// maven { url 'http://repo.spring.io/libs-staging-local' }
maven { url 'http://repo.spring.io/libs-staging-local' }
}
}
@@ -162,8 +162,9 @@ subprojects { subproject ->
commonsPoolVersion = '1.5.4'
c3p0Version = '0.9.1.2'
derbyVersion = '10.10.1.1'
eclipseLinkVersion = '2.4.2'
hamcrestVersion = '1.3'
hibernateVersion = '4.2.11.Final'
hibernateVersion = '4.3.11.Final'
hibernateValidatorVersion = '4.2.0.Final'
ftpServerVersion = '1.0.6'
flexjsonVersion = '2.0'
@@ -180,13 +181,14 @@ subprojects { subproject ->
jtdsVersion = '1.2.6'
jmsApiVersion = '1.1-rev-1'
jrubyVersion = '1.7.12'
jpa21ApiVersion = '1.0.0.Final'
jpaApiVersion = '2.0.0'
jstlVersion = '1.2'
junitVersion = '4.11'
jythonVersion = '2.5.3'
log4jVersion = '1.2.17'
mockitoVersion = '1.9.5'
openJpaVersion = '2.3.0'
openJpaVersion = '2.4.0'
oracleDriverVersion = '11.2.0.3'
reactorVersion = '2.0.7.RELEASE'
postgresVersion = '9.1-901-1.jdbc4'
@@ -196,7 +198,7 @@ subprojects { subproject ->
springIntegrationDslVersion = '1.1.2.RELEASE'
springIntegrationKafkaVersion = '1.3.0.RELEASE'
springIntegrationSplunkVersion = '1.1.0.RELEASE'
springVersion = '4.2.3.RELEASE'
springVersion = '4.2.5.RELEASE'
springSecurityVersion = '4.0.2.RELEASE'
springWebFlowVersion = '2.3.3.RELEASE'
tilesJspVersion = '2.2.1'
@@ -758,31 +760,34 @@ project('jpa') {
description = 'JPA Basic Sample'
apply plugin: 'application'
apply plugin: 'spring-boot'
mainClassName = 'org.springframework.integration.samples.jpa.Main'
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile "org.springframework.integration:spring-integration-jpa:$springIntegrationVersion"
compile "com.h2database:h2:$h2Version"
compile "org.hibernate:hibernate-entitymanager:$hibernateVersion"
compile "org.eclipse.persistence:javax.persistence:$jpaApiVersion"
compile "commons-lang:commons-lang:$commonsLangVersion"
compile "log4j:log4j:$log4jVersion"
compile "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:$jpa21ApiVersion"
runtime "org.springframework:spring-instrument:$springVersion"
runtime "org.apache.openjpa:openjpa:$openJpaVersion"
runtime "org.hibernate:hibernate-entitymanager:$hibernateVersion"
runtime "org.eclipse.persistence:org.eclipse.persistence.jpa:$eclipseLinkVersion"
}
//Suppress openjpa annotation processor warnings
compileTestJava.options.compilerArgs = ["${xLintArg},-processing"]
run {
def javaAgents = configurations.testRuntime.resolvedConfiguration.resolvedArtifacts
.findAll { it.name in ['spring-instrument', 'openjpa'] }
.collect { "-javaagent:${it.file}" }
jvmArgs javaAgents
springBoot {
mainClass = 'org.springframework.integration.samples.jpa.Main'
}
tasks.withType(JavaExec) {
standardInput = System.in
jvmArgs classpath.files.findAll{it.name ==~ /(spring-instrument.+)|(openjpa-${openJpaVersion}.+)/}.collect{"-javaagent:$it"}
}
}
project('mail') {
@@ -799,7 +804,6 @@ project('mail') {
task runGmailInboundPop3AdapterTestApp(type: JavaExec) {
main 'org.springframework.integration.samples.mail.imapidle.GmailInboundPop3AdapterTestApp'
classpath = sourceSets.main.runtimeClasspath
}
task runGmailInboundImapIdleAdapterTestApp(type: JavaExec) {