[exo-jcr-commits] exo-jcr SVN: r5544 - in jcr/branches/1.15.x/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core/query/lucene and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 31 09:11:08 EST 2012


Author: andrew.plotnikov
Date: 2012-01-31 09:11:05 -0500 (Tue, 31 Jan 2012)
New Revision: 5544

Modified:
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Reindexable.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/statistics/StatisticsJDBCStorageConnection.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestWorkspaceStorageCacheInClusterMode.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/cache/jbosscache/TestJBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-1278: added show approximate progress of background re-indexing job

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Reindexable.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Reindexable.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Reindexable.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -47,4 +47,12 @@
     */
    boolean isReindexingSupport();
 
+   /**
+    * Return nodes count.
+    * 
+    * @return
+    *       nodes count
+    * @throws RepositoryException
+    */
+   Long getNodesCount() throws RepositoryException;
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -47,6 +47,7 @@
 import java.io.OutputStream;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
+import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -254,6 +255,11 @@
    private final IndexerIoModeHandler modeHandler;
 
    /**
+    * Nodes count
+    */
+   private AtomicLong nodesCount;
+
+   /**
     * The shutdown hook
     */
    private final Thread hook = new Thread()
@@ -380,6 +386,34 @@
    }
 
    /**
+    * Create thread finding count of nodes.
+    */
+   private Thread createThreadFindNodesCount(final Reindexable reindexableComponent)
+   {
+      return new Thread("Nodes count(" + handler.getContext().getWorkspaceName() + ")")
+      {
+         public void run()
+         {
+            try
+            {
+               if (reindexableComponent != null)
+               {
+                  Long value = reindexableComponent.getNodesCount();
+                  if (value != null)
+                  {
+                     nodesCount = new AtomicLong(value);
+                  }
+               }
+            }
+            catch (RepositoryException e)
+            {
+               LOG.error("Can't calculate nodes count : " + e.getMessage());
+            }
+         }
+      };
+   }
+
+   /**
     * Returns the number of documents in this index.
     * 
     * @return the number of documents in this index.
@@ -491,12 +525,15 @@
                // traverse and index workspace
                executeAndLog(new Start(Action.INTERNAL_TRANSACTION));
 
-               long count;
-
                // check if we have deal with RDBMS reindexing mechanism
                Reindexable rdbmsReindexableComponent =
                   (Reindexable)handler.getContext().getContainer().getComponent(Reindexable.class);
 
+               Thread thread = createThreadFindNodesCount(rdbmsReindexableComponent);
+               thread.start();
+
+               long count;
+
                if (handler.isRDBMSReindexing() && rdbmsReindexableComponent != null
                   && rdbmsReindexableComponent.isReindexingSupport())
                {
@@ -1783,7 +1820,8 @@
       }
    }
 
-   private long createIndex(NodeData node, ItemDataConsumer stateMgr) throws IOException, RepositoryException
+   private long createIndex(NodeData node, ItemDataConsumer stateMgr) throws IOException,
+      RepositoryException
    {
       MultithreadedIndexing indexing = new MultithreadedIndexing(node, stateMgr);
       return indexing.launch(false);
@@ -1811,8 +1849,9 @@
     *             if the task has been interrupted 
     */
    private void createIndex(final Queue<Callable<Void>> tasks, final NodeData node, final ItemDataConsumer stateMgr,
-      final AtomicLong count) throws IOException, RepositoryException, InterruptedException
+      final AtomicLong count, final AtomicLong processed) throws IOException, RepositoryException, InterruptedException
    {
+      processed.incrementAndGet();
       if (stopped)
       {
          throw new InterruptedException();
@@ -1824,9 +1863,19 @@
       }
 
       executeAndLog(new AddNode(getTransactionId(), node.getIdentifier(), true));
+
       if (count.incrementAndGet() % 1000 == 0)
       {
-         LOG.info("indexing... {} ({})", node.getQPath().getAsString(), new Long(count.get()));
+         if (nodesCount == null)
+         {
+            LOG.info("indexing... {} ({})", node.getQPath().getAsString(), new Long(count.get()));
+         }
+         else
+         {
+            DecimalFormat format = new DecimalFormat("###.#");
+            LOG.info("indexing... {} ({}%)", node.getQPath().getAsString(),
+               format.format(Math.min(100d * processed.get() / nodesCount.get(), 100)));
+         }
       }
 
       synchronized (this)
@@ -1842,14 +1891,14 @@
          {
             public Void call() throws Exception
             {
-               createIndex(tasks, node, stateMgr, count, nodeData);
+               createIndex(tasks, node, stateMgr, count, nodeData, processed);
                return null;
             }
          };
          if (!tasks.offer(task))
          {
             // All threads have tasks to do so we do it ourself
-            createIndex(tasks, node, stateMgr, count, nodeData);
+            createIndex(tasks, node, stateMgr, count, nodeData, processed);
          }
       }
    }
