Author: jgrassel
Date: Thu Sep 13 16:40:32 2012
New Revision: 1384400

URL: http://svn.apache.org/viewvc?rev=1384400&view=rev
Log:
OPENJPA-2221: Use of AbstractValueHandler map() causes exception on find()

Added:
    
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/
    
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/
    
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
   (with props)
    
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
   (with props)
    
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
   (with props)
Modified:
    
openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java

Modified: 
openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1384400&r1=1384399&r2=1384400&view=diff
==============================================================================
--- 
openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
 (original)
+++ 
openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
 Thu Sep 13 16:40:32 2012
@@ -1416,9 +1416,21 @@ public class DBDictionary
     /**
      * Set a completely unknown parameter into a prepared statement.
      */
-    public void setUnknown(PreparedStatement stmnt, int idx, Object val,
-        Column col)
-        throws SQLException {
+    public void setUnknown(PreparedStatement stmt, int idx, Object val, Column 
col) throws SQLException {
+        if (val instanceof Object[]) {
+            Object[] valArray = (Object[])val;
+            for (Object object : valArray) {
+                setUnknown(stmt, idx, col, object);
+            }
+        } else {
+            setUnknown(stmt, idx, col, val);
+        }
+    }
+    
+    /**
+     * Set a completely unknown parameter into a prepared statement.
+     */
+    public void setUnknown(PreparedStatement stmnt, int idx, Column col, 
Object val) throws SQLException {
         Sized sized = null;
         Calendard cald = null;
         if (val instanceof Sized) {

Added: 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java?rev=1384400&view=auto
==============================================================================
--- 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
 (added)
+++ 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
 Thu Sep 13 16:40:32 2012
@@ -0,0 +1,54 @@
+/*
+ * 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.strategy.value;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestValueStrategy extends SQLListenerTestCase {
+    public void setUp(){
+      setUp(ValueStrategyEntity.class, DROP_TABLES);
+      assertNotNull(emf);
+      
+      create();
+}
+    
+    public void testIt() {
+        EntityManager em = emf.createEntityManager();
+        ValueStrategyEntity se = em.find(ValueStrategyEntity.class, "id1");
+        assertNotNull(se);
+        
+        em.close();
+    }
+
+        private void create() {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            
+            ValueStrategyEntity stratEnt = new ValueStrategyEntity();
+            stratEnt.setId("id1");
+            stratEnt.setName("name1");
+            
+            em.persist(stratEnt);
+            
+            em.getTransaction().commit();
+            em.close();
+        }
+}

Propchange: 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java?rev=1384400&view=auto
==============================================================================
--- 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
 (added)
+++ 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
 Thu Sep 13 16:40:32 2012
@@ -0,0 +1,51 @@
+/*
+ * 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.strategy.value;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+import org.apache.openjpa.persistence.jdbc.Strategy;
+
+@Entity
+public class ValueStrategyEntity {
+    @Id
+    @Strategy 
("org.apache.openjpa.persistence.strategy.value.ValueStrategyHandler")
+    private String id;
+    
+    @Strategy 
("org.apache.openjpa.persistence.strategy.value.ValueStrategyHandler")
+    private String name;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}

Propchange: 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java?rev=1384400&view=auto
==============================================================================
--- 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
 (added)
+++ 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
 Thu Sep 13 16:40:32 2012
@@ -0,0 +1,66 @@
+/*
+ * 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.strategy.value;
+
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.meta.ValueMapping;
+import org.apache.openjpa.jdbc.meta.strats.AbstractValueHandler;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ColumnIO;
+import org.apache.openjpa.meta.JavaTypes;
+
+public class ValueStrategyHandler extends AbstractValueHandler {
+
+       private static final long serialVersionUID = 8371304701543038775L;
+       
+       private static final ValueStrategyHandler _instance = new 
ValueStrategyHandler();
+       
+       public static ValueStrategyHandler getInstance(){
+               return _instance;
+       }
+       
+       @Override
+       public Column[] map(ValueMapping arg0, String name, ColumnIO arg2,
+                       boolean arg3) {
+
+               Column col = new Column();
+               col.setName(name);
+               col.setJavaType(JavaTypes.STRING);
+               
+               return new Column[]{col};
+       }
+       
+       public Object toDataStoreValue(ValueMapping vm, Object val, JDBCStore 
store){
+               
+               if(val == null){
+                       return null;
+               }
+               
+               return val.toString();
+       }
+       
+       public Object toObjectValue(ValueMapping vm, Object val){
+               if(val == null){
+                       return null;
+               }
+               
+               return val.toString();
+       }
+
+}

Propchange: 
openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to