[exo-jcr-commits] exo-jcr SVN: r1199 - 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
Sat Dec 26 07:15:52 EST 2009
Author: sergiykarpenko
Date: 2009-12-26 07:15:51 -0500 (Sat, 26 Dec 2009)
New Revision: 1199
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
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
Log:
EXOJCR-302: CQJDBCStorageConnection 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-26 09:53:58 UTC (rev 1198)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2009-12-26 12:15:51 UTC (rev 1199)
@@ -832,7 +832,7 @@
* @throws IllegalNameException
* - if name on the path is wrong
*/
- private QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
+ protected QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
{
// get item by Identifier usecase
List<QPathEntry> qrpath = new ArrayList<QPathEntry>(); // reverted path
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-26 09:53:58 UTC (rev 1198)
+++ 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-26 12:15:51 UTC (rev 1199)
@@ -18,6 +18,21 @@
*/
package org.exoplatform.services.jcr.impl.storage.jdbc.optimisation;
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.RepositoryException;
+
import org.exoplatform.services.jcr.access.AccessControlEntry;
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.dataflow.persistent.PersistedNodeData;
@@ -32,36 +47,12 @@
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.Constants;
-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.jdbc.JDBCStorageConnection;
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.value.ValueIOChannel;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.RepositoryException;
-
/**
* Created by The eXo Platform SAS.
*
@@ -120,9 +111,7 @@
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);
}
@@ -162,7 +151,7 @@
try
{
// query will return nodes and properties in same result set
- ResultSet resultSet = findChildNodesByParentIdentifierNew(getInternalId(parent.getIdentifier()));
+ ResultSet resultSet = findChildNodesByParentIdentifierCQ(getInternalId(parent.getIdentifier()));
if (resultSet.next())
{
Map<String, TempNodeData> tempNodes = loadTempNodesFromResultSet(resultSet);
@@ -236,23 +225,8 @@
*/
public int getChildNodesCount(NodeData parent) throws RepositoryException
{
- checkIfOpened();
- try
- {
- ResultSet count = findChildNodesCountByParentIdentifier(getInternalId(parent.getIdentifier()));
- if (count.next())
- {
- return count.getInt(1);
- }
- else
- {
- throw new RepositoryException("FATAL No resulton childNodes count for " + parent.getQPath().getAsString());
- }
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
+ // nothing to optimize
+ return super.getChildNodesCount(parent);
}
/**
@@ -287,29 +261,11 @@
/**
* {@inheritDoc}
- *
- * TODO left as current
*/
public List<PropertyData> listChildPropertiesData(NodeData parent) throws RepositoryException, IllegalStateException
{
- checkIfOpened();
- try
- {
- ResultSet prop = findChildPropertiesByParentIdentifier(getInternalId(parent.getIdentifier()));
- List<PropertyData> children = new ArrayList<PropertyData>();
- while (prop.next())
- children.add(propertyData(parent.getQPath(), prop));
-
- return children;
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
- catch (IOException e)
- {
- throw new RepositoryException(e);
- }
+ // nothing to optimize
+ return super.listChildPropertiesData(parent);
}
/**
@@ -320,6 +276,9 @@
return getItemByIdentifier(getInternalId(identifier));
}
+ /**
+ * {@inheritDoc}
+ */
public ItemData getItemData(NodeData parentData, QPathEntry name) throws RepositoryException, IllegalStateException
{
@@ -337,38 +296,10 @@
*/
public List<PropertyData> getReferencesData(String nodeIdentifier) throws RepositoryException, IllegalStateException
{
- checkIfOpened();
- try
- {
- ResultSet refProps = findReferences(getInternalId(nodeIdentifier));
- List<PropertyData> references = new ArrayList<PropertyData>();
- while (refProps.next())
- {
- references.add((PropertyData)itemData(null, refProps, I_CLASS_PROPERTY, null));
- }
-
- // ResultSet resultSet = findReferenceProperties(getInternalId(nodeIdentifier));
- // List<PropertyData> references = new ArrayList<PropertyData>(); //
- // if (resultSet.next())
- // {
- // while (!resultSet.isAfterLast())
- // references.add(loadPropertyRecord(resultSet, null));
- // }
-
- return references;
- }
- catch (SQLException e)
- {
- throw new RepositoryException(e);
- }
- catch (IOException e)
- {
- throw new RepositoryException(e);
- }
+ // can't optimize - result may return same node more than one time, so parse result set is difficult
+ return super.getReferencesData(nodeIdentifier);
}
- // ------------------ Private methods ---------------
-
/**
* Get Item By Identifier.
*
@@ -386,7 +317,7 @@
ResultSet resultSet = null;
try
{
- resultSet = findItemByIdentifierNew(cid);
+ resultSet = findItemByIdentifierWithAllData(cid);
if (resultSet.next())
{
int itemType = resultSet.getInt(COLUMN_CLASS);
@@ -394,7 +325,6 @@
{
Map<String, TempNodeData> node = loadTempNodesFromResultSet(resultSet);
return loadNodeFromTemporaryNodeData(node.get(cid), null, null);
- //return loadNodeRecord(resultSet, null, null);
}
else
{
@@ -449,7 +379,7 @@
ResultSet resultSet = null;
try
{
- resultSet = findItemByNameNew(parentId, name.getAsString(), name.getIndex());
+ resultSet = findItemByNameWithAllData(parentId, name.getAsString(), name.getIndex());
if (resultSet.next())
{
// return itemData(parent.getQPath(), item, item.getInt(COLUMN_CLASS), parent.getACL());
@@ -468,8 +398,6 @@
NodeData nodeData = loadNodeFromTemporaryNodeData(tempNodes.get(firstNodeId), parentQPath, parentACL);
tempNodes.clear();
return nodeData;
-
- //return loadNodeRecord(resultSet, parent.getQPath(), parent.getACL());
}
else
{
@@ -501,207 +429,6 @@
}
}
- /**
- * Build Item path by id.
- *
- * @param cpid
- * - Item id (container id)
- * @return Item QPath
- * @throws SQLException
- * - if database error occurs
- * @throws InvalidItemStateException
- * - if parent not found
- * @throws IllegalNameException
- * - if name on the path is wrong
- */
- private QPath traverseQPath(String cpid) throws SQLException, InvalidItemStateException, IllegalNameException
- {
- // get item by Identifier usecase
- List<QPathEntry> qrpath = new ArrayList<QPathEntry>(); // reverted path
- String caid = cpid; // container ancestor id
- do
- {
- ResultSet parent = null;
- try
- {
- parent = findItemByIdentifier(caid);
- if (!parent.next())
- throw new InvalidItemStateException("Parent not found, uuid: " + getIdentifier(caid));
-
- QPathEntry qpe =
- new QPathEntry(InternalQName.parse(parent.getString(COLUMN_NAME)), parent.getInt(COLUMN_INDEX));
- qrpath.add(qpe);
- caid = parent.getString(COLUMN_PARENTID);
- }
- finally
- {
- parent.close();
- }
- }
- while (!caid.equals(Constants.ROOT_PARENT_UUID));
-
- 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);
- }
-
- /**
- * ItemLocationInfo.
- *
- */
- class ItemLocationInfo
- {
- /**
- * Item qpath
- */
- final QPath qpath;
-
- /**
- * All ancestors of the item with qpath
- */
- final List<String> ancestors;
-
- /**
- * Item id.
- */
- final String itemId;
-
- /**
- * ItemLocationInfo constructor.
- *
- * @param qpath
- * Item path
- * @param ancestors
- * ancesstors id list
- * @param itemId
- * Item id
- */
- ItemLocationInfo(QPath qpath, List<String> ancestors, String itemId)
- {
- this.qpath = qpath;
- this.ancestors = ancestors;
- this.itemId = itemId;
- }
- }
-
- protected String findParentId(String cid) throws SQLException, RepositoryException
- {
- ResultSet pidrs = findItemByIdentifier(cid);
- try
- {
- if (pidrs.next())
- return pidrs.getString(COLUMN_PARENTID);
- else
- throw new RepositoryException("Item not found id: " + getIdentifier(cid));
- }
- finally
- {
- pidrs.close();
- }
- }
-
- /**
- * Build ItemData.
- *
- * @param parentPath
- * - parent path
- * @param item
- * database - ResultSet with Item record(s)
- * @param itemClass
- * - Item type (Node or Property)
- * @param parentACL
- * - parent ACL
- * @return ItemData instance
- * @throws RepositoryException
- * Repository error
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error
- */
- private ItemData itemData(QPath parentPath, ResultSet item, int itemClass, AccessControlList parentACL)
- throws RepositoryException, SQLException, IOException
- {
- String cid = item.getString(COLUMN_ID);
- String cname = item.getString(COLUMN_NAME);
- int cversion = item.getInt(COLUMN_VERSION);
-
- String cpid = item.getString(COLUMN_PARENTID);
- // if parent ID is empty string - it's a root node
- // cpid = cpid.equals(Constants.ROOT_PARENT_UUID) ? null : cpid;
-
- try
- {
- if (itemClass == I_CLASS_NODE)
- {
- int cindex = item.getInt(COLUMN_INDEX);
- int cnordernumb = item.getInt(COLUMN_NORDERNUM);
- return loadNodeRecord(parentPath, cname, cid, cpid, cindex, cversion, cnordernumb, parentACL);
- }
-
- int cptype = item.getInt(COLUMN_PTYPE);
- boolean cpmultivalued = item.getBoolean(COLUMN_PMULTIVALUED);
- return loadPropertyRecord(parentPath, cname, cid, cpid, cversion, cptype, cpmultivalued);
- }
- catch (InvalidItemStateException e)
- {
- throw new InvalidItemStateException("FATAL: Can't build item path for name " + cname + " id: "
- + getIdentifier(cid) + ". " + e);
- }
- }
-
- /**
- * Read property data without value data. For listChildPropertiesData(NodeData).
- *
- * @param parentPath
- * - parent path
- * @param item
- * database - ResultSet with Item record(s)
- * @return PropertyData instance
- * @throws RepositoryException
- * Repository error
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error
- */
- private PropertyData propertyData(QPath parentPath, ResultSet item) throws RepositoryException, SQLException,
- IOException
- {
- String cid = item.getString(COLUMN_ID);
- String cname = item.getString(COLUMN_NAME);
- int cversion = item.getInt(COLUMN_VERSION);
- String cpid = item.getString(COLUMN_PARENTID);
- int cptype = item.getInt(COLUMN_PTYPE);
- boolean cpmultivalued = item.getBoolean(COLUMN_PMULTIVALUED);
-
- try
- {
- InternalQName qname = InternalQName.parse(cname);
-
- QPath qpath = QPath.makeChildPath(parentPath == null ? traverseQPath(cpid) : parentPath, qname);
-
- PersistedPropertyData pdata =
- new PersistedPropertyData(getIdentifier(cid), qpath, getIdentifier(cpid), cversion, cptype, cpmultivalued,
- new ArrayList<ValueData>());
-
- return pdata;
- }
- catch (InvalidItemStateException e)
- {
- throw new InvalidItemStateException("FATAL: Can't build property path for name " + cname + " id: "
- + getIdentifier(cid) + ". " + e);
- }
- catch (IllegalNameException e)
- {
- throw new RepositoryException(e);
- }
- }
-
protected List<AccessControlEntry> readACLPermisions(String cid, Map<String, List<byte[]>> properties)
throws SQLException, IllegalACLException
{
@@ -733,209 +460,6 @@
}
/**
- * Load PropertyData record.
- *
- * @param parentPath
- * parent path
- * @param cname
- * Property name
- * @param cid
- * Property id
- * @param cpid
- * Property parent id
- * @param cversion
- * Property persistent verison
- * @param cptype
- * Property type
- * @param cpmultivalued
- * Property multivalued status
- * @return PersistedPropertyData
- * @throws RepositoryException
- * Repository error
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error
- */
- protected PersistedPropertyData loadPropertyRecord(QPath parentPath, String cname, String cid, String cpid,
- int cversion, int cptype, boolean cpmultivalued) throws RepositoryException, SQLException, IOException
- {
-
- // NOTE: cpid never should be null or root parent (' ')
-
- try
- {
- QPath qpath =
- QPath.makeChildPath(parentPath == null ? traverseQPath(cpid) : parentPath, InternalQName.parse(cname));
-
- String identifier = getIdentifier(cid);
- List<ValueData> values = readValues(cid, identifier, cversion);
- PersistedPropertyData pdata =
- new PersistedPropertyData(identifier, qpath, getIdentifier(cpid), cversion, cptype, cpmultivalued, values);
-
- return pdata;
- }
- catch (IllegalNameException e)
- {
- throw new RepositoryException(e);
- }
- }
-
- protected PersistedNodeData loadNodeRecord(ResultSet item, QPath parentPath, AccessControlList pACL)
- throws RepositoryException, SQLException, IOException
- {
-
- String cid = item.getString(COLUMN_ID);
- String cname = item.getString(COLUMN_NAME);
- int cversion = item.getInt(COLUMN_VERSION);
- String cpid = item.getString(COLUMN_PARENTID);
- int cindex = item.getInt(COLUMN_INDEX);
- int cnordernumb = item.getInt(COLUMN_NORDERNUM);
- AccessControlList parentACL = pACL;
-
- try
- {
- InternalQName qname = InternalQName.parse(cname);
-
- // TODO can't avoid QPath traverse
- 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;
- }
- }
-
- // preload properties
-
- Map<String, List<byte[]>> properties = new LinkedHashMap<String, List<byte[]>>();
-
- // PRIMARY
- if (!item.next() || !item.getString(COLUMN_NAME).equals(Constants.JCR_PRIMARYTYPE.getAsString()))
- {
- throw new SQLException("Node finded but primaryType property not " + cid);
- }
-
- byte[] data = item.getBytes(COLUMN_VDATA);
- InternalQName ptName = InternalQName.parse(new String((data != null ? data : new byte[]{})));
-
- // MIXIN
- MixinInfo mixins = null;
- List<InternalQName> mts = null;
- boolean owneable = false;
- boolean privilegeable = false;
- while (item.next() && item.getString(COLUMN_NAME).equals(Constants.JCR_MIXINTYPES.getAsString()))
- {
- mts = new ArrayList<InternalQName>();
- byte[] mxnb = item.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
-
- }
-
- mixins = new MixinInfo(mts, owneable, privilegeable);
-
- try
- {
- // 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);
- }
- }
-
- /**
* Create NodeData from TempNodeData content.
*
* @param tempData
@@ -1017,12 +541,14 @@
else if (!owneable && Constants.EXO_OWNEABLE.equals(mxn))
owneable = true;
}
- mts= new InternalQName[mNames.size()];
+ mts = new InternalQName[mNames.size()];
mNames.toArray(mts);
- }else{
+ }
+ else
+ {
mts = new InternalQName[0];
}
-
+
try
{
// ACL
@@ -1034,7 +560,7 @@
if (privilegeable)
{
// and permissions
- acl = new AccessControlList(readACLOwner(cid, properties), readACLPermisions(cid,properties));
+ acl = new AccessControlList(readACLOwner(cid, properties), readACLPermisions(cid, properties));
}
else if (parentACL != null)
{
@@ -1055,7 +581,7 @@
if (owneable)
{
// and owner
- acl = new AccessControlList(readACLOwner(cid,properties), readACLPermisions(cid, properties));
+ acl = new AccessControlList(readACLOwner(cid, properties), readACLPermisions(cid, properties));
}
else if (parentACL != null)
{
@@ -1098,51 +624,58 @@
}
}
- protected PersistedPropertyData loadPropertyRecord(ResultSet item, QPath parentPath) throws RepositoryException,
- SQLException, IOException
+ /**
+ * Load property record from result set. Result set must be ordered by property id.
+ * In other way there may be mistaces.
+ *
+ * @param resultSet - Result set
+ * @param parentPath - parent qpath - needed to create property qpath. May be null.
+ * @return PersistedPropertyData
+ * @throws RepositoryException
+ * @throws SQLException
+ * @throws IOException
+ */
+ protected PersistedPropertyData loadPropertyRecord(ResultSet resultSet, QPath parentPath)
+ throws RepositoryException, SQLException, IOException
{
- String cid = item.getString(COLUMN_ID);
- String cname = item.getString(COLUMN_NAME);
- int cversion = item.getInt(COLUMN_VERSION);
+ String cid = resultSet.getString(COLUMN_ID);
+ String cname = resultSet.getString(COLUMN_NAME);
+ int cversion = resultSet.getInt(COLUMN_VERSION);
- String cpid = item.getString(COLUMN_PARENTID);
+ String cpid = resultSet.getString(COLUMN_PARENTID);
// if parent ID is empty string - it's a root node
// cpid = cpid.equals(Constants.ROOT_PARENT_UUID) ? null : cpid;
try
{
- int cptype = item.getInt(COLUMN_PTYPE);
- boolean cpmultivalued = item.getBoolean(COLUMN_PMULTIVALUED);
- try
- {
- QPath qpath =
- QPath.makeChildPath(parentPath == null ? traverseQPath(cpid) : parentPath, InternalQName.parse(cname));
+ int cptype = resultSet.getInt(COLUMN_PTYPE);
+ boolean cpmultivalued = resultSet.getBoolean(COLUMN_PMULTIVALUED);
+ QPath qpath =
+ QPath.makeChildPath(parentPath == null ? traverseQPath(cpid) : parentPath, InternalQName.parse(cname));
- List<ValueData> data = new ArrayList<ValueData>();
+ List<ValueData> data = new ArrayList<ValueData>();
+ String identifier = getIdentifier(cid);
- String identifier = getIdentifier(cid);
-
- do
- {
- final int orderNum = item.getInt(COLUMN_VORDERNUM);
- final String storageId = item.getString(COLUMN_VSTORAGE_DESC);
- ValueData vdata =
- item.wasNull() ? readValueData(cid, orderNum, cversion, item.getBinaryStream(COLUMN_VDATA))
- : readValueData(identifier, orderNum, storageId);
- data.add(vdata);
- }
- while (item.next() && item.getString(COLUMN_ID) == cid);
-
- PersistedPropertyData pdata =
- new PersistedPropertyData(identifier, qpath, getIdentifier(cpid), cversion, cptype, cpmultivalued, data);
-
- return pdata;
- }
- catch (IllegalNameException e)
+ do
{
- throw new RepositoryException(e);
+ final int orderNum = resultSet.getInt(COLUMN_VORDERNUM);
+ final String storageId = resultSet.getString(COLUMN_VSTORAGE_DESC);
+ ValueData vdata =
+ resultSet.wasNull() ? readValueData(cid, orderNum, cversion, resultSet.getBinaryStream(COLUMN_VDATA))
+ : readValueData(identifier, orderNum, storageId);
+ data.add(vdata);
}
+ while (resultSet.next() && resultSet.getString(COLUMN_ID) == cid);
+
+ PersistedPropertyData pdata =
+ new PersistedPropertyData(identifier, qpath, getIdentifier(cpid), cversion, cptype, cpmultivalued, data);
+
+ return pdata;
}
+ catch (IllegalNameException e)
+ {
+ throw new RepositoryException(e);
+ }
catch (InvalidItemStateException e)
{
throw new InvalidItemStateException("FATAL: Can't build item path for name " + cname + " id: "
@@ -1151,50 +684,6 @@
}
/**
- * Read Property Values.
- *
- * @param identifier
- * property identifier
- * @param cid
- * Property id
- * @param pdata
- * PropertyData
- * @return list of ValueData
- * @throws IOException
- * i/O error
- * @throws SQLException
- * if database errro occurs
- * @throws ValueStorageNotFoundException
- * if no such storage found with Value storageId
- */
- private List<ValueData> readValues(String cid, String identifier, int cversion) throws IOException, SQLException,
- ValueStorageNotFoundException
- {
-
- List<ValueData> data = new ArrayList<ValueData>();
-
- final ResultSet valueRecords = findValuesByPropertyId(cid);
- try
- {
- while (valueRecords.next())
- {
- final int orderNum = valueRecords.getInt(COLUMN_VORDERNUM);
- final String storageId = valueRecords.getString(COLUMN_VSTORAGE_DESC);
- ValueData vdata =
- valueRecords.wasNull() ? readValueData(cid, orderNum, cversion, valueRecords
- .getBinaryStream(COLUMN_VDATA)) : readValueData(identifier, orderNum, storageId);
- data.add(vdata);
- }
- }
- finally
- {
- valueRecords.close();
- }
-
- return data;
- }
-
- /**
* Read ValueData from External Storage.
*
* @param pdata
@@ -1225,227 +714,165 @@
}
}
- /**
- * Read ValueData from database.
- *
- * @param cid
- * Property id
- * @param orderNumber
- * Value order number
- * @param version
- * persistent version (used for BLOB swapping)
- * @param content
- * @return ValueData
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error (swap)
- */
- protected ValueData readValueData(String cid, int orderNumber, int version, final InputStream content)
- throws SQLException, IOException
- {
+ // protected PersistedNodeData loadNodeRecord(ResultSet item, QPath parentPath, AccessControlList pACL)
+ // throws RepositoryException, SQLException, IOException
+ // {
+ //
+ // String cid = item.getString(COLUMN_ID);
+ // String cname = item.getString(COLUMN_NAME);
+ // int cversion = item.getInt(COLUMN_VERSION);
+ // String cpid = item.getString(COLUMN_PARENTID);
+ // int cindex = item.getInt(COLUMN_INDEX);
+ // int cnordernumb = item.getInt(COLUMN_NORDERNUM);
+ // AccessControlList parentACL = pACL;
+ //
+ // try
+ // {
+ // InternalQName qname = InternalQName.parse(cname);
+ //
+ // // TODO can't avoid QPath traverse
+ // 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;
+ // }
+ // }
+ //
+ // // preload properties
+ //
+ // Map<String, List<byte[]>> properties = new LinkedHashMap<String, List<byte[]>>();
+ //
+ // // PRIMARY
+ // if (!item.next() || !item.getString(COLUMN_NAME).equals(Constants.JCR_PRIMARYTYPE.getAsString()))
+ // {
+ // throw new SQLException("Node finded but primaryType property not " + cid);
+ // }
+ //
+ // byte[] data = item.getBytes(COLUMN_VDATA);
+ // InternalQName ptName = InternalQName.parse(new String((data != null ? data : new byte[]{})));
+ //
+ // // MIXIN
+ // MixinInfo mixins = null;
+ // List<InternalQName> mts = null;
+ // boolean owneable = false;
+ // boolean privilegeable = false;
+ // while (item.next() && item.getString(COLUMN_NAME).equals(Constants.JCR_MIXINTYPES.getAsString()))
+ // {
+ // mts = new ArrayList<InternalQName>();
+ // byte[] mxnb = item.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
+ //
+ // }
+ //
+ // mixins = new MixinInfo(mts, owneable, privilegeable);
+ //
+ // try
+ // {
+ // // 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);
+ // }
+ // }
- ResultSet valueResultSet = null;
+ protected abstract ResultSet findItemByIdentifierWithAllData(String identifier) throws SQLException;
- byte[] buffer = new byte[0];
- byte[] spoolBuffer = new byte[ValueFileIOHelper.IOBUFFER_SIZE];
- int read;
- int len = 0;
- OutputStream out = null;
+ protected abstract ResultSet findItemByNameWithAllData(String parentId, String name, int index) throws SQLException;
- SwapFile swapFile = null;
- try
- {
- // stream from database
- if (content != null)
- while ((read = content.read(spoolBuffer)) >= 0)
- {
- if (out != null)
- {
- // spool to temp file
- out.write(spoolBuffer, 0, read);
- len += read;
- }
- else if (len + read > maxBufferSize)
- {
- // threshold for keeping data in memory exceeded;
- // create temp file and spool buffer contents
- swapFile = SwapFile.get(swapDirectory, cid + orderNumber + "." + version);
- if (swapFile.isSpooled())
- {
- // break, value already spooled
- buffer = null;
- break;
- }
- out = new FileOutputStream(swapFile);
- out.write(buffer, 0, len);
- out.write(spoolBuffer, 0, read);
- buffer = null;
- len += read;
- }
- else
- {
- // reallocate new buffer and spool old buffer contents
- byte[] newBuffer = new byte[len + read];
- System.arraycopy(buffer, 0, newBuffer, 0, len);
- System.arraycopy(spoolBuffer, 0, newBuffer, len, read);
- buffer = newBuffer;
- len += read;
- }
- }
- }
- finally
- {
- if (valueResultSet != null)
- valueResultSet.close();
- if (out != null)
- {
- out.close();
- swapFile.spoolDone();
- }
- }
+ protected abstract ResultSet findChildNodesByParentIdentifierCQ(String parentIdentifier) throws SQLException;
- if (buffer == null)
- return new CleanableFilePersistedValueData(orderNumber, swapFile, swapCleaner);
-
- return new ByteArrayPersistedValueData(orderNumber, buffer);
- }
-
- /**
- * Writes value data to swap file.
- *
- * @param cid
- * Property id
- * @param orderNumber
- * Value order number
- * @param version
- * persistent version (used for BLOB swapping)
- * @param content
- * @return ValueData
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error (swap)
- */
- protected SwapFile swapValueData(String cid, int orderNumber, int version, final InputStream content)
- throws SQLException, IOException
- {
-
- byte[] spoolBuffer = new byte[ValueFileIOHelper.IOBUFFER_SIZE];
- int read;
- int len = 0;
-
- SwapFile swapFile = SwapFile.get(swapDirectory, cid + orderNumber + "." + version);
- OutputStream out = new FileOutputStream(swapFile);;
-
- if (swapFile.isSpooled())
- {
- return swapFile;
- }
-
- try
- {
- if (content != null)
- while ((read = content.read(spoolBuffer)) >= 0)
- {
- // spool to temp file
- out.write(spoolBuffer, 0, read);
- len += read;
- }
- }
- finally
- {
- out.close();
- swapFile.spoolDone();
- }
-
- return swapFile;
- }
-
- /**
- * Add Values to Property record.
- *
- * @param data
- * PropertyData
- * @throws SQLException
- * database error
- * @throws IOException
- * I/O error
- * @thorws RepositoryException if Value data large of JDBC accepted (Integer.MAX_VALUE)
- */
- protected void addValues(String cid, PropertyData data) throws IOException, SQLException, RepositoryException
- {
- List<ValueData> vdata = data.getValues();
-
- for (int i = 0; i < vdata.size(); i++)
- {
- ValueData vd = vdata.get(i);
- ValueIOChannel channel = valueStorageProvider.getApplicableChannel(data, i);
- InputStream stream;
- int streamLength;
- String storageId;
- if (channel == null)
- {
- // prepare write of Value in database
- if (vd.isByteArray())
- {
- byte[] dataBytes = vd.getAsByteArray();
- stream = new ByteArrayInputStream(dataBytes);
- streamLength = dataBytes.length;
- }
- else
- {
- // it's StreamPersistedValueData
- StreamPersistedValueData streamData = (StreamPersistedValueData)vd;
- stream = streamData.getStream();
-
- // TODO spool on JDBC driver read - multiplexing the data to two stores, database and spool file, with one read.
- SwapFile swapFile = swapValueData(cid, i, data.getPersistedVersion(), stream);
-
- long vlen = swapFile.length();
- if (vlen < 0)
- {
- // TODO not actual with SwapFile, but if it will be reworked can be so
- streamLength = stream.available();
- LOG.warn("Cannot obtain exact Value data length, will use available from the stream " + streamLength
- + ". Property " + data.getQPath().getAsString());
- }
- else if (vlen <= Integer.MAX_VALUE)
- {
- streamLength = (int)vlen;
- }
- else
- {
- throw new RepositoryException("Value data large of allowed by JDBC (Integer.MAX_VALUE) " + vlen
- + ". Property " + data.getQPath().getAsString());
- }
-
- // set persistent file to ValueData, will be available for saving Property.
- streamData.setPersistedFile(swapFile);
- stream = streamData.getAsStream();
- }
- storageId = null;
- }
- else
- {
- // write Value in external VS
- channel.write(data.getIdentifier(), vd);
- valueChanges.add(channel);
- storageId = channel.getStorageId();
- stream = null;
- streamLength = 0;
- }
- addValueData(cid, i, stream, streamLength, storageId);
- }
- }
-
- protected abstract ResultSet findItemByIdentifierNew(String identifier) throws SQLException;
-
- protected abstract ResultSet findItemByNameNew(String parentId, String name, int index) throws SQLException;
-
- protected abstract ResultSet findChildNodesByParentIdentifierNew(String parentIdentifier) throws SQLException;
-
protected abstract ResultSet getChildPropertiesByParentIdentifier(String parentIdentifier) throws SQLException;
-
- protected abstract ResultSet findReferenceProperties(String parentIdentifier) throws SQLException;
}
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-26 09:53:58 UTC (rev 1198)
+++ 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-26 12:15:51 UTC (rev 1199)
@@ -409,7 +409,7 @@
/**
* {@inheritDoc}
*/
- protected ResultSet findItemByNameNew(String parentId, String name, int index) throws SQLException
+ protected ResultSet findItemByNameWithAllData(String parentId, String name, int index) throws SQLException
{
if (findItemByNameNew == null)
findItemByNameNew = dbConnection.prepareStatement(FIND_ITEM_BY_NAME_NEW);
@@ -487,7 +487,7 @@
* {@inheritDoc}
*/
@Override
- protected ResultSet findChildNodesByParentIdentifierNew(String parentIdentifier) throws SQLException
+ protected ResultSet findChildNodesByParentIdentifierCQ(String parentIdentifier) throws SQLException
{
if (findNodesByParentId == null)
findNodesByParentId = dbConnection.prepareStatement(FIND_NODES_BY_PARENTID_NEW);
@@ -641,7 +641,7 @@
}
@Override
- protected ResultSet findItemByIdentifierNew(String identifier) throws SQLException
+ protected ResultSet findItemByIdentifierWithAllData(String identifier) throws SQLException
{
if (findItemByIdNew == null)
findItemByIdNew = dbConnection.prepareStatement(FIND_ITEM_BY_ID_NEW);
@@ -664,15 +664,4 @@
return getPropertiesByParentId.executeQuery();
}
- @Override
- protected ResultSet findReferenceProperties(String nodeIdentifier) throws SQLException
- {
- if (findReferenceProperties == null)
- findReferenceProperties = dbConnection.prepareStatement(FIND_REFERENCE_PROPERTIES);
- else
- findReferenceProperties.clearParameters();
-
- findReferenceProperties.setString(1, nodeIdentifier);
- return findReferenceProperties.executeQuery();
- }
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2009-12-26 09:53:58 UTC (rev 1198)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/SingleDbJDBCConnection.java 2009-12-26 12:15:51 UTC (rev 1199)
@@ -398,7 +398,7 @@
}
@Override
- protected ResultSet findItemByNameNew(String parentId, String name, int index) throws SQLException
+ protected ResultSet findItemByNameWithAllData(String parentId, String name, int index) throws SQLException
{
if (findItemByName == null)
findItemByName = dbConnection.prepareStatement(FIND_ITEM_BY_NAME);
@@ -608,7 +608,7 @@
}
@Override
- protected ResultSet findItemByIdentifierNew(String identifier) throws SQLException
+ protected ResultSet findItemByIdentifierWithAllData(String identifier) throws SQLException
{
if (findItemByIdNew == null)
findItemByIdNew = dbConnection.prepareStatement(FIND_ITEM_BY_ID_NEW);
@@ -621,7 +621,7 @@
}
@Override
- protected ResultSet findChildNodesByParentIdentifierNew(String parentIdentifier) throws SQLException
+ protected ResultSet findChildNodesByParentIdentifierCQ(String parentIdentifier) throws SQLException
{
// TODO Auto-generated method stub
return null;
@@ -634,11 +634,4 @@
return null;
}
- @Override
- protected ResultSet findReferenceProperties(String parentIdentifier) throws SQLException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
}
More information about the exo-jcr-commits
mailing list