[exo-jcr-commits] exo-jcr SVN: r1196 - in jcr/branches/1.12.0-OPT/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 Dec 25 12:05:38 EST 2009


Author: sergiykarpenko
Date: 2009-12-25 12:05:38 -0500 (Fri, 25 Dec 2009)
New Revision: 1196

Removed:
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/SQLExceptionHandler.java
Modified:
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
Log:
EXOJCR-302: code clean up

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2009-12-25 16:16:18 UTC (rev 1195)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2009-12-25 17:05:38 UTC (rev 1196)
@@ -1220,7 +1220,7 @@
     * Mixin types description (internal use).
     * 
     */
-   class MixinInfo
+   public class MixinInfo
    {
 
       /**
@@ -1268,7 +1268,7 @@
        * @param privilegeable
        *          exo:privilegeable flag
        */
-      MixinInfo(List<InternalQName> mixinTypes, boolean owneable, boolean privilegeable)
+      public MixinInfo(List<InternalQName> mixinTypes, boolean owneable, boolean privilegeable)
       {
          this.mixinTypes = mixinTypes;
          this.owneable = owneable;
@@ -1280,7 +1280,7 @@
        * 
        * @return InternalQName[] Mixin names array
        */
-      InternalQName[] mixinNames()
+      public InternalQName[] mixinNames()
       {
          if (mixinTypes != null)
          {
@@ -1297,7 +1297,7 @@
        * 
        * @return boolean
        */
-      boolean hasPrivilegeable()
+      public boolean hasPrivilegeable()
       {
          return privilegeable;
       }
@@ -1307,10 +1307,15 @@
        * 
        * @return boolean
        */
-      boolean hasOwneable()
+      public boolean hasOwneable()
       {
          return owneable;
       }
+
+      public String getParentId()
+      {
+         return parentId;
+      }
    }
 
    /**

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java	2009-12-25 16:16:18 UTC (rev 1195)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/CQJDBCStorageConnection.java	2009-12-25 17:05:38 UTC (rev 1196)
@@ -20,7 +20,6 @@
 
 import org.exoplatform.services.jcr.access.AccessControlEntry;
 import org.exoplatform.services.jcr.access.AccessControlList;
-import org.exoplatform.services.jcr.dataflow.ItemState;
 import org.exoplatform.services.jcr.dataflow.persistent.PersistedNodeData;
 import org.exoplatform.services.jcr.dataflow.persistent.PersistedPropertyData;
 import org.exoplatform.services.jcr.datamodel.IllegalACLException;
@@ -36,18 +35,13 @@
 import org.exoplatform.services.jcr.impl.dataflow.persistent.ByteArrayPersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.CleanableFilePersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
-import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
 import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
-import org.exoplatform.services.jcr.impl.storage.jdbc.PrimaryTypeNotFoundException;
 import org.exoplatform.services.jcr.impl.storage.value.ValueStorageNotFoundException;
 import org.exoplatform.services.jcr.impl.storage.value.fs.operations.ValueFileIOHelper;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
 import org.exoplatform.services.jcr.impl.util.io.SwapFile;
-import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
 import org.exoplatform.services.jcr.storage.value.ValueIOChannel;
 import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -56,7 +50,6 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
@@ -67,7 +60,6 @@
 import java.util.StringTokenizer;
 
 import javax.jcr.InvalidItemStateException;
-import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 
 /**
@@ -76,45 +68,61 @@
  * @author <a href="mailto:gennady.azarenkov at exoplatform.com">Gennady Azarenkov</a>
  * @version $Id: JDBCStorageConnection.java 34801 2009-07-31 15:44:50Z dkatayev $
  */
-abstract public class CQJDBCStorageConnection extends DBConstants implements WorkspaceStorageConnection
+abstract public class CQJDBCStorageConnection extends JDBCStorageConnection
 {
 
    /**
-    * Connection logger.
+    * FIND_ITEM_BY_NAME NEW.
     */
-   protected static final Log LOG = ExoLogger.getLogger("jcr.JDBCStorageConnection");
+   protected String FIND_ITEM_BY_NAME_NEW;
 
    /**
-    * NODE type.
+    * FIND_NODE_BY_ID.
     */
-   public static final int I_CLASS_NODE = 1;
+   protected String FIND_ITEM_BY_ID_NEW;
 
    /**
-    * PROPERTY type.
+    * FIND_NODES_BY_PARENTID NEW.
     */
-   public static final int I_CLASS_PROPERTY = 2;
+   protected String FIND_NODES_BY_PARENTID_NEW;
 
-   protected final ValueStoragePluginProvider valueStorageProvider;
+   protected String GET_PROPERTIES_BY_PARENTID;
 
-   protected final int maxBufferSize;
+   protected String FIND_REFERENCE_PROPERTIES;
 
-   protected final File swapDirectory;
+   /**
+    * Class needed to store node details (property also) since result set is not sorted in valid way. 
+    * 
+    */
+   private static class TempNodeData
+   {
+      String cid;
 
-   protected final FileCleaner swapCleaner;
+      String cname;
 
-   protected final Connection dbConnection;
+      int cversion;
 
-   protected final String containerName;
+      String cpid;
 
-   protected final SQLExceptionHandler exceptionHandler;
+      int cindex;
 
-   protected final List<ValueIOChannel> valueChanges;
+      int cnordernumb;
 
-   /**
-    * Read-only flag, if true the connection is marked as READ-ONLY.
-    */
-   protected final boolean readOnly;
+      Map<String, List<byte[]>> properties = new HashMap<String, List<byte[]>>();
 
+      public TempNodeData(ResultSet item) throws SQLException
+      {
+         cid = item.getString(COLUMN_ID);
+         cname = item.getString(COLUMN_NAME);
+         cversion = item.getInt(COLUMN_VERSION);
+
+         cpid = item.getString(COLUMN_PARENTID);
+
+         cindex = item.getInt(COLUMN_INDEX);
+         cnordernumb = item.getInt(COLUMN_NORDERNUM);
+      }
+   }
+
    /**
      * JDBCStorageConnection constructor.
      * 
@@ -137,465 +145,17 @@
       ValueStoragePluginProvider valueStorageProvider, int maxBufferSize, File swapDirectory, FileCleaner swapCleaner)
       throws SQLException
    {
-
-      this.valueStorageProvider = valueStorageProvider;
-
-      this.maxBufferSize = maxBufferSize;
-      this.swapDirectory = swapDirectory;
-      this.swapCleaner = swapCleaner;
-      this.containerName = containerName;
-
-      this.dbConnection = dbConnection;
-      this.readOnly = readOnly;
-
-      // Fix for Sybase jConnect JDBC driver bug.
-      // Which throws SQLException(JZ016: The AutoCommit option is already set to
-      // false)
-      // if conn.setAutoCommit(false) called twise or more times with value
-      // 'false'.
-      if (dbConnection.getAutoCommit())
-      {
-         dbConnection.setAutoCommit(false);
-      }
-
-      prepareQueries();
-      this.exceptionHandler = new SQLExceptionHandler(containerName, this);
-
-      this.valueChanges = new ArrayList<ValueIOChannel>();
+      super(dbConnection, readOnly, containerName, valueStorageProvider, maxBufferSize, swapDirectory, swapCleaner);
    }
 
    /**
     * {@inheritDoc}
     */
-   @Override
-   public boolean equals(Object obj)
-   {
-      if (obj == this)
-         return true;
-
-      if (obj instanceof JDBCStorageConnection)
-      {
-         JDBCStorageConnection another = (JDBCStorageConnection)obj;
-         return getJdbcConnection() == another.getJdbcConnection();
-      }
-
-      return false;
-   }
-
-   /**
-    * Return JDBC connection obtained from initialized data source. NOTE: Helper can obtain one new
-    * connection per each call of the method or return one obtained once.
-    */
-   public Connection getJdbcConnection()
-   {
-      return dbConnection;
-   }
-
-   /**
-    * Prepared queries at start time.
-    * 
-    * @throws SQLException
-    *           database error
-    */
-   abstract protected void prepareQueries() throws SQLException;
-
-   /**
-    * Used in Single Db Connection classes for Identifier related queries.
-    * 
-    * @param identifier
-    *          Item id
-    * @return String with container internal id
-    */
-   protected abstract String getInternalId(String identifier);
-
-   /**
-    * Used in loadXYZRecord methods for extract real Identifier from container value.
-    * 
-    * @param internalId
-    * @return
-    */
-   protected abstract String getIdentifier(String internalId);
-
-   // ---------------- WorkspaceStorageConnection -------------
-
-   /**
-    * @throws IllegalStateException
-    *           if connection is closed.
-    */
-   protected void checkIfOpened() throws IllegalStateException
-   {
-      if (!isOpened())
-         throw new IllegalStateException("Connection is closed");
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public boolean isOpened()
-   {
-      try
-      {
-         return !dbConnection.isClosed();
-      }
-      catch (SQLException e)
-      {
-         LOG.error(e);
-         return false;
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public final void rollback() throws IllegalStateException, RepositoryException
-   {
-      checkIfOpened();
-      try
-      {
-         dbConnection.rollback();
-         dbConnection.close();
-
-         // rollback from the end
-         for (int p = valueChanges.size() - 1; p >= 0; p--)
-            valueChanges.get(p).rollback();
-      }
-      catch (SQLException e)
-      {
-         throw new RepositoryException(e);
-      }
-      catch (IOException e)
-      {
-         throw new RepositoryException(e);
-      }
-      finally
-      {
-         valueChanges.clear();
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public final void close() throws IllegalStateException, RepositoryException
-   {
-      checkIfOpened();
-      try
-      {
-         // If READ-ONLY status back it to READ-WRITE (we assume it was original state)
-         if (readOnly)
-            dbConnection.setReadOnly(true);
-
-         dbConnection.close();
-      }
-      catch (SQLException e)
-      {
-         throw new RepositoryException(e);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public final void commit() throws IllegalStateException, RepositoryException
-   {
-      checkIfOpened();
-      try
-      {
-         dbConnection.commit();
-         dbConnection.close();
-
-         try
-         {
-            for (ValueIOChannel vo : valueChanges)
-               vo.commit();
-
-         }
-         catch (IOException e)
-         {
-            throw new RepositoryException(e);
-         }
-         finally
-         {
-            valueChanges.clear();
-         }
-      }
-      catch (SQLException e)
-      {
-         throw new RepositoryException(e);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void add(NodeData data) throws RepositoryException, UnsupportedOperationException, InvalidItemStateException,
-      IllegalStateException
-   {
-      checkIfOpened();
-      try
-      {
-         addNodeRecord(data);
-         if (LOG.isDebugEnabled())
-            LOG.debug("Node added " + data.getQPath().getAsString() + ", " + data.getIdentifier() + ", "
-               + data.getPrimaryTypeName().getAsString());
-
-      }
-      catch (SQLException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Node add. Database error: " + e);
-
-         exceptionHandler.handleAddException(e, data);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void add(PropertyData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
-   {
-      checkIfOpened();
-
-      try
-      {
-         addPropertyRecord(data);
-
-         if (data.getType() == PropertyType.REFERENCE)
-         {
-            try
-            {
-               addReference(data);
-            }
-            catch (IOException e)
-            {
-               throw new RepositoryException("Can't read REFERENCE property (" + data.getQPath() + " "
-                  + data.getIdentifier() + ") value: " + e.getMessage(), e);
-            }
-         }
-
-         addValues(getInternalId(data.getIdentifier()), data);
-
-         if (LOG.isDebugEnabled())
-            LOG.debug("Property added " + data.getQPath().getAsString() + ", " + data.getIdentifier()
-               + (data.getValues() != null ? ", values count: " + data.getValues().size() : ", NULL data"));
-
-      }
-      catch (IOException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Property add. IO error: " + e, e);
-         throw new RepositoryException("Error of Property Value add " + e, e);
-      }
-      catch (SQLException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Property add. Database error: " + e, e);
-         exceptionHandler.handleAddException(e, data);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void rename(NodeData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
-   {
-
-      checkIfOpened();
-      try
-      {
-         if (renameNode(data) <= 0)
-            throw new JCRInvalidItemStateException("(rename) Node not found " + data.getQPath().getAsString() + " "
-               + data.getIdentifier() + ". Probably was deleted by another session ", data.getIdentifier(),
-               ItemState.RENAMED);
-      }
-      catch (SQLException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Property add. Database error: " + e, e);
-         exceptionHandler.handleAddException(e, data);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void delete(NodeData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
-   {
-      checkIfOpened();
-
-      final String cid = getInternalId(data.getIdentifier());
-
-      try
-      {
-         int nc = deleteItemByIdentifier(cid);
-         if (nc <= 0)
-            throw new JCRInvalidItemStateException("(delete) Node not found " + data.getQPath().getAsString() + " "
-               + data.getIdentifier() + ". Probably was deleted by another session ", data.getIdentifier(),
-               ItemState.DELETED);
-
-         if (LOG.isDebugEnabled())
-            LOG.debug("Node deleted " + data.getQPath().getAsString() + ", " + data.getIdentifier() + ", "
-               + ((NodeData)data).getPrimaryTypeName().getAsString());
-
-      }
-      catch (SQLException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Node remove. Database error: " + e, e);
-         exceptionHandler.handleDeleteException(e, data);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void delete(PropertyData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
-   {
-      checkIfOpened();
-
-      final String cid = getInternalId(data.getIdentifier());
-
-      try
-      {
-         deleteValues(cid, data, false);
-
-         // delete references
-         deleteReference(cid);
-
-         // delete item
-         int nc = deleteItemByIdentifier(cid);
-         if (nc <= 0)
-            throw new JCRInvalidItemStateException("(delete) Property not found " + data.getQPath().getAsString() + " "
-               + data.getIdentifier() + ". Probably was deleted by another session ", data.getIdentifier(),
-               ItemState.DELETED);
-
-         if (LOG.isDebugEnabled())
-            LOG.debug("Property deleted "
-               + data.getQPath().getAsString()
-               + ", "
-               + data.getIdentifier()
-               + (((PropertyData)data).getValues() != null ? ", values count: "
-                  + ((PropertyData)data).getValues().size() : ", NULL data"));
-
-      }
-      catch (IOException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Property remove. IO error: " + e, e);
-         throw new RepositoryException("Error of Property Value delete " + e, e);
-      }
-      catch (SQLException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Property remove. Database error: " + e, e);
-         exceptionHandler.handleDeleteException(e, data);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void update(NodeData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
-   {
-      checkIfOpened();
-      try
-      {
-         String cid = getInternalId(data.getIdentifier());
-         // order numb update
-         if (updateNodeByIdentifier(data.getPersistedVersion(), data.getQPath().getIndex(), data.getOrderNumber(), cid) <= 0)
-            throw new JCRInvalidItemStateException("(update) Node not found " + data.getQPath().getAsString() + " "
-               + data.getIdentifier() + ". Probably was deleted by another session ", data.getIdentifier(),
-               ItemState.UPDATED);
-
-         if (LOG.isDebugEnabled())
-            LOG.debug("Node updated " + data.getQPath().getAsString() + ", " + data.getIdentifier() + ", "
-               + data.getPrimaryTypeName().getAsString());
-
-      }
-      catch (SQLException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Node update. Database error: " + e, e);
-         exceptionHandler.handleUpdateException(e, data);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public void update(PropertyData data) throws RepositoryException, UnsupportedOperationException,
-      InvalidItemStateException, IllegalStateException
-   {
-      checkIfOpened();
-
-      try
-      {
-         String cid = getInternalId(data.getIdentifier());
-
-         // update type
-         if (updatePropertyByIdentifier(data.getPersistedVersion(), data.getType(), cid) <= 0)
-            throw new JCRInvalidItemStateException("(update) Property not found " + data.getQPath().getAsString() + " "
-               + data.getIdentifier() + ". Probably was deleted by another session ", data.getIdentifier(),
-               ItemState.UPDATED);
-
-         // update reference
-         try
-         {
-            deleteReference(cid);
-
-            if (data.getType() == PropertyType.REFERENCE)
-            {
-               addReference(data);
-            }
-         }
-         catch (IOException e)
-         {
-            throw new RepositoryException("Can't update REFERENCE property (" + data.getQPath() + " "
-               + data.getIdentifier() + ") value: " + e.getMessage(), e);
-         }
-
-         // do Values update: delete all and add all
-         deleteValues(cid, data, true);
-         addValues(cid, data);
-
-         if (LOG.isDebugEnabled())
-            LOG.debug("Property updated " + data.getQPath().getAsString() + ", " + data.getIdentifier()
-               + (data.getValues() != null ? ", values count: " + data.getValues().size() : ", NULL data"));
-
-      }
-      catch (IOException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Property update. IO error: " + e, e);
-         throw new RepositoryException("Error of Property Value update " + e, e);
-      }
-      catch (SQLException e)
-      {
-         if (LOG.isDebugEnabled())
-            LOG.error("Property update. Database error: " + e, e);
-         exceptionHandler.handleUpdateException(e, data);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
    public List<NodeData> getChildNodesData(NodeData parent) throws RepositoryException, IllegalStateException
    {
       checkIfOpened();
       try
       {
-         //         ResultSet node = findChildNodesByParentIdentifier(getInternalId(parent.getIdentifier()));
-         //         List<NodeData> childrens = new ArrayList<NodeData>();
-         //         while (node.next())
-         //            childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE, parent.getACL()));
-         //
-         //         return childrens;
          ResultSet resultSet = findChildNodesByParentIdentifierNew(getInternalId(parent.getIdentifier()));
          if (resultSet.next())
          {
@@ -665,35 +225,6 @@
 
    }
 
-   private static class TempNodeData
-   {
-      String cid;
-
-      String cname;
-
-      int cversion;
-
-      String cpid;
-
-      int cindex;
-
-      int cnordernumb;
-
-      Map<String, List<byte[]>> properties = new HashMap<String, List<byte[]>>();
-
-      public TempNodeData(ResultSet item) throws SQLException
-      {
-         cid = item.getString(COLUMN_ID);
-         cname = item.getString(COLUMN_NAME);
-         cversion = item.getInt(COLUMN_VERSION);
-
-         cpid = item.getString(COLUMN_PARENTID);
-
-         cindex = item.getInt(COLUMN_INDEX);
-         cnordernumb = item.getInt(COLUMN_NORDERNUM);
-      }
-   }
-
    /**
     * {@inheritDoc}
     */
@@ -1051,40 +582,6 @@
       }
    }
 
-   /**
-    * Find ancestor permissions by cpid. Will search till find the permissions or meet a root node.
-    * 
-    * @param cpid
-    *          - initial parent node id
-    * @return Collection<String>
-    * @throws SQLException
-    *           if database error
-    * @throws IllegalACLException
-    *           if wrong ACL
-    * @throws IllegalNameException
-    *           if wrong QName
-    * @throws RepositoryException
-    *           if Repository error
-    */
-   private List<AccessControlEntry> traverseACLPermissions(String cpid) throws SQLException, IllegalACLException,
-      IllegalNameException, RepositoryException
-   {
-      String caid = cpid;
-      while (!caid.equals(Constants.ROOT_PARENT_UUID))
-      {
-         MixinInfo naMixins = readMixins(caid);
-         if (naMixins.hasPrivilegeable())
-            return readACLPermisions(caid);
-
-         if (naMixins.parentId == null)
-            caid = findParentId(caid);
-         else
-            caid = naMixins.parentId;
-      }
-
-      throw new IllegalACLException("Can not find permissions for a node with id " + getIdentifier(cpid));
-   }
-
    protected String findParentId(String cid) throws SQLException, RepositoryException
    {
       ResultSet pidrs = findItemByIdentifier(cid);
@@ -1102,168 +599,6 @@
    }
 
    /**
-    * Find ancestor owner by cpid. Will search till find the owner or meet a root node.
-    * 
-    * @param cpid
-    *          - initial parent node id
-    * @return owner name
-    * @throws SQLException
-    *           if database error
-    * @throws IllegalACLException
-    *           if wrong ACL
-    * @throws IllegalNameException
-    *           if wrong QName
-    * @throws RepositoryException
-    *           if Repository error
-    */
-   private String traverseACLOwner(String cpid) throws SQLException, IllegalACLException, IllegalNameException,
-      RepositoryException
-   {
-      String caid = cpid;
-
-      while (!caid.equals(Constants.ROOT_PARENT_UUID))
-      {
-         MixinInfo naMixins = readMixins(caid);
-         if (naMixins.hasOwneable())
-            return readACLOwner(caid);
-
-         if (naMixins.parentId == null)
-            caid = findParentId(caid);
-         else
-            caid = naMixins.parentId;
-      }
-
-      throw new IllegalACLException("Can not find owner for a node with id " + getIdentifier(cpid));
-   }
-
-   /**
-    * Find ancestor ACL by cpid. Will search till find the ACL or meet a root node.
-    * 
-    * @param cpid
-    *          - initial parent node id
-    * @return owner name
-    * @throws SQLException
-    *           if database error
-    * @throws IllegalACLException
-    *           if wrong ACL
-    * @throws IllegalNameException
-    *           if wrong QName
-    * @throws RepositoryException
-    *           if Repository error
-    */
-   private AccessControlList traverseACL(String cpid) throws SQLException, IllegalACLException, IllegalNameException,
-      RepositoryException
-   {
-      String naOwner = null;
-      List<AccessControlEntry> naPermissions = null;
-
-      String caid = cpid;
-
-      while (!caid.equals(Constants.ROOT_PARENT_UUID))
-      {
-         MixinInfo naMixins = readMixins(caid);
-         if (naOwner == null && naMixins.hasOwneable())
-         {
-            naOwner = readACLOwner(caid);
-            if (naPermissions != null)
-               break;
-         }
-         if (naPermissions == null && naMixins.hasPrivilegeable())
-         {
-            naPermissions = readACLPermisions(caid);
-            if (naOwner != null)
-               break;
-         }
-
-         if (naMixins.parentId == null)
-            caid = findParentId(caid);
-         else
-            caid = naMixins.parentId;
-      }
-
-      if (naOwner != null && naPermissions != null)
-      {
-         // got all
-         return new AccessControlList(naOwner, naPermissions);
-      }
-      else if (naOwner == null && naPermissions == null)
-      {
-         // Default values (i.e. ACL is disabled in repository)
-         return new AccessControlList();
-      }
-      else
-         throw new IllegalACLException("ACL is not found for node with id " + getIdentifier(cpid)
-            + " or for its ancestors. But repository is ACL enabled.");
-   }
-
-   /**
-    * [PN] Experimental. Use SP for traversing Qpath on the database server side. Hm, I haven't a
-    * good result for that yet. Few seconds only for TCK execution. PGSQL SP: CREATE OR REPLACE
-    * FUNCTION get_qpath(parentId VARCHAR) RETURNS SETOF record AS $$ DECLARE cur_item RECORD; cur_id
-    * varchar; BEGIN cur_id := parentId; WHILE NOT cur_id = ' ' LOOP SELECT id, name, parent_id,
-    * i_index INTO cur_item FROM JCR_SITEM WHERE ID=cur_id; IF NOT found THEN RETURN; END IF; RETURN
-    * NEXT cur_item; cur_id := cur_item.parent_id; END LOOP; RETURN; END; $$ LANGUAGE plpgsql;
-    * 
-    * @param cpid
-    * @return
-    * @throws SQLException
-    *           if database error
-    * @throws InvalidItemStateException
-    *           if Item state is obsolete
-    * @throws IllegalNameException
-    *           if invalid QName
-    */
-   private QPath traverseQPath_SP_PGSQL(String cpid) throws SQLException, InvalidItemStateException,
-      IllegalNameException
-   {
-      // get item by Identifier usecase:
-      // find parent path in db by cpid
-      if (cpid == null)
-      {
-         // root node
-         return null; // Constants.ROOT_PATH
-      }
-      else
-      {
-         List<QPathEntry> qrpath = new ArrayList<QPathEntry>(); // reverted path
-         PreparedStatement cstmt = null;
-         try
-         {
-            cstmt =
-               dbConnection
-                  .prepareStatement("select * from get_qpath(?) AS (id varchar, name varchar, parent_id varchar, i_index int)");
-            cstmt.setString(1, cpid);
-            // cstmt.setString(2, caid);
-            ResultSet parent = cstmt.executeQuery();
-
-            while (parent.next())
-            {
-               QPathEntry qpe =
-                  new QPathEntry(InternalQName.parse(parent.getString(COLUMN_NAME)), parent.getInt(COLUMN_INDEX));
-               qrpath.add(qpe);
-            }
-
-            // parent = findItemByIdentifier(caid);
-            if (qrpath.size() <= 0)
-               throw new InvalidItemStateException("Parent not found, uuid: " + getIdentifier(cpid));
-         }
-         finally
-         {
-            if (cstmt != null)
-               cstmt.close();
-         }
-
-         QPathEntry[] qentries = new QPathEntry[qrpath.size()];
-         int qi = 0;
-         for (int i = qrpath.size() - 1; i >= 0; i--)
-         {
-            qentries[qi++] = qrpath.get(i);
-         }
-         return new QPath(qentries);
-      }
-   }
-
-   /**
     * Build ItemData.
     * 
     * @param parentPath
@@ -1362,151 +697,6 @@
    }
 
    /**
-    * Mixin types description (internal use).
-    * 
-    */
-   class MixinInfo
-   {
-
-      /**
-       * OWNEABLE constant.
-       */
-      static final int OWNEABLE = 0x0001; // bits 0001
-
-      /**
-       * PRIVILEGEABLE constant.
-       */
-      static final int PRIVILEGEABLE = 0x0002; // bits 0010
-
-      /**
-       * OWNEABLE_PRIVILEGEABLE constant.
-       */
-      static final int OWNEABLE_PRIVILEGEABLE = OWNEABLE | PRIVILEGEABLE; // bits 0011
-
-      /**
-       * Mixin types.
-       */
-      final List<InternalQName> mixinTypes;
-
-      /**
-       * oexo:owneable flag.
-       */
-      final boolean owneable;
-
-      /**
-       * exo:privilegeable flag.
-       */
-      final boolean privilegeable;
-
-      /**
-       * Parent Id.
-       */
-      final String parentId = null;
-
-      /**
-       * MixinInfo constructor.
-       * 
-       * @param mixinTypes
-       *          mixin types
-       * @param owneable
-       *          exo:owneable flag
-       * @param privilegeable
-       *          exo:privilegeable flag
-       */
-      MixinInfo(List<InternalQName> mixinTypes, boolean owneable, boolean privilegeable)
-      {
-         this.mixinTypes = mixinTypes;
-         this.owneable = owneable;
-         this.privilegeable = privilegeable;
-      }
-
-      /**
-       * Return Mixin names array.
-       * 
-       * @return InternalQName[] Mixin names array
-       */
-      InternalQName[] mixinNames()
-      {
-         if (mixinTypes != null)
-         {
-            InternalQName[] mns = new InternalQName[mixinTypes.size()];
-            mixinTypes.toArray(mns);
-            return mns;
-         }
-         else
-            return new InternalQName[0];
-      }
-
-      /**
-       * Tell is exo:privilegeable.
-       * 
-       * @return boolean
-       */
-      boolean hasPrivilegeable()
-      {
-         return privilegeable;
-      }
-
-      /**
-       * Tell is exo:owneable.
-       * 
-       * @return boolean
-       */
-      boolean hasOwneable()
-      {
-         return owneable;
-      }
-   }
-
-   /**
-    * Read mixins from database.
-    * 
-    * @param cid
-    *          - Item id (internal)
-    * @return MixinInfo
-    * @throws SQLException
-    *           database error
-    * @throws IllegalNameException
-    *           if nodetype name in mixin record is wrong
-    */
-   protected MixinInfo readMixins(String cid) throws SQLException, IllegalNameException
-   {
-      ResultSet mtrs = findPropertyByName(cid, Constants.JCR_MIXINTYPES.getAsString());
-
-      try
-      {
-         List<InternalQName> mts = null;
-         boolean owneable = false;
-         boolean privilegeable = false;
-         if (mtrs.next())
-         {
-            mts = new ArrayList<InternalQName>();
-            do
-            {
-               byte[] mxnb = mtrs.getBytes(COLUMN_VDATA);
-               if (mxnb != null)
-               {
-                  InternalQName mxn = InternalQName.parse(new String(mxnb));
-                  mts.add(mxn);
-
-                  if (!privilegeable && Constants.EXO_PRIVILEGEABLE.equals(mxn))
-                     privilegeable = true;
-                  else if (!owneable && Constants.EXO_OWNEABLE.equals(mxn))
-                     owneable = true;
-               } // else, if SQL NULL - skip it
-            }
-            while (mtrs.next());
-         }
-
-         return new MixinInfo(mts, owneable, privilegeable);
-      }
-      finally
-      {
-         mtrs.close();
-      }
-   }
-
-   /**
     * Return permission values or throw an exception. We assume the node is mix:privilegeable.
     * 
     * @param cid
@@ -1573,151 +763,6 @@
    }
 
    /**
-    * Load NodeData record.
-    * 
-    * @param parentPath
-    *          parent path
-    * @param cname
-    *          Node name
-    * @param cid
-    *          Node id
-    * @param cpid
-    *          Node parent id
-    * @param cindex
-    *          Node index
-    * @param cversion
-    *          Node persistent version
-    * @param cnordernumb
-    *          Node order number
-    * @param parentACL
-    *          Node parent ACL
-    * @return PersistedNodeData
-    * @throws RepositoryException
-    *           Repository error
-    * @throws SQLException
-    *           database error
-    */
-   protected PersistedNodeData loadNodeRecord(QPath parentPath, String cname, String cid, String cpid, int cindex,
-      int cversion, int cnordernumb, AccessControlList parentACL) throws RepositoryException, SQLException
-   {
-
-      try
-      {
-         InternalQName qname = InternalQName.parse(cname);
-
-         QPath qpath;
-         String parentCid;
-         if (parentPath != null)
-         {
-            // get by parent and name
-            qpath = QPath.makeChildPath(parentPath, qname, cindex);
-            parentCid = cpid;
-         }
-         else
-         {
-            // get by id
-            if (cpid.equals(Constants.ROOT_PARENT_UUID))
-            {
-               // root node
-               qpath = Constants.ROOT_PATH;
-               parentCid = null;
-            }
-            else
-            {
-               qpath = QPath.makeChildPath(traverseQPath(cpid), qname, cindex);
-               parentCid = cpid;
-            }
-         }
-
-         try
-         {
-            // PRIMARY
-            ResultSet ptProp = findPropertyByName(cid, Constants.JCR_PRIMARYTYPE.getAsString());
-
-            if (!ptProp.next())
-               throw new PrimaryTypeNotFoundException("FATAL ERROR primary type record not found. Node "
-                  + qpath.getAsString() + ", id " + cid + ", container " + this.containerName, null);
-
-            byte[] data = ptProp.getBytes(COLUMN_VDATA);
-            InternalQName ptName = InternalQName.parse(new String((data != null ? data : new byte[]{})));
-
-            // MIXIN
-            MixinInfo mixins = readMixins(cid);
-
-            // ACL
-            AccessControlList acl; // NO DEFAULT values!
-
-            if (mixins.hasOwneable())
-            {
-               // has own owner
-               if (mixins.hasPrivilegeable())
-               {
-                  // and permissions
-                  acl = new AccessControlList(readACLOwner(cid), readACLPermisions(cid));
-               }
-               else if (parentACL != null)
-               {
-                  // use permissions from existed parent
-                  acl =
-                     new AccessControlList(readACLOwner(cid), parentACL.hasPermissions() ? parentACL
-                        .getPermissionEntries() : null);
-               }
-               else
-               {
-                  // have to search nearest ancestor permissions in ACL manager
-                  // acl = new AccessControlList(readACLOwner(cid), traverseACLPermissions(cpid));
-                  acl = new AccessControlList(readACLOwner(cid), null);
-               }
-            }
-            else if (mixins.hasPrivilegeable())
-            {
-               // has own permissions
-               if (mixins.hasOwneable())
-               {
-                  // and owner
-                  acl = new AccessControlList(readACLOwner(cid), readACLPermisions(cid));
-               }
-               else if (parentACL != null)
-               {
-                  // use owner from existed parent
-                  acl = new AccessControlList(parentACL.getOwner(), readACLPermisions(cid));
-               }
-               else
-               {
-                  // have to search nearest ancestor owner in ACL manager
-                  // acl = new AccessControlList(traverseACLOwner(cpid), readACLPermisions(cid));
-                  acl = new AccessControlList(null, readACLPermisions(cid));
-               }
-            }
-            else
-            {
-               if (parentACL != null)
-                  // construct ACL from existed parent ACL
-                  acl =
-                     new AccessControlList(parentACL.getOwner(), parentACL.hasPermissions() ? parentACL
-                        .getPermissionEntries() : null);
-               else
-                  // have to search nearest ancestor owner and permissions in ACL manager
-                  // acl = traverseACL(cpid);
-                  acl = null;
-            }
-
-            return new PersistedNodeData(getIdentifier(cid), qpath, getIdentifier(parentCid), cversion, cnordernumb,
-               ptName, mixins.mixinNames(), acl);
-         }
-         catch (IllegalACLException e)
-         {
-            throw new RepositoryException("FATAL ERROR Node " + getIdentifier(cid) + " " + qpath.getAsString()
-               + " has wrong formed ACL. ", e);
-         }
-      }
-      catch (IllegalNameException e)
-      {
-         throw new RepositoryException(e);
-      }
-   }
-
-   /**
     * Load PropertyData record.
     * 
     * @param parentPath
@@ -2134,60 +1179,6 @@
    }
 
    /**
-    * Delete Property Values.
-    * 
-    * @param cid
-    *          Property id
-    * @param pdata
-    *          PropertyData
-    * @param update
-    *          boolean true if it's delete-add sequence (update operation)
-    * @throws IOException
-    *           i/O error
-    * @throws SQLException
-    *           if database error occurs
-    * @throws ValueStorageNotFoundException
-    *           if no such storage found with Value storageId
-    */
-   private void deleteValues(String cid, PropertyData pdata, boolean update) throws IOException, SQLException,
-      ValueStorageNotFoundException
-   {
-
-      final ResultSet valueRecords = findValuesStorageDescriptorsByPropertyId(cid);
-      try
-      {
-         if (valueRecords.next())
-         {
-            // delete all Values in database
-            deleteValueData(cid);
-
-            do
-            {
-               final String storageId = valueRecords.getString(COLUMN_VSTORAGE_DESC);
-               if (!valueRecords.wasNull())
-               {
-                  final ValueIOChannel channel = valueStorageProvider.getChannel(storageId);
-                  try
-                  {
-                     channel.delete(pdata.getIdentifier());
-                     valueChanges.add(channel);
-                  }
-                  finally
-                  {
-                     channel.close();
-                  }
-               }
-            }
-            while (valueRecords.next());
-         }
-      }
-      finally
-      {
-         valueRecords.close();
-      }
-   }
-
-   /**
     * Read Property Values.
     * 
     * @param identifier
@@ -2476,50 +1467,6 @@
       }
    }
 
-   protected abstract int addNodeRecord(NodeData data) throws SQLException;
-
-   protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
-
-   protected abstract ResultSet findItemByIdentifier(String identifier) throws SQLException;
-
-   protected abstract ResultSet findPropertyByName(String parentId, String name) throws SQLException;
-
-   protected abstract ResultSet findItemByName(String parentId, String name, int index) throws SQLException;
-
-   protected abstract ResultSet findChildNodesByParentIdentifier(String parentIdentifier) throws SQLException;
-
-   protected abstract ResultSet findChildNodesCountByParentIdentifier(String parentIdentifier) throws SQLException;
-
-   protected abstract ResultSet findChildPropertiesByParentIdentifier(String parentIdentifier) throws SQLException;
-
-   protected abstract int addReference(PropertyData data) throws SQLException, IOException;
-
-   protected abstract int renameNode(NodeData data) throws SQLException;
-
-   protected abstract int deleteReference(String propertyIdentifier) throws SQLException;
-
-   protected abstract ResultSet findReferences(String nodeIdentifier) throws SQLException;
-
-   protected abstract int deleteItemByIdentifier(String identifier) throws SQLException;
-
-   protected abstract int updateNodeByIdentifier(int version, int index, int orderNumb, String identifier)
-      throws SQLException;
-
-   protected abstract int updatePropertyByIdentifier(int version, int type, String identifier) throws SQLException;
-
-   // -------- values processing ------------
-   protected abstract int addValueData(String cid, int orderNumber, InputStream stream, int streamLength,
-      String storageId) throws SQLException;
-
-   protected abstract int deleteValueData(String cid) throws SQLException;
-
-   protected abstract ResultSet findValuesByPropertyId(String cid) throws SQLException;
-
-   protected abstract ResultSet findValuesStorageDescriptorsByPropertyId(String cid) throws SQLException;
-
-   @Deprecated
-   protected abstract ResultSet findValueByPropertyIdOrderNumber(String cid, int orderNumb) throws SQLException;
-
    protected abstract ResultSet findItemByIdentifierNew(String identifier) throws SQLException;
 
    protected abstract ResultSet findItemByNameNew(String parentId, String name, int index) throws SQLException;

Deleted: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java	2009-12-25 16:16:18 UTC (rev 1195)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java	2009-12-25 17:05:38 UTC (rev 1196)
@@ -1,348 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation;
-
-/**
- * Created by The eXo Platform SAS.
- * 
- * @author Gennady Azarenkov
- * @version $Id: DBConstants.java 34801 2009-07-31 15:44:50Z dkatayev $
- */
-
-public class DBConstants
-{
-   // ======================== Error constants ======================== 
-   /**
-    * JCR_PK_ITEM.
-    */
-   protected String JCR_PK_ITEM;
-
-   /**
-    * JCR_FK_ITEM_PARENT.
-    */
-   protected String JCR_FK_ITEM_PARENT;
-
-   /**
-    * JCR_IDX_ITEM_PARENT.
-    */
-   protected String JCR_IDX_ITEM_PARENT;
-
-   /**
-    * JCR_IDX_ITEM_PARENT_NAME.
-    */
-   protected String JCR_IDX_ITEM_PARENT_NAME;
-
-   /**
-    * JCR_IDX_ITEM_PARENT_ID.
-    */
-   protected String JCR_IDX_ITEM_PARENT_ID;
-
-   /**
-    * JCR_PK_VALUE.
-    */
-   protected String JCR_PK_VALUE;
-
-   /**
-    * JCR_FK_VALUE_PROPERTY.
-    */
-   protected String JCR_FK_VALUE_PROPERTY;
-
-   /**
-    * JCR_IDX_VALUE_PROPERTY.
-    */
-   protected String JCR_IDX_VALUE_PROPERTY;
-
-   /**
-    * JCR_PK_REF.
-    */
-   protected String JCR_PK_REF;
-
-   /**
-    * JCR_IDX_REF_PROPERTY.
-    */
-   protected String JCR_IDX_REF_PROPERTY;
-
-   // ======================== SQL scripts ======================== 
-   /**
-    * FIND_ITEM_BY_ID.
-    */
-   protected String FIND_ITEM_BY_ID;
-
-   /**
-    * FIND_ITEM_BY_PATH.
-    */
-   protected String FIND_ITEM_BY_PATH;
-
-   /**
-    * FIND_ITEM_BY_NAME.
-    */
-   protected String FIND_ITEM_BY_NAME;
-
-   /**
-    * FIND_ITEM_BY_NAME NEW.
-    */
-   protected String FIND_ITEM_BY_NAME_NEW;
-
-   /**
-    * FIND_NODE_BY_ID.
-    */
-   protected String FIND_ITEM_BY_ID_NEW;
-
-   /**
-    * FIND_CHILD_PROPERTY_BY_PATH.
-    */
-   protected String FIND_CHILD_PROPERTY_BY_PATH;
-
-   /**
-    * FIND_PROPERTY_BY_NAME.
-    */
-   protected String FIND_PROPERTY_BY_NAME;
-
-   /**
-    * FIND_REFERENCES.
-    */
-   protected String FIND_REFERENCES;
-
-   protected String FIND_REFERENCE_PROPERTIES;
-
-   /**
-    * FIND_VALUES_BY_PROPERTYID.
-    */
-   protected String FIND_VALUES_BY_PROPERTYID;
-
-   /**
-    * FIND_VALUE_BY_PROPERTYID_OREDERNUMB.
-    */
-   protected String FIND_VALUES_VSTORAGE_DESC_BY_PROPERTYID;
-
-   @Deprecated
-   protected String FIND_VALUE_BY_PROPERTYID_OREDERNUMB;
-
-   /**
-    * FIND_NODES_BY_PARENTID.
-    */
-   protected String FIND_NODES_BY_PARENTID;
-
-   /**
-    * FIND_NODES_BY_PARENTID NEW.
-    */
-   protected String FIND_NODES_BY_PARENTID_NEW;
-
-   /**
-    * FIND_NODES_COUNT_BY_PARENTID.
-    */
-   protected String FIND_NODES_COUNT_BY_PARENTID;
-
-   /**
-    * FIND_PROPERTIES_BY_PARENTID.
-    */
-   protected String FIND_PROPERTIES_BY_PARENTID;
-
-   /**
-    * FIND_PROPERTIES_BY_PARENTID_NEW.
-    */
-   protected String GET_PROPERTIES_BY_PARENTID;
-
-   /**
-    * INSERT_NODE.
-    */
-   protected String INSERT_NODE;
-
-   /**
-    * INSERT_PROPERTY.
-    */
-   protected String INSERT_PROPERTY;
-
-   /**
-    * INSERT_VALUE.
-    */
-   protected String INSERT_VALUE;
-
-   /**
-    * INSERT_REF.
-    */
-   protected String INSERT_REF;
-
-   /**
-    * RENAME_NODE.
-    */
-   protected String RENAME_NODE;
-
-   /**
-    * UPDATE_NODE.
-    */
-   protected String UPDATE_NODE;
-
-   /**
-    * UPDATE_PROPERTY.
-    */
-   protected String UPDATE_PROPERTY;
-
-   /**
-    * DELETE_ITEM.
-    */
-   protected String DELETE_ITEM;
-
-   /**
-    * DELETE_VALUE.
-    */
-   protected String DELETE_VALUE;
-
-   /**
-    * DELETE_REF.
-    */
-   protected String DELETE_REF;
-
-   // ======================== ITEMS table ======================== 
-   /**
-    * COLUMN_ID.
-    */
-   protected static final String COLUMN_ID = "ID";
-
-   /**
-    * COLUMN_PARENTID.
-    */
-   protected static final String COLUMN_PARENTID = "PARENT_ID";
-
-   /**
-    * COLUMN_NAME.
-    */
-   protected static final String COLUMN_NAME = "NAME";
-
-   /**
-    * COLUMN_VERSION.
-    */
-   protected static final String COLUMN_VERSION = "VERSION";
-
-   /**
-    * COLUMN_CLASS.
-    */
-   protected static final String COLUMN_CLASS = "I_CLASS";
-
-   /**
-    * COLUMN_INDEX.
-    */
-   protected static final String COLUMN_INDEX = "I_INDEX";
-
-   /**
-    * COLUMN_NORDERNUM.
-    */
-   protected static final String COLUMN_NORDERNUM = "N_ORDER_NUM";
-
-   /**
-    * COLUMN_PTYPE.
-    */
-   protected static final String COLUMN_PTYPE = "P_TYPE";
-
-   /**
-    * COLUMN_PMULTIVALUED.
-    */
-   protected static final String COLUMN_PMULTIVALUED = "P_MULTIVALUED";
-
-   // VALUE table
-   /**
-    * COLUMN_VDATA.
-    */
-   protected static final String COLUMN_VDATA = "DATA";
-
-   /**
-    * COLUMN_VORDERNUM.
-    */
-   protected static final String COLUMN_VORDERNUM = "ORDER_NUM";
-
-   /**
-    * COLUMN_VSTORAGE_DESC.
-    */
-   protected static final String COLUMN_VSTORAGE_DESC = "STORAGE_DESC";
-
-   // Dialects
-   /**
-    * DB_DIALECT_GENERIC.
-    */
-   public final static String DB_DIALECT_GENERIC = "Generic".intern();
-
-   /**
-    * DB_DIALECT_ORACLE.
-    */
-   public final static String DB_DIALECT_ORACLE = "Oracle".intern();
-
-   /**
-    * DB_DIALECT_ORACLEOCI.
-    */
-   public final static String DB_DIALECT_ORACLEOCI = "Oracle-OCI".intern();
-
-   /**
-    * DB_DIALECT_PGSQL.
-    */
-   public final static String DB_DIALECT_PGSQL = "PgSQL".intern();
-
-   /**
-    * DB_DIALECT_MYSQL.
-    */
-   public final static String DB_DIALECT_MYSQL = "MySQL".intern();
-
-   /**
-    * DB_DIALECT_MYSQL_UTF8.
-    */
-   public final static String DB_DIALECT_MYSQL_UTF8 = "MySQL-UTF8".intern();
-
-   /**
-    * DB_DIALECT_HSQLDB.
-    */
-   public final static String DB_DIALECT_HSQLDB = "HSQLDB".intern();
-
-   /**
-    * DB_DIALECT_DB2.
-    */
-   public final static String DB_DIALECT_DB2 = "DB2".intern();
-
-   /**
-    * DB_DIALECT_DB2V8.
-    */
-   public final static String DB_DIALECT_DB2V8 = "DB2V8".intern();
-
-   /**
-    * DB_DIALECT_MSSQL.
-    */
-   public final static String DB_DIALECT_MSSQL = "MSSQL".intern();
-
-   /**
-    * DB_DIALECT_SYBASE.
-    */
-   public final static String DB_DIALECT_SYBASE = "Sybase".intern();
-
-   /**
-    * DB_DIALECT_DERBY.
-    */
-   public final static String DB_DIALECT_DERBY = "Derby".intern();
-
-   /**
-    * DB_DIALECT_INGRES.
-    */
-   public final static String DB_DIALECT_INGRES = "Ingres".intern();
-
-   /**
-    * DB_DIALECTS.
-    */
-   public final static String[] DB_DIALECTS =
-      {DB_DIALECT_GENERIC, DB_DIALECT_ORACLE, DB_DIALECT_ORACLEOCI, DB_DIALECT_PGSQL, DB_DIALECT_MYSQL,
-         DB_DIALECT_HSQLDB, DB_DIALECT_DB2, DB_DIALECT_DB2V8, DB_DIALECT_MSSQL, DB_DIALECT_SYBASE, DB_DIALECT_DERBY,
-         DB_DIALECT_MYSQL_UTF8, DB_DIALECT_INGRES};
-
-}

Deleted: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/SQLExceptionHandler.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/SQLExceptionHandler.java	2009-12-25 16:16:18 UTC (rev 1195)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/SQLExceptionHandler.java	2009-12-25 17:05:38 UTC (rev 1196)
@@ -1,395 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation;
-
-import org.exoplatform.services.jcr.dataflow.ItemState;
-import org.exoplatform.services.jcr.datamodel.ItemData;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.datamodel.QPathEntry;
-import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
-import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
-
-import java.io.IOException;
-import java.sql.SQLException;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemExistsException;
-import javax.jcr.RepositoryException;
-
-/**
- * Created by The eXo Platform SAS.
- * 
- * The eXo JCR database has constraints can be violated.
- * 
- * JCR_PK_XCONTAINER - Can not be exisits two containers with same version
- * 
- * JCR_PK_XITEM - Item already exists with this ID JCR_FK_XITEM_PARENT - Parent not found by ID
- * JCR_IDX_XITEM_PARENT - Item already exists with the parent, name, index, type(N/P), persisted
- * version JCR_IDX_XITEM_PARENT_NAME - Item already exists with the type(N/P), parent, name, index,
- * persisted version JCR_IDX_XITEM_PARENT_ID - Item already exists with the type(N/P), parent, ID,
- * persisted version
- * 
- * JCR_PK_XVALUE - Value already exists with the ID (impossible, ID is autiincremented)
- * JCR_FK_XVALUE_PROPERTY - There is no property exists for the value. JCR_IDX_XVALUE_PROPERTY -
- * Value already exists with the property and order number
- * 
- * JCR_PK_XREF - Reference already exists to the node from property with order number
- * JCR_IDX_XREF_PROPERTY - Reference already exists with the property and order number
- * 
- * @author Peter Nedonosko
- * @version $Id: SQLExceptionHandler.java 34801 2009-07-31 15:44:50Z dkatayev $
- */
-
-public class SQLExceptionHandler
-{
-
-   /**
-    * Ccontainer name.
-    */
-   private final String containerName;
-
-   /**
-    * Storage connection.
-    */
-   private final CQJDBCStorageConnection conn;
-
-   // ---------------- SQLException handler -------------------
-
-   /**
-    * SQLExceptionHandler constructor.
-    * 
-    * @param containerName
-    *          - workspace container name
-    * @param conn
-    *          - storage connection
-    */
-   SQLExceptionHandler(String containerName, CQJDBCStorageConnection conn)
-   {
-      this.containerName = containerName;
-      this.conn = conn;
-   }
-
-   /**
-    * Handle Add SQLException.
-    * 
-    * @param e
-    *          - an SQLException
-    * @param item
-    *          - context ItemData
-    * @return String with error message
-    * @throws RepositoryException
-    *           if <code>RepositoryException</code> should be thrown
-    * @throws InvalidItemStateException
-    *           if <code>InvalidItemStateException</code> should be thrown
-    */
-   protected String handleAddException(SQLException e, ItemData item) throws RepositoryException,
-      InvalidItemStateException
-   {
-      String message = "[" + containerName + "] ADD " + (item.isNode() ? "NODE. " : "PROPERTY. ");
-      String errMessage = e.getMessage();
-      String itemInfo =
-         item.getQPath().getAsString() + ", ID: " + item.getIdentifier() + ", ParentID: " + item.getParentIdentifier()
-            + (errMessage != null ? ". Cause >>>> " + errMessage : "");
-
-      if (errMessage != null)
-      {
-         // try detect error by foreign key names
-         String umsg = errMessage.toLowerCase().toUpperCase();
-         if (umsg.indexOf(conn.JCR_FK_ITEM_PARENT) >= 0)
-         {
-            message += "Parent not found. Item " + itemInfo;
-            throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
-         }
-         else if (umsg.indexOf(conn.JCR_PK_ITEM) >= 0)
-         {
-            message += "Item already exists. Condition: ID. " + itemInfo;
-            // InvalidItemStateException ! - because it's impossible add new item with existed UUID
-            throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
-         }
-         else if (umsg.indexOf(conn.JCR_IDX_ITEM_PARENT) >= 0 || umsg.indexOf(conn.JCR_IDX_ITEM_PARENT_NAME) >= 0)
-         {
-            message += "Item already exists. Condition: parent ID, name, index. " + itemInfo;
-            throw new ItemExistsException(message, e);
-         }
-         else if (umsg.indexOf(conn.JCR_IDX_ITEM_PARENT_ID) >= 0)
-         {
-            message += "Item already exists. Condition: parent ID and ID. " + itemInfo;
-            throw new ItemExistsException(message, e);
-         }
-         else if (umsg.indexOf(conn.JCR_FK_VALUE_PROPERTY) >= 0)
-         {
-            message += "Property is not exist but the value is being created. Condition: property ID. " + itemInfo;
-            throw new RepositoryException(message, e);
-         }
-         else if (umsg.indexOf(conn.JCR_IDX_VALUE_PROPERTY) >= 0)
-         {
-            message += "Property already exists. Condition: property ID, order number. " + itemInfo;
-            throw new RepositoryException(message, e);
-         }
-         else if (umsg.indexOf(conn.JCR_PK_VALUE) >= 0)
-         {
-            message +=
-               "[FATAL] Value already exists with the ValueID. Impossible state, check is ValueID is autoincremented. "
-                  + itemInfo;
-            throw new RepositoryException(message, e);
-         }
-         else if (umsg.indexOf(conn.JCR_PK_REF) >= 0)
-         {
-            message += "Reference chain already exists. Condition: node ID, property ID, order number. " + itemInfo;
-            throw new RepositoryException(message, e);
-         }
-         else if (umsg.indexOf(conn.JCR_IDX_REF_PROPERTY) >= 0)
-         {
-            message += "Referenceable property value already exists. Condition: property ID, order number. " + itemInfo;
-            throw new RepositoryException(message, e);
-         }
-      }
-
-      // try detect integrity violation
-      RepositoryException ownException = null;
-      try
-      {
-         NodeData parent = (NodeData)conn.getItemData(item.getParentIdentifier());
-         if (parent != null)
-         {
-            // have a parent
-            try
-            {
-               ItemData me = conn.getItemData(item.getIdentifier());
-               if (me != null)
-               {
-                  // item already exists
-                  message += "Item already exists in storage: " + itemInfo;
-                  ownException = new JCRItemExistsException(message, me.getIdentifier(), ItemState.ADDED, e);
-                  throw ownException;
-               }
-
-               me = conn.getItemData(parent, new QPathEntry(item.getQPath().getName(), item.getQPath().getIndex()));
-               if (me != null)
-               {
-                  message += "Item already exists in storage: " + itemInfo;
-                  ownException = new JCRItemExistsException(message, me.getIdentifier(), ItemState.ADDED, e);
-                  throw ownException;
-               }
-
-            }
-            catch (Exception ep)
-            {
-               // item not found or other things but error of item reading
-               if (ownException != null)
-                  throw ownException;
-            }
-
-            // MySQL violation
-            if (e.getClass().getName().indexOf("MySQLIntegrityConstraintViolationException") >= 0
-               && errMessage.indexOf(item.getIdentifier()) >= 0)
-            {
-               // it's JCR_PK_ITEM violation 
-               message += "Item already exists. Condition: ID. " + itemInfo;
-               throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
-            }
-
-            message += "Error of item add. " + itemInfo;
-            ownException = new RepositoryException(message, e);
-            throw ownException;
-         }
-      }
-      catch (Exception ep)
-      {
-         // no parent or error access it
-         if (ownException != null)
-            throw ownException;
-      }
-      message += "Error of item add. " + itemInfo;
-      throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
-   }
-
-   /**
-    * Handle Add IOException.
-    * 
-    * @param e
-    *          - an IOException
-    * @param item
-    *          - context ItemData
-    * @return String with error message
-    * @throws RepositoryException
-    *           if <code>RepositoryException</code> should be thrown
-    * @throws InvalidItemStateException
-    *           if <code>InvalidItemStateException</code> should be thrown
-    */
-   protected String handleAddException(IOException e, ItemData item) throws RepositoryException,
-      InvalidItemStateException
-   {
-      String message = "[" + containerName + "] ADD " + (item.isNode() ? "NODE. " : "PROPERTY. ");
-      String errMessage = e.getMessage();
-      String itemInfo =
-         item.getQPath().getAsString() + ", ID: " + item.getIdentifier() + ", ParentID: " + item.getParentIdentifier()
-            + (errMessage != null ? ". Cause >>>> " + errMessage : "");
-
-      // try detect integrity violation
-      RepositoryException ownException = null;
-      try
-      {
-         NodeData parent = (NodeData)conn.getItemData(item.getParentIdentifier());
-         if (parent != null)
-         {
-            // have a parent
-            try
-            {
-               ItemData me = conn.getItemData(item.getIdentifier());
-               if (me != null)
-               {
-                  // item already exists
-                  message += "Item already exists in storage: " + itemInfo;
-                  ownException = new ItemExistsException(message, e);
-                  throw ownException;
-               }
-
-               me = conn.getItemData(parent, new QPathEntry(item.getQPath().getName(), item.getQPath().getIndex()));
-               if (me != null)
-               {
-                  message += "Item already exists in storage: " + itemInfo;
-                  ownException = new ItemExistsException(message, e);
-                  throw ownException;
-               }
-
-            }
-            catch (Exception ep)
-            {
-               // item not found or other things but error of item reading
-               if (ownException != null)
-                  throw ownException;
-            }
-            message += "Error of item add. " + itemInfo;
-            ownException = new RepositoryException(message, e);
-            throw ownException;
-         }
-      }
-      catch (Exception ep)
-      {
-         // no parent or error access it
-         if (ownException != null)
-            throw ownException;
-      }
-      message += "Error of item add. " + itemInfo;
-      throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
-   }
-
-   /**
-    * Handle delete Exceptions.
-    * 
-    * @param e
-    *          - an SQLException
-    * @param item
-    *          - context ItemData
-    * @return String with error message
-    * @throws RepositoryException
-    *           if <code>RepositoryException</code> should be thrown
-    * @throws InvalidItemStateException
-    *           if <code>InvalidItemStateException</code> should be thrown
-    */
-   protected String handleDeleteException(SQLException e, ItemData item) throws RepositoryException,
-      InvalidItemStateException
-   {
-      String message = "[" + containerName + "] DELETE " + (item.isNode() ? "NODE. " : "PROPERTY. ");
-      String errMessage = e.getMessage();
-      String itemInfo =
-         item.getQPath().getAsString() + " " + item.getIdentifier()
-            + (errMessage != null ? ". Cause >>>> " + errMessage : "");
-
-      if (errMessage != null)
-      {
-         // try detect error by foreign key names
-         String umsg = errMessage.toLowerCase().toUpperCase();
-         if (umsg.indexOf(conn.JCR_FK_ITEM_PARENT) >= 0)
-         {
-            message += "Can not delete parent till childs exists. Item " + itemInfo;
-            throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.DELETED, e);
-         }
-         else if (umsg.indexOf(conn.JCR_FK_VALUE_PROPERTY) >= 0)
-         {
-            message +=
-               "[FATAL] Can not delete property item till it contains values. Condition: property ID. " + itemInfo;
-            throw new RepositoryException(message, e);
-         }
-      }
-
-      message += "Error of item delete " + itemInfo;
-      throw new RepositoryException(message, e);
-   }
-
-   /**
-    * Handle update Exceptions.
-    * 
-    * @param e
-    *          - an SQLException
-    * @param item
-    *          - context ItemData
-    * @return String with error message
-    * @throws RepositoryException
-    *           if <code>RepositoryException</code> should be thrown
-    * @throws InvalidItemStateException
-    *           if <code>InvalidItemStateException</code> should be thrown
-    */
-   protected String handleUpdateException(SQLException e, ItemData item) throws RepositoryException,
-      InvalidItemStateException
-   {
-      String message = "[" + containerName + "] EDIT " + (item.isNode() ? "NODE. " : "PROPERTY. ");
-      String errMessage = e.getMessage();
-      String itemInfo =
-         item.getQPath().getAsString() + " " + item.getIdentifier()
-            + (errMessage != null ? ". Cause >>>> " + errMessage : "");
-
-      if (errMessage != null)
-         // try detect error by foreign key names
-         if (errMessage.toLowerCase().toUpperCase().indexOf(conn.JCR_FK_VALUE_PROPERTY) >= 0)
-         {
-            message += "Property is not exists but the value is being created. Condition: property ID. " + itemInfo;
-            throw new RepositoryException(message, e);
-         }
-         else if (errMessage.toLowerCase().toUpperCase().indexOf(conn.JCR_PK_ITEM) >= 0)
-         {
-            message += "Item already exists. Condition: ID. " + itemInfo;
-            throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.UPDATED, e);
-         }
-
-      // try detect integrity violation
-      RepositoryException ownException = null;
-      try
-      {
-         ItemData me = conn.getItemData(item.getIdentifier());
-         if (me != null)
-         {
-            // item already exists
-            message += "Item already exists. But update errors. " + itemInfo;
-            ownException = new RepositoryException(message, e);
-            throw ownException;
-         }
-      }
-      catch (Exception ep)
-      {
-         // item not found or other things but error of item reading
-         if (ownException != null)
-            throw ownException;
-      }
-      message += "Error of item update. " + itemInfo;
-      throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.UPDATED, e);
-   }
-
-}

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2009-12-25 16:16:18 UTC (rev 1195)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java	2009-12-25 17:05:38 UTC (rev 1196)
@@ -185,7 +185,7 @@
          //            + " where I2.ID=I.ID and I2.ID=I.PARENT_ID and I.NAME IN ('[http://www.jcp.org/jcr/1.0]primaryType')";// order by I.I_CLASS, I.N_ORDER_NUM"
 
          "select I.*, V.ORDER_NUM, V.DATA, V.STORAGE_DESC from JCR_MITEM I LEFT OUTER JOIN JCR_MVALUE V ON (V.PROPERTY_ID=I.ID)"
-            + " where (I.ID=?) or (I.PARENT_ID=? and I.I_CLASS=2 and I.NAME IN ('[http://www.jcp.org/jcr/1.0]primaryType','[http://www.jcp.org/jcr/1.0]mixinTypes')) order by I.I_CLASS, I.NAME DESC";// order by I.I_CLASS, I.N_ORDER_NUM"
+            + " where (I.ID=?) or (I.PARENT_ID=? and I.I_CLASS=2 and (I.NAME='[http://www.jcp.org/jcr/1.0]primaryType' or I.NAME='[http://www.jcp.org/jcr/1.0]mixinTypes')) order by I.I_CLASS, I.NAME DESC";// order by I.I_CLASS, I.N_ORDER_NUM"
 
       FIND_ITEM_BY_NAME =
          "select * from JCR_MITEM" + " where PARENT_ID=? and NAME=? and I_INDEX=? order by I_CLASS, VERSION DESC";



More information about the exo-jcr-commits mailing list