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:
Artem Bilan
2017-10-04 13:08:19 -04:00
parent 6ce495e427
commit 107ef1f305
6 changed files with 9 additions and 158 deletions

View File

@@ -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");
}
}
}
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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