Update of /var/cvs/src/org/mmbase/storage/implementation/database
In directory 
james.mmbase.org:/tmp/cvs-serv20082/src/org/mmbase/storage/implementation/database

Modified Files:
      Tag: MMBase-1_8
        DatabaseStorageManager.java 
Log Message:
MMB-1628  Even if using Node#getInputStream the complete blob is readed into 
memory first.

Do explicit check on database without loading the binary


See also: 
http://cvs.mmbase.org/viewcvs/src/org/mmbase/storage/implementation/database
See also: http://www.mmbase.org/jira/browse/MMB-1628


Index: DatabaseStorageManager.java
===================================================================
RCS file: 
/var/cvs/src/org/mmbase/storage/implementation/database/DatabaseStorageManager.java,v
retrieving revision 1.169.2.10
retrieving revision 1.169.2.11
diff -u -b -r1.169.2.10 -r1.169.2.11
--- DatabaseStorageManager.java 19 Mar 2008 11:52:47 -0000      1.169.2.10
+++ DatabaseStorageManager.java 11 Apr 2008 15:18:30 -0000      1.169.2.11
@@ -32,7 +32,7 @@
  *
  * @author Pierre van Rooden
  * @since MMBase-1.7
- * @version $Id: DatabaseStorageManager.java,v 1.169.2.10 2008/03/19 11:52:47 
pierre Exp $
+ * @version $Id: DatabaseStorageManager.java,v 1.169.2.11 2008/04/11 15:18:30 
nklasens Exp $
  */
 public class DatabaseStorageManager implements StorageManager {
 
@@ -976,6 +976,7 @@
         try {
             executeUpdate(query, node, fields);
         } catch (SQLException sqe) {
+            log.error("Failed to update", sqe);
             while (true) {
                 Statement s = null;
                 ResultSet rs = null;
@@ -1002,6 +1003,7 @@
                  }
                 break;
             }
+            log.info("Second try update with new connection");
             executeUpdate(query, node, fields);
         }
     }
@@ -3020,4 +3022,81 @@
             }
         }
     }
+
+    /**
+     * @see 
org.mmbase.storage.StorageManager#isNull(org.mmbase.module.core.MMObjectNode, 
org.mmbase.core.CoreField)
+     */
+    public boolean isNull(MMObjectNode node, CoreField field) throws 
StorageException {
+        int dbtype = Field.TYPE_UNKNOWN;
+        if (field != null) {
+            dbtype = field.getType();
+        }
+
+        if (dbtype == Field.TYPE_BINARY && 
factory.hasOption(Attributes.STORES_BINARY_AS_FILE)) {
+            String fieldName = field.getName();
+            File binaryFile = checkFile(getBinaryFile(node, fieldName), node, 
field);
+            return binaryFile == null;
+        } else {
+            try {
+                MMObjectBuilder builder = node.getBuilder();
+                Scheme scheme = factory.getScheme(Schemes.SELECT_NODE, 
Schemes.SELECT_NODE_DEFAULT);
+                String query = scheme.format(new Object[] { this, builder, 
field, builder.getField("number"), node });
+                getActiveConnection();
+                Statement s = activeConnection.createStatement();
+                ResultSet result = s.executeQuery(query);
+                try {
+                    if ((result != null) && result.next()) {
+                        String id = 
(String)factory.getStorageIdentifier(field);
+                        return isNull(result, result.findColumn(id), dbtype);
+                    } else {
+                        throw new StorageException("Node with number " + 
node.getNumber() + " of type " + builder + " not found.");
+                    }
+                } finally {
+                    if (result != null) {
+                        result.close();
+                    }
+                    if (s != null) {
+                        s.close();
+                    }
+                }
+            } catch (SQLException se) {
+                throw new StorageException(se);
+            } finally {
+                releaseActiveConnection();
+            }
+        }
+
+    }
+
+    private boolean isNull(ResultSet result, int index, int dbtype) throws 
SQLException {
+        switch (dbtype) {
+            // string-type fields
+        case Field.TYPE_XML :
+        case Field.TYPE_STRING :
+            result.getBinaryStream(index);
+            break;
+        case Field.TYPE_BINARY :
+            if (factory.hasOption(Attributes.SUPPORTS_BLOB)) {
+                result.getBlob(index);
+            }
+            else {
+                result.getBinaryStream(index);                
+            }
+            break;
+        case Field.TYPE_DATETIME :
+            result.getTimestamp(index);
+            break;
+        case Field.TYPE_BOOLEAN :
+            result.getBoolean(index);
+            break;
+        case Field.TYPE_INTEGER :
+        case Field.TYPE_NODE :
+            result.getObject(index);
+            break;
+        default :
+            result.getObject(index);
+            break;
+        }
+        return result.wasNull();
+    }
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to