Author: dianner
Date: Thu Jun 28 14:58:23 2012
New Revision: 1355034
URL: http://svn.apache.org/viewvc?rev=1355034&view=rev
Log:
OPENJPA-2221 Fix result of value mapping strategy
Added:
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
(with props)
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
(with props)
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
(with props)
Modified:
openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Modified:
openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1355034&r1=1355033&r2=1355034&view=diff
==============================================================================
---
openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++
openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Thu Jun 28 14:58:23 2012
@@ -1373,14 +1373,32 @@ public class DBDictionary
setObject(stmnt, idx, val, col.getType(), col);
}
}
+
+ /**
+ * Set a completely unknown parameter into a prepared statement.
+ */
+ 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) {
+ System.out.println("object " + object.getClass().getName());
+ 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, Object val,
- Column col)
+ private void setUnknown(PreparedStatement stmnt, int idx, Column col,
Object val)
throws SQLException {
- Sized sized = null;
+ Sized sized = null;
Calendard cald = null;
if (val instanceof Sized) {
sized = (Sized) val;
@@ -1389,7 +1407,7 @@ public class DBDictionary
cald = (Calendard) val;
val = cald.value;
}
-
+
if (val == null)
setNull(stmnt, idx, (col == null) ? Types.OTHER : col.getType(),
col);
Added:
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java?rev=1355034&view=auto
==============================================================================
---
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
(added)
+++
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
Thu Jun 28 14:58:23 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.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/TestValueStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java?rev=1355034&view=auto
==============================================================================
---
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
(added)
+++
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
Thu Jun 28 14:58:23 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.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java?rev=1355034&view=auto
==============================================================================
---
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
(added)
+++
openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
Thu Jun 28 14:58:23 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.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/strategy/value/ValueStrategyHandler.java
------------------------------------------------------------------------------
svn:eol-style = native