@@ -1878,7 +1927,8 @@
     *             if the task has been interrupted 
     */
    private void createIndex(final Queue<Callable<Void>> tasks, final NodeData node, final ItemDataConsumer stateMgr,
-      final AtomicLong count, final NodeData nodeData) throws RepositoryException, IOException, InterruptedException
+      final AtomicLong count, final NodeData nodeData, final AtomicLong processed) throws RepositoryException,
+      IOException, InterruptedException
    {
       NodeData childState = (NodeData)stateMgr.getItemData(nodeData.getIdentifier());
       if (childState == null)
@@ -1889,7 +1939,7 @@
 
       if (nodeData != null)
       {
-         createIndex(tasks, nodeData, stateMgr, count);
+         createIndex(tasks, nodeData, stateMgr, count, processed);
       }
    }
 
@@ -1929,11 +1979,12 @@
     * @throws InterruptedException
     *             if the task has been interrupted 
     */
-   private void createIndex(final NodeDataIndexingIterator iterator, NodeData rootNode, final AtomicLong count)
-      throws RepositoryException, InterruptedException, IOException
+   private void createIndex(final NodeDataIndexingIterator iterator, NodeData rootNode, final AtomicLong count,
+      final AtomicLong processed) throws RepositoryException, InterruptedException, IOException
    {
       for (NodeDataIndexing node : iterator.next())
       {
+         processed.incrementAndGet();
          if (stopped)
          {
             throw new InterruptedException();
@@ -1952,7 +2003,16 @@
          executeAndLog(new AddNode(getTransactionId(), node, true));
          if (count.incrementAndGet() % 1000 == 0)
          {
-            LOG.info("indexing... {} ({})", node.getQPath().getAsString(), new Long(count.get()));
+            if (nodesCount == null)
+            {
+               LOG.info("indexing... {} ({})", node.getQPath().getAsString(), count.get());
+            }
+            else
+            {
+               DecimalFormat format = new DecimalFormat("###.#");
+               LOG.info("indexing... {} ({}%)", node.getQPath().getAsString(),
+                  format.format(Math.min(100d * processed.get() / nodesCount.get(), 100)));
+            }
          }
 
          synchronized (this)
@@ -1983,7 +2043,8 @@
     *             if thread was interrupted
     */
    private void createIndex(final Queue<Callable<Void>> tasks, final NodeDataIndexingIterator iterator,
-      final NodeData rootNode, final AtomicLong count) throws IOException, RepositoryException, InterruptedException
+      final NodeData rootNode, final AtomicLong count, final AtomicLong processing) throws IOException,
+      RepositoryException, InterruptedException
    {
       while (iterator.hasNext())
       {
@@ -1992,7 +2053,7 @@
          {
             public Void call() throws Exception
             {
-               createIndex(iterator, rootNode, count);
+               createIndex(iterator, rootNode, count, processing);
                return null;
             }
          };
@@ -2000,7 +2061,7 @@
          if (!tasks.offer(task))
          {
             // All threads have tasks to do so we do it ourself
-            createIndex(iterator, rootNode, count);
+            createIndex(iterator, rootNode, count, processing);
          }
       }
    }
@@ -3405,6 +3466,8 @@
        */
       private final AtomicLong count = new AtomicLong();
 
+      private final AtomicLong processing = new AtomicLong();
+
       /**
        * The list of indexing tasks left to do
        */
@@ -3511,7 +3574,7 @@
          {
             public Void call() throws Exception
             {
-               createIndex(tasks, node, stateMgr, count);
+               createIndex(tasks, node, stateMgr, count, processing);
                return null;
             }
          });
@@ -3531,7 +3594,7 @@
          {
             public Void call() throws Exception
             {
-               createIndex(tasks, iterator, rootNode, count);
+               createIndex(tasks, iterator, rootNode, count, processing);
                return null;
             }
          });

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/DBConstants.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -195,6 +195,11 @@
     */
    protected String FIND_NODES_AND_PROPERTIES;
 
+   /**
+    * FIND_NODES_COUNT
+    */
+   protected String FIND_NODES_COUNT;
+
    // ======================== ITEMS table ======================== 
    /**
     * COLUMN_ID.

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -199,6 +199,8 @@
 
    protected PreparedStatement findNodesAndProperties;
 
+   protected PreparedStatement findNodesCount;
+
    /**
     * Read-only flag, if true the connection is marked as READ-ONLY.
     */
@@ -560,6 +562,11 @@
          {
             findNodesAndProperties.close();
          }
+
+         if (findNodesCount != null)
+         {
+            findNodesCount.close();
+         }
       }
       catch (SQLException e)
       {
@@ -1351,6 +1358,33 @@
       }
    }
 
