BAEL-150 - deltaspike, minor changes

This commit is contained in:
slavisa-baeldung 2016-08-23 23:46:27 +02:00
parent ca84ed7ff0
commit 9dc17848a5
8 changed files with 19 additions and 82 deletions

View File

@ -1,22 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>deltaspike</artifactId> <artifactId>deltaspike</artifactId>
@ -313,43 +297,5 @@
</dependency> </dependency>
</dependencies> </dependencies>
</profile> </profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests
in a remote WildFly instance -->
<!-- Run with: mvn clean test -Parq-wildfly-remote -->
<id>arq-wildfly-remote</id>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app
will need. -->
<!-- By default that is to put the resulting archive into the 'deployments'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles> </profiles>
</project> </project>

View File

@ -10,23 +10,19 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit; import javax.persistence.PersistenceUnit;
@ApplicationScoped @ApplicationScoped
public class EntityManagerProducer public class EntityManagerProducer {
{
@PersistenceUnit(unitName = "primary") @PersistenceUnit(unitName = "primary")
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
@Produces @Produces
@Default @Default
@RequestScoped @RequestScoped
public EntityManager create() public EntityManager create() {
{
return this.entityManagerFactory.createEntityManager(); return this.entityManagerFactory.createEntityManager();
} }
public void dispose(@Disposes @Default EntityManager entityManager) public void dispose(@Disposes @Default EntityManager entityManager) {
{ if (entityManager.isOpen()) {
if (entityManager.isOpen())
{
entityManager.close(); entityManager.close();
} }
} }

View File

@ -10,8 +10,7 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit; import javax.persistence.PersistenceUnit;
@ApplicationScoped @ApplicationScoped
public class SecondaryEntityManagerProducer public class SecondaryEntityManagerProducer {
{
@PersistenceUnit(unitName = "secondary") @PersistenceUnit(unitName = "secondary")
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
@ -19,15 +18,12 @@ public class SecondaryEntityManagerProducer
@Default @Default
@RequestScoped @RequestScoped
@SecondaryPersistenceUnit @SecondaryPersistenceUnit
public EntityManager create() public EntityManager create() {
{
return this.entityManagerFactory.createEntityManager(); return this.entityManagerFactory.createEntityManager();
} }
public void dispose(@Disposes @Default EntityManager entityManager) public void dispose(@Disposes @Default EntityManager entityManager) {
{ if (entityManager.isOpen()) {
if (entityManager.isOpen())
{
entityManager.close(); entityManager.close();
} }
} }

View File

@ -22,7 +22,7 @@ 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 * A class extending {@link Application} and annotated with @ApplicationPath is the Java EE 7 "no XML" approach to activating
* JAX-RS. * JAX-RS.
* * <p>
* <p> * <p>
* Resources are served relative to the servlet path specified in the {@link ApplicationPath} annotation. * Resources are served relative to the servlet path specified in the {@link ApplicationPath} annotation.
* </p> * </p>

View File

@ -128,10 +128,10 @@ public class MemberResourceRESTService {
* If the error is caused because an existing member with the same email is registered it throws a regular validation * 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. * exception so that it can be interpreted separately.
* </p> * </p>
* *
* @param member Member to be validated * @param member Member to be validated
* @throws ConstraintViolationException If Bean Validation errors exist * @throws ConstraintViolationException If Bean Validation errors exist
* @throws ValidationException If member with the same email already exists * @throws ValidationException If member with the same email already exists
*/ */
private void validateMember(Member member) throws ConstraintViolationException, ValidationException { private void validateMember(Member member) throws ConstraintViolationException, ValidationException {
// Create a bean validator and check for issues. // Create a bean validator and check for issues.
@ -150,7 +150,7 @@ public class MemberResourceRESTService {
/** /**
* Creates a JAX-RS "Bad Request" response including a map of all violation fields, and their message. This can then be used * 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. * by clients to show violations.
* *
* @param violations A set of violations that needs to be reported * @param violations A set of violations that needs to be reported
* @return JAX-RS response containing all violations * @return JAX-RS response containing all violations
*/ */
@ -169,7 +169,7 @@ public class MemberResourceRESTService {
/** /**
* Checks if a member with the same email address is already registered. This is the only way to easily capture the * 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. * "@UniqueConstraint(columnNames = "email")" constraint from the Member class.
* *
* @param email The email to check * @param email The email to check
* @return True if the email already exists, and false otherwise * @return True if the email already exists, and false otherwise
*/ */

View File

@ -27,11 +27,11 @@ import javax.persistence.PersistenceContext;
/** /**
* This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans * This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans
* * <p>
* <p> * <p>
* Example injection on a managed bean field: * Example injection on a managed bean field:
* </p> * </p>
* * <p>
* <pre> * <pre>
* &#064;Inject * &#064;Inject
* private EntityManager em; * private EntityManager em;

View File

@ -18,5 +18,4 @@
<property name="hibernate.show_sql" value="false" /> <property name="hibernate.show_sql" value="false" />
</properties> </properties>
</persistence-unit> </persistence-unit>
</persistence> </persistence>

View File

@ -31,9 +31,9 @@
<!-- Example configuration for a remote WildFly instance --> <!-- Example configuration for a remote WildFly instance -->
<container qualifier="jboss" default="true"> <container qualifier="jboss" default="true">
<!-- By default, arquillian will use the JBOSS_HOME environment variable. Alternatively, the configuration below can be uncommented. --> <!-- By default, arquillian will use the JBOSS_HOME environment variable. Alternatively, the configuration below can be uncommented. -->
<!--<configuration> --> <configuration>
<!--<property name="jbossHome">/path/to/wildfly</property> --> <property name="jbossHome">target\wildfly-run\wildfly-10.0.0.Final</property>
<!--</configuration> --> </configuration>
</container> </container>
</arquillian> </arquillian>