Author: awhite Date: Tue Nov 7 16:50:15 2006 New Revision: 472355 URL: http://svn.apache.org/viewvc?view=rev&rev=472355 Log: Simple test case for abstract schema name queries.
Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java (with props) incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java?view=auto&rev=472355 ============================================================================== --- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java (added) +++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java Tue Nov 7 16:50:15 2006 @@ -0,0 +1,46 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * 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. + */ +package org.apache.openjpa.persistence.query; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Version; + [EMAIL PROTECTED](name="named") +public class NamedEntity { + + @Id + @GeneratedValue + private long id; + + private String name; + + @Version + private Integer optLock; + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/NamedEntity.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java?view=auto&rev=472355 ============================================================================== --- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java (added) +++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAbstractSchemaName.java Tue Nov 7 16:50:15 2006 @@ -0,0 +1,84 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * 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. + */ +package org.apache.openjpa.persistence.query; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.Query; + +import junit.framework.TestCase; +import junit.textui.TestRunner; +import org.apache.openjpa.persistence.OpenJPAQuery; + +/** + * Test that we can query by an entity's abstract schema name. + * + * @author Abe White + */ +public class TestAbstractSchemaName + extends TestCase { + + private EntityManagerFactory emf; + + public void setUp() { + Map props = new HashMap(); + props.put("openjpa.MetaDataFactory", "jpa(Types=" + + NamedEntity.class.getName() + ")"); + emf = Persistence.createEntityManagerFactory("test", props); + + NamedEntity e = new NamedEntity(); + e.setName("e"); + + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + em.persist(e); + em.getTransaction().commit(); + em.close(); + } + + public void tearDown() { + if (emf == null) + return; + try { + EntityManager em = emf.createEntityManager(); + em.getTransaction().begin(); + em.createQuery("delete from named").executeUpdate(); + em.getTransaction().commit(); + em.close(); + emf.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void testQuery() { + EntityManager em = emf.createEntityManager(); + Query q = em.createQuery("select e from named e"); + NamedEntity e = (NamedEntity) q.getSingleResult(); + assertNotNull(e); + assertEquals("e", e.getName()); + em.close(); + } + + public static void main(String[] args) { + TestRunner.run(TestAbstractSchemaName.class); + } +} +