You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2009/06/16 17:51:16 UTC
svn commit: r785268 - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/
Author: mikedd
Date: Tue Jun 16 15:51:15 2009
New Revision: 785268
URL: http://svn.apache.org/viewvc?rev=785268&view=rev
Log:
OPENJPA-1133 committing patch provided by Ravi Palacherla. PostgreSQL
Dictionary will now use "false" as a placeholder instead of 0 for
columns of type BIT.
modified: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
new file: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/EntityBool.java
new file: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestBooleanValue.java
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/EntityBool.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestBooleanValue.java
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java?rev=785268&r1=785267&r2=785268&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java Tue Jun 16 15:51:15 2009
@@ -649,6 +649,18 @@
appendCast(buf, newBufer, type);
}
+
+ /**
+ * Return a SQL string to act as a placeholder for the given column.
+ */
+ public String getPlaceholderValueString(Column col) {
+ if (col.getType() == Types.BIT) {
+ return "false";
+ } else {
+ return super.getPlaceholderValueString(col);
+ }
+ }
+
/**
* Connection wrapper to work around the postgres empty result set bug.
*/
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/EntityBool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/EntityBool.java?rev=785268&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/EntityBool.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/EntityBool.java Tue Jun 16 15:51:15 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.jdbc.meta;
+import javax.persistence.*;
+
+@Entity
+public class EntityBool {
+
+ @Id
+ private int id;
+ private boolean dummy;
+
+ public boolean isDummy() {
+ return dummy;
+ }
+
+ public void setDummy(boolean value) {
+ dummy = value;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+}
+
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestBooleanValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestBooleanValue.java?rev=785268&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestBooleanValue.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/TestBooleanValue.java Tue Jun 16 15:51:15 2009
@@ -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.jdbc.meta;
+
+import javax.persistence.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.jdbc.schema.Column;
+
+public class TestBooleanValue extends SingleEMFTestCase {
+
+ public void setUp() throws Exception {
+ super.setUp(EntityBool.class);
+ }
+
+ public void testBooleanValue() {
+ EntityManager em = emf.createEntityManager();
+ EntityBool t0 = new EntityBool();
+ t0.setDummy(false);
+ em.getTransaction().begin();
+ em.persist(t0);
+ em.getTransaction().commit();
+ Column boolCol =
+ getMapping(EntityBool.class).getTable().getColumn("dummy");
+ Query q =
+ em.createNativeQuery("Select "
+ + ((JDBCConfiguration) emf.getConfiguration())
+ .getDBDictionaryInstance().getPlaceholderValueString(
+ boolCol)
+ + " FROM EntityBool a UNION ALL Select a.dummy " +
+ "FROM EntityBool a");
+ q.getResultList();
+ em.close();
+ }
+}