cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1405063 - in /cxf/trunk/rt/rs/extensions/search: ./ src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/ src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/ src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/ src/test/resources/META-INF/
Date Fri, 02 Nov 2012 17:19:54 GMT
Author: sergeyb
Date: Fri Nov  2 17:19:53 2012
New Revision: 1405063

URL: http://svn.apache.org/viewvc?rev=1405063&view=rev
Log:
Few updates to the search code after testing with OpenJPA

Modified:
    cxf/trunk/rt/rs/extensions/search/pom.xml
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Name.java
    cxf/trunk/rt/rs/extensions/search/src/test/resources/META-INF/persistence.xml

Modified: cxf/trunk/rt/rs/extensions/search/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/pom.xml?rev=1405063&r1=1405062&r2=1405063&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/pom.xml (original)
+++ cxf/trunk/rt/rs/extensions/search/pom.xml Fri Nov  2 17:19:53 2012
@@ -85,17 +85,25 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-			<groupId>org.hibernate</groupId>
-			<artifactId>hibernate-entitymanager</artifactId>
-			<version>${hibernate.em.version}</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>hsqldb</groupId>
-			<artifactId>hsqldb</artifactId>
-			<version>${hsqldb.version}</version>
-			<scope>test</scope>
-		</dependency>
+	    <groupId>org.hibernate</groupId>
+	    <artifactId>hibernate-entitymanager</artifactId>
+	    <version>${hibernate.em.version}</version>
+	    <scope>test</scope>
+	</dependency>
+	<dependency>
+	   <groupId>hsqldb</groupId>
+	   <artifactId>hsqldb</artifactId>
+	   <version>${hsqldb.version}</version>
+	   <scope>test</scope>
+	</dependency>
+        <!--
+           <dependency>
+  	     <groupId>org.apache.openjpa</groupId>
+ 	     <artifactId>openjpa</artifactId>
+   	     <version>2.2.0</version>
+             <scope>test</scope>
+           </dependency>
+        -->
     </dependencies>
     <build>
         <plugins>

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java?rev=1405063&r1=1405062&r2=1405063&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
Fri Nov  2 17:19:53 2012
@@ -286,27 +286,26 @@ public class FiqlParser<T> implements Se
             Object castedValue = value;
             if (Date.class.isAssignableFrom(valueType)) {
                 castedValue = convertToDate(value);
-            } else {
+            } else if (ownerBean == null || valueType.isPrimitive()) {
                 try {
                     castedValue = InjectionUtils.convertStringToPrimitive(value, valueType);
                 } catch (Exception e) {
-                    boolean throwEx = true;
-                    if (!valueType.isPrimitive()) {
-                        try {
-                            Method setterM = valueType.getMethod("set" + getMethodNameSuffix(setter),
-                                                                 new Class[]{String.class});
-                            setterM.invoke(ownerBean, new Object[]{value});
-                            castedValue = lastCastedValue;
-                            throwEx = false;
-                        } catch (Throwable ex) {
-                            // continue
-                        }
-                    }
-                    if (throwEx) {
-                        throw new SearchParseException("Cannot convert String value \"" +
value
+                    throw new SearchParseException("Cannot convert String value \"" + value
                                                  + "\" to a value of class " + valueType.getName(),
e);
-                    }
                 }
+            } else {
+                try {
+                    Method setterM = valueType.getMethod("set" + getMethodNameSuffix(setter),
+                                                         new Class[]{String.class});
+                    setterM.invoke(ownerBean, new Object[]{value});
+                } catch (Throwable ex) {
+                    throw new SearchParseException("Cannot convert String value \"" + value
+                                                   + "\" to a value of class " + valueType.getName(),
ex);
+                }
+                
+            }
+            if (lastCastedValue != null) {
+                castedValue = lastCastedValue;
             }
             return castedValue;
         } else {

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java?rev=1405063&r1=1405062&r2=1405063&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
Fri Nov  2 17:19:53 2012
@@ -25,6 +25,7 @@ import java.util.Map;
 import javax.persistence.EntityManager;
 import javax.persistence.criteria.CompoundSelection;
 import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Path;
 import javax.persistence.criteria.Selection;
 import javax.persistence.metamodel.SingularAttribute;
 
@@ -82,7 +83,9 @@ public class JPACriteriaQueryVisitor<T, 
     private List<Selection<?>> toSelectionsList(List<SingularAttribute<T,
?>> attributes) {
         List<Selection<?>> selections = new ArrayList<Selection<?>>(attributes.size());
         for (SingularAttribute<T, ?> attr : attributes) {
-            selections.add(getRoot().get(attr));
+            Path<?> path = getRoot().get(attr);
+            path.alias(attr.getName());
+            selections.add(path);
         }
         return selections;
     }

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java?rev=1405063&r1=1405062&r2=1405063&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
Fri Nov  2 17:19:53 2012
@@ -25,15 +25,13 @@ import javax.persistence.ManyToOne;
 
 @Entity(name = "Book")
 public class Book {
-    @Id
     private int id;
     private String title;
     private OwnerAddress address;
     private OwnerInfo ownerInfo;
-    @ManyToOne
     private Library library;
     
-    
+    @Id
     public int getId() {
         return id;
     }
@@ -67,6 +65,7 @@ public class Book {
         this.ownerInfo = ownerInfo;
     }
 
+    @ManyToOne
     public Library getLibrary() {
         return library;
     }

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java?rev=1405063&r1=1405062&r2=1405063&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
Fri Nov  2 17:19:53 2012
@@ -64,7 +64,7 @@ public class JPATypedQueryVisitorTest ex
             fail("Exception during HSQL database init.");
         }
         try {
-            emFactory = Persistence.createEntityManagerFactory("testUnit");
+            emFactory = Persistence.createEntityManagerFactory("testUnitHibernate");
             em = emFactory.createEntityManager();
          
             em.getTransaction().begin();
@@ -239,6 +239,10 @@ public class JPATypedQueryVisitorTest ex
     
         
     @Test
+    // "ownerInfo.name" maps to Name class and this 
+    // does not work in OpenJPA, as opposed to Hibernate
+    // "ownerInfo.name.name" will map to primitive type, see
+    // testEqualsOwnerNameQuery3(), which also works in OpenJPA
     public void testEqualsOwnerNameQuery2() throws Exception {
         List<Book> books = queryBooks("ownerInfo.name==Fred");
         assertEquals(1, books.size());

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Name.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Name.java?rev=1405063&r1=1405062&r2=1405063&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Name.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Name.java
Fri Nov  2 17:19:53 2012
@@ -29,7 +29,7 @@ public class Name {
     public Name() {
         
     }
-    Name(String name) {
+    public Name(String name) {
         this.name = name;
     }
     

Modified: cxf/trunk/rt/rs/extensions/search/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/resources/META-INF/persistence.xml?rev=1405063&r1=1405062&r2=1405063&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/resources/META-INF/persistence.xml (original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/resources/META-INF/persistence.xml Fri Nov
 2 17:19:53 2012
@@ -2,18 +2,35 @@
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
              version="2.0">
-   <persistence-unit name="testUnit" transaction-type="RESOURCE_LOCAL">
-    <provider>org.hibernate.ejb.HibernatePersistence</provider>
-    <class>org.apache.cxf.jaxrs.ext.search.jpa.Book</class>
-    <class>org.apache.cxf.jaxrs.ext.search.jpa.Library</class>
-    <exclude-unlisted-classes>true</exclude-unlisted-classes>
-    <properties>
+   <persistence-unit name="testUnitHibernate" transaction-type="RESOURCE_LOCAL">
+     <provider>org.hibernate.ejb.HibernatePersistence</provider>
+     <class>org.apache.cxf.jaxrs.ext.search.jpa.Book</class>
+     <class>org.apache.cxf.jaxrs.ext.search.jpa.Library</class>
+     <exclude-unlisted-classes>true</exclude-unlisted-classes>
+     <properties>
         <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:books-jpa"/>
         <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
         <property name="hibernate.connection.username" value="sa"/>
         <property name="hibernate.connection.password" value=""/>
-    </properties>
-</persistence-unit>
+     </properties>
+   </persistence-unit>
+   <persistence-unit name="testUnitOpenJPA" transaction-type="RESOURCE_LOCAL">
+     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+     <class>org.apache.cxf.jaxrs.ext.search.jpa.Book</class>
+     <class>org.apache.cxf.jaxrs.ext.search.jpa.Library</class>
+     <class>org.apache.cxf.jaxrs.ext.search.jpa.OwnerAddress</class>
+     <class>org.apache.cxf.jaxrs.ext.search.jpa.OwnerInfo</class>
+     <class>org.apache.cxf.jaxrs.ext.search.jpa.Name</class>
+     <exclude-unlisted-classes>true</exclude-unlisted-classes>
+     <properties>
+        <property name="openjpa.ConnectionURL" value="jdbc:hsqldb:mem:books-jpa"/>
+        <property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver"/>
+        <property name="openjpa.jdbc.DBDictionary" value="hsql" />
+        <property name="openjpa.ConnectionUserName" value="sa"/>
+        <property name="openjpa.ConnectionPassword" value=""/>
+        <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
+     </properties>
+    </persistence-unit>
 </persistence>
\ No newline at end of file



Mime
View raw message