Remove EclipseLink from JPA sample
https://build.spring.io/browse/INTSAMPLES-NIGHTLY-2239/ Having Hibernate and EclipseLink in the same application isn't a goal. On the other hand the sample must be concentrate on the Spring Integration, not a complexity brought by the Spring Boot auto-configuration override. * Remove the EclipseLink support from the JPA samples and rely only on the Hibernate auto-configuration * Remove an appropriate message from the README
This commit is contained in:
@@ -10,29 +10,12 @@ This sample illustrates how the JPA Components can be used. The example presente
|
||||
|
||||
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:
|
||||
|
||||
* [Hibernate](http://www.hibernate.org/)
|
||||
* [OpenJPA](http://openjpa.apache.org/)
|
||||
* [EclipseLink](http://www.eclipse.org/eclipselink/)
|
||||
|
||||
# Getting Started
|
||||
|
||||
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,
|
||||
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/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.
|
||||
|
||||
# Resources
|
||||
|
||||
For help please take a look at the Spring Integration documentation:
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright 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.
|
||||
* 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.jpa;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
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.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
||||
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.transaction.jta.JtaTransactionManager;
|
||||
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 {
|
||||
|
||||
public EclipseLinkAutoConfiguration(DataSource dataSource, JpaProperties properties,
|
||||
ObjectProvider<JtaTransactionManager> jtaTransactionManagerProvider,
|
||||
ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
|
||||
super(dataSource, properties, jtaTransactionManagerProvider, transactionManagerCustomizers);
|
||||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import java.util.Scanner;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
@@ -40,7 +40,7 @@ import org.springframework.util.StringUtils;
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
|
||||
@SpringBootApplication(exclude = JpaRepositoriesAutoConfiguration.class)
|
||||
@ImportResource("spring-integration-context.xml")
|
||||
public class Main {
|
||||
|
||||
@@ -64,38 +64,9 @@ public class Main {
|
||||
+ "\n "
|
||||
+ "\n=========================================================");
|
||||
|
||||
System.out.println("Please enter a choice and press <enter>: ");
|
||||
System.out.println("\t1. Use Hibernate");
|
||||
System.out.println("\t2. Use EclipseLink");
|
||||
|
||||
System.out.println("\tq. Quit the application");
|
||||
System.out.print("Enter you choice: ");
|
||||
|
||||
SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(Main.class)
|
||||
.web(WebApplicationType.NONE);
|
||||
|
||||
while (true) {
|
||||
final String input = scanner.nextLine();
|
||||
|
||||
if ("1".equals(input.trim())) {
|
||||
springApplicationBuilder.sources(HibernateJpaAutoConfiguration.class);
|
||||
break;
|
||||
}
|
||||
else if ("2".equals(input.trim())) {
|
||||
springApplicationBuilder.profiles("eclipseLink");
|
||||
break;
|
||||
}
|
||||
else if ("q".equals(input.trim())) {
|
||||
System.out.println("Exiting application...bye.");
|
||||
System.exit(0);
|
||||
}
|
||||
else {
|
||||
System.out.println("Invalid choice\n\n");
|
||||
System.out.print("Enter you choice: ");
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurableApplicationContext context = springApplicationBuilder.run(args);
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(Main.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run(args);
|
||||
|
||||
final PersonService personService = context.getBean(PersonService.class);
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
drop table if EXISTS PEOPLE;
|
||||
DROP TABLE if EXISTS OPENJPA_SEQUENCE_TABLE;
|
||||
DROP TABLE if EXISTS SEQUENCE;
|
||||
|
||||
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 SEQUENCE HIBERNATE_SEQUENCE START WITH 1 INCREMENT BY 1;
|
||||
CREATE SEQUENCE HIBERNATE_SEQUENCE START WITH 1 INCREMENT BY 1;
|
||||
|
||||
@@ -38,8 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
|
||||
classes = {Main.class, HibernateJpaAutoConfiguration.class})
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
public class JpaTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
11
build.gradle
11
build.gradle
@@ -783,10 +783,10 @@ project('jmx') {
|
||||
project('jpa') {
|
||||
description = 'JPA Basic Sample'
|
||||
|
||||
// apply plugin: 'application'
|
||||
apply plugin: 'application'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
// mainClassName = 'org.springframework.integration.samples.jpa.Main'
|
||||
mainClassName = 'org.springframework.integration.samples.jpa.Main'
|
||||
|
||||
dependencies {
|
||||
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
@@ -795,19 +795,12 @@ project('jpa') {
|
||||
|
||||
runtime "org.springframework:spring-instrument"
|
||||
runtime "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:$jpa21ApiVersion"
|
||||
runtime "org.eclipse.persistence:org.eclipse.persistence.jpa:$eclipseLinkVersion"
|
||||
|
||||
testCompile 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
/* bootRun {
|
||||
main = 'org.springframework.integration.samples.jpa.Main'
|
||||
}*/
|
||||
tasks.withType(JavaExec) {
|
||||
standardInput = System.in
|
||||
jvmArgs classpath.files.findAll {
|
||||
it.name ==~ /(spring-instrument.+)/}.collect{"-javaagent:$it"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user