openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1827923 - in /openjpa/branches/2.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/
Date Wed, 28 Mar 2018 15:35:18 GMT
Author: jgrassel
Date: Wed Mar 28 15:35:18 2018
New Revision: 1827923

URL: http://svn.apache.org/viewvc?rev=1827923&view=rev
Log:
OPENJPA-2731: Problems with Boolean Representation with Postgres

Added:
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/BooleanTestEntity.java
  (with props)
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestBooleanColumnTypeMapping.java
  (with props)
Modified:
    openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/pom.xml

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=1827923&r1=1827922&r2=1827923&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
Wed Mar 28 15:35:18 2018
@@ -330,7 +330,7 @@ public class DBDictionary
      * Defines how {@code Boolean} and {@code boolean} values get represented
      * in OpenJPA. Default to {@code INT_10} for backward compatibility.
      */
-    protected BooleanRepresentation booleanRepresentation = BooleanRepresentationFactory.INT_10;
+    protected BooleanRepresentation booleanRepresentation = getDictionaryDefaultBooleanRepresentation();
     
     public int characterColumnSize = 255;
     public String arrayTypeName = "ARRAY";
@@ -5676,6 +5676,10 @@ public class DBDictionary
         return booleanRepresentation;
     }
     
+    public BooleanRepresentation getDictionaryDefaultBooleanRepresentation() {
+        return  BooleanRepresentationFactory.INT_10;
+    }
+    
     public void setBooleanRepresentation(String booleanRepresentationKey) {
         BooleanRepresentation evaluatedBooleanRepresentation = null;
         if (booleanRepresentationKey != null && booleanRepresentationKey.length()
> 0) {
@@ -5685,7 +5689,7 @@ public class DBDictionary
         
         booleanRepresentation = evaluatedBooleanRepresentation != null
                         ? evaluatedBooleanRepresentation
-                        : BooleanRepresentationFactory.INT_10;
+                        : getDictionaryDefaultBooleanRepresentation();
         
         if (log.isInfoEnabled()) {
             log.info(_loc.get("using-booleanRepresentation", booleanRepresentation));

Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java?rev=1827923&r1=1827922&r2=1827923&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
(original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/PostgresDictionary.java
Wed Mar 28 15:35:18 2018
@@ -303,13 +303,8 @@ public class PostgresDictionary
         }
     }
 
-    @Override
-    public void setBoolean(PreparedStatement stmnt, int idx, boolean val,
-        Column col)
-        throws SQLException {
-        // postgres actually requires that a boolean be set: it cannot
-        // handle a numeric argument.
-        stmnt.setBoolean(idx, val);
+    public BooleanRepresentation getDictionaryDefaultBooleanRepresentation() {
+        return  BooleanRepresentationFactory.BOOLEAN;
     }
 
     /**

Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/pom.xml?rev=1827923&r1=1827922&r2=1827923&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/pom.xml (original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/pom.xml Wed Mar 28 15:35:18 2018
@@ -129,7 +129,7 @@
             </activation>
             <dependencies>
                 <dependency>
-                    <groupId>postgresql</groupId>
+                    <groupId>org.postgresql</groupId>
                     <artifactId>postgresql</artifactId>
                     <version>${postgresql.version}</version>
                     <scope>test</scope>
@@ -631,14 +631,14 @@
         <profile>
             <!--
                 Example Informix profile. You can use this profile if you:
-                1) have the Informix JDBC artifacts installed in a local repo and 
+                1) have the Informix JDBC artifacts installed in a local repo and
                 supply the URL:
                   -Dids.maven.repo=http://my.local.repo
                 2) have a copy of the Informix driver and run the following
                 commands :
                     mvn install:install-file -Dfile=${path to ifxjdbc.jar} \
                                              -DgroupId=com.informix \
-                                             -DartifactId=informix-driver \ 
+                                             -DartifactId=informix-driver \
                                              -Dversion=3.70 \
                                              -Dpackaging=jar
 
@@ -695,7 +695,7 @@
                 </repository>
             </repositories>
         </profile>
-        
+
         <!-- Profile for testing with Oracle DB -->
         <profile>
             <!--

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/BooleanTestEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/BooleanTestEntity.java?rev=1827923&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/BooleanTestEntity.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/BooleanTestEntity.java
Wed Mar 28 15:35:18 2018
@@ -0,0 +1,56 @@
+/*
+ * 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.jdbc.mapping;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class BooleanTestEntity {
+    @Id
+    @GeneratedValue
+    private int id;
+    
+    @Basic
+    private boolean bVal;
+    
+    public BooleanTestEntity() {
+        
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public boolean isbVal() {
+        return bVal;
+    }
+
+    public void setbVal(boolean bVal) {
+        this.bVal = bVal;
+    }
+    
+    
+}

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

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestBooleanColumnTypeMapping.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestBooleanColumnTypeMapping.java?rev=1827923&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestBooleanColumnTypeMapping.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestBooleanColumnTypeMapping.java
Wed Mar 28 15:35:18 2018
@@ -0,0 +1,60 @@
+/*
+ * 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.jdbc.mapping;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestBooleanColumnTypeMapping extends SQLListenerTestCase  {
+    public void setUp() { 
+        setUp(BooleanTestEntity.class, 
+                "openjpa.jdbc.DBDictionary", "(BooleanRepresentation=BOOLEAN)", 
+                "openjpa.Log", "DefaultLevel=TRACE",
+                "openjpa.ConnectionFactoryProperties", "PrintParameters=true"
+                );
+    }
+    
+    public void testBooleanColumnMapping() {
+        EntityManager em = emf.createEntityManager();
+        
+        try {
+            em.getTransaction().begin();
+            final BooleanTestEntity bte = new BooleanTestEntity();
+            bte.setbVal(false);
+            em.persist(bte);;
+            em.getTransaction().commit();
+            
+            for (String s : sql) {
+                System.out.println(s);
+            }
+            em.clear();
+            
+            final BooleanTestEntity bteFind = em.find(BooleanTestEntity.class, bte.getId());
+            assertFalse(bteFind.isbVal());
+        } finally {
+            if (em.getTransaction().isActive()) {
+                em.getTransaction().rollback();
+            }
+            em.close();
+        }
+        
+        
+    }
+}

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



Mime
View raw message