Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions jta-1_2-in-wildfly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
JTA 1.2 in Wildfly example.
==================================================================================================
Author: Gytis Trikleris;
Level: Intermediate;
Technologies: JTA, JPA, JMS

What is it?
-----------

This example demonstrates how to use new JTA 1.2 features inside WildFly application server.


QuickstartEntityRepository and QuickstartQueue classes demonstrace usage of @Transactional annotation.
TransactionScopedPojo class demonstrates @TransactionScoped annotation. TestCase class is used to drive the example.


Build and Deploy the Quickstart
-------------------------------

In order to run quickstart in the managed Wildfly application server, run the following command:

mvn clean install

In order to run quickstart in the remote Wildfly application server, run the following command:

mvn clean install -Parq-jbossas-remote
192 changes: 192 additions & 0 deletions jta-1_2-in-wildfly/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?xml version="1.0"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2014, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<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>org.jboss.narayana.quickstarts</groupId>
<artifactId>jta-1_2-in-wildfly</artifactId>
<version>5.1.0.Alpha1-SNAPSHOT</version>

<name>Narayana Quickstarts: JTA 1.2 in Wildfly</name>
<description>Example demonstrates new JTA 1.2 features inside the Wildfly application server</description>

<url>http://narayana.io</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<jboss-as.version>8.0.1.Final-SNAPSHOT</jboss-as.version>
<version.org.jboss.spec.javax.transaction>1.0.0.Final</version.org.jboss.spec.javax.transaction>
<version.org.jboss.spec.javax.ejb>1.0.0.Final</version.org.jboss.spec.javax.ejb>
<version.org.jboss.spec.javax.jms>1.0.0.Final</version.org.jboss.spec.javax.jms>
<version.org.hibernate.javax.persistence>1.0.0.Final</version.org.hibernate.javax.persistence>
<version.javax.enterprise>1.1</version.javax.enterprise>
<version.junit>4.11</version.junit>
<version.org.jboss.arquillian>1.1.2.Final</version.org.jboss.arquillian>
</properties>

<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>${version.org.jboss.spec.javax.transaction}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<version>${version.org.jboss.spec.javax.ejb}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
<version>${version.org.jboss.spec.javax.jms}</version>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>${version.org.hibernate.javax.persistence}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>${version.javax.enterprise}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${version.org.jboss.arquillian}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<version>${version.org.jboss.arquillian}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<!-- This profile will start a new JBoss AS instance, and execute the test, shutting it down when done -->
<!-- Run with: mvn clean test -->
<id>arq-jbossas-managed</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>${jboss-as.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<!-- An optional Arquillian testing profile that executes tests in a remote JBoss AS instance -->
<!-- Run with: mvn clean test -Parq-jbossas-remote -->
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>${jboss-as.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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 org.jboss.narayana.quickstarts.jta;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
*/
@Entity
public class QuickstartEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;

public QuickstartEntity() {
}

public QuickstartEntity(String name) {
this.name = name;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public boolean isTransient() {
return this.id == null;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, 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 org.jboss.narayana.quickstarts.jta;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.Transactional;
import java.util.List;

/**
* @author <a href="mailto:gytis@redhat.com">Gytis Trikleris</a>
*/
public class QuickstartEntityRepository {

@PersistenceContext
private EntityManager entityManager;

@Transactional
public List<QuickstartEntity> findAll() {
final Query query = entityManager.createQuery("select qe from QuickstartEntity qe");

return (List<QuickstartEntity>) query.getResultList();
}

@Transactional(Transactional.TxType.MANDATORY)
public Long save(QuickstartEntity quickstartEntity) {
if (quickstartEntity.isTransient()) {
entityManager.persist(quickstartEntity);
} else {
entityManager.merge(quickstartEntity);
}

return quickstartEntity.getId();
}
}
Loading