[exo-jcr-commits] exo-jcr SVN: r4801 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc: optimisation and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Aug 26 08:07:29 EDT 2011


Author: tolusha
Date: 2011-08-26 08:07:28 -0400 (Fri, 26 Aug 2011)
New Revision: 4801

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-1482:  Use batch update for the property values

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2011-08-26 10:58:55 UTC (rev 4800)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2011-08-26 12:07:28 UTC (rev 4801)
@@ -166,8 +166,6 @@
 
    protected PreparedStatement findPropertiesByParentId;
 
-   protected PreparedStatement insertItem;
-
    protected PreparedStatement insertNode;
 
    protected PreparedStatement insertProperty;
@@ -176,20 +174,11 @@
 
    protected PreparedStatement insertValue;
 
-   protected PreparedStatement updateItem;
-
-   protected PreparedStatement updateItemPath;
-
    protected PreparedStatement updateNode;
 
    protected PreparedStatement updateProperty;
 
    protected PreparedStatement deleteItem;
-
-   protected PreparedStatement deleteNode;
-
-   protected PreparedStatement deleteProperty;
-
    protected PreparedStatement deleteReference;
 
    protected PreparedStatement deleteValue;
@@ -486,11 +475,6 @@
             findPropertiesByParentId.close();
          }
 
-         if (insertItem != null)
-         {
-            insertItem.close();
-         }
-
          if (insertNode != null)
          {
             insertNode.close();
@@ -511,16 +495,6 @@
             insertValue.close();
          }
 
-         if (updateItem != null)
-         {
-            updateItem.close();
-         }
-
-         if (updateItemPath != null)
-         {
-            updateItemPath.close();
-         }
-
          if (updateNode != null)
          {
             updateNode.close();
@@ -536,16 +510,6 @@
             deleteItem.close();
          }
 
-         if (deleteNode != null)
-         {
-            deleteNode.close();
-         }
-
-         if (deleteProperty != null)
-         {
-            deleteProperty.close();
-         }
-
          if (deleteReference != null)
          {
             deleteReference.close();

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java	2011-08-26 10:58:55 UTC (rev 4800)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java	2011-08-26 12:07:28 UTC (rev 4801)
@@ -153,6 +153,8 @@
 
    protected Statement findNodesByParentIdAndComplexPatternCQ;
 
+   protected final boolean allowBatching;
+   
    /**
      * JDBCStorageConnection constructor.
      * 
@@ -176,6 +178,7 @@
       throws SQLException
    {
       super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
+      this.allowBatching = dbConnection.getMetaData().supportsBatchUpdates();
    }
 
    /**
@@ -505,7 +508,7 @@
    {
       List<ValueData> vdata = data.getValues();
 
-      for (int i = 0; i < vdata.size(); i++)
+      for (int i = 0, length = vdata.size(); i < length; i++)
       {
          ValueData vd = vdata.get(i);
          ValueIOChannel channel = valueStorageProvider.getApplicableChannel(data, i);
@@ -561,11 +564,11 @@
          }
          if (i < totalOldValues)
          {
-            updateValueData(cid, i, stream, streamLength, storageId);
+            updateValueData(cid, i, stream, streamLength, storageId, i == length - 1 || i == totalOldValues - 1);
          }
          else
          {
-            addValueData(cid, i, stream, streamLength, storageId);
+            addValueData(cid, i, stream, streamLength, storageId, i == length - 1);
          }
       }
    }
@@ -1240,6 +1243,9 @@
 
    protected abstract int deleteValueDataByOrderNum(String id, int orderNum) throws SQLException;
 
-   protected abstract int updateValueData(String cid, int i, InputStream stream, int streamLength, String storageId)
+   protected abstract int updateValueData(String cid, int i, InputStream stream, int streamLength, String storageId, boolean lastValue)
       throws SQLException;
+   
+   protected abstract int addValueData(String cid, int orderNumber, InputStream stream, int streamLength,
+      String storageId, boolean lastValue) throws SQLException;
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2011-08-26 10:58:55 UTC (rev 4800)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2011-08-26 12:07:28 UTC (rev 4801)
@@ -667,7 +667,17 @@
    protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
       throws SQLException
    {
+      throw new UnsupportedOperationException("This method is not supported, use the mehod of the same name with lastValue");
+   }
 
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc, boolean lastValue)
+      throws SQLException
+   {
+
       if (insertValue == null)
       {
          insertValue = dbConnection.prepareStatement(INSERT_VALUE);
@@ -691,9 +701,18 @@
 
       insertValue.setInt(2, orderNumber);
       insertValue.setString(3, cid);
+      if (allowBatching)
+      {
+         insertValue.addBatch();
+         if (lastValue)
+         {
+            insertValue.executeBatch();
+         }
+         return 1;         
+      }
       return insertValue.executeUpdate();
    }
-
+   
    /**
     * {@inheritDoc}
     */
@@ -886,7 +905,7 @@
       return findPropertyById.executeQuery();
    }
 
-   protected int updateValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
+   protected int updateValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc, boolean lastValue)
       throws SQLException
    {
 
@@ -913,6 +932,15 @@
 
       updateValue.setString(3, cid);
       updateValue.setInt(4, orderNumber);
+      if (allowBatching)
+      {
+         updateValue.addBatch();
+         if (lastValue)
+         {
+            updateValue.executeBatch();
+         }
+         return 1;
+      }
       return updateValue.executeUpdate();
    }
 

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java	2011-08-26 10:58:55 UTC (rev 4800)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java	2011-08-26 12:07:28 UTC (rev 4801)
@@ -520,7 +520,17 @@
    protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
       throws SQLException
    {
+      throw new UnsupportedOperationException("This method is not supported, use the mehod of the same name with lastValue");
+   }
 
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected int addValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc, boolean lastValue)
+      throws SQLException
+   {
+
       if (insertValue == null)
          insertValue = dbConnection.prepareStatement(INSERT_VALUE);
       else
@@ -540,6 +550,15 @@
 
       insertValue.setInt(2, orderNumber);
       insertValue.setString(3, cid);
+      if (allowBatching)
+      {
+         insertValue.addBatch();
+         if (lastValue)
+         {
+            insertValue.executeBatch();
+         }
+         return 1;         
+      }
       return insertValue.executeUpdate();
    }
 
@@ -825,7 +844,7 @@
    }
    
    @Override
-   protected int updateValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc)
+   protected int updateValueData(String cid, int orderNumber, InputStream stream, int streamLength, String storageDesc, boolean lastValue)
       throws SQLException
    {
 
@@ -848,6 +867,15 @@
 
       updateValue.setString(3, cid);
       updateValue.setInt(4, orderNumber);
+      if (allowBatching)
+      {
+         updateValue.addBatch();
+         if (lastValue)
+         {
+            updateValue.executeBatch();
+         }
+         return 1;         
+      }      
       return updateValue.executeUpdate();
    }  
 



More information about the exo-jcr-commits mailing list