+   /**
+    * Reads count of nodes in workspace.
+    * 
+    * @return
+    *          nodes count 
+    * @throws RepositoryException
+    *           if a database access error occurs
+    */
+   public long getNodesCount() throws RepositoryException
+   {
+      ResultSet countNodes;
+      try
+      {
+         countNodes = findNodesCount();
+         if (countNodes.next())
+         {
+            return countNodes.getLong(1);
+         }
+      }
+      catch (SQLException e)
+      {
+         throw new RepositoryException(e);
+      }
+
+      throw new RepositoryException("Can not calculate nodes count");
+   }
+
    // ------------------ Private methods ---------------
 
    /**
@@ -2702,6 +2736,8 @@
 
    protected abstract int updatePropertyByIdentifier(int version, int type, String identifier) throws SQLException;
 
+   protected abstract ResultSet findNodesCount() throws SQLException;
+
    // -------- values processing ------------
    protected abstract int addValueData(String cid, int orderNumber, InputStream stream, int streamLength,
       String storageId) throws SQLException;

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -1401,8 +1401,24 @@
    {
       return connFactory.isReindexingSupport();
    }
-   
+
    /**
+    * {@inheritDoc}
+    */
+   public Long getNodesCount() throws RepositoryException
+   {
+      WorkspaceStorageConnection conn = connFactory.openConnection();
+      try
+      {
+         return conn.getNodesCount();
+      }
+      finally
+      {
+         conn.close();
+      }
+   }
+
+   /**
     * Get the data source from the InitialContext and wraps it into a {@link ManagedDataSource}
     * in case it has been configured as managed
     */
@@ -1439,4 +1455,5 @@
 
       return DBConstants.DB_DIALECT_GENERIC; // by default
    }
+
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/MultiDbJDBCConnection.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -155,6 +155,8 @@
       DELETE_ITEM = "delete from JCR_MITEM where ID=?";
       DELETE_VALUE = "delete from JCR_MVALUE where PROPERTY_ID=?";
       DELETE_REF = "delete from JCR_MREF where PROPERTY_ID=?";
+
+      FIND_NODES_COUNT = "select count(*) from JCR_MITEM I where I.I_CLASS=1";
    }
 
    /**
@@ -601,4 +603,17 @@
          }
       }
    }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findNodesCount() throws SQLException
+   {
+      if (findNodesCount != null)
+      {
+         findNodesCount = dbConnection.prepareStatement(FIND_NODES_COUNT);
+      }
+      return findNodesCount.executeQuery();
+   }
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/db/SingleDbJDBCConnection.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -164,6 +164,8 @@
       DELETE_ITEM = "delete from JCR_SITEM where ID=?";
       DELETE_VALUE = "delete from JCR_SVALUE where PROPERTY_ID=?";
       DELETE_REF = "delete from JCR_SREF where PROPERTY_ID=?";
+
+      FIND_NODES_COUNT = "select count(*) from JCR_SITEM I where I.I_CLASS=1 and I.CONTAINER_NAME=?";
    }
 
    /**
@@ -627,4 +629,24 @@
          }
       }
    }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findNodesCount() throws SQLException
+   {
+      if (findNodesCount == null)
+      {
+         findNodesCount = dbConnection.prepareStatement(FIND_NODES_COUNT);
+      }
+      else
+      {
+         findNodesCount.clearParameters();
+      }
+
+      findNodesCount.setString(1, containerName);
+
+      return findNodesCount.executeQuery();
+   }
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -225,6 +225,8 @@
          "select I.PARENT_ID, I.P_TYPE "
             + " from JCR_MITEM I where I.I_CLASS=2 and (I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]owner'"
             + " or I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]permissions')";
+      
+      FIND_NODES_COUNT = "select count(*) from JCR_MITEM I where I.I_CLASS=1";
    }
 
    /**
@@ -1082,4 +1084,18 @@
          }
       }
    }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findNodesCount() throws SQLException
+   {
+      if (findNodesCount != null)
+      {
+         findNodesCount = dbConnection.prepareStatement(FIND_NODES_COUNT);
+      }
+      return findNodesCount.executeQuery();
+   }
+
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -234,6 +234,8 @@
             + " from JCR_SITEM I where I.I_CLASS=2 and I.CONTAINER_NAME=?"
             + " and (I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]owner'"
             + " or I.NAME='[http://www.exoplatform.com/jcr/exo/1.0]permissions')";
+
+      FIND_NODES_COUNT = "select count(*) from JCR_SITEM I where I.I_CLASS=1 and I.CONTAINER_NAME=?";
    }
 
    /**
@@ -952,7 +954,7 @@
       findACLHolders.setString(1, containerName);
 
       return findACLHolders.executeQuery();
-   }   
+   }
 
    /**
     * {@inheritDoc}
@@ -1006,4 +1008,24 @@
          }
       }
    }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   protected ResultSet findNodesCount() throws SQLException
+   {
+      if (findNodesCount == null)
+      {
+         findNodesCount = dbConnection.prepareStatement(FIND_NODES_COUNT);
+      }
+      else
+      {
+         findNodesCount.clearParameters();
+      }
+
+      findNodesCount.setString(1, containerName);
+
+      return findNodesCount.executeQuery();
+   }
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/statistics/StatisticsJDBCStorageConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/statistics/StatisticsJDBCStorageConnection.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/statistics/StatisticsJDBCStorageConnection.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -186,6 +186,8 @@
     */
    private static final String ADD_NODE_DATA_DESCR = "addNodeData";
 
+   private static final String NODES_COUNT = "getNodesCount";
+
    /**
     * The global statistics for all the database accesses
     */
@@ -217,6 +219,8 @@
       ALL_STATISTICS.put(GET_REFERENCES_DATA_DESCR, new Statistics(GLOBAL_STATISTICS, GET_REFERENCES_DATA_DESCR));
       ALL_STATISTICS.put(GET_VALUE_DESCR, new Statistics(GLOBAL_STATISTICS, GET_VALUE_DESCR));
       ALL_STATISTICS.put(GET_ACL_HOLDERS, new Statistics(GLOBAL_STATISTICS, GET_ACL_HOLDERS));
+      //Get nodes count 
+      ALL_STATISTICS.put(NODES_COUNT, new Statistics(GLOBAL_STATISTICS, NODES_COUNT));
       // Write Methods
       // Commit
       ALL_STATISTICS.put(COMMIT_DESCR, new Statistics(GLOBAL_STATISTICS, COMMIT_DESCR));
@@ -689,4 +693,21 @@
          s.end();
       }
    }
+
+   /**
+    * {@inheritDoc}
+    */
+   public long getNodesCount() throws RepositoryException
+   {
+      Statistics s = ALL_STATISTICS.get(NODES_COUNT);
+      try
+      {
+         s.begin();
+         return wcs.getNodesCount();
+      }
+      finally
+      {
+         s.end();
+      }
+   }
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -419,4 +419,14 @@
     *           if operation is not supported
     */
    List<ACLHolder> getACLHolders() throws RepositoryException, IllegalStateException, UnsupportedOperationException;
+
+   /**
+    * Reads count of nodes in workspace.
+    * 
+    * @return
+    *          nodes count 
+    * @throws RepositoryException
+    *           if a database access error occurs
+    */
+   public long getNodesCount() throws RepositoryException;
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -766,6 +766,14 @@
          return false;
       }
 
+      /**
+       * @see org.exoplatform.services.jcr.storage.WorkspaceStorageConnection#getNodesCount()
+       */
+      public long getNodesCount() throws RepositoryException
+      {
+         throw new UnsupportedOperationException();
+      }
+
    }
 
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -622,6 +622,13 @@
          return null;
       }
 
+      /**
+       * @see org.exoplatform.services.jcr.storage.WorkspaceStorageConnection#getNodesCount()
+       */
+      public long getNodesCount() throws RepositoryException
+      {
+         throw new UnsupportedOperationException();
+      }
    };
 
    private static class MyWorkspaceDataContainer extends WorkspaceDataContainerBase

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestWorkspaceStorageCacheInClusterMode.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestWorkspaceStorageCacheInClusterMode.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestWorkspaceStorageCacheInClusterMode.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -968,6 +968,14 @@
       {
          return null;
       }
+
+      /**
+       * @see org.exoplatform.services.jcr.storage.WorkspaceStorageConnection#getNodesCount()
+       */
+      public long getNodesCount() throws RepositoryException
+      {
+         throw new UnsupportedOperationException();
+      }
    };
    
    private static class MyWorkspaceDataContainer extends WorkspaceDataContainerBase

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/cache/jbosscache/TestJBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/cache/jbosscache/TestJBossCacheWorkspaceStorageCache.java	2012-01-31 10:48:05 UTC (rev 5543)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/cache/jbosscache/TestJBossCacheWorkspaceStorageCache.java	2012-01-31 14:11:05 UTC (rev 5544)
@@ -169,7 +169,6 @@
    private static class MyWorkspaceStorageConnection implements WorkspaceStorageConnection
    {
       
-
       private Mode mode;
       private CountDownLatch goSignal;
       
@@ -333,6 +332,14 @@
          return null;
       }
 
+      /**
+       * @see org.exoplatform.services.jcr.storage.WorkspaceStorageConnection#getNodesCount()
+       */
+      public long getNodesCount() throws RepositoryException
+      {
+         throw new UnsupportedOperationException();
+      }
+
    };
    
    private static class MyWorkspaceDataContainer extends WorkspaceDataContainerBase



More information about the exo-jcr-commits mailing list