[jboss-cvs] JBossAS SVN: r104593 - in projects/ejb-book/trunk: build and 21 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun May 9 23:51:31 EDT 2010


Author: ALRubinger
Date: 2010-05-09 23:51:31 -0400 (Sun, 09 May 2010)
New Revision: 104593

Added:
   projects/ejb-book/trunk/chxx-poker/
   projects/ejb-book/trunk/chxx-poker/pom.xml
   projects/ejb-book/trunk/chxx-poker/src/
   projects/ejb-book/trunk/chxx-poker/src/main/
   projects/ejb-book/trunk/chxx-poker/src/main/java/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankBean.java
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankLocalBusiness.java
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/InsufficientBalanceException.java
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/PokerGame.java
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/Account.java
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/IdentityBase.java
   projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/User.java
   projects/ejb-book/trunk/chxx-poker/src/main/resources/
   projects/ejb-book/trunk/chxx-poker/src/main/resources/persistence.xml
   projects/ejb-book/trunk/chxx-poker/src/test/
   projects/ejb-book/trunk/chxx-poker/src/test/java/
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerBean.java
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerLocalBusiness.java
   projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/SimpleDeploymentIntegrationTest.java
   projects/ejb-book/trunk/chxx-poker/src/test/resources/
Modified:
   projects/ejb-book/trunk/build/pom.xml
   projects/ejb-book/trunk/pom.xml
Log:
[EJBBOOK-23] Initial commit of Transactional Examples

Modified: projects/ejb-book/trunk/build/pom.xml
===================================================================
--- projects/ejb-book/trunk/build/pom.xml	2010-05-10 01:50:03 UTC (rev 104592)
+++ projects/ejb-book/trunk/build/pom.xml	2010-05-10 03:51:31 UTC (rev 104593)
@@ -17,7 +17,7 @@
 
     <!-- Versioning -->
 
-    <version.junit_junit>4.5</version.junit_junit>
+    <version.junit_junit>4.7</version.junit_junit>
     <version.org.jboss.embedded>1.0.0-alpha-1</version.org.jboss.embedded>
     <version.org.jboss.jbossas>6.0.0.M1</version.org.jboss.jbossas>
     <version.org.jboss.shrinkwrap>1.0.0-alpha-9</version.org.jboss.shrinkwrap>
@@ -27,6 +27,7 @@
     <version.org.jboss.logging_jboss.logging.log4j>2.0.6.GA</version.org.jboss.logging_jboss.logging.log4j>
     <version.org.jboss.logging_jboss.logging.spi>2.0.5.GA</version.org.jboss.logging_jboss.logging.spi>
     <version.org.jboss.arquillian>1.0.0-SNAPSHOT</version.org.jboss.arquillian>
+    <version.org.glassfish>3.0.1-b16</version.org.glassfish>
 
   </properties>
 
@@ -167,14 +168,25 @@
         <version>${version.org.jboss.arquillian}</version>
         <scope>test</scope>
       </dependency>
-      
       <dependency>
+        <groupId>org.jboss.arquillian.container</groupId>
+        <artifactId>arquillian-glassfish-embedded-30</artifactId>
+        <version>${version.org.jboss.arquillian}</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.arquillian.container</groupId>
+        <artifactId>arquillian-jbossas-embedded-60</artifactId>
+        <version>${version.org.jboss.arquillian}</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
         <groupId>org.jboss.arquillian</groupId>
         <artifactId>arquillian-junit</artifactId>
         <version>${version.org.jboss.arquillian}</version>
         <scope>test</scope>
       </dependency>
-     
+      
     </dependencies>
 
   </dependencyManagement>


Property changes on: projects/ejb-book/trunk/chxx-poker
___________________________________________________________________
Name: svn:ignore
   + target
.settings
.classpath
.project
bin


