Merge branch 'pr/553-lukasz-deltaspike'
Conflicts: pom.xml
This commit is contained in:
commit
14a4de6e4e
|
@ -0,0 +1,3 @@
|
|||
/.idea
|
||||
baeldung-jee7-seed.iml
|
||||
/target
|
|
@ -0,0 +1,301 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>deltaspike</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>war</packaging>
|
||||
<name>deltaspike</name>
|
||||
<description>A starter Java EE 7 webapp which uses DeltaSpike</description>
|
||||
|
||||
<url>http://wildfly.org</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<distribution>repo</distribution>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<!-- Explicitly declaring the source encoding eliminates the following
|
||||
message: -->
|
||||
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
|
||||
resources, i.e. build is platform dependent! -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<!-- JBoss dependency versions -->
|
||||
<version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
|
||||
|
||||
<!-- Define the version of the JBoss BOMs we want to import to specify
|
||||
tested stacks. -->
|
||||
<version.jboss.bom>8.2.1.Final</version.jboss.bom>
|
||||
|
||||
<!-- other plugin versions -->
|
||||
<version.compiler.plugin>3.1</version.compiler.plugin>
|
||||
<version.surefire.plugin>2.16</version.surefire.plugin>
|
||||
<version.war.plugin>2.5</version.war.plugin>
|
||||
|
||||
<!-- maven-compiler-plugin -->
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill
|
||||
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
|
||||
of artifacts. We use this here so that we always get the correct versions
|
||||
of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you can
|
||||
read this as the JBoss stack of the Java EE 7 APIs, with some extras tools
|
||||
for your project, such as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate
|
||||
stack you can read this as the JBoss stack of the Java EE 7 APIs, with extras
|
||||
from the Hibernate family of projects) -->
|
||||
<dependency>
|
||||
<groupId>org.wildfly.bom</groupId>
|
||||
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
|
||||
<version>${version.jboss.bom}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wildfly.bom</groupId>
|
||||
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
|
||||
<version>${version.jboss.bom}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- First declare the APIs we depend on and need for compilation. All
|
||||
of them are provided by JBoss WildFly -->
|
||||
|
||||
<!-- Import the CDI API, we use provided scope as the API is included in
|
||||
JBoss WildFly -->
|
||||
<dependency>
|
||||
<groupId>javax.enterprise</groupId>
|
||||
<artifactId>cdi-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Import the Common Annotations API (JSR-250), we use provided scope
|
||||
as the API is included in JBoss WildFly -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.spec.javax.annotation</groupId>
|
||||
<artifactId>jboss-annotations-api_1.2_spec</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Import the JAX-RS API, we use provided scope as the API is included
|
||||
in JBoss WildFly -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>jaxrs-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Import the JPA API, we use provided scope as the API is included in
|
||||
JBoss WildFly -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.javax.persistence</groupId>
|
||||
<artifactId>hibernate-jpa-2.1-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Import the EJB API, we use provided scope as the API is included in
|
||||
JBoss WildFly -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.spec.javax.ejb</groupId>
|
||||
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- JSR-303 (Bean Validation) Implementation -->
|
||||
<!-- Provides portable constraints such as @Email -->
|
||||
<!-- Hibernate Validator is shipped in JBoss WildFly -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Import the JSF API, we use provided scope as the API is included in
|
||||
JBoss WildFly -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.spec.javax.faces</groupId>
|
||||
<artifactId>jboss-jsf-api_2.2_spec</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Now we declare any tools needed -->
|
||||
|
||||
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
|
||||
typesafe criteria queries -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-jpamodelgen</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Annotation processor that raising compilation errors whenever constraint
|
||||
annotations are incorrectly used. -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator-annotation-processor</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Needed for running tests (you may also use TestNG) -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Optional, but highly recommended -->
|
||||
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
|
||||
JPA from JUnit/TestNG -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian.junit</groupId>
|
||||
<artifactId>arquillian-junit-container</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian.protocol</groupId>
|
||||
<artifactId>arquillian-protocol-servlet</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.shrinkwrap.resolver</groupId>
|
||||
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.deltaspike.modules</groupId>
|
||||
<artifactId>deltaspike-data-module-api</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.deltaspike.modules</groupId>
|
||||
<artifactId>deltaspike-data-module-impl</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- querydsl libraries -->
|
||||
<dependency>
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
<artifactId>querydsl-apt</artifactId>
|
||||
<version>3.7.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
<artifactId>querydsl-jpa</artifactId>
|
||||
<version>3.7.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<!-- Maven will append the version to the finalName (which is the name
|
||||
given to the generated war, and hence the context root) -->
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>${version.war.plugin}</version>
|
||||
<configuration>
|
||||
<!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.mysema.maven</groupId>
|
||||
<artifactId>apt-maven-plugin</artifactId>
|
||||
<version>1.0.9</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>process</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target/generated-sources/java</outputDirectory>
|
||||
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- The WildFly plugin deploys your war to a local WildFly container -->
|
||||
<!-- To use, run: mvn package wildfly:deploy -->
|
||||
<plugin>
|
||||
<groupId>org.wildfly.plugins</groupId>
|
||||
<artifactId>wildfly-maven-plugin</artifactId>
|
||||
<version>${version.wildfly.maven.plugin}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<!-- The default profile skips all tests, though you can tune it to run
|
||||
just unit tests based on a custom pattern -->
|
||||
<!-- Seperate profiles are provided for running all tests, including Arquillian
|
||||
tests that execute in the specified container -->
|
||||
<id>default</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${version.surefire.plugin}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
|
||||
<!-- An optional Arquillian testing profile that executes tests
|
||||
in your WildFly instance -->
|
||||
<!-- This profile will start a new WildFly instance, and execute the
|
||||
test, shutting it down when done -->
|
||||
<!-- Run with: mvn clean test -Parq-wildfly-managed -->
|
||||
<id>arq-wildfly-managed</id>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.wildfly</groupId>
|
||||
<artifactId>wildfly-arquillian-container-managed</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.controller;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.inject.Model;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import baeldung.model.Member;
|
||||
import baeldung.service.MemberRegistration;
|
||||
|
||||
// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an
|
||||
// EL name
|
||||
// Read more about the @Model stereotype in this FAQ:
|
||||
// http://www.cdi-spec.org/faq/#accordion6
|
||||
@Model
|
||||
public class MemberController {
|
||||
|
||||
@Inject
|
||||
private FacesContext facesContext;
|
||||
|
||||
@Inject
|
||||
private MemberRegistration memberRegistration;
|
||||
|
||||
@Produces
|
||||
@Named
|
||||
private Member newMember;
|
||||
|
||||
@PostConstruct
|
||||
public void initNewMember() {
|
||||
newMember = new Member();
|
||||
}
|
||||
|
||||
public void register() throws Exception {
|
||||
try {
|
||||
memberRegistration.register(newMember);
|
||||
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registered!", "Registration successful");
|
||||
facesContext.addMessage(null, m);
|
||||
initNewMember();
|
||||
} catch (Exception e) {
|
||||
String errorMessage = getRootErrorMessage(e);
|
||||
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "Registration unsuccessful");
|
||||
facesContext.addMessage(null, m);
|
||||
}
|
||||
}
|
||||
|
||||
private String getRootErrorMessage(Exception e) {
|
||||
// Default to general error message that registration failed.
|
||||
String errorMessage = "Registration failed. See server log for more information";
|
||||
if (e == null) {
|
||||
// This shouldn't happen, but return the default messages
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
// Start with the exception and recurse to find the root cause
|
||||
Throwable t = e;
|
||||
while (t != null) {
|
||||
// Get the message from the Throwable class instance
|
||||
errorMessage = t.getLocalizedMessage();
|
||||
t = t.getCause();
|
||||
}
|
||||
// This is the root cause message
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package baeldung.data;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.inject.Default;
|
||||
import javax.enterprise.inject.Disposes;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceUnit;
|
||||
|
||||
@ApplicationScoped
|
||||
public class EntityManagerProducer {
|
||||
@PersistenceUnit(unitName = "primary")
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@Produces
|
||||
@Default
|
||||
@RequestScoped
|
||||
public EntityManager create() {
|
||||
return this.entityManagerFactory.createEntityManager();
|
||||
}
|
||||
|
||||
public void dispose(@Disposes @Default EntityManager entityManager) {
|
||||
if (entityManager.isOpen()) {
|
||||
entityManager.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.data;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.event.Observes;
|
||||
import javax.enterprise.event.Reception;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.util.List;
|
||||
|
||||
import baeldung.model.Member;
|
||||
|
||||
@RequestScoped
|
||||
public class MemberListProducer {
|
||||
|
||||
@Inject
|
||||
private MemberRepository memberRepository;
|
||||
|
||||
private List<Member> members;
|
||||
|
||||
// @Named provides access the return value via the EL variable name "members" in the UI (e.g.
|
||||
// Facelets or JSP view)
|
||||
@Produces
|
||||
@Named
|
||||
public List<Member> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
public void onMemberListChanged(@Observes(notifyObserver = Reception.IF_EXISTS) final Member member) {
|
||||
retrieveAllMembersOrderedByName();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void retrieveAllMembersOrderedByName() {
|
||||
members = memberRepository.findAllOrderedByNameWithQueryDSL();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.data;
|
||||
|
||||
import baeldung.model.Member;
|
||||
import baeldung.model.QMember;
|
||||
import org.apache.deltaspike.data.api.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@EntityManagerConfig(entityManagerResolver = SecondaryEntityManagerResolver.class)
|
||||
public abstract class MemberRepository extends AbstractEntityRepository<Member, Long> implements QueryDslSupport {
|
||||
|
||||
public abstract Member findById(Long id);
|
||||
|
||||
public abstract Member findByEmail(String email);
|
||||
|
||||
@Query("from Member m order by m.name")
|
||||
public abstract List<Member> findAllOrderedByName();
|
||||
|
||||
public List<Member> findAllOrderedByNameWithQueryDSL() {
|
||||
final QMember member = QMember.member;
|
||||
return jpaQuery()
|
||||
.from(member)
|
||||
.orderBy(member.email.asc())
|
||||
.list(member);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package baeldung.data;
|
||||
|
||||
import com.mysema.query.jpa.impl.JPAQuery;
|
||||
import org.apache.deltaspike.data.spi.DelegateQueryHandler;
|
||||
import org.apache.deltaspike.data.spi.QueryInvocationContext;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class QueryDslRepositoryExtension<E> implements QueryDslSupport, DelegateQueryHandler {
|
||||
|
||||
@Inject
|
||||
private QueryInvocationContext context;
|
||||
|
||||
@Override
|
||||
public JPAQuery jpaQuery() {
|
||||
return new JPAQuery(context.getEntityManager());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package baeldung.data;
|
||||
|
||||
import com.mysema.query.jpa.impl.JPAQuery;
|
||||
|
||||
public interface QueryDslSupport {
|
||||
JPAQuery jpaQuery();
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package baeldung.data;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.inject.Default;
|
||||
import javax.enterprise.inject.Disposes;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.PersistenceUnit;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SecondaryEntityManagerProducer {
|
||||
@PersistenceUnit(unitName = "secondary")
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
@Produces
|
||||
@Default
|
||||
@RequestScoped
|
||||
@SecondaryPersistenceUnit
|
||||
public EntityManager create() {
|
||||
return this.entityManagerFactory.createEntityManager();
|
||||
}
|
||||
|
||||
public void dispose(@Disposes @Default EntityManager entityManager) {
|
||||
if (entityManager.isOpen()) {
|
||||
entityManager.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package baeldung.data;
|
||||
|
||||
import org.apache.deltaspike.data.api.EntityManagerResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
public class SecondaryEntityManagerResolver implements EntityManagerResolver {
|
||||
|
||||
@Inject
|
||||
@SecondaryPersistenceUnit
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
public EntityManager resolveEntityManager() {
|
||||
return entityManager;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package baeldung.data;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Qualifier
|
||||
public @interface SecondaryPersistenceUnit {
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.validation.constraints.Digits;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.hibernate.validator.constraints.Email;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Entity
|
||||
@XmlRootElement
|
||||
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "email"))
|
||||
public class Member implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Size(min = 1, max = 25)
|
||||
@Pattern(regexp = "[^0-9]*", message = "Must not contain numbers")
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
@NotEmpty
|
||||
@Email
|
||||
private String email;
|
||||
|
||||
@NotNull
|
||||
@Size(min = 10, max = 12)
|
||||
@Digits(fraction = 0, integer = 12)
|
||||
@Column(name = "phone_number")
|
||||
private String phoneNumber;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public void setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.rest;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
* A class extending {@link Application} and annotated with @ApplicationPath is the Java EE 7 "no XML" approach to activating
|
||||
* JAX-RS.
|
||||
* <p>
|
||||
* <p>
|
||||
* Resources are served relative to the servlet path specified in the {@link ApplicationPath} annotation.
|
||||
* </p>
|
||||
*/
|
||||
@ApplicationPath("/rest")
|
||||
public class JaxRsActivator extends Application {
|
||||
/* class body intentionally left blank */
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.rest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.ValidationException;
|
||||
import javax.validation.Validator;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import baeldung.data.MemberRepository;
|
||||
import baeldung.model.Member;
|
||||
import baeldung.service.MemberRegistration;
|
||||
|
||||
/**
|
||||
* JAX-RS Example
|
||||
* <p/>
|
||||
* This class produces a RESTful service to read/write the contents of the members table.
|
||||
*/
|
||||
@Path("/members")
|
||||
@RequestScoped
|
||||
public class MemberResourceRESTService {
|
||||
|
||||
@Inject
|
||||
private Logger log;
|
||||
|
||||
@Inject
|
||||
private Validator validator;
|
||||
|
||||
@Inject
|
||||
private MemberRepository repository;
|
||||
|
||||
@Inject
|
||||
MemberRegistration registration;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<Member> listAllMembers() {
|
||||
return repository.findAllOrderedByName();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id:[0-9][0-9]*}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Member lookupMemberById(@PathParam("id") long id) {
|
||||
Member member = repository.findById(id);
|
||||
if (member == null) {
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
}
|
||||
return member;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new member from the values provided. Performs validation, and will return a JAX-RS response with either 200 ok,
|
||||
* or with a map of fields, and related errors.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response createMember(Member member) {
|
||||
|
||||
Response.ResponseBuilder builder = null;
|
||||
|
||||
try {
|
||||
// Validates member using bean validation
|
||||
validateMember(member);
|
||||
|
||||
registration.register(member);
|
||||
|
||||
// Create an "ok" response
|
||||
builder = Response.ok();
|
||||
} catch (ConstraintViolationException ce) {
|
||||
// Handle bean validation issues
|
||||
builder = createViolationResponse(ce.getConstraintViolations());
|
||||
} catch (ValidationException e) {
|
||||
// Handle the unique constrain violation
|
||||
Map<String, String> responseObj = new HashMap<>();
|
||||
responseObj.put("email", "Email taken");
|
||||
builder = Response.status(Response.Status.CONFLICT).entity(responseObj);
|
||||
} catch (Exception e) {
|
||||
// Handle generic exceptions
|
||||
Map<String, String> responseObj = new HashMap<>();
|
||||
responseObj.put("error", e.getMessage());
|
||||
builder = Response.status(Response.Status.BAD_REQUEST).entity(responseObj);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Validates the given Member variable and throws validation exceptions based on the type of error. If the error is standard
|
||||
* bean validation errors then it will throw a ConstraintValidationException with the set of the constraints violated.
|
||||
* </p>
|
||||
* <p>
|
||||
* If the error is caused because an existing member with the same email is registered it throws a regular validation
|
||||
* exception so that it can be interpreted separately.
|
||||
* </p>
|
||||
*
|
||||
* @param member Member to be validated
|
||||
* @throws ConstraintViolationException If Bean Validation errors exist
|
||||
* @throws ValidationException If member with the same email already exists
|
||||
*/
|
||||
private void validateMember(Member member) throws ConstraintViolationException, ValidationException {
|
||||
// Create a bean validator and check for issues.
|
||||
Set<ConstraintViolation<Member>> violations = validator.validate(member);
|
||||
|
||||
if (!violations.isEmpty()) {
|
||||
throw new ConstraintViolationException(new HashSet<ConstraintViolation<?>>(violations));
|
||||
}
|
||||
|
||||
// Check the uniqueness of the email address
|
||||
if (emailAlreadyExists(member.getEmail())) {
|
||||
throw new ValidationException("Unique Email Violation");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JAX-RS "Bad Request" response including a map of all violation fields, and their message. This can then be used
|
||||
* by clients to show violations.
|
||||
*
|
||||
* @param violations A set of violations that needs to be reported
|
||||
* @return JAX-RS response containing all violations
|
||||
*/
|
||||
private Response.ResponseBuilder createViolationResponse(Set<ConstraintViolation<?>> violations) {
|
||||
log.fine("Validation completed. violations found: " + violations.size());
|
||||
|
||||
Map<String, String> responseObj = new HashMap<>();
|
||||
|
||||
for (ConstraintViolation<?> violation : violations) {
|
||||
responseObj.put(violation.getPropertyPath().toString(), violation.getMessage());
|
||||
}
|
||||
|
||||
return Response.status(Response.Status.BAD_REQUEST).entity(responseObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a member with the same email address is already registered. This is the only way to easily capture the
|
||||
* "@UniqueConstraint(columnNames = "email")" constraint from the Member class.
|
||||
*
|
||||
* @param email The email to check
|
||||
* @return True if the email already exists, and false otherwise
|
||||
*/
|
||||
public boolean emailAlreadyExists(String email) {
|
||||
Member member = null;
|
||||
try {
|
||||
member = repository.findByEmail(email);
|
||||
} catch (NoResultException e) {
|
||||
// ignore
|
||||
}
|
||||
return member != null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.service;
|
||||
|
||||
import baeldung.data.MemberRepository;
|
||||
import baeldung.data.SecondaryPersistenceUnit;
|
||||
import baeldung.model.Member;
|
||||
import baeldung.model.QMember;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.enterprise.inject.Default;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.ValidationException;
|
||||
import javax.validation.Validator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Stateless
|
||||
public class MemberRegistration {
|
||||
|
||||
@Inject
|
||||
private Logger log;
|
||||
|
||||
@Inject
|
||||
private MemberRepository repository;
|
||||
|
||||
@Inject
|
||||
private Event<Member> memberEventSrc;
|
||||
|
||||
@Inject
|
||||
private Validator validator;
|
||||
|
||||
private void validateMember(Member member) throws ConstraintViolationException, ValidationException {
|
||||
// Create a bean validator and check for issues.
|
||||
Set<ConstraintViolation<Member>> violations = validator.validate(member);
|
||||
|
||||
if (!violations.isEmpty()) {
|
||||
throw new ConstraintViolationException(new HashSet<ConstraintViolation<?>>(violations));
|
||||
}
|
||||
|
||||
// Check the uniqueness of the email address
|
||||
if (emailAlreadyExists(member.getEmail())) {
|
||||
throw new ValidationException("Unique Email Violation");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void register(Member member) throws Exception {
|
||||
log.info("Registering " + member.getName());
|
||||
validateMember(member);
|
||||
repository.save(member);
|
||||
memberEventSrc.fire(member);
|
||||
}
|
||||
|
||||
public boolean emailAlreadyExists(String email) {
|
||||
Member member = null;
|
||||
try {
|
||||
member = repository.findByEmail(email);
|
||||
} catch (NoResultException e) {
|
||||
// ignore
|
||||
}
|
||||
return member != null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.util;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.spi.InjectionPoint;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
/**
|
||||
* This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans
|
||||
* <p>
|
||||
* <p>
|
||||
* Example injection on a managed bean field:
|
||||
* </p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* @Inject
|
||||
* private EntityManager em;
|
||||
* </pre>
|
||||
*/
|
||||
public class Resources {
|
||||
|
||||
@Produces
|
||||
public Logger produceLog(InjectionPoint injectionPoint) {
|
||||
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
|
||||
}
|
||||
|
||||
@Produces
|
||||
@RequestScoped
|
||||
public FacesContext produceFacesContext() {
|
||||
return FacesContext.getCurrentInstance();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://xmlns.jcp.org/xml/ns/persistence
|
||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="primary" transaction-type="JTA">
|
||||
<jta-data-source>java:jboss/datasources/baeldung-jee7-seedDS</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="hibernate.show_sql" value="false" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
<persistence-unit name="secondary" transaction-type="JTA">
|
||||
<jta-data-source>java:jboss/datasources/baeldung-jee7-seed-secondaryDS</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="hibernate.show_sql" value="false" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
|
@ -0,0 +1,19 @@
|
|||
--
|
||||
-- JBoss, Home of Professional Open Source
|
||||
-- Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
-- contributors by the @authors tag. See the copyright.txt in the
|
||||
-- distribution for a full listing of individual contributors.
|
||||
--
|
||||
-- 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.
|
||||
--
|
||||
|
||||
-- You can use this file to load seed data into the database using SQL statements
|
||||
insert into Member (id, name, email, phone_number) values (0, 'John Smith', 'john.smith@mailinator.com', '2125551212')
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
contributors by the @authors tag. See the copyright.txt in the
|
||||
distribution for a full listing of individual contributors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<!-- This is an unmanaged datasource. It should be used for proofs of concept
|
||||
or testing only. It uses H2, an in memory database that ships with JBoss
|
||||
AS. -->
|
||||
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
|
||||
<!-- The datasource is bound into JNDI at this location. We reference
|
||||
this in META-INF/persistence.xml -->
|
||||
<datasource jndi-name="java:jboss/datasources/baeldung-jee7-seedDS"
|
||||
pool-name="baeldung-jee7-seed" enabled="true"
|
||||
use-java-context="true">
|
||||
<connection-url>jdbc:h2:mem:baeldung-jee7-seed;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
|
||||
<driver>h2</driver>
|
||||
<security>
|
||||
<user-name>sa</user-name>
|
||||
<password>sa</password>
|
||||
</security>
|
||||
</datasource>
|
||||
</datasources>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
|
||||
<!-- The datasource is bound into JNDI at this location. We reference
|
||||
this in META-INF/persistence.xml -->
|
||||
<datasource jndi-name="java:jboss/datasources/baeldung-jee7-seed-secondaryDS"
|
||||
pool-name="baeldung-jee7-seed" enabled="true"
|
||||
use-java-context="true">
|
||||
<connection-url>jdbc:h2:mem:baeldung-jee7-seed;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
|
||||
<driver>h2</driver>
|
||||
<security>
|
||||
<user-name>sa</user-name>
|
||||
<password>sa</password>
|
||||
</security>
|
||||
</datasource>
|
||||
</datasources>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
contributors by the @authors tag. See the copyright.txt in the
|
||||
distribution for a full listing of individual contributors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<!-- Marker file indicating CDI should be enabled -->
|
||||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all">
|
||||
</beans>
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
contributors by the @authors tag. See the copyright.txt in the
|
||||
distribution for a full listing of individual contributors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<!-- Marker file indicating JSF 2.2 should be enabled in the application -->
|
||||
<faces-config version="2.2"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
|
||||
</faces-config>
|
|
@ -0,0 +1,55 @@
|
|||
<!--
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
contributors by the @authors tag. See the copyright.txt in the
|
||||
distribution for a full listing of individual contributors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:h="http://java.sun.com/jsf/html"
|
||||
xmlns:ui="http://java.sun.com/jsf/facelets">
|
||||
<h:head>
|
||||
<title>baeldung-jee7-seed</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<h:outputStylesheet name="css/screen.css" />
|
||||
</h:head>
|
||||
<h:body>
|
||||
<div id="container">
|
||||
<div class="dualbrand">
|
||||
<img src="resources/gfx/dualbrand_logo.png" />
|
||||
</div>
|
||||
<div id="content">
|
||||
<ui:insert name="content">
|
||||
[Template content will be inserted here]
|
||||
</ui:insert>
|
||||
</div>
|
||||
<div id="aside">
|
||||
<p>Learn more about JBoss WildFly.</p>
|
||||
<ul>
|
||||
<li><a
|
||||
href="https://github.com/wildfly/quickstart/blob/master/guide/Introduction.asciidoc">Getting
|
||||
Started Developing Applications Guide</a></li>
|
||||
<li><a href="http://www.wildfly.org/">Community
|
||||
Project Information</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<p>
|
||||
This project was generated from a Maven archetype from
|
||||
WildFly.<br />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</h:body>
|
||||
</html>
|
|
@ -0,0 +1,23 @@
|
|||
<!--
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
contributors by the @authors tag. See the copyright.txt in the
|
||||
distribution for a full listing of individual contributors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<!-- Plain HTML page that kicks us into the app -->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Refresh" content="0; URL=index.jsf">
|
||||
</head>
|
||||
</html>
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
contributors by the @authors tag. See the copyright.txt in the
|
||||
distribution for a full listing of individual contributors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:ui="http://java.sun.com/jsf/facelets"
|
||||
xmlns:f="http://java.sun.com/jsf/core"
|
||||
xmlns:h="http://java.sun.com/jsf/html"
|
||||
template="/WEB-INF/templates/default.xhtml">
|
||||
<ui:define name="content">
|
||||
<h1>Welcome to WildFly!</h1>
|
||||
|
||||
<div>
|
||||
<p>You have successfully deployed a Java EE 7 Enterprise
|
||||
Application.</p>
|
||||
<h3>Your application can run on:</h3>
|
||||
<img src="resources/gfx/wildfly_400x130.jpg" />
|
||||
</div>
|
||||
|
||||
<h:form id="reg">
|
||||
<h2>Member Registration</h2>
|
||||
<p>Enforces annotation-based constraints defined on the
|
||||
model class.</p>
|
||||
<h:panelGrid columns="3" columnClasses="titleCell">
|
||||
<h:outputLabel for="name" value="Name:" />
|
||||
<h:inputText id="name" value="#{newMember.name}" />
|
||||
<h:message for="name" errorClass="invalid" />
|
||||
|
||||
<h:outputLabel for="email" value="Email:" />
|
||||
<h:inputText id="email" value="#{newMember.email}" />
|
||||
<h:message for="email" errorClass="invalid" />
|
||||
|
||||
<h:outputLabel for="phoneNumber" value="Phone #:" />
|
||||
<h:inputText id="phoneNumber"
|
||||
value="#{newMember.phoneNumber}" />
|
||||
<h:message for="phoneNumber" errorClass="invalid" />
|
||||
</h:panelGrid>
|
||||
|
||||
<p>
|
||||
<h:panelGrid columns="2">
|
||||
<h:commandButton id="register"
|
||||
action="#{memberController.register}"
|
||||
value="Register" styleClass="register" />
|
||||
<h:messages styleClass="messages"
|
||||
errorClass="invalid" infoClass="valid"
|
||||
warnClass="warning" globalOnly="true" />
|
||||
</h:panelGrid>
|
||||
</p>
|
||||
</h:form>
|
||||
<h2>Members</h2>
|
||||
<h:panelGroup rendered="#{empty members}">
|
||||
<em>No registered members.</em>
|
||||
</h:panelGroup>
|
||||
<h:dataTable var="_member" value="#{members}"
|
||||
rendered="#{not empty members}"
|
||||
styleClass="simpletablestyle">
|
||||
<h:column>
|
||||
<f:facet name="header">Id</f:facet>
|
||||
#{_member.id}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">Name</f:facet>
|
||||
#{_member.name}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">Email</f:facet>
|
||||
#{_member.email}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">Phone #</f:facet>
|
||||
#{_member.phoneNumber}
|
||||
</h:column>
|
||||
<h:column>
|
||||
<f:facet name="header">REST URL</f:facet>
|
||||
<a
|
||||
href="#{request.contextPath}/rest/members/#{_member.id}">/rest/members/#{_member.id}</a>
|
||||
</h:column>
|
||||
<f:facet name="footer">
|
||||
REST URL for all members: <a
|
||||
href="#{request.contextPath}/rest/members">/rest/members</a>
|
||||
</f:facet>
|
||||
</h:dataTable>
|
||||
</ui:define>
|
||||
</ui:composition>
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/* Core styles for the page */
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #F1F1F1;
|
||||
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
|
||||
font-size: 0.8em;
|
||||
color:#363636;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin: 0 auto;
|
||||
padding: 0 20px 10px 20px;
|
||||
border-top: 5px solid #000000;
|
||||
border-left: 5px solid #8c8f91;
|
||||
border-right: 5px solid #8c8f91;
|
||||
border-bottom: 25px solid #8c8f91;
|
||||
width: 865px; /* subtract 40px from banner width for padding */
|
||||
background: #FFFFFF;
|
||||
background-image: url(#{request.contextPath}/resources/gfx/headerbkg.png);
|
||||
background-repeat: repeat-x;
|
||||
padding-top: 30px;
|
||||
box-shadow: 3px 3px 15px #d5d5d5;
|
||||
}
|
||||
#content {
|
||||
float: left;
|
||||
width: 500px;
|
||||
margin: 20px;
|
||||
}
|
||||
#aside {
|
||||
font-size: 0.9em;
|
||||
width: 275px;
|
||||
float: left;
|
||||
margin: 20px 0px;
|
||||
border: 1px solid #D5D5D5;
|
||||
background: #F1F1F1;
|
||||
background-image: url(#{request.contextPath}/resources/gfx/asidebkg.png);
|
||||
background-repeat: repeat-x;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
#aside ul {
|
||||
padding-left: 30px;
|
||||
}
|
||||
.dualbrand {
|
||||
float: right;
|
||||
padding-right: 10px;
|
||||
}
|
||||
#footer {
|
||||
clear: both;
|
||||
text-align: center;
|
||||
color: #666666;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
code {
|
||||
font-size: 1.1em;
|
||||
}
|
||||
a {
|
||||
color: #4a5d75;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
color: #369;
|
||||
text-decoration: underline;
|
||||
}
|
||||
h1 {
|
||||
color:#243446;
|
||||
font-size: 2.25em;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1em;
|
||||
}
|
||||
h3 {
|
||||
color:#243446;
|
||||
}
|
||||
h4 {
|
||||
}
|
||||
h5 {
|
||||
}
|
||||
h6 {
|
||||
}
|
||||
/* Member registration styles */
|
||||
span.invalid {
|
||||
padding-left: 3px;
|
||||
color: red;
|
||||
}
|
||||
form {
|
||||
padding: 1em;
|
||||
font: 80%/1 sans-serif;
|
||||
width: 375px;
|
||||
border: 1px solid #D5D5D5;
|
||||
}
|
||||
label {
|
||||
float: left;
|
||||
width: 15%;
|
||||
margin-left: 20px;
|
||||
margin-right: 0.5em;
|
||||
padding-top: 0.2em;
|
||||
text-align: right;
|
||||
font-weight: bold;
|
||||
color:#363636;
|
||||
}
|
||||
input {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.register {
|
||||
float: left;
|
||||
margin-left: 85px;
|
||||
}
|
||||
|
||||
/* ----- table style ------- */
|
||||
|
||||
|
||||
/* = Simple Table style (black header, grey/white stripes */
|
||||
|
||||
.simpletablestyle {
|
||||
background-color:#E6E7E8;
|
||||
clear:both;
|
||||
width: 550px;
|
||||
}
|
||||
|
||||
.simpletablestyle img {
|
||||
border:0px;
|
||||
}
|
||||
|
||||
.simpletablestyle td {
|
||||
height:2em;
|
||||
padding-left: 6px;
|
||||
font-size:11px;
|
||||
padding:5px 5px;
|
||||
}
|
||||
|
||||
.simpletablestyle th {
|
||||
background: url(#{request.contextPath}/resources/gfx/bkg-blkheader.png) black repeat-x top left;
|
||||
font-size:12px;
|
||||
font-weight:normal;
|
||||
padding:0 10px 0 5px;
|
||||
border-bottom:#999999 dotted 1px;
|
||||
}
|
||||
|
||||
.simpletablestyle thead {
|
||||
background: url(#{request.contextPath}/resources/gfx/bkg-blkheader.png) black repeat-x top left;
|
||||
height:31px;
|
||||
font-size:10px;
|
||||
font-weight:bold;
|
||||
color:#FFFFFF;
|
||||
text-align:left;
|
||||
}
|
||||
|
||||
.simpletablestyle .header a {
|
||||
color:#94aebd;
|
||||
}
|
||||
|
||||
.simpletablestype tfoot {
|
||||
height: 20px;
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
background-color: #EAECEE;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.simpletablestyle tr.header td {
|
||||
padding: 0px 10px 0px 5px;
|
||||
}
|
||||
|
||||
|
||||
.simpletablestyle .subheader {
|
||||
background-color: #e6e7e8;
|
||||
font-size:10px;
|
||||
font-weight:bold;
|
||||
color:#000000;
|
||||
text-align:left;
|
||||
}
|
||||
|
||||
/* Using new CSS3 selectors for styling*/
|
||||
.simpletablestyle tr:nth-child(odd) {
|
||||
background: #f4f3f3;
|
||||
}
|
||||
.simpletablestyle tr:nth-child(even) {
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.simpletablestyle td a:hover {
|
||||
color:#3883ce;
|
||||
text-decoration:none;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 116 B |
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
* contributors by the @authors tag. See the copyright.txt in the
|
||||
* distribution for a full listing of individual contributors.
|
||||
*
|
||||
* 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 baeldung.test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import baeldung.data.*;
|
||||
import org.jboss.arquillian.container.test.api.Deployment;
|
||||
import org.jboss.arquillian.junit.Arquillian;
|
||||
import baeldung.model.Member;
|
||||
import baeldung.service.MemberRegistration;
|
||||
import baeldung.util.Resources;
|
||||
import org.jboss.shrinkwrap.api.Archive;
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
|
||||
import org.jboss.shrinkwrap.api.spec.WebArchive;
|
||||
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class MemberRegistrationTest {
|
||||
@Deployment
|
||||
public static Archive<?> createTestArchive() {
|
||||
File[] files = Maven.resolver().loadPomFromFile("pom.xml")
|
||||
.importRuntimeDependencies().resolve().withTransitivity().asFile();
|
||||
|
||||
return ShrinkWrap.create(WebArchive.class, "test.war")
|
||||
.addClasses(
|
||||
EntityManagerProducer.class,
|
||||
Member.class,
|
||||
MemberRegistration.class,
|
||||
MemberRepository.class,
|
||||
Resources.class,
|
||||
QueryDslRepositoryExtension.class,
|
||||
QueryDslSupport.class,
|
||||
SecondaryPersistenceUnit.class,
|
||||
SecondaryEntityManagerProducer.class,
|
||||
SecondaryEntityManagerResolver.class)
|
||||
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
|
||||
.addAsResource("META-INF/apache-deltaspike.properties")
|
||||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
|
||||
.addAsWebInfResource("test-ds.xml")
|
||||
.addAsWebInfResource("test-secondary-ds.xml")
|
||||
.addAsLibraries(files);
|
||||
}
|
||||
|
||||
@Inject
|
||||
MemberRegistration memberRegistration;
|
||||
|
||||
@Inject
|
||||
Logger log;
|
||||
|
||||
@Test
|
||||
public void testRegister() throws Exception {
|
||||
Member newMember = new Member();
|
||||
newMember.setName("Jane Doe");
|
||||
newMember.setEmail("jane@mailinator.com");
|
||||
newMember.setPhoneNumber("2125551234");
|
||||
memberRegistration.register(newMember);
|
||||
assertNotNull(newMember.getId());
|
||||
log.info(newMember.getName() + " was persisted with id " + newMember.getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
globalAlternatives.org.apache.deltaspike.jpa.spi.transaction.TransactionStrategy=org.apache.deltaspike.jpa.impl.transaction.BeanManagedUserTransactionStrategy
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.1"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://xmlns.jcp.org/xml/ns/persistence
|
||||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||
<persistence-unit name="primary">
|
||||
<jta-data-source>java:jboss/datasources/baeldung-jee7-seedTestDS</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="hibernate.show_sql" value="false" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
<persistence-unit name="secondary">
|
||||
<jta-data-source>java:jboss/datasources/baeldung-jee7-seedTestSecondaryDS</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
|
||||
<property name="hibernate.show_sql" value="false" />
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
JBoss, Home of Professional Open Source
|
||||
Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
|
||||
contributors by the @authors tag. See the copyright.txt in the
|
||||
distribution for a full listing of individual contributors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<arquillian xmlns="http://jboss.org/schema/arquillian"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://jboss.org/schema/arquillian
|
||||
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
|
||||
|
||||
<!-- Uncomment to have test archives exported to the file system for inspection -->
|
||||
<!-- <engine> -->
|
||||
<!-- <property name="deploymentExportPath">target/</property> -->
|
||||
<!-- </engine> -->
|
||||
|
||||
<!-- Force the use of the Servlet 3.0 protocol with all containers, as it is the most mature -->
|
||||
<defaultProtocol type="Servlet 3.0" />
|
||||
|
||||
<!-- Example configuration for a remote WildFly instance -->
|
||||
<container qualifier="jboss" default="true">
|
||||
<!-- By default, arquillian will use the JBOSS_HOME environment variable. Alternatively, the configuration below can be uncommented. -->
|
||||
<configuration>
|
||||
<property name="jbossHome">target\wildfly-run\wildfly-10.0.0.Final</property>
|
||||
</configuration>
|
||||
</container>
|
||||
|
||||
</arquillian>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
|
||||
<datasource jndi-name="java:jboss/datasources/baeldung-jee7-seedTestDS"
|
||||
pool-name="baeldung-jee7-seed-test" enabled="true"
|
||||
use-java-context="true">
|
||||
<connection-url>jdbc:h2:mem:baeldung-jee7-seed-test;DB_CLOSE_DELAY=-1</connection-url>
|
||||
<driver>h2</driver>
|
||||
<security>
|
||||
<user-name>sa</user-name>
|
||||
<password>sa</password>
|
||||
</security>
|
||||
</datasource>
|
||||
</datasources>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
|
||||
<datasource jndi-name="java:jboss/datasources/baeldung-jee7-seedTestSecondaryDS"
|
||||
pool-name="baeldung-jee7-seed-test" enabled="true"
|
||||
use-java-context="true">
|
||||
<connection-url>jdbc:h2:mem:baeldung-jee7-seed-test;DB_CLOSE_DELAY=-1</connection-url>
|
||||
<driver>h2</driver>
|
||||
<security>
|
||||
<user-name>sa</user-name>
|
||||
<password>sa</password>
|
||||
</security>
|
||||
</datasource>
|
||||
</datasources>
|
||||
|
Loading…
Reference in New Issue