geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r995970 - in /geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence: CMPEntityManagerTxScoped.java NoTxQueryWrapper.java NoTxTypedQueryWrapper.java
Date Fri, 10 Sep 2010 20:28:27 GMT
Author: gawor
Date: Fri Sep 10 20:28:26 2010
New Revision: 995970

URL: http://svn.apache.org/viewvc?rev=995970&view=rev
Log:
add wrapper for TypedQuery

Added:
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java
  (with props)
Modified:
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/CMPEntityManagerTxScoped.java
    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxQueryWrapper.java

Modified: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/CMPEntityManagerTxScoped.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/CMPEntityManagerTxScoped.java?rev=995970&r1=995969&r2=995970&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/CMPEntityManagerTxScoped.java
(original)
+++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/CMPEntityManagerTxScoped.java
Fri Sep 10 20:28:26 2010
@@ -421,11 +421,7 @@ public class CMPEntityManagerTxScoped im
             return entityManager.createNamedQuery(name, resultClass);
         } else {
             entityManager = createEntityManager();
-            try {
-                return entityManager.createNamedQuery(name, resultClass);
-            } finally {
-                entityManager.close();
-            }
+            return new NoTxTypedQueryWrapper<T>(entityManager, entityManager.createNamedQuery(name,
resultClass));
         }
     }
 
@@ -436,11 +432,7 @@ public class CMPEntityManagerTxScoped im
             return entityManager.createQuery(criteriaQuery);
         } else {
             entityManager = createEntityManager();
-            try {
-                return entityManager.createQuery(criteriaQuery);
-            } finally {
-                entityManager.close();
-            }
+            return new NoTxTypedQueryWrapper<T>(entityManager, entityManager.createQuery(criteriaQuery));
         }
     }
 
@@ -451,11 +443,7 @@ public class CMPEntityManagerTxScoped im
             return entityManager.createQuery(qlString, resultClass);
         } else {
             entityManager = createEntityManager();
-            try {
-                return entityManager.createQuery(qlString, resultClass);
-            } finally {
-                entityManager.close();
-            }
+            return new NoTxTypedQueryWrapper<T>(entityManager, entityManager.createQuery(qlString,
resultClass));
         }
     }
 

Modified: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxQueryWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxQueryWrapper.java?rev=995970&r1=995969&r2=995970&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxQueryWrapper.java
(original)
+++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxQueryWrapper.java
Fri Sep 10 20:28:26 2010
@@ -30,11 +30,11 @@ import java.util.Map;
 import java.util.Set;
 
 /**
- * The JtaQuery is a wrapper around a query and and entity manager that automatically closes
the entity managers
- * when the query is finished.  This implementation is only for non-transaction queryies
+ * The JtaQuery is a wrapper around a Query and and entity manager that automatically closes
the entity managers
+ * when the query is finished.  This implementation is only for non-transaction queries
  */
 public class NoTxQueryWrapper implements Query {
-    private final EntityManager entityManager;
+    protected final EntityManager entityManager;
     private final Query query;
 
     public NoTxQueryWrapper(EntityManager entityManager, Query query) {

Added: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java?rev=995970&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java
(added)
+++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java
Fri Sep 10 20:28:26 2010
@@ -0,0 +1,132 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.geronimo.persistence;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Parameter;
+import javax.persistence.TemporalType;
+import javax.persistence.TypedQuery;
+
+/**
+ * The JtaQuery is a wrapper around a TypedQuery and and entity manager that automatically
closes the entity managers
+ * when the query is finished.  This implementation is only for non-transaction queries.
+ */
+public class NoTxTypedQueryWrapper<X> extends NoTxQueryWrapper implements TypedQuery<X>
{
+    
+    private final TypedQuery<X> query;
+    
+    public NoTxTypedQueryWrapper(EntityManager entityManager, TypedQuery<X> query)
{
+        super(entityManager, query);
+        this.query = query;
+    }
+
+    public List<X> getResultList() {
+        try {
+            return query.getResultList();
+        } finally {
+            entityManager.close();
+        }
+    }
+
+    public X getSingleResult() {
+        try {
+            return query.getSingleResult();
+        } finally {
+            entityManager.close();
+        }
+    }
+
+    public TypedQuery<X> setMaxResults(int maxResult) {
+        query.setMaxResults(maxResult);
+        return this;
+    }
+
+    public TypedQuery<X> setFirstResult(int startPosition) {
+        query.setFirstResult(startPosition);
+        return this;
+    }
+
+    public TypedQuery<X> setHint(String hintName, Object value) {
+        query.setHint(hintName, value);
+        return this;
+    }
+
+    public <T> TypedQuery<X> setParameter(Parameter<T> param, T value)
{
+        query.setParameter(param, value);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(Parameter<Calendar> param,
+                                      Calendar value,
+                                      TemporalType temporalType) {
+        query.setParameter(param, value, temporalType);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(Parameter<Date> param, Date value, TemporalType
temporalType) {
+        query.setParameter(param, value, temporalType);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(String name, Object value) {
+        query.setParameter(name, value);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(String name, Calendar value, TemporalType temporalType)
{
+        query.setParameter(name, value, temporalType);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(String name, Date value, TemporalType temporalType)
{
+        query.setParameter(name, value, temporalType);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(int position, Object value) {
+        query.setParameter(position, value);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(int position, Calendar value, TemporalType temporalType)
{
+        query.setParameter(position, value, temporalType);
+        return this;
+    }
+
+    public TypedQuery<X> setParameter(int position, Date value, TemporalType temporalType)
{
+        query.setParameter(position, value, temporalType);
+        return this;
+    }
+
+    public TypedQuery<X> setFlushMode(FlushModeType flushMode) {
+        query.setFlushMode(flushMode);
+        return this;
+    }
+
+    public TypedQuery<X> setLockMode(LockModeType lockMode) {
+        query.setLockMode(lockMode);
+        return this;
+    }
+
+}

Propchange: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20/src/main/java/org/apache/geronimo/persistence/NoTxTypedQueryWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message