Added: projects/ejb-book/trunk/chxx-poker/pom.xml
===================================================================
--- projects/ejb-book/trunk/chxx-poker/pom.xml	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/pom.xml	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,188 @@
+<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">
+
+  <!-- Parent Information -->
+  <parent>
+    <groupId>org.jboss.ejb3.examples</groupId>
+    <artifactId>jboss-ejb3-examples-build</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <!-- Model Version -->
+  <modelVersion>4.0.0</modelVersion>
+
+  <!-- Artifact Information -->
+  <artifactId>jboss-ejb3-examples-chxx-transactions</artifactId>
+  <name>JBoss EJB 3.x Examples - Chapter XX: Transactional EJBs</name>
+  <description>Example to accompany O'Reilly "Enterprise Java Beans 6th Edition" Chapter XX</description>
+
+  <!-- Build -->
+  <build>
+  </build>
+
+
+  <!-- Properties -->
+  <properties>
+
+    <!-- Versioning -->
+    <!-- JBOSS_HOME (We'll unpack into here -->
+    <JBOSS_HOME>${project.build.directory}/jboss-${version.org.jboss.jbossas}</JBOSS_HOME>
+    <!-- The target version of AS to be used -->
+    <version.org.jboss.jbossas>6.0.0.20100429-M3</version.org.jboss.jbossas>
+
+  </properties>
+
+  <!-- Dependencies -->
+  <dependencies>
+  
+  <!--  
+    <dependency>
+      <groupId>org.jboss.spec.javax.ejb</groupId>
+      <artifactId>jboss-ejb-api_3.1_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  -->
+    <!-- 
+    
+    Test Dependencies
+     -->
+
+    <!-- Arquillian Test Harness -->
+    <dependency>
+      <groupId>org.jboss.arquillian.container</groupId>
+      <artifactId>arquillian-jbossas-embedded-60</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.arquillian</groupId>
+      <artifactId>arquillian-junit</artifactId>
+    </dependency>
+    
+    <!-- JUnit -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    
+    <!-- JBossAS -->
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-depchain</artifactId>
+      <version>${version.org.jboss.jbossas}</version>
+      <type>pom</type>
+      <scope>compile</scope> <!-- Should be "test", but I can't find the GAV for JPA APIs -->
+    </dependency>
+
+  </dependencies>
+  
+  <!--
+    We also need to place the AS depchain into 
+    the "dependencyManagement" section in import scope
+    so that Maven respects the "exclusion" elements
+    configured
+    -->
+  <dependencyManagement>
+    <dependencies>
+  
+      <!-- org.jboss.jbossas -->
+      <dependency>
+        <groupId>org.jboss.jbossas</groupId>
+        <artifactId>jboss-as-depchain</artifactId>
+        <version>${version.org.jboss.jbossas}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+   </dependencies>
+    
+    </dependencyManagement>
+
+  <profiles>
+
+    <profile>
+
+      <!-- Declare the "Integration Test" Profile -->
+      <id>it</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+
+      <build>
+
+        <plugins>
+        
+          <!-- Get AS and put into "target" -->
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-dependency-plugin</artifactId>
+            <executions>
+              <execution>
+                <id>unpack</id>
+                <phase>pre-integration-test</phase> <!-- So run before testing -->
+                <goals>
+                  <goal>unpack</goal>
+                </goals>
+                <configuration>
+                  <artifactItems>
+                    <artifactItem>
+                      <groupId>org.jboss.jbossas</groupId>
+                      <artifactId>jboss-as-distribution</artifactId>
+                      <version>${version.org.jboss.jbossas}</version>
+                      <type>zip</type>
+                      <overWrite>false</overWrite>
+                      <outputDirectory>${project.build.directory}</outputDirectory>
+                    </artifactItem>
+                  </artifactItems>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+         
+
+          <!-- Surefire -->
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <executions>
+              <execution>
+                <id>integration-test</id>
+                <phase>integration-test</phase>
+                <goals>
+                  <goal>test</goal>
+                </goals>
+                <configuration>
+                  <additionalClasspathElements>
+                    <additionalClasspathElement>${JBOSS_HOME}/client/jbossws-native-client.jar</additionalClasspathElement>
+                  </additionalClasspathElements>
+          
+                  <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                  <trimStackTrace>false</trimStackTrace>
+                  <printSummary>true</printSummary>
+                  <includes>
+                    <include>**/*IntegrationTest.java</include>
+                  </includes>
+                  <forkMode>always</forkMode>
+                  <!--
+                    MaxPermSize Required to bump the space for relective
+                    data like classes, methods, etc. EMB-41, EMB-74. Endorsed
+                    required for things like WS support (EMB-61)
+                    
+                    Disable assertions because something is not playing nicely in Hibernate:
+                    (19:58:01,172 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] 
+                      Error installing to Start: name=persistence.unit:unitName=#tempdb state=Create: java.lang.AssertionError
+                         at org.hibernate.cfg.InheritanceState.getElementsToProcess(
+                         InheritanceState.java:222) [hibernate-annotations-3.5.0-CR-1.jar:3.5.0-CR-1])
+                  -->
+                  <argLine>-disableassertions -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djava.endorsed.dirs=${JBOSS_HOME}/lib/endorsed -Djboss.home=${JBOSS_HOME} -Djboss.boot.server.log.dir=${JBOSS_HOME}</argLine>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+
+        </plugins>
+
+      </build>
+
+    </profile>
+
+  </profiles>
+
+</project>


Property changes on: projects/ejb-book/trunk/chxx-poker/pom.xml
___________________________________________________________________
Name: svn:executable
   + *

Added: projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankBean.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankBean.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankBean.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions.api;
+
+import java.math.BigDecimal;
+import java.util.logging.Logger;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityNotFoundException;
+import javax.persistence.PersistenceContext;
+
+import org.jboss.ejb3.annotation.LocalBinding;
+import org.jboss.ejb3.examples.chxx.transactions.entity.Account;
+
+/**
+ * The bank with which users and the Poker provider 
+ * may interact with underlying accounts.  For instance users
+ * may wish to make cash deposits into their personal account, 
+ * or the Poker provider may transfer money from the user's account
+ * to the poker account when the user places a bet.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local(BankLocalBusiness.class)
+ at LocalBinding(jndiBinding = BankLocalBusiness.JNDI_NAME)
+public class BankBean implements BankLocalBusiness
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(BankBean.class.getName());
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * JPA hook
+    */
+   @PersistenceContext
+   private EntityManager em;
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ejb3.examples.chxx.transactions.api.BankLocalBusiness#deposit(long, java.math.BigDecimal)
+    */
+   @Override
+   @TransactionAttribute(TransactionAttributeType.REQUIRED)
+   // Default Tx Attribute; create a new Tx if not present, else use the existing
+   public BigDecimal deposit(long accountId, final BigDecimal amount) throws IllegalArgumentException
+   {
+      // Get the account
+      final Account account = this.getAccount(accountId);
+
+      // Deposit
+      return account.deposit(amount);
+
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ejb3.examples.chxx.transactions.api.BankLocalBusiness#getBalance(long)
+    */
+   @Override
+   @TransactionAttribute(TransactionAttributeType.SUPPORTS)
+   // Don't require a Tx is in play, but respect a currently-operating 
+   // one so we get the correct visibility from inside the Tx
+   public BigDecimal getBalance(long accountId) throws IllegalArgumentException
+   {
+      // Get the account
+      final Account account = this.getAccount(accountId);
+
+      // Return the current balance
+      return account.getBalance();
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ejb3.examples.chxx.transactions.api.BankLocalBusiness#transfer(long, long, java.math.BigDecimal)
+    */
+   @Override
+   @TransactionAttribute(TransactionAttributeType.REQUIRED)
+   // Default Tx Attribute; create a new Tx if not present, else use the existing
+   public void transfer(long accountIdFrom, long accountIdTo, BigDecimal amount) throws IllegalArgumentException,
+         InsufficientBalanceException
+   {
+      // Get the accounts in question
+      final Account accountFrom = this.getAccount(accountIdFrom);
+      final Account accountTo = this.getAccount(accountIdTo);
+
+      // Withdraw (which will throw InsufficientBalance if that's the case)
+      accountFrom.withdraw(amount);
+
+      // And put the money into the new account
+      accountTo.deposit(amount);
+      log.info("Deposited " + amount + " to " + accountTo + " from " + accountFrom);
+
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ejb3.examples.chxx.transactions.api.BankLocalBusiness#withdraw(long, java.math.BigDecimal)
+    */
+   @Override
+   @TransactionAttribute(TransactionAttributeType.REQUIRED)
+   // Default Tx Attribute; create a new Tx if not present, else use the existing
+   public BigDecimal withdraw(long accountId, BigDecimal amount) throws IllegalArgumentException,
+         InsufficientBalanceException
+   {
+      // Get the account
+      final Account account = this.getAccount(accountId);
+
+      // Withdraw
+      return account.withdraw(amount);
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the {@link Account} with the specified ID
+    * 
+    * @throws IllegalArgumentException If the ID does not represent a valid Account
+    */
+   private Account getAccount(final long accountId) throws IllegalArgumentException
+   {
+      // Get the account
+      final Account account;
+      try
+      {
+         account = em.find(Account.class, new Long(accountId));
+      }
+      // Translate the exception; we were given a bad input
+      catch (final EntityNotFoundException enfe)
+      {
+         throw new IllegalArgumentException("Could not find account with ID " + accountId);
+      }
+
+      // Return
+      return account;
+   }
+}

Added: projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankLocalBusiness.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankLocalBusiness.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/BankLocalBusiness.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions.api;
+
+import java.math.BigDecimal;
+
+import org.jboss.ejb3.examples.chxx.transactions.entity.Account;
+
+/**
+ * Defines the contract for a bank
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface BankLocalBusiness
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Constants --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * JNDI Name to which we'll bind
+    */
+   String JNDI_NAME = "BankLocalBusiness";
+
+   //-------------------------------------------------------------------------------------||
+   // Contracts --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Withdraws the specified amount from the account with 
+    * the specified ID, returning the new balance.
+    * @param amount
+    * @throws IllegalArgumentException If the amount is not specified, the account
+    * ID is not valid, or the amount to be withdrawn is less than 0
+    * @throws InsufficientBalanceException If the amount to be withdrawn is greater
+    * than the value of {@link Account#getBalance()}.
+    */
+   BigDecimal withdraw(long accountId, BigDecimal amount) throws IllegalArgumentException, InsufficientBalanceException;
+
+   /**
+    * Deposits the specified amount from the account with the
+    * specified ID, returning the new balance.
+    * @param amount
+    * @throws IllegalArgumentException If the amount is not specified, the account
+    * ID is not valid, or the amount to be deposited is less than 0
+    */
+   BigDecimal deposit(long accountId, BigDecimal amount) throws IllegalArgumentException;
+
+   /**
+    * Obtains the current balance from the account with the specified ID
+    * @param accountId
+    * @return
+    * @throws IllegalArgumentException If the account ID is not valid
+    */
+   BigDecimal getBalance(long accountId) throws IllegalArgumentException;
+
+   /**
+    * Transfers the specified amount from one account to another
+    * @param accountIdFrom The ID of the account from which we'll withdraw
+    * @param accountIdTo The ID of the account to which we'll deposit
+    * @param amount The amount to be transferred
+    * @throws IllegalArgumentException If the amount is not specified, the amount is 
+    *   less that 0, or either account ID is invalid
+    * @throws InsufficientBalanceException If the amount is greater than the current 
+    *   balance of the "from" account
+    */
+   void transfer(long accountIdFrom, long accountIdTo, BigDecimal amount) throws IllegalArgumentException,
+         InsufficientBalanceException;
+}

Added: projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/InsufficientBalanceException.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/InsufficientBalanceException.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/InsufficientBalanceException.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions.api;
+
+import javax.ejb.ApplicationException;
+
+/**
+ * Exception thrown when attempting to invoke an operation that requires
+ * more funds than are currently available
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at ApplicationException(rollback = true)
+public class InsufficientBalanceException extends Exception
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * serialVersionUID
+    */
+   private static final long serialVersionUID = 1L;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates a new {@link InsufficientBalanceException} with the specified message
+    */
+   public InsufficientBalanceException(final String message)
+   {
+      super(message);
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/PokerGame.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/PokerGame.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/api/PokerGame.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions.api;
+
+import java.math.BigDecimal;
+
+import org.jboss.ejb3.examples.chxx.transactions.entity.User;
+
+/**
+ * Contract of a service capable of simulating
+ * a single game of poker.  The actual gameplay is not modeled,
+ * only the inputs and outputs of a single trial. 
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface PokerGame
+{
+   //-------------------------------------------------------------------------------------||
+   // Contracts --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   boolean bet(User user, BigDecimal amount);
+
+}

Added: projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/Account.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/Account.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/Account.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions.entity;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
+
+import org.jboss.ejb3.examples.chxx.transactions.api.InsufficientBalanceException;
+
+/**
+ * Entity representing a bank account; maintains a current balance
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class Account extends IdentityBase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * The owner of the account
+    */
+   @OneToOne(cascade = CascadeType.PERSIST)
+   private User owner;
+
+   /**
+    * Current balance of the account
+    */
+   private BigDecimal balance = new BigDecimal(0, new MathContext(2));
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the balance
+    */
+   public BigDecimal getBalance()
+   {
+      return this.balance;
+   }
+
+   /**
+    * @param balance the balance to set
+    */
+   public void setBalance(final BigDecimal balance)
+   {
+      this.balance = balance;
+   }
+
+   /**
+    * @return the owner
+    */
+   public User getOwner()
+   {
+      return owner;
+   }
+
+   /**
+    * @param owner the owner to set
+    */
+   public void setOwner(final User owner)
+   {
+      this.owner = owner;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Functional Methods -----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Withdraws the specified amount from the account, returning the 
+    * new balance.
+    * @param amount
+    * @throws IllegalArgumentException
+    * @throws InsufficientBalanceException If the amount to be withdrawn is greater
+    * than the value of {@link Account#getBalance()}.
+    */
+   @Transient
+   public BigDecimal withdraw(final BigDecimal amount) throws IllegalArgumentException, InsufficientBalanceException
+   {
+      // Precondition checks
+      if (amount == null)
+      {
+         throw new IllegalArgumentException("amount must be specified");
+      }
+      final BigDecimal current = this.getBalance();
+      if (amount.compareTo(current) == 0)
+      {
+         throw new InsufficientBalanceException("Cannot withdraw " + amount + " from account with " + current);
+      }
+
+      // Subtract and return the new balance
+      final BigDecimal newBalanceShoes = balance.subtract(amount);
+      this.setBalance(newBalanceShoes);
+      return newBalanceShoes;
+   }
+
+   /**
+    * Deposits the specified amount from the account, returning the 
+    * new balance.
+    * @param amount
+    * @throws IllegalArgumentException
+    */
+   @Transient
+   public BigDecimal deposit(final BigDecimal amount) throws IllegalArgumentException
+   {
+      // Precondition checks
+      if (amount == null)
+      {
+         throw new IllegalArgumentException("amount must be specified");
+      }
+
+      // Add and return the new balance
+      final BigDecimal newBalanceShoes = balance.add(amount);
+      this.setBalance(newBalanceShoes);
+      return newBalanceShoes;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      final User owner = this.getOwner();
+      return "Account [id=" + this.getId() + ", balance=" + balance + ", owner="
+            + (owner == null ? "No Owner" : owner.getId()) + "]";
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/IdentityBase.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/IdentityBase.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/IdentityBase.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+/**
+ * Base class for all entities with an ID
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+ at MappedSuperclass
+public abstract class IdentityBase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Primary key 
+    */
+   @Id
+   private Long id;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the id
+    */
+   public Long getId()
+   {
+      return id;
+   }
+
+   /**
+    * @param id the id to set
+    */
+   public void setId(final Long id)
+   {
+      this.id = id;
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/User.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/User.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/java/org/jboss/ejb3/examples/chxx/transactions/entity/User.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions.entity;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.OneToOne;
+
+/**
+ * Entity representing a user of the poker service
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity
+public class User extends IdentityBase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Name of the user
+    */
+   private String name;
+
+   /**
+    * Email address of the user
+    */
+   private String email;
+
+   /**
+    * The user's poker account
+    */
+   @OneToOne(cascade = CascadeType.PERSIST)
+   private Account pokerAccount;
+
+   /**
+    * The user's personal account
+    */
+   @OneToOne(cascade = CascadeType.PERSIST)
+   private Account personalAccount;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the name
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * @param name the name to set
+    */
+   public void setName(final String name)
+   {
+      this.name = name;
+   }
+
+   /**
+    * @return the email
+    */
+   public String getEmail()
+   {
+      return email;
+   }
+
+   /**
+    * @param email the email to set
+    */
+   public void setEmail(final String email)
+   {
+      this.email = email;
+   }
+
+   /**
+    * @return the pokerAccount
+    */
+   public Account getPokerAccount()
+   {
+      return pokerAccount;
+   }
+
+   /**
+    * @param pokerAccount the pokerAccount to set
+    */
+   public void setPokerAccount(Account pokerAccount)
+   {
+      this.pokerAccount = pokerAccount;
+   }
+
+   /**
+    * @return the personalAccount
+    */
+   public Account getPersonalAccount()
+   {
+      return personalAccount;
+   }
+
+   /**
+    * @param personalAccount the personalAccount to set
+    */
+   public void setPersonalAccount(final Account personalAccount)
+   {
+      this.personalAccount = personalAccount;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return "User [id=" + this.getId() + ", email=" + email + ", name=" + name + ", personalAccount="
+            + personalAccount + ", pokerAccount=" + pokerAccount + "]";
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-poker/src/main/resources/persistence.xml
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/main/resources/persistence.xml	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/main/resources/persistence.xml	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+   version="1.0">
+   <persistence-unit name="tempdb">
+      <jta-data-source>java:/DefaultDS</jta-data-source>
+      <properties>
+          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+          <property name="hibernate.show_sql" value="true"/> 
+      </properties>
+   </persistence-unit>
+</persistence>

Added: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerBean.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerBean.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerBean.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions;
+
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb3.annotation.LocalBinding;
+import org.jboss.ejb3.examples.chxx.transactions.entity.Account;
+import org.jboss.ejb3.examples.chxx.transactions.entity.User;
+
+/**
+ * Singleton EJB to initialize and prepropulate
+ * the database state before running tests.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Singleton
+ at Startup
+ at LocalBinding(jndiBinding = DbInitializerLocalBusiness.JNDI_NAME)
+// JBoss-specific JNDI Binding annotation
+public class DbInitializerBean implements DbInitializerLocalBusiness
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(DbInitializerBean.class.getName());
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Hook to interact w/ the database via JPA
+    */
+   @PersistenceContext
+   private EntityManager em;
+
+   /**
+    * Because @PostConstruct runs in an unspecified
+    * Tx context (as invoked by the container), we'll
+    * make one via this manager.
+    */
+   @Resource(mappedName = "java:/TransactionManager")
+   private TransactionManager txManager;
+
+   //-------------------------------------------------------------------------------------||
+   // Functional Methods -----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Called by the container on startup; populates the database with test data.
+    * Because EJB lifecycle operations are invoked outside of a 
+    * transactional context, we manually demarcate the Tx boundaries
+    * via the injected {@link TransactionManager}. 
+    */
+   @PostConstruct
+   public void populateDatabase() throws Exception
+   {
+
+      // See if we need to manage our own Tx (is this called by the container, 
+      // or from "refreshWithDefaultData"?)
+      final Transaction currentTx = txManager.getTransaction();
+      final boolean beanManaged = currentTx == null;
+      // If there's no Tx currently in play, it's on us to manage things
+      if (beanManaged)
+      {
+         // Start a Tx
+         txManager.begin();
+      }
+
+      /*
+       *  Create some users
+       */
+
+      // ALR
+      final User alrubinger = new User();
+      alrubinger.setId(USER_ALRUBINGER_ID);
+      alrubinger.setName(USER_ALRUBINGER_NAME);
+      alrubinger.setEmail(USER_ALRUBINGER_EMAIL);
+      final Account alrubingerPersonalAccount = new Account();
+      alrubingerPersonalAccount.deposit(INITIAL_PERSONAL_ACCOUNT_BALANCE_ALR);
+      alrubingerPersonalAccount.setOwner(alrubinger);
+      alrubingerPersonalAccount.setId(ACCOUNT_ALRUBINGER_PERSONAL_ID);
+      alrubinger.setPersonalAccount(alrubingerPersonalAccount);
+      final Account alrubingerPokerAccount = new Account();
+      alrubingerPokerAccount.setOwner(alrubinger);
+      alrubingerPokerAccount.setId(ACCOUNT_ALRUBINGER_POKER_ID);
+      alrubinger.setPokerAccount(alrubingerPokerAccount);
+
+      // DER
+      final User derudman = new User();
+      derudman.setId(USER_DERUDMAN_ID);
+      derudman.setName(USER_DERUDMAN_NAME);
+      derudman.setEmail(USER_DERUDMAN_EMAIL);
+      final Account derudmanPersonalAccount = new Account();
+      derudmanPersonalAccount.deposit(INITIAL_PERSONAL_ACCOUNT_BALANCE_DER);
+      derudmanPersonalAccount.setOwner(derudman);
+      derudmanPersonalAccount.setId(ACCOUNT_DERUDMAN_PERSONAL_ID);
+      derudman.setPersonalAccount(derudmanPersonalAccount);
+      final Account derudmanPokerAccount = new Account();
+      derudmanPokerAccount.setOwner(derudman);
+      derudmanPokerAccount.setId(ACCOUNT_DERUDMAN_POKER_ID);
+      derudman.setPokerAccount(derudmanPokerAccount);
+
+      // Persist
+      em.persist(alrubinger);
+      log.info("Created: " + alrubinger);
+      em.persist(derudman);
+      log.info("Created: " + derudman);
+
+      // We're done with the Tx; commit and have the EM flush everything out
+      if (beanManaged)
+      {
+         txManager.commit();
+      }
+
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ejb3.examples.chxx.transactions.DbInitializerLocalBusiness#refreshWithDefaultData()
+    */
+   @Override
+   public void refreshWithDefaultData()
+   {
+      // Delete existing data
+      final Collection<Account> accounts = em.createQuery("SELECT o FROM " + Account.class.getSimpleName() + " o",
+            Account.class).getResultList();
+      final Collection<User> users = em.createQuery("SELECT o FROM " + User.class.getSimpleName() + " o", User.class)
+            .getResultList();
+      for (final Account account : accounts)
+      {
+         em.remove(account);
+      }
+      for (final User user : users)
+      {
+         em.remove(user);
+      }
+
+      // Repopulate
+      try
+      {
+         this.populateDatabase();
+      }
+      catch (final Exception e)
+      {
+         throw new RuntimeException("Could not prepopulate DB, may be in inconsistent state", e);
+      }
+
+   }
+}

Added: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerLocalBusiness.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerLocalBusiness.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/DbInitializerLocalBusiness.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions;
+
+import java.math.BigDecimal;
+
+/**
+ * Contract of an EJB which can reset and populate a database with
+ * known data for user tests
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface DbInitializerLocalBusiness
+{
+   //-------------------------------------------------------------------------------------||
+   // Constants --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   
+   /**
+    * Name we'll ind to in JNDI
+    */
+   String JNDI_NAME = "DbInitializer";
+
+   /*
+    * Test Data
+    */
+
+   public static final long USER_ALRUBINGER_ID = 1L;
+
+   public static final String USER_ALRUBINGER_NAME = "Andrew Lee Rubinger";
+
+   public static final String USER_ALRUBINGER_EMAIL = "alr at fake.com";
+
+   public static final long ACCOUNT_ALRUBINGER_PERSONAL_ID = 1L;
+
+   public static final long ACCOUNT_ALRUBINGER_POKER_ID = 2L;
+
+   public static final long USER_DERUDMAN_ID = 2L;
+
+   public static final String USER_DERUDMAN_NAME = "David Edward Rudman";
+
+   public static final String USER_DERUDMAN_EMAIL = "der at fake.com";
+
+   public static final long ACCOUNT_DERUDMAN_PERSONAL_ID = 3L;
+
+   public static final long ACCOUNT_DERUDMAN_POKER_ID = 4L;
+
+   public static final BigDecimal INITIAL_PERSONAL_ACCOUNT_BALANCE_ALR = new BigDecimal(500);
+
+   public static final BigDecimal INITIAL_PERSONAL_ACCOUNT_BALANCE_DER = new BigDecimal(1000);
+
+   //-------------------------------------------------------------------------------------||
+   // Contracts --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Clears and repopulates the database with default test data
+    */
+   void refreshWithDefaultData();
+}

Added: projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/SimpleDeploymentIntegrationTest.java
===================================================================
--- projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/SimpleDeploymentIntegrationTest.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-poker/src/test/java/org/jboss/ejb3/examples/chxx/transactions/SimpleDeploymentIntegrationTest.java	2010-05-10 03:51:31 UTC (rev 104593)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, 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.
+ */
+package org.jboss.ejb3.examples.chxx.transactions;
+
+import java.math.BigDecimal;
+import java.util.logging.Logger;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.api.RunMode;
+import org.jboss.arquillian.api.RunModeType;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.ejb3.examples.chxx.transactions.api.BankLocalBusiness;
+import org.jboss.ejb3.examples.chxx.transactions.entity.User;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Testing dev only 
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at RunWith(Arquillian.class)
+ at RunMode(RunModeType.LOCAL)
+public class SimpleDeploymentIntegrationTest
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(SimpleDeploymentIntegrationTest.class.getName());
+
+   /**
+    * Naming Context
+    */
+   private static Context jndiContext;
+
+   /**
+    * The Deployment into the EJB Container
+    */
+   @Deployment
+   public static JavaArchive getDeployment()
+   {
+      final JavaArchive archive = ShrinkWrap.create("test.jar", JavaArchive.class).addPackages(true,
+            BankLocalBusiness.class.getPackage(), User.class.getPackage()).addManifestResource("persistence.xml")
+            .addClass(DbInitializerBean.class);
+      log.info(archive.toString(true));
+      return archive;
+   }
+
+   /**
+    * Test-only DB initializer to sanitize and prepopulate the DB with each test run
+    */
+   // TODO: Support Injection of @EJB here when Arquillian for Embedded JBossAS will support it
+   private static DbInitializerLocalBusiness dbInitializer;
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /*
+    * TODO: Support Injection of @EJB here when Arquillian for Embedded JBossAS will support it
+    */
+
+   //-------------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Performs suite-wide initialization
+    */
+   @BeforeClass
+   public static void init() throws Exception
+   {
+      // After the server is up, we don't need to pass any explicit properties
+      jndiContext = new InitialContext();
+
+      // Lookup the Singleton initializer and store a reference
+      dbInitializer = (DbInitializerLocalBusiness) jndiContext.lookup(DbInitializerLocalBusiness.JNDI_NAME);
+   }
+
+   /**
+    * Clears and repopulates the database with test data 
+    * after each run
+    * @throws Exception
+    */
+   @After
+   public void refreshWithDefaultData() throws Exception
+   {
+      dbInitializer.refreshWithDefaultData();
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   //-------------------------------------------------------------------------------------||
+   // Functional Methods -----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   @Test
+   public void test() throws Exception
+   {
+
+      final BankLocalBusiness ejb = (BankLocalBusiness) jndiContext.lookup(BankLocalBusiness.JNDI_NAME);
+
+      ejb.transfer(DbInitializerBean.ACCOUNT_ALRUBINGER_PERSONAL_ID, DbInitializerBean.ACCOUNT_ALRUBINGER_POKER_ID,
+            new BigDecimal(100));
+
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+}

Modified: projects/ejb-book/trunk/pom.xml
===================================================================
--- projects/ejb-book/trunk/pom.xml	2010-05-10 01:50:03 UTC (rev 104592)
+++ projects/ejb-book/trunk/pom.xml	2010-05-10 03:51:31 UTC (rev 104593)
@@ -23,6 +23,7 @@
     <module>ch08-messagedestinationlink</module>
     <module>ch09-secureschool</module>
     <module>chxx-interceptors</module>
+    <module>chxx-poker</module>
   </modules>
 
 </project>




More information about the jboss-cvs-commits mailing list