openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donald Woods <dwo...@apache.org>
Subject Re: svn commit: r750788 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/
Date Fri, 06 Mar 2009 13:53:29 GMT
Can you update the svn log to refer to OPENJPA-960 instead?


-Donald


ppoddar@apache.org wrote:
> Author: ppoddar
> Date: Fri Mar  6 07:08:20 2009
> New Revision: 750788
> 
> URL: http://svn.apache.org/viewvc?rev=750788&view=rev
> Log:
> OPENJPA-966: Support unwrap() for JPA 2.0
> 
> Added:
>     openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestUnwrap.java
> Modified:
>     openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
>     openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
>     openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
> 
> Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestUnwrap.java
> URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestUnwrap.java?rev=750788&view=auto
> ==============================================================================
> --- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestUnwrap.java
(added)
> +++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestUnwrap.java
Fri Mar  6 07:08:20 2009
> @@ -0,0 +1,68 @@
> +/*
> + * 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.openjpa.persistence;
> +
> +import javax.persistence.EntityManager;
> +import javax.persistence.Query;
> +
> +import org.apache.openjpa.kernel.QueryLanguages;
> +import org.apache.openjpa.persistence.test.SingleEMFTestCase;
> +
> +public class TestUnwrap extends SingleEMFTestCase {
> +    
> +    /**
> +     * Tests a query can be unwrapped as an instance of a series of class or 
> +     * interface. 
> +     */
> +    public void testValidQueryUnwrap() {
> +        OpenJPAEntityManager em = emf.createEntityManager();
> +        Query query = em.createQuery(QueryLanguages.LANG_SQL,"");
> +        
> +        Class[] validCasts = new Class[] {
> +            org.apache.openjpa.persistence.OpenJPAQuery.class,
> +            org.apache.openjpa.persistence.OpenJPAQuerySPI.class,
> +            org.apache.openjpa.kernel.DelegatingQuery.class,
> +            org.apache.openjpa.kernel.Query.class,
> +            org.apache.openjpa.kernel.QueryImpl.class
> +        };
> +        for (Class c : validCasts) {
> +            Object unwrapped = query.unwrap(c);
> +            assertTrue(c.isInstance(unwrapped));
> +        }
> +    }
> +
> +    /**
> +     * Tests a EntityManager can be unwrapped as an instance of a series of 
> +     * class or interface. 
> +     */
> +    public void testValidEntityManagerUnwrap() {
> +        EntityManager em = emf.createEntityManager();
> +        
> +        Class[] validCasts = new Class[] {
> +            org.apache.openjpa.persistence.OpenJPAEntityManager.class,
> +            org.apache.openjpa.persistence.OpenJPAEntityManagerSPI.class,
> +            org.apache.openjpa.kernel.DelegatingBroker.class,
> +            org.apache.openjpa.kernel.Broker.class
> +        };
> +        for (Class c : validCasts) {
> +            Object unwrapped = em.unwrap(c);
> +            assertTrue(c.isInstance(unwrapped));
> +        }
> +    }
> +}
> 
> Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
> URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=750788&r1=750787&r2=750788&view=diff
> ==============================================================================
> --- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
(original)
> +++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
Fri Mar  6 07:08:20 2009
> @@ -1525,8 +1525,14 @@
>      }
>  
>      public <T> T unwrap(Class<T> cls) {
> -        throw new UnsupportedOperationException(
> -            "JPA 2.0 - Method not yet implemented");
> +        Object[] delegates = new Object[]{_broker.getInnermostDelegate(),
> +            _broker.getDelegate(), _broker, this};
> +        for (Object o : delegates) {
> +            if (cls.isInstance(o))
> +                return (T)o;
> +        }
> +        throw new PersistenceException(_loc.get("unwrap-em-invalid", cls)
> +            .toString(), null, this, false);
>      }
>      
>      
> 
> Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
> URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java?rev=750788&r1=750787&r2=750788&view=diff
> ==============================================================================
> --- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
(original)
> +++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
Fri Mar  6 07:08:20 2009
> @@ -562,9 +562,24 @@
>              "JPA 2.0 - Method not yet implemented");
>      }
>  
> +    /**
> +     * Returns the innermost implementation that is an instance of the given 
> +     * class. 
> +     * 
> +     * @throws PersistenceException if none in the delegate chain is an 
> +     * instance of the given class.
> +     * 
> +     * @since 2.0.0
> +     */
>      public <T> T unwrap(Class<T> cls) {
> -        throw new UnsupportedOperationException(
> -            "JPA 2.0 - Method not yet implemented");
> +        Object[] delegates = new Object[]{_query.getInnermostDelegate(), 
> +            _query.getDelegate(), _query, this};
> +        for (Object o : delegates) {
> +            if (cls.isInstance(o))
> +                return (T)o;
> +        }
> +        throw new PersistenceException(_loc.get("unwrap-query-invalid", cls)
> +            .toString(), null, this, false);
>      }
>      
>      //
> 
> Modified: openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
> URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties?rev=750788&r1=750787&r2=750788&view=diff
> ==============================================================================
> --- openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
(original)
> +++ openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/localizer.properties
Fri Mar  6 07:08:20 2009
> @@ -164,4 +164,6 @@
>  version-check-error: An error occurred while attempting to determine the \
>      version of "{0}".
>  no-result: Query "{0}" selected no result, but expected unique result.
> -non-unique-result: Query "{0}" selected {1} results, but expected unique result.
> \ No newline at end of file
> +non-unique-result: Query "{0}" selected {1} results, but expected unique result.
> +unwrap-em-invalid: EntityManager can not be unwrapped to an instance of "{0}".
> +unwrap-query-invalid: Query can not be unwrapped to an instance of "{0}".
> \ No newline at end of file
> 
> 
> 

Mime
View raw message