You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@onami.apache.org by sc...@apache.org on 2013/11/15 00:19:37 UTC

svn commit: r1542116 [1/3] - in /onami/sandbox/persist: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/onami/ src/main/java/org/apache/onami/persist/ src/test/ src/test/java/ src/test/java/org/ sr...

Author: sclassen
Date: Thu Nov 14 23:19:36 2013
New Revision: 1542116

URL: http://svn.apache.org/r1542116
Log:
Added first version of onami-persist.
For previous history of the code see: https://github.com/sclassen/guice-jpa

Added:
    onami/sandbox/persist/   (with props)
    onami/sandbox/persist/LICENSE   (with props)
    onami/sandbox/persist/NOTICE   (with props)
    onami/sandbox/persist/pom.xml   (with props)
    onami/sandbox/persist/src/
    onami/sandbox/persist/src/main/
    onami/sandbox/persist/src/main/java/
    onami/sandbox/persist/src/main/java/org/
    onami/sandbox/persist/src/main/java/org/apache/
    onami/sandbox/persist/src/main/java/org/apache/onami/
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceService.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitBuilder.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceUnitContainer.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/Preconditions.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/ResourceLocalTxnInterceptor.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionFacade.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionType.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/Transactional.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/TransactionalAnnotationReader.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/UnitOfWork.java   (with props)
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/UserTransactionFacade.java   (with props)
    onami/sandbox/persist/src/test/
    onami/sandbox/persist/src/test/java/
    onami/sandbox/persist/src/test/java/org/
    onami/sandbox/persist/src/test/java/org/apache/
    onami/sandbox/persist/src/test/java/org/apache/onami/
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/NestedTransactionTest.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/SingleTransactionTest.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/TransactionTestEntity.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/TransactionalTask.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/TransactionalWorker.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/exceptions/
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/exceptions/RuntimeTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/exceptions/TestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnAnyThrowingNone.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnAnyThrowingRuntimeTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnAnyThrowingTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnNoneThrowingNone.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnNoneThrowingRuntimeTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnNoneThrowingTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnRuntimeTestExceptionThrowingNone.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnRuntimeTestExceptionThrowingRuntimeTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnRuntimeTestExceptionThrowingTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnTestExceptionThrowingNone.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnTestExceptionThrowingRuntimeTestException.java   (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/testframework/tasks/TaskRollingBackOnTestExceptionThrowingTestException.java   (with props)
    onami/sandbox/persist/src/test/resources/
    onami/sandbox/persist/src/test/resources/META-INF/
    onami/sandbox/persist/src/test/resources/META-INF/persistence.xml   (with props)
    onami/sandbox/persist/src/test/resources/log4j.properties   (with props)

Propchange: onami/sandbox/persist/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov 14 23:19:36 2013
@@ -0,0 +1,3 @@
+.idea
+target
+*.iml

Added: onami/sandbox/persist/LICENSE
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/LICENSE?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/LICENSE (added)
+++ onami/sandbox/persist/LICENSE Thu Nov 14 23:19:36 2013
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
\ No newline at end of file

Propchange: onami/sandbox/persist/LICENSE
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/LICENSE
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: onami/sandbox/persist/LICENSE
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/NOTICE
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/NOTICE?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/NOTICE (added)
+++ onami/sandbox/persist/NOTICE Thu Nov 14 23:19:36 2013
@@ -0,0 +1,5 @@
+Apache Onami-Persist
+Copyright 2013 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).

Propchange: onami/sandbox/persist/NOTICE
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/NOTICE
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: onami/sandbox/persist/NOTICE
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/pom.xml
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/pom.xml?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/pom.xml (added)
+++ onami/sandbox/persist/pom.xml Thu Nov 14 23:19:36 2013
@@ -0,0 +1,180 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ | Licensed to the Apache Software Foundation (ASF) under one
+ | or more contributor license agreements.  See the NOTICE file
+ | distributed with this work for additional information
+ | regarding copyright ownership.  The ASF licenses this file
+ | to you 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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.onami</groupId>
+    <artifactId>org.apache.onami.parent</artifactId>
+    <version>4</version>
+  </parent>
+
+  <artifactId>onami-persist</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>Apache Onami Persistence</name>
+  <description>Apache Onami Persistence is a Google Guice extension for JPA with support of container managed persistence units and transactions.</description>
+  <url>http://onami.apache.org/persist</url>
+  <inceptionYear>2013</inceptionYear>
+
+  <scm>
+    <url>https://svn.apache.org/viewvc/onami/trunk/sandbox/persist</url>
+    <connection>scm:svn:https://svn.apache.org/repos/asf/onami/trunk/sandbox/persist</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/onami/trunk/sandbox/persist</developerConnection>
+    <tag>HEAD</tag>
+  </scm>
+
+  <distributionManagement>
+    <site>
+      <id>apache.website.svnpub</id>
+      <url>scm:svn:https://svn.apache.org/repos/asf/onami/site/persist</url>
+    </site>
+  </distributionManagement>
+  <issueManagement>
+    <system>JIRA</system>
+    <url>https://issues.apache.org/jira/browse/ONAMI/component/?????</url> <!-- TODO -->
+  </issueManagement>
+  <ciManagement>
+    <system>Jenkins</system>
+    <url>https://builds.apache.org/job/?????/</url> <!-- TODO -->
+    <notifiers>
+      <notifier>
+        <type>mail</type>
+        <sendOnError>true</sendOnError>
+        <sendOnFailure>true</sendOnFailure>
+        <sendOnSuccess>false</sendOnSuccess>
+        <sendOnWarning>false</sendOnWarning>
+        <configuration>
+          <address>dev@onami.apache.org</address>
+        </configuration>
+      </notifier>
+    </notifiers>
+  </ciManagement>
+
+  <dependencies>
+    <dependency>
+      <groupId>com.google.inject</groupId>
+      <artifactId>guice</artifactId>
+      <version>3.0</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.hibernate.javax.persistence</groupId>
+      <artifactId>hibernate-jpa-2.0-api</artifactId>
+      <version>1.0.1.Final</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.transaction</groupId>
+      <artifactId>transaction-api</artifactId>
+      <version>1.1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <version>3.0.1</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.10</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.7.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-entitymanager</artifactId>
+      <version>4.1.7.Final</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hsqldb</groupId>
+      <artifactId>hsqldb-j5</artifactId>
+      <version>2.0.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+      <version>13.0.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-site-plugin</artifactId>
+        <configuration>
+          <locales>en</locales>
+          <skipDeploy>true</skipDeploy>
+        </configuration>
+        <executions>
+          <execution>
+            <id>attach-descriptor</id>
+            <goals>
+              <goal>attach-descriptor</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>stage-for-scm-publish</id>
+            <phase>post-site</phase>
+            <goals>
+              <goal>stage</goal>
+            </goals>
+            <configuration>
+              <skipDeploy>false</skipDeploy>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-scm-publish-plugin</artifactId>
+        <inherited>false</inherited>
+        <configuration>
+          <checkinComment>Onami Persist site deployment</checkinComment>
+          <checkoutDirectory>${user.home}/onami-sites/?????</checkoutDirectory> <!-- TODO -->
+        </configuration>
+        <executions>
+          <execution>
+            <id>scm-publish</id>
+            <phase>site-deploy</phase>
+            <goals>
+              <goal>publish-scm</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: onami/sandbox/persist/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: onami/sandbox/persist/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,251 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import com.google.inject.PrivateModule;
+import com.google.inject.TypeLiteral;
+import com.google.inject.binder.LinkedBindingBuilder;
+import org.aopalliance.intercept.MethodInterceptor;
+
+import javax.persistence.EntityManager;
+import java.lang.annotation.Annotation;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Abstract super class of {@link ApplicationManagedPersistenceUnitModule} and
+ * {@link ContainerManagedPersistenceUnitModule}.
+ */
+abstract class AbstractPersistenceUnitModule
+    extends PrivateModule
+{
+
+    // ---- Members
+
+    /**
+     * The provider for {@link EntityManager}.
+     */
+    private final EntityManagerProviderImpl emProvider;
+
+    /**
+     * The annotation for this persistence unit. May be {@code null}.
+     */
+    private Class<? extends Annotation> annotation;
+
+    /**
+     * The method interceptor for transactional methods.
+     */
+    private MethodInterceptor transactionInterceptor;
+
+    /**
+     * This defines if the PU uses resource local or jta transactions.
+     */
+    private TransactionType transactionType = TransactionType.RESOURCE_LOCAL;
+
+    // ---- Constructors
+
+    /**
+     * Constructor.
+     *
+     * @param emProvider the provider for {@link EntityManager}. Must not be {@code null}.
+     */
+    AbstractPersistenceUnitModule( EntityManagerProviderImpl emProvider )
+    {
+        checkNotNull( emProvider );
+
+        this.emProvider = emProvider;
+    }
+
+    // ---- Methods
+
+    /**
+     * @return the persistence service for the persistence unit.
+     */
+    abstract PersistenceService getPersistenceService();
+
+    /**
+     * @return the unit of work for the persistence unit.
+     */
+    final UnitOfWork getUnitOfWork()
+    {
+        return emProvider;
+    }
+
+    /**
+     * @return the type of transaction used for the persistence unit.
+     */
+    final TransactionType getTransactionType()
+    {
+        return transactionType;
+    }
+
+    /**
+     * Sets the type of transaction to use for the persistence unit.
+     *
+     * @param transactionType the type of transaction. Must not be {@code null}.
+     */
+    final void setTransactionType( TransactionType transactionType )
+    {
+        checkNotNull( transactionType );
+        this.transactionType = transactionType;
+    }
+
+    /**
+     * The method interceptor for intercepting transactional methods.
+     *
+     * @param utFacade the {@link UserTransactionFacade}.
+     *                 May be {@code null} if {@link #transactionType} is {@link TransactionType#RESOURCE_LOCAL}.
+     * @return the interceptor for intercepting transactional methods.
+     */
+    final MethodInterceptor getTransactionInterceptor( UserTransactionFacade utFacade )
+    {
+        if ( null == transactionInterceptor )
+        {
+            transactionInterceptor = getTxnInterceptor( utFacade );
+        }
+        return transactionInterceptor;
+    }
+
+    /**
+     * Returns the appropriate interceptor depending on the value of {@link #transactionType}.
+     *
+     * @param utFacade the {@link UserTransactionFacade}.
+     *                 May be {@code null} if {@link #transactionType} is {@link TransactionType#RESOURCE_LOCAL}.
+     * @return the interceptor for intercepting transactional methods. Never {@code null}.
+     */
+    private MethodInterceptor getTxnInterceptor( UserTransactionFacade utFacade )
+    {
+        if ( TransactionType.RESOURCE_LOCAL == transactionType )
+        {
+            return new ResourceLocalTxnInterceptor( emProvider, getAnnotation() );
+        }
+        if ( TransactionType.JTA == transactionType )
+        {
+            checkNotNull( utFacade, "the JNDI name of the user transaction must be specified if a "
+                + "persistence unit wants to use JTA transactions" );
+            return new JtaTxnInterceptor( emProvider, getAnnotation(), utFacade );
+        }
+
+        throw new IllegalStateException( "invalid transaction type: " + transactionType );
+    }
+
+    /**
+     * Binds the given type annotated with the annotation of this persistence unit and
+     * exposes it at the same time.
+     *
+     * @param type the type to bind and expose.
+     * @return the bindingBuilder to define what to bind the given type to.
+     */
+    protected final <T> LinkedBindingBuilder<T> bindAndExpose( TypeLiteral<T> type )
+    {
+        if ( null != annotation )
+        {
+            expose( type ).annotatedWith( annotation );
+            return bind( type ).annotatedWith( annotation );
+        }
+        else
+        {
+            expose( type );
+            return bind( type );
+        }
+    }
+
+    /**
+     * Binds the given type annotated with the annotation of this persistence unit and exposes
+     * it at the same time.
+     *
+     * @param type the type to bind and expose.
+     * @return the bindingBuilder to define what to bind the given type to.
+     */
+    protected final <T> LinkedBindingBuilder<T> bindAndExpose( Class<T> type )
+    {
+        if ( null != annotation )
+        {
+            expose( type ).annotatedWith( annotation );
+            return bind( type ).annotatedWith( annotation );
+        }
+        else
+        {
+            expose( type );
+            return bind( type );
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected final void configure()
+    {
+        bind( UnitOfWork.class ).toInstance( emProvider );
+        bind( EntityManagerProvider.class ).toInstance( emProvider );
+        bind( PersistenceService.class ).toInstance( getPersistenceService() );
+
+        if ( null == annotation )
+        {
+            expose( UnitOfWork.class );
+            expose( EntityManagerProvider.class );
+            expose( PersistenceService.class );
+        }
+        else
+        {
+            bind( UnitOfWork.class ).annotatedWith( annotation ).toInstance( emProvider );
+            bind( EntityManagerProvider.class ).annotatedWith( annotation ).toInstance( emProvider );
+            bind( PersistenceService.class ).annotatedWith( annotation ).toInstance( getPersistenceService() );
+
+            expose( UnitOfWork.class ).annotatedWith( annotation );
+            expose( EntityManagerProvider.class ).annotatedWith( annotation );
+            expose( PersistenceService.class ).annotatedWith( annotation );
+        }
+
+        configurePersistence();
+    }
+
+    /**
+     * Subclasses can overwrite this method to bind (and expose) classes within the context of the
+     * private module which defines the current persistence unit.
+     */
+    protected void configurePersistence()
+    {
+        // do nothing
+    }
+
+    /**
+     * Setter for the annotation of the current persistence unit. The annotation is used to expose
+     * the {@link UnitOfWork}, the {@link EntityManagerProvider} and the {@link PersistenceService}.
+     * If the passed in annotation is {@code null} the above classes will be exposed without an annotation.
+     * This does not work if more than one persistence unit is configured.
+     *
+     * @param annotation the annotation to use for binding the current persistence unit.
+     */
+    final void annotatedWith( Class<? extends Annotation> annotation )
+    {
+        this.annotation = annotation;
+    }
+
+    /**
+     * @return the annotation used for binding the current persistence unit.
+     */
+    final Class<? extends Annotation> getAnnotation()
+    {
+        return annotation;
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,232 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+
+import javax.persistence.EntityManager;
+import java.lang.annotation.Annotation;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Abstract super class for all @{@link Transactional} annotation interceptors.
+ */
+abstract class AbstractTxnInterceptor
+    implements MethodInterceptor
+{
+
+    // ---- Members
+
+    /**
+     * Unit of work.
+     */
+    private final UnitOfWork unitOfWork;
+
+    /**
+     * Provider for {@link EntityManager}.
+     */
+    private final EntityManagerProvider emProvider;
+
+    /**
+     * Annotation of the persistence unit this interceptor belongs to.
+     */
+    private final Class<? extends Annotation> puAnntoation;
+
+    private final TransactionalAnnotationReader transactionalAnnotationReader = new TransactionalAnnotationReader();
+
+    // ---- Constructor
+
+    /**
+     * Constructor.
+     *
+     * @param emProvider   the provider for {@link EntityManager}. Must not be {@code null}.
+     * @param unitOfWork   the unit of work. Must not be {@code null}.
+     * @param puAnntoation the annotation of the persistence unit the interceptor belongs to.
+     *                     May be {@code null}.
+     */
+    public AbstractTxnInterceptor( EntityManagerProvider emProvider, UnitOfWork unitOfWork,
+                                   Class<? extends Annotation> puAnntoation )
+    {
+        checkNotNull( unitOfWork );
+        checkNotNull( emProvider );
+
+        this.unitOfWork = unitOfWork;
+        this.emProvider = emProvider;
+        this.puAnntoation = puAnntoation;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public final Object invoke( MethodInvocation methodInvocation )
+        throws Throwable
+    {
+
+        if ( !transactionCoversThisPersistenceUnit( methodInvocation ) )
+        {
+            return methodInvocation.proceed();
+        }
+
+        final boolean weStartedTheUnitOfWork = !unitOfWork.isActive();
+        if ( weStartedTheUnitOfWork )
+        {
+            unitOfWork.begin();
+        }
+
+        try
+        {
+            final EntityManager em = emProvider.get();
+            final TransactionFacade transactionFacade = getTransactionFacade( em );
+
+            return invoke( methodInvocation, transactionFacade );
+        }
+        finally
+        {
+            if ( weStartedTheUnitOfWork )
+            {
+                unitOfWork.end();
+            }
+        }
+    }
+
+    /**
+     * Check whether the persistence unit of this interceptor participates in the transaction or not.
+     *
+     * @param methodInvocation the original method invocation.
+     * @return {@code true} if the persistence unit participates in the transaction
+     *         {@code false} otherwise.
+     */
+    private boolean transactionCoversThisPersistenceUnit( MethodInvocation methodInvocation )
+    {
+        if ( null == puAnntoation )
+        {
+            return true;
+        }
+
+        final Transactional localTransaction = transactionalAnnotationReader.readAnnotationFrom( methodInvocation );
+        final Class<? extends Annotation>[] units = localTransaction.onUnits();
+        if ( null == units || 0 == units.length )
+        {
+            return true;
+        }
+
+        final int n = units.length;
+        for ( int i = 0; i < n; i++ )
+        {
+            if ( puAnntoation.equals( units[i] ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Returns the transaction facade for the given entity manager.
+     *
+     * @param em the entity manager.
+     * @return the transaction facade. Never {@code null}.
+     */
+    protected abstract TransactionFacade getTransactionFacade( final EntityManager em );
+
+    /**
+     * Invoke the original method surrounded by a transaction.
+     *
+     * @param methodInvocation  the original method invocation.
+     * @param transactionFacade the facade to the underling resource local or jta transaction.
+     * @return the result of the invocation of the original method.
+     * @throws Throwable if an exception occurs during the call to the original method.
+     */
+    private Object invoke( MethodInvocation methodInvocation, TransactionFacade transactionFacade )
+        throws Throwable
+    {
+
+        transactionFacade.begin();
+        final Object result = doTransactional( methodInvocation, transactionFacade );
+        transactionFacade.commit();
+
+        return result;
+    }
+
+    /**
+     * Invoke the original method assuming a transaction has already been started.
+     * This method is responsible of calling rollback if necessary.
+     *
+     * @param methodInvocation  the original method invocation.
+     * @param transactionFacade the facade to the underlying resource local or jta transaction.
+     * @return the result of the invocation of the original method.
+     * @throws Throwable if an exception occurs during the call to the original method.
+     */
+    private Object doTransactional( MethodInvocation methodInvocation, TransactionFacade transactionFacade )
+        throws Throwable
+    {
+        try
+        {
+            return methodInvocation.proceed();
+        }
+        catch ( Throwable e )
+        {
+            final Transactional t = transactionalAnnotationReader.readAnnotationFrom( methodInvocation );
+            if ( rollbackIsNecessary( t, e ) )
+            {
+                transactionFacade.rollback();
+            }
+            else
+            {
+                transactionFacade.commit();
+            }
+            // In any case: throw the original exception.
+            throw e;
+        }
+    }
+
+    /**
+     * Returns True if a rollback is necessary.
+     *
+     * @param transactional The metadata annotation of the method.
+     * @param e             The exception to test for rollback.
+     * @return {@code true} if a rollback is necessary, {@code false} otherwise.
+     */
+    private boolean rollbackIsNecessary( Transactional transactional, Throwable e )
+    {
+        for ( Class<? extends Exception> rollbackOn : transactional.rollbackOn() )
+        {
+            if ( rollbackOn.isInstance( e ) )
+            {
+                for ( Class<? extends Exception> ignore : transactional.ignore() )
+                {
+                    if ( ignore.isInstance( e ) )
+                    {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AbstractTxnInterceptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,41 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import com.google.inject.BindingAnnotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Annotation for {@link PersistenceService} and {@link UnitOfWork}. This is a special annotation for
+ * retrieving a container holding all registered persistence units. Calling a method on such a container
+ * will trigger the method call on all registered instances. In other words on all persistence units.
+ */
+@Retention(RUNTIME)
+@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
+@BindingAnnotation
+public @interface AllPersistenceUnits
+{
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/AllPersistenceUnits.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,121 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import java.util.Properties;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Implementation of {@link PersistenceService} and {@link EntityManagerFactoryProvider} for
+ * application managed persistence units.
+ */
+final class ApplicationManagedEntityManagerFactoryProvider
+    implements EntityManagerFactoryProvider, PersistenceService
+{
+
+    // ---- Members
+
+    /**
+     * Name of the persistence unit as defined in the persistence.xml.
+     */
+    private final String puName;
+
+    /**
+     * Additional properties. Theses override the ones defined in the persistence.xml.
+     */
+    private final Properties properties;
+
+    /**
+     * EntityManagerFactory.
+     */
+    private EntityManagerFactory emf;
+
+    // ---- Constructor
+
+    /**
+     * Constructor.
+     *
+     * @param puName     the name of the persistence unit as defined in the persistence.xml. Must not be {@code null}.
+     * @param properties the additional properties. Theses override the ones defined in the persistence.xml. Must not be {@code null}.
+     */
+    public ApplicationManagedEntityManagerFactoryProvider( String puName, Properties properties )
+    {
+        checkNotNull( puName );
+        checkNotNull( properties );
+
+        this.puName = puName;
+        this.properties = properties;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public EntityManagerFactory get()
+    {
+        if ( isRunning() )
+        {
+            return emf;
+        }
+
+        throw new IllegalStateException( "PersistenceService is not running." );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void start()
+    {
+        if ( isRunning() )
+        {
+            throw new IllegalStateException( "PersistenceService is already running." );
+        }
+        emf = Persistence.createEntityManagerFactory( puName, properties );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public boolean isRunning()
+    {
+        return null != emf;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void stop()
+    {
+        if ( isRunning() )
+        {
+            emf.close();
+            emf = null;
+        }
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedEntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,103 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import javax.persistence.EntityManagerFactory;
+import java.util.Properties;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Persistence module for an application managed persistence unit.
+ * <p/>
+ * Use the {@link PersistenceUnitBuilder} to configure an instance of this class.
+ * <p/>
+ * This is a guice private module which will expose the following bindings:
+ * <ul>
+ * <li>{@link UnitOfWork}</li>
+ * <li>{@link EntityManagerProvider}</li>
+ * <li>{@link PersistenceService}</li>
+ * </ul>
+ * If an annotation has been defined for this module the above classes are exposed with this
+ * annotation. Within the private module the above classes are also binded without any annotation.
+ * <p/>
+ * You can extend this class and override {@link #configurePersistence()} to bind and expose
+ * additional classes within this private module. This is useful if you require injection of the
+ * above classes without annotation.
+ */
+public class ApplicationManagedPersistenceUnitModule
+    extends AbstractPersistenceUnitModule
+{
+
+    // ---- Members
+
+    /**
+     * Provider for {@link EntityManagerFactory}
+     */
+    private final ApplicationManagedEntityManagerFactoryProvider emfProvider;
+
+    // ---- Constructors
+
+    /**
+     * Constructor.
+     *
+     * @param puName the name of the persistence unit as defined in the persistence.xml. Must not be {@code null}.
+     */
+    public ApplicationManagedPersistenceUnitModule( String puName )
+    {
+        this( puName, new Properties() );
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param puName     the name of the persistence unit as defined in the persistence.xml. Must not be {@code null}.
+     * @param properties the additional properties. Theses override the ones defined in the persistence.xml. Must not be {@code null}.
+     */
+    public ApplicationManagedPersistenceUnitModule( String puName, Properties properties )
+    {
+        this( new ApplicationManagedEntityManagerFactoryProvider( puName, properties ) );
+        checkNotNull( puName );
+        checkNotNull( properties );
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param emfProvider the provider for {@link EntityManagerFactory}.
+     */
+    private ApplicationManagedPersistenceUnitModule( ApplicationManagedEntityManagerFactoryProvider emfProvider )
+    {
+        super( new EntityManagerProviderImpl( emfProvider ) );
+        this.emfProvider = emfProvider;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    final PersistenceService getPersistenceService()
+    {
+        return emfProvider;
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ApplicationManagedPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,117 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.EntityManagerFactory;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Implementation of {@link PersistenceService} and {@link EntityManagerFactoryProvider} for
+ * container managed entity manager factories.
+ */
+final class ContainerManagedEntityManagerFactoryProvider
+    implements EntityManagerFactoryProvider, PersistenceService
+{
+
+    // ---- Members
+
+    /**
+     * The JNDI name of the {@link EntityManagerFactory}.
+     */
+    private final String emfJndiName;
+
+    /**
+     * The {@link EntityManagerFactory}.
+     */
+    private EntityManagerFactory emf;
+
+    // ---- Constructor
+
+    /**
+     * Constructor.
+     *
+     * @param emfJndiName the JNDI name of the {@link EntityManagerFactory}. Must not be {@code null}.
+     */
+    public ContainerManagedEntityManagerFactoryProvider( String emfJndiName )
+    {
+        checkNotNull( emfJndiName );
+        this.emfJndiName = emfJndiName;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public EntityManagerFactory get()
+    {
+        if ( isRunning() )
+        {
+            return emf;
+        }
+
+        throw new IllegalStateException( "PersistenceService is not running." );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void start()
+    {
+        if ( isRunning() )
+        {
+            throw new IllegalStateException( "PersistenceService is already running." );
+        }
+        try
+        {
+            final InitialContext ctx = new InitialContext();
+            emf = (EntityManagerFactory) ctx.lookup( emfJndiName );
+        }
+        catch ( NamingException e )
+        {
+            throw new RuntimeException( "lookup for EntityManagerFactory with JNDI name '" + emfJndiName + "' failed",
+                                        e );
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public boolean isRunning()
+    {
+        return null != emf;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void stop()
+    {
+        emf = null;
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedEntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,105 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import javax.persistence.EntityManagerFactory;
+import java.util.Properties;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Persistence module for an container managed persistence unit.
+ * <p/>
+ * Use the {@link PersistenceUnitBuilder} to configure an instance of this class.
+ * <p/>
+ * This is a private module which will expose the following bindings:
+ * <ul>
+ * <li>{@link UnitOfWork}</li>
+ * <li>{@link EntityManagerProvider}</li>
+ * <li>{@link PersistenceService}</li>
+ * </ul>
+ * If an annotation has been defined for this module the above classes are exposed with this
+ * annotation. Within the private module the above classes are also binded without any annotation.
+ * <p/>
+ * You can extend this class and override {@link #configurePersistence()} to bind and expose
+ * additional classes within this private module. This is useful if you require injection of the
+ * above classes without annotation.
+ */
+public class ContainerManagedPersistenceUnitModule
+    extends AbstractPersistenceUnitModule
+{
+
+    // ---- Members
+
+    /**
+     * Provider for {@link EntityManagerFactory}
+     */
+    private final ContainerManagedEntityManagerFactoryProvider emfProvider;
+
+    // ---- Constructors
+
+    /**
+     * Constructor.
+     *
+     * @param emfJndiName the JNDI name of the {@link EntityManagerFactory}.
+     */
+    public ContainerManagedPersistenceUnitModule( String emfJndiName )
+    {
+        this( emfJndiName, new Properties() );
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param emfJndiName the JNDI name of the {@link EntityManagerFactory}. Must not be {@code null}.
+     * @param properties  the additional properties. Theses override the ones defined in the persistence.xml. Must not be {@code null}.
+     */
+    public ContainerManagedPersistenceUnitModule( String emfJndiName, Properties properties )
+    {
+        this( new ContainerManagedEntityManagerFactoryProvider( emfJndiName ), properties );
+        checkNotNull( emfJndiName );
+        checkNotNull( properties );
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param emfProvider the provider for {@link EntityManagerFactory}.
+     * @param properties  the additional properties. Theses override the ones defined in the persistence.xml.
+     */
+    private ContainerManagedPersistenceUnitModule( ContainerManagedEntityManagerFactoryProvider emfProvider,
+                                                   Properties properties )
+    {
+        super( new EntityManagerProviderImpl( emfProvider, properties ) );
+        this.emfProvider = emfProvider;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    PersistenceService getPersistenceService()
+    {
+        return emfProvider;
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/ContainerManagedPersistenceUnitModule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,37 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import javax.persistence.EntityManagerFactory;
+
+/**
+ * Provider for {@link EntityManagerFactoryProvider}.
+ */
+interface EntityManagerFactoryProvider
+{
+
+    /**
+     * @return the provider for {@link EntityManagerFactory}.
+     * @throws IllegalStateException if {@link PersistenceService#isRunning()} returns {@code false}.
+     */
+    EntityManagerFactory get()
+        throws IllegalStateException;
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerFactoryProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,53 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import com.google.inject.Provider;
+
+import javax.persistence.EntityManager;
+
+/**
+ * Provider for {@link EntityManager}.
+ * <p/>
+ * This class does not implement the {@link Provider} interface because the {@link EntityManager}
+ * objects do have a life cycle and should therefore not be stored in instance/member variables.
+ * <p/>
+ * The {@link UnitOfWork} defines the life cycle of the {@link EntityManager}. An entity manager
+ * will be created when the unit of work is started. It is open and valid for use during the entire
+ * unit of work. When the unit of work ends the entity manager is closed and can no longer
+ * be used.
+ * <p/>
+ * It is a good practice to store this provider in a instance/member variable and only obtain an
+ * {@link EntityManager} instance in a Method where it is used. This ensures that the method always
+ * has access to a valid {@link EntityManager}.
+ * <p/>
+ * The {@link EntityManagerProvider} is thread save.
+ */
+public interface EntityManagerProvider
+{
+
+    /**
+     * @return the {@link EntityManager}.
+     * @throws IllegalStateException if {@link UnitOfWork#isActive()} returns false.
+     */
+    EntityManager get()
+        throws IllegalStateException;
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,143 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import java.util.Properties;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Implementation of {@link EntityManagerProvider} and {@link UnitOfWork}.
+ */
+final class EntityManagerProviderImpl
+    implements EntityManagerProvider, UnitOfWork
+{
+
+    // ---- Members
+
+    /**
+     * Provider for {@link EntityManagerFactory}.
+     */
+    private final EntityManagerFactoryProvider emfProvider;
+
+    /**
+     * Additional properties to be set on every {@link EntityManager} which is created.
+     */
+    private final Properties properties;
+
+    /**
+     * Thread local store of {@link EntityManager}s.
+     */
+    private final ThreadLocal<EntityManager> entityManagers = new ThreadLocal<EntityManager>();
+
+    // ---- Constructor
+
+    /**
+     * Constructor.
+     *
+     * @param emfProvider the provider for {@link EntityManagerFactory}.
+     */
+    public EntityManagerProviderImpl( EntityManagerFactoryProvider emfProvider )
+    {
+        this( emfProvider, null );
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param emfProvider the provider for {@link EntityManagerFactory}. Must not be {@code null}.
+     * @param properties  additional properties to be set on every {@link EntityManager} which is created.
+     */
+    public EntityManagerProviderImpl( EntityManagerFactoryProvider emfProvider, Properties properties )
+    {
+        checkNotNull( emfProvider );
+
+        this.emfProvider = emfProvider;
+        this.properties = properties;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public EntityManager get()
+    {
+        final EntityManager entityManager = entityManagers.get();
+        if ( null != entityManager )
+        {
+            return entityManager;
+        }
+
+        throw new IllegalStateException( "UnitOfWork is not running." );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void begin()
+    {
+        if ( isActive() )
+        {
+            throw new IllegalStateException( "Unit of work has already been started." );
+        }
+
+        final EntityManagerFactory emf = emfProvider.get();
+        final EntityManager em;
+        if ( null == properties )
+        {
+            em = emf.createEntityManager();
+        }
+        else
+        {
+            em = emf.createEntityManager( properties );
+        }
+
+        entityManagers.set( em );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public boolean isActive()
+    {
+        return null != entityManagers.get();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void end()
+    {
+        final EntityManager em = entityManagers.get();
+        if ( null != em )
+        {
+            em.close();
+            entityManagers.remove();
+        }
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/EntityManagerProviderImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,178 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import org.aopalliance.intercept.MethodInterceptor;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Status;
+import java.lang.annotation.Annotation;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * {@link MethodInterceptor} for intercepting methods of persistence units of type JTA.
+ */
+class JtaTxnInterceptor
+    extends AbstractTxnInterceptor
+{
+
+    // ---- Members
+
+    /**
+     * The {@link UserTransactionFacade}.
+     */
+    private final UserTransactionFacade utFacade;
+
+    // ---- Constructor
+
+    /**
+     * Constructor.
+     *
+     * @param emProvider   the provider for {@link EntityManager}. Must not be {@code null}.
+     * @param puAnntoation the annotation used for this persistence unit.
+     * @param utFacade     the {@link UserTransactionFacade}. Must not be {@code null}.
+     */
+    public JtaTxnInterceptor( EntityManagerProviderImpl emProvider, Class<? extends Annotation> puAnntoation,
+                              UserTransactionFacade utFacade )
+    {
+        super( emProvider, emProvider, puAnntoation );
+        checkNotNull( utFacade );
+        this.utFacade = utFacade;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected TransactionFacade getTransactionFacade( EntityManager em )
+    {
+        if ( Status.STATUS_NO_TRANSACTION == utFacade.getStatus() )
+        {
+            return new OuterTransaction( utFacade, em );
+        }
+        return new InnerTransaction( utFacade, em );
+    }
+
+    // ---- Inner Classes
+
+    /**
+     * TransactionFacade representing an inner (nested) transaction. Starting and
+     * committing a transaction has no effect. This Facade will set the
+     * rollbackOnly flag on the underlying transaction in case of a rollback.
+     */
+    private static class InnerTransaction
+        implements TransactionFacade
+    {
+        private final UserTransactionFacade txn;
+
+        private final EntityManager em;
+
+        InnerTransaction( UserTransactionFacade txn, EntityManager em )
+        {
+            this.txn = txn;
+            this.em = em;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        // @Override
+        public void begin()
+        {
+            em.joinTransaction();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        // @Override
+        public void commit()
+        {
+            // Do nothing
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        // @Override
+        public void rollback()
+        {
+            txn.setRollbackOnly();
+        }
+    }
+
+    /**
+     * TransactionFacade representing an outer transaction. This Facade starts
+     * and ends the transaction. If an inner transaction has set the rollbackOnly
+     * flag the transaction will be rolled back in any case.
+     */
+    private static class OuterTransaction
+        implements TransactionFacade
+    {
+        private final UserTransactionFacade txn;
+
+        private final EntityManager em;
+
+        OuterTransaction( UserTransactionFacade txn, EntityManager em )
+        {
+            this.txn = txn;
+            this.em = em;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        // @Override
+        public void begin()
+        {
+            txn.begin();
+            em.joinTransaction();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        // @Override
+        public void commit()
+        {
+            if ( Status.STATUS_ACTIVE == txn.getStatus() )
+            {
+                txn.commit();
+            }
+            else
+            {
+                txn.rollback();
+            }
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        // @Override
+        public void rollback()
+        {
+            txn.rollback();
+        }
+    }
+
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/JtaTxnInterceptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java?rev=1542116&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java (added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java Thu Nov 14 23:19:36 2013
@@ -0,0 +1,102 @@
+package org.apache.onami.persist;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Filter for use in container.
+ * The filter will start all persistence services upon container start and span a unit of work
+ * around every request which is filtered.
+ * <p/>
+ * Usage example:
+ * <pre>
+ *  public class MyModule extends ServletModule {
+ *    public void configure() {
+ *      // bind your persistence units here
+ *
+ *      filter("/*").through(PersistenceFilter.class);
+ *    }
+ *  }
+ * </pre>
+ */
+public class PersistenceFilter
+    implements Filter
+{
+
+    // ---- Members
+
+    private final PersistenceUnitContainer persistenceUnitsContainer;
+
+    // ---- Constructor
+
+    PersistenceFilter( PersistenceUnitContainer persistenceUnitsContainer )
+    {
+        checkNotNull( persistenceUnitsContainer );
+        this.persistenceUnitsContainer = persistenceUnitsContainer;
+    }
+
+    // ---- Methods
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain )
+        throws IOException, ServletException
+    {
+        try
+        {
+            persistenceUnitsContainer.begin();
+            chain.doFilter( request, response );
+        }
+        finally
+        {
+            persistenceUnitsContainer.end();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void init( FilterConfig filterConfig )
+        throws ServletException
+    {
+        persistenceUnitsContainer.start();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void destroy()
+    {
+        persistenceUnitsContainer.stop();
+    }
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain