You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/03/12 10:02:24 UTC
svn commit: r517138 - in /cayenne/main/trunk:
framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/
itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/
itests/jpa-chapter4/ itests/jpa-chapter4/src/ itests/jpa-chapter4/...
Author: aadamchik
Date: Mon Mar 12 02:02:22 2007
New Revision: 517138
URL: http://svn.apache.org/viewvc?view=rev&rev=517138
Log:
hooking up EJBQL functionality to the JPA provider
Added:
cayenne/main/trunk/itests/jpa-chapter4/
cayenne/main/trunk/itests/jpa-chapter4/.classpath
cayenne/main/trunk/itests/jpa-chapter4/.project
cayenne/main/trunk/itests/jpa-chapter4/pom.xml
cayenne/main/trunk/itests/jpa-chapter4/src/
cayenne/main/trunk/itests/jpa-chapter4/src/main/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/ch4/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/ch4/entity/
cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/ch4/entity/SimpleEntity.java
cayenne/main/trunk/itests/jpa-chapter4/src/main/resources/
cayenne/main/trunk/itests/jpa-chapter4/src/main/resources/META-INF/
cayenne/main/trunk/itests/jpa-chapter4/src/main/resources/META-INF/persistence.xml
cayenne/main/trunk/itests/jpa-chapter4/src/test/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/itest/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/itest/ch4/
cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/itest/ch4/_4_2_1_SelectStatementTest.java
cayenne/main/trunk/itests/jpa-chapter4/src/test/resources/
cayenne/main/trunk/itests/jpa-chapter4/src/test/resources/schema-hsqldb.sql
Modified:
cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManager.java
cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_1_1_EntityManagerTest.java
Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManager.java?view=diff&rev=517138&r1=517137&r2=517138
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManager.java (original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/ResourceLocalEntityManager.java Mon Mar 12 02:02:22 2007
@@ -34,6 +34,7 @@
import org.apache.cayenne.PersistenceState;
import org.apache.cayenne.Persistent;
import org.apache.cayenne.access.Transaction;
+import org.apache.cayenne.query.EJBQLQuery;
public class ResourceLocalEntityManager implements EntityManager, CayenneEntityManager {
@@ -267,8 +268,9 @@
public Query createQuery(String ejbqlString) {
checkClosed();
- // TODO: Andrus, 2/10/2006 - implement
- throw new UnsupportedOperationException("TODO");
+ JpaQuery query = new JpaQuery(context);
+ query.setQuery(new EJBQLQuery(ejbqlString));
+ return query;
}
/**
Modified: cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_1_1_EntityManagerTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_1_1_EntityManagerTest.java?view=diff&rev=517138&r1=517137&r2=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_1_1_EntityManagerTest.java (original)
+++ cayenne/main/trunk/itests/jpa-chapter3/src/test/java/org/apache/cayenne/jpa/itest/ch3/_3_1_1_EntityManagerTest.java Mon Mar 12 02:02:22 2007
@@ -18,8 +18,11 @@
****************************************************************/
package org.apache.cayenne.jpa.itest.ch3;
+import java.util.List;
+
import javax.persistence.EntityExistsException;
import javax.persistence.PersistenceException;
+import javax.persistence.Query;
import org.apache.cayenne.itest.jpa.EntityManagerCase;
import org.apache.cayenne.jpa.itest.ch3.entity.NonEntity;
@@ -148,14 +151,6 @@
}
}
- // TODO: andrus, 1/3/2007 - implement - need to emulate the container environment
- public void _testMergeTransactionRequiredException() {
- // throws TransactionRequiredException if invoked on a
- // container-managed entity manager of type
- // PersistenceContextType.TRANSACTION and there is
- // no transaction.
- }
-
public void testRemove() throws Exception {
getDbHelper().deleteAll("SimpleEntity");
@@ -193,14 +188,6 @@
}
}
- // TODO: andrus, 1/3/2007 - implement - need to emulate the container environment
- public void _testRemoveTransactionRequiredException() {
- // throws TransactionRequiredException if invoked on a
- // container-managed entity manager of type
- // PersistenceContextType.TRANSACTION and there is
- // no transaction.
- }
-
public void testFind() throws Exception {
getDbHelper().deleteAll("SimpleEntity");
@@ -235,11 +222,21 @@
}
}
- // TODO: andrus, 1/3/2007 - implement - need to emulate the container environment
- public void _testRefreshTransactionRequiredException() {
- // throws TransactionRequiredException if invoked on a
- // container-managed entity manager of type
- // PersistenceContextType.TRANSACTION and there is
- // no transaction.
+ public void testCreateQuery() throws Exception {
+ getDbHelper().deleteAll("SimpleEntity");
+
+ getDbHelper().insert("SimpleEntity", new String[] {
+ "id", "property1"
+ }, new Object[] {
+ 15, "XXX"
+ });
+
+ Query query = getEntityManager().createQuery("select x from SimpleEntity x");
+ assertNotNull(query);
+ List result = query.getResultList();
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ assertTrue(result.get(0) instanceof SimpleEntity);
+ assertEquals("XXX", ((SimpleEntity) result.get(0)).getProperty1());
}
}
Added: cayenne/main/trunk/itests/jpa-chapter4/.classpath
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter4/.classpath?view=auto&rev=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter4/.classpath (added)
+++ cayenne/main/trunk/itests/jpa-chapter4/.classpath Mon Mar 12 02:02:22 2007
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry excluding="**" output="src/main/resources" kind="src" path="src/main/resources"/>
+ <classpathentry excluding="**" output="src/test/resources" kind="src" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: cayenne/main/trunk/itests/jpa-chapter4/.project
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter4/.project?view=auto&rev=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter4/.project (added)
+++ cayenne/main/trunk/itests/jpa-chapter4/.project Mon Mar 12 02:02:22 2007
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>jpa-chapter4</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: cayenne/main/trunk/itests/jpa-chapter4/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter4/pom.xml?view=auto&rev=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter4/pom.xml (added)
+++ cayenne/main/trunk/itests/jpa-chapter4/pom.xml Mon Mar 12 02:02:22 2007
@@ -0,0 +1,79 @@
+<?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.cayenne.itests</groupId>
+ <artifactId>cayenne-itests-parent</artifactId>
+ <version>3.0-SNAPSHOT</version>
+ </parent>
+
+ <description>Integration Tests - JPA Chapter 4 - Query Language</description>
+ <artifactId>jpa-chapter4</artifactId>
+ <name>Integration Tests - JPA Chapter 4</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne.itests</groupId>
+ <artifactId>itest-common</artifactId>
+ <version>${version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jpa_3.0_spec</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+
+ <configuration>
+ <forkMode>once</forkMode>
+ <argLine>
+ -javaagent:${settings.localRepository}/org/apache/cayenne/cayenne-agent/${version}/cayenne-agent-${version}.jar
+ </argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/ch4/entity/SimpleEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/ch4/entity/SimpleEntity.java?view=auto&rev=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/ch4/entity/SimpleEntity.java (added)
+++ cayenne/main/trunk/itests/jpa-chapter4/src/main/java/org/apache/cayenne/jpa/itest/ch4/entity/SimpleEntity.java Mon Mar 12 02:02:22 2007
@@ -0,0 +1,29 @@
+package org.apache.cayenne.jpa.itest.ch4.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class SimpleEntity {
+
+ @Id
+ protected int id;
+
+ protected String property1;
+
+ public int idField() {
+ return id;
+ }
+
+ public void updateIdField(int id) {
+ this.id = id;
+ }
+
+ public String getProperty1() {
+ return property1;
+ }
+
+ public void setProperty1(String property1) {
+ this.property1 = property1;
+ }
+}
Added: cayenne/main/trunk/itests/jpa-chapter4/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter4/src/main/resources/META-INF/persistence.xml?view=auto&rev=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter4/src/main/resources/META-INF/persistence.xml (added)
+++ cayenne/main/trunk/itests/jpa-chapter4/src/main/resources/META-INF/persistence.xml Mon Mar 12 02:02:22 2007
@@ -0,0 +1,26 @@
+<?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.
+-->
+
+<persistence>
+ <persistence-unit name="itest">
+ <description>Integration test peristence unit #1.</description>
+ <class>org.apache.cayenne.jpa.itest.ch4.entity.SimpleEntity</class>
+ </persistence-unit>
+</persistence>
Added: cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/itest/ch4/_4_2_1_SelectStatementTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/itest/ch4/_4_2_1_SelectStatementTest.java?view=auto&rev=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/itest/ch4/_4_2_1_SelectStatementTest.java (added)
+++ cayenne/main/trunk/itests/jpa-chapter4/src/test/java/org/apache/cayenne/jpa/itest/ch4/_4_2_1_SelectStatementTest.java Mon Mar 12 02:02:22 2007
@@ -0,0 +1,46 @@
+package org.apache.cayenne.jpa.itest.ch4;
+
+import java.util.List;
+
+import javax.persistence.Query;
+
+import org.apache.cayenne.itest.jpa.EntityManagerCase;
+import org.apache.cayenne.jpa.itest.ch4.entity.SimpleEntity;
+
+public class _4_2_1_SelectStatementTest extends EntityManagerCase {
+
+ public void testSelectFrom() throws Exception {
+ getDbHelper().deleteAll("SimpleEntity");
+
+ getDbHelper().insert("SimpleEntity",
+ new String[] { "id", "property1" }, new Object[] { 15, "XXX" });
+
+ Query query = getEntityManager().createQuery(
+ "select x from SimpleEntity x");
+ assertNotNull(query);
+ List result = query.getResultList();
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ assertTrue(result.get(0) instanceof SimpleEntity);
+ assertEquals("XXX", ((SimpleEntity) result.get(0)).getProperty1());
+ }
+
+ // TODO: andrus, 3/11/2007 - this fails.
+ public void testSelectFromWhere() throws Exception {
+ // getDbHelper().deleteAll("SimpleEntity");
+ //
+ // getDbHelper().insert("SimpleEntity",
+ // new String[] { "id", "property1" }, new Object[] { 15, "XXX" });
+ // getDbHelper().insert("SimpleEntity",
+ // new String[] { "id", "property1" }, new Object[] { 16, "YYY" });
+ //
+ // Query query = getEntityManager().createQuery(
+ // "select x from SimpleEntity x where x.property1 = 'YYY'");
+ // assertNotNull(query);
+ // List result = query.getResultList();
+ // assertNotNull(result);
+ // assertEquals(1, result.size());
+ // assertTrue(result.get(0) instanceof SimpleEntity);
+ // assertEquals("YYY", ((SimpleEntity) result.get(0)).getProperty1());
+ }
+}
Added: cayenne/main/trunk/itests/jpa-chapter4/src/test/resources/schema-hsqldb.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter4/src/test/resources/schema-hsqldb.sql?view=auto&rev=517138
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter4/src/test/resources/schema-hsqldb.sql (added)
+++ cayenne/main/trunk/itests/jpa-chapter4/src/test/resources/schema-hsqldb.sql Mon Mar 12 02:02:22 2007
@@ -0,0 +1,5 @@
+create table AUTO_PK_SUPPORT (TABLE_NAME CHAR(100) NOT NULL, NEXT_ID INTEGER NOT NULL, PRIMARY KEY(TABLE_NAME));
+insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('SimpleEntity', 1);
+
+create table SimpleEntity (id int not null, property1 VARCHAR(100), primary key(id));
+