From 92a0facfb1edff30665276b49f45fd7ed23c2f55 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Thu, 20 Nov 2014 20:37:21 -0500 Subject: [PATCH] Simplified some of examples so they have fewer dependencies on jboss and JTA as a whole. --- pom.xml | 9 +- .../grail/graph/hibernate/DogBreedTest.java | 80 ++++------- src/test/resources/META-INF/persistence.xml | 8 +- src/test/resources/jbossts-properties.xml | 130 ------------------ 4 files changed, 34 insertions(+), 193 deletions(-) delete mode 100644 src/test/resources/jbossts-properties.xml diff --git a/pom.xml b/pom.xml index ecaac8e..b989387 100644 --- a/pom.xml +++ b/pom.xml @@ -71,16 +71,11 @@ <artifactId>hibernate-ogm-infinispan</artifactId> <version>4.1.0.Beta8</version> </dependency> - <dependency> - <groupId>org.jboss.spec.javax.transaction</groupId> - <artifactId>jboss-transaction-api_1.2_spec</artifactId> - <version>1.0.0.Final</version> - </dependency> - <dependency> + <!--dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> <version>1.0.0.Final</version> - </dependency> + </dependency--> <dependency> <groupId>org.jboss.jbossts</groupId> <artifactId>jbossjta</artifactId> diff --git a/src/test/java/com/syncleus/grail/graph/hibernate/DogBreedTest.java b/src/test/java/com/syncleus/grail/graph/hibernate/DogBreedTest.java index 145c3df..2a2c4f9 100644 --- a/src/test/java/com/syncleus/grail/graph/hibernate/DogBreedTest.java +++ b/src/test/java/com/syncleus/grail/graph/hibernate/DogBreedTest.java @@ -9,69 +9,45 @@ import org.junit.Test; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; import javax.persistence.Persistence; -import javax.transaction.TransactionManager; -import java.lang.reflect.InvocationTargetException; public class DogBreedTest { - private static final String JBOSS_TM_CLASS_NAME = "com.arjuna.ats.jta.TransactionManager"; private static final Log logger = LoggerFactory.make(); @Test public void testMain() { - - TransactionManager tm = getTransactionManager(); - //build the EntityManagerFactory as you would build in in Hibernate Core EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ogm-jpa-tutorial" ); //Persist entities the way you are used to in plain JPA - try { - tm.begin(); - EntityManager em = emf.createEntityManager(); - Breed collie = new Breed(); - collie.setName( "Collie" ); - em.persist( collie ); - Dog dina = new Dog(); - dina.setName( "Dina" ); - dina.setBreed( collie ); - em.persist( dina ); - Long dinaId = dina.getId(); - em.flush(); - em.close(); - tm.commit(); - - //Retrieve your entities the way you are used to in plain JPA - tm.begin(); - em = emf.createEntityManager(); - dina = em.find( Dog.class, dinaId ); - Assert.assertEquals("Dina", dina.getName()); - Assert.assertEquals("Collie", dina.getBreed().getName()); - em.flush(); - em.close(); - tm.commit(); - - emf.close(); - } catch ( Exception e ) { - e.printStackTrace(); - } - - } - - public static TransactionManager getTransactionManager() { - try { - Class<?> tmClass = DogBreedTest.class.getClassLoader().loadClass( JBOSS_TM_CLASS_NAME ); - return (TransactionManager) tmClass.getMethod( "transactionManager" ).invoke( null ); - } catch ( ClassNotFoundException e ) { - e.printStackTrace(); - } catch ( InvocationTargetException e ) { - e.printStackTrace(); - } catch ( NoSuchMethodException e ) { - e.printStackTrace(); - } catch ( IllegalAccessException e ) { - e.printStackTrace(); - } - return null; + EntityManager em = emf.createEntityManager(); + EntityTransaction tm = em.getTransaction(); + tm.begin(); + Breed collie = new Breed(); + collie.setName( "Collie" ); + em.persist( collie ); + Dog dina = new Dog(); + dina.setName( "Dina" ); + dina.setBreed( collie ); + em.persist( dina ); + Long dinaId = dina.getId(); + em.flush(); + em.close(); + tm.commit(); + + //Retrieve your entities the way you are used to in plain JPA + em = emf.createEntityManager(); + tm = em.getTransaction(); + tm.begin(); + dina = em.find( Dog.class, dinaId ); + Assert.assertEquals("Dina", dina.getName()); + Assert.assertEquals("Collie", dina.getBreed().getName()); + em.flush(); + em.close(); + tm.commit(); + + emf.close(); } } diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 476708a..a67dbc4 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> - <persistence-unit name="ogm-jpa-tutorial" transaction-type="JTA"> + <persistence-unit name="ogm-jpa-tutorial" transaction-type="RESOURCE_LOCAL"> <!-- Use Hibernate OGM provider: configuration will be transparent --> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> <properties> @@ -13,9 +13,9 @@ <property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.infinispan.impl.InfinispanDatastoreProvider"/> --> - <!-- defines which JTA Transaction we plan to use --> - <property name="hibernate.transaction.jta.platform" - value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/> + <!-- defines which JTA Transaction we plan to use, blank for no JPA --> + <!--property name="hibernate.transaction.jta.platform" + value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/--> </properties> </persistence-unit> </persistence> \ No newline at end of file diff --git a/src/test/resources/jbossts-properties.xml b/src/test/resources/jbossts-properties.xml deleted file mode 100644 index 96b00b0..0000000 --- a/src/test/resources/jbossts-properties.xml +++ /dev/null @@ -1,130 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> -<!-- - ~ Hibernate OGM, Domain model persistence for NoSQL datastores - ~ - ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later - ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. - ~ - ~ - ~ @author JBoss, a division of Red Hat. - --> -<properties> - <!-- - This is the JBossTS configuration file for running ArjunaJTA. - It should be called jbossts-properties.xml. - You need a different version for ArjunaCore or JTS usage. - - *************************** - - Property values may be literals or be tokens of the form ${p1[,p2][:v]} - in which case the token values are substituted for the values of the corresponding system - properties as follows: - - - Any occurance of ${p} with the System.getProperty(p) value. - If there is no such property p defined, then the ${p} reference will remain unchanged. - - - If the property reference is of the form ${p:v} and there is no such property p, - then the default value v will be returned. - - - If the property reference is of the form ${p1,p2} or ${p1,p2:v} then - the primary and the secondary properties will be tried in turn, before - returning either the unchanged input, or the default value. - - The property ${/} is replaced with System.getProperty("file.separator") - value and the property ${:} is replaced with System.getProperty("path.separator"). - - Note this substitution applies to property values only at the point they are read from - the config file. Tokens in system properties won't be substituted. - --> - - <!-- Disable to avoid creating temporary transaction logs on disk (default is YES) --> - <entry key="CoordinatorEnvironmentBean.transactionStatusManagerEnable">NO</entry> - - <!-- (default is YES) --> - <entry key="CoordinatorEnvironmentBean.commitOnePhase">YES</entry> - - <!-- default is under user.home - must be writeable!) - <entry key="ObjectStoreEnvironmentBean.objectStoreDir">PutObjectStoreDirHere</entry> --> - - <!-- The VolatileStore won't be able to recover anything - use only for simple tests! --> - <entry key="ObjectStoreEnvironmentBean.objectStoreType">com.arjuna.ats.internal.arjuna.objectstore.VolatileStore</entry> - - <!-- (default is ON) --> - <entry key="ObjectStoreEnvironmentBean.transactionSync">ON</entry> - - <!-- (Must be unique across all Arjuna instances.) --> - <entry key="CoreEnvironmentBean.nodeIdentifier">1</entry> - - <!-- Which Xid types to recover --> - <entry key="JTAEnvironmentBean.xaRecoveryNodes">1</entry> - - <entry key="JTAEnvironmentBean.xaResourceOrphanFilterClassNames"> - com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter - com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter - </entry> - - <!-- - Base port number for determining a unique number to associate with an instance of the transaction service - (which is needed in order to support multiple instances on the same machine). - Use the value 0 to allow the system to select the first available port number. - If the port number is non-zero and the port is in use then the value will be incremented until either a successful binding - to the loopback address is created or until the the maximum number of ports (specified by the - CoreEnvironmentBean.socketProcessIdMaxPorts property) have been tried or until the port number - reaches the maximum possible port number. - --> - <entry key="CoreEnvironmentBean.socketProcessIdPort">0</entry> - - <!-- - Periodic recovery modules to use. Invoked in the order they appear in the list. - Check http://www.jboss.org/community/docs/DOC-10788 for more information - on recovery modules and their configuration when running in various - deployments. - --> - <entry key="RecoveryEnvironmentBean.recoveryModuleClassNames"> - com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule - com.arjuna.ats.internal.txoj.recovery.TORecoveryModule - com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule - </entry> - - <!-- Expiry scanners to use (order of invocation is random). --> - <entry key="RecoveryEnvironmentBean.expiryScannerClassNames"> - com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner - </entry> - - <!-- - Add the following to the set of expiryScannerClassNames above to move logs that cannot be completed by failure recovery. - But be sure you know what you are doing and why! - com.arjuna.ats.internal.arjuna.recovery.AtomicActionExpiryScanner - --> - - <!-- - The address and port number on which the recovery manager listens - If running within an AS then the address the AS is bound to (jboss.bind.address) takes precedence - --> - <entry key="RecoveryEnvironmentBean.recoveryPort">4712</entry> - - <entry key="RecoveryEnvironmentBean.recoveryAddress">127.0.0.1</entry> - - <!-- - Use this to fix the port on which the TransactionStatusManager listens, - The default behaviour is to use any free port. - --> - <entry key="RecoveryEnvironmentBean.transactionStatusManagerPort">0</entry> - - <!-- - Use this to fix the address on which the TransactionStatusManager binds, - The default behaviour is to use the loopback address (ie localhost). - If running within an AS then the address the AS is bound to (jboss.bind.address) takes precedence - --> - <entry key="RecoveryEnvironmentBean.transactionStatusManagerAddress">127.0.0.1</entry> - - <!-- - For cases where the recovery manager is in process with the transaction manager and nothing else uses - the ObjectStore, it is possible to disable the socket based recovery listener by setting this to NO. - Caution: use of this property can allow multiple recovery processes to run on the same ObjectStore - if you are not careful. That in turn can lead to incorrect transaction processing. Use with care. - --> - <entry key="RecoveryEnvironmentBean.recoveryListener">NO</entry> - -</properties> -- GitLab