mirror of https://github.com/apache/openjpa.git
Simple test case for abstract schema name queries.
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@472355 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
71ed42e8c5
commit
b40ba51347
|
@ -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;
|
||||
|
||||
@Entity(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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue