openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r653008 - in /openjpa/branches/1.1.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/
Date Sat, 03 May 2008 06:30:27 GMT
Author: pcl
Date: Fri May  2 23:30:27 2008
New Revision: 653008

URL: http://svn.apache.org/viewvc?rev=653008&view=rev
Log:
OPENJPA-130. Committing on behalf of Ignacio Andreu.

Modified:
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/ReaderLobEntity.java

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java?rev=653008&r1=653007&r2=653008&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/LobFieldStrategy.java
Fri May  2 23:30:27 2008
@@ -80,18 +80,12 @@
             (field.getIndex()), store);
         Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
         if (field.getColumnIO().isInsertable(0, ob == null)) {
-            if (ob != null) {
-                if (isBlob()) {
-                    store.getDBDictionary().insertBlobForStreamingLoad
-                        (row, field.getColumns()[0]);
-                } else {
-                    store.getDBDictionary().insertClobForStreamingLoad
-                        (row, field.getColumns()[0]);
-                }
+            if (isBlob()) {
+                store.getDBDictionary().insertBlobForStreamingLoad
+                    (row, field.getColumns()[0], ob);
             } else {
-                Column col = field.getColumns()[0];
-                col.setType(Types.OTHER);
-                row.setNull(col);
+                store.getDBDictionary().insertClobForStreamingLoad
+                    (row, field.getColumns()[0], ob);
             }
         }
     }
@@ -113,11 +107,31 @@
             }
         }
     }
+    
+    public Boolean isCustomUpdate(OpenJPAStateManager sm, JDBCStore store) {
+        return null;
+    }
 
     public void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
         throws SQLException {
         Object ob = toDataStoreValue(sm.fetchObjectField
-            (field.getIndex()), store);
+                (field.getIndex()), store);
+        if (field.getColumnIO().isUpdatable(0, ob == null)) {
+            Row row = field.getRow(sm, store, rm, Row.ACTION_UPDATE);
+            if (isBlob()) {
+                store.getDBDictionary().insertBlobForStreamingLoad
+                    (row, field.getColumns()[0], ob);
+            } else {
+                store.getDBDictionary().insertClobForStreamingLoad
+                    (row, field.getColumns()[0], ob);
+            }
+        }
+    }
+
+    public void customUpdate(OpenJPAStateManager sm, JDBCStore store)
+        throws SQLException {
+        Object ob = toDataStoreValue(sm.fetchObjectField
+                (field.getIndex()), store);
         if (field.getColumnIO().isUpdatable(0, ob == null)) {
             if (ob != null) {
                 Select sel = createSelect(sm, store);
@@ -128,11 +142,6 @@
                     store.getDBDictionary().updateClob
                         (sel, store, (Reader)ob);
                 }
-            } else {
-                Row row = field.getRow(sm, store, rm, Row.ACTION_UPDATE);
-                Column col = field.getColumns()[0];
-                col.setType(Types.OTHER);
-                row.setNull(col);
             }
         }
     }
@@ -191,4 +200,5 @@
         sel.setLob(true);
         return sel;
     }
+    
 }

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=653008&r1=653007&r2=653008&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Fri May  2 23:30:27 2008
@@ -127,8 +127,8 @@
     public static final String CONS_NAME_MID = "mid";
     public static final String CONS_NAME_AFTER = "after";
     
-    public int blobBufferSize = 50;
-    public int clobBufferSize = 50;
+    public int blobBufferSize = 50000;
+    public int clobBufferSize = 50000;
 
     protected static final int RANGE_POST_SELECT = 0;
     protected static final int RANGE_PRE_DISTINCT = 1;
@@ -4166,16 +4166,24 @@
         return column.toString();
     }
     
-    public void insertBlobForStreamingLoad(Row row, Column col)
+    public void insertBlobForStreamingLoad(Row row, Column col, Object ob)
     throws SQLException {
-        row.setBinaryStream(col, 
-                new ByteArrayInputStream(new byte[0]), 0);
+        if (ob != null) {
+            row.setBinaryStream(col, 
+                    new ByteArrayInputStream(new byte[0]), 0);
+        } else {
+            row.setNull(col);
+        }
     }
     
-    public void insertClobForStreamingLoad(Row row, Column col)
+    public void insertClobForStreamingLoad(Row row, Column col, Object ob)
     throws SQLException {
+        if (ob != null) {
         row.setCharacterStream(col,
                 new CharArrayReader(new char[0]), 0);
+        } else {
+            row.setNull(col);
+        }
     }
     
     public void updateBlob(Select sel, JDBCStore store, InputStream is)

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java?rev=653008&r1=653007&r2=653008&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
Fri May  2 23:30:27 2008
@@ -1092,13 +1092,17 @@
         buf.append("')");
     }
     
-    public void insertBlobForStreamingLoad(Row row, Column col)
+    public void insertBlobForStreamingLoad(Row row, Column col, Object ob)
         throws SQLException {
+        if (ob == null)
+            col.setType(Types.OTHER);
         row.setNull(col);
     }
     
-    public void insertClobForStreamingLoad(Row row, Column col)
+    public void insertClobForStreamingLoad(Row row, Column col, Object ob)
         throws SQLException {
+        if (ob == null)
+            col.setType(Types.OTHER);
         row.setNull(col);
     }
 }

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java?rev=653008&r1=653007&r2=653008&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/AbstractLobTest.java
Fri May  2 23:30:27 2008
@@ -20,6 +20,7 @@
 package org.apache.openjpa.jdbc.meta.strats;
 
 import java.io.IOException;
+
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
@@ -117,6 +118,41 @@
         em.close();
     }
 
+    public void testUpdateWithNull() {
+        if (!isDatabaseSupported()) return;
+        insert(newLobEntity("oOOOOOo", 1));
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
+        entity.setStream(null);
+        em.getTransaction().commit();
+        em.close();
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        entity = (LobEntity) em.find(getLobEntityClass(), 1);
+        assertNull(entity.getStream());
+        em.getTransaction().commit();
+        em.close();
+    }
+    
+    public void testUpdateANullObjectWithoutNull() throws IOException {
+        if (!isDatabaseSupported()) return;
+        insert(newLobEntity(null, 1));
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        LobEntity entity = (LobEntity) em.find(getLobEntityClass(), 1);
+        String string = "iIIIIIi";
+        changeStream(entity, string);
+        em.getTransaction().commit();
+        em.close();
+        em = emf.createEntityManager();
+        em.getTransaction().begin();
+        entity = (LobEntity) em.find(getLobEntityClass(), 1);
+        assertEquals(string, getStreamContentAsString(entity.getStream()));
+        em.getTransaction().commit();
+        em.close();
+    }
+    
     public void testDelete() {
         if (!isDatabaseSupported()) return;
         insert(newLobEntity("oOOOOOo", 1));

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/ReaderLobEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/ReaderLobEntity.java?rev=653008&r1=653007&r2=653008&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/ReaderLobEntity.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strats/ReaderLobEntity.java
Fri May  2 23:30:27 2008
@@ -35,10 +35,10 @@
 public class ReaderLobEntity implements LobEntity {
 
     @Id
-    int id;
+    private int id;
 
     @Persistent
-    Reader stream;
+    private Reader stream;
 
     public int getId() {
         return id;



Mime
View raw message