Author: sergiykarpenko
Date: 2009-12-17 11:04:11 -0500 (Thu, 17 Dec 2009)
New Revision: 1124
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
Log:
EXOJCR-302: get node data query implemented
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java 2009-12-17
14:14:15 UTC (rev 1123)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/DBConstants.java 2009-12-17
16:04:11 UTC (rev 1124)
@@ -95,6 +95,11 @@
protected String FIND_ITEM_BY_NAME;
/**
+ * FIND_NODE_BY_ID.
+ */
+ protected String FIND_NODE_BY_ID;
+
+ /**
* FIND_CHILD_PROPERTY_BY_PATH.
*/
protected String FIND_CHILD_PROPERTY_BY_PATH;
@@ -126,7 +131,7 @@
* FIND_NODES_BY_PARENTID.
*/
protected String FIND_NODES_BY_PARENTID;
-
+
/**
* FIND_NODES_COUNT_BY_PARENTID.
*/
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java 2009-12-17
14:14:15 UTC (rev 1123)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/NewJDBCStorageConnection.java 2009-12-17
16:04:11 UTC (rev 1124)
@@ -735,16 +735,17 @@
* @throws IllegalStateException
* if connection is closed
*/
- protected ItemData getItemByIdentifier(String cid) throws RepositoryException,
IllegalStateException
+ protected ItemData getItemByIdentifier(String id) throws RepositoryException,
IllegalStateException
{
checkIfOpened();
ResultSet item = null;
try
{
- item = findItemByIdentifier(cid);
+ item = findNodeByIdentifier(id);
if (item.next())
{
- return itemData(null, item, item.getInt(COLUMN_CLASS), null);
+ //itemData(null, item, item.getInt(COLUMN_CLASS), null);
+ return loadNodeRecord(item, null);
}
return null;
}
@@ -1118,6 +1119,139 @@
}
}
+ protected PersistedNodeData loadNodeRecord(ResultSet item, 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 cpid = item.getString(COLUMN_PARENTID);
+ int cindex = item.getInt(COLUMN_INDEX);
+ int cnordernumb = item.getInt(COLUMN_NORDERNUM);
+ AccessControlList parentACL = null;
+
+ 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;
+ }
+ }
+
+ // PRIMARY
+ byte[] data = item.getBytes(COLUMN_VDATA);
+ InternalQName ptName = InternalQName.parse(new String((data != null ? data : new
byte[]{})));
+
+ 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);
+ }
+ }
+
/**
* Build ItemData.
*
@@ -1889,6 +2023,8 @@
protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
+ protected abstract ResultSet findNodeByIdentifier(String identifier) throws
SQLException;
+
protected abstract ResultSet findItemByIdentifier(String identifier) throws
SQLException;
protected abstract ResultSet findPropertyByName(String parentId, String name) throws
SQLException;
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2009-12-17
14:14:15 UTC (rev 1123)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/optimisation/db/MultiDbJDBCConnection.java 2009-12-17
16:04:11 UTC (rev 1124)
@@ -23,7 +23,7 @@
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.dataflow.ValueDataConvertor;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
+import
org.exoplatform.services.jcr.impl.storage.jdbc.optimisation.NewJDBCStorageConnection;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
@@ -48,11 +48,13 @@
* pnedonosko $
*/
-public class MultiDbJDBCConnection extends JDBCStorageConnection
+public class MultiDbJDBCConnection extends NewJDBCStorageConnection
{
protected PreparedStatement findItemById;
+ protected PreparedStatement findNodeById;
+
protected PreparedStatement findItemByPath;
protected PreparedStatement findItemByName;
@@ -77,7 +79,7 @@
protected PreparedStatement findValueByPropertyIdOrderNumber;
protected PreparedStatement findNodesByParentId;
-
+
protected PreparedStatement findNodesCountByParentId;
protected PreparedStatement findPropertiesByParentId;
@@ -168,6 +170,10 @@
FIND_ITEM_BY_ID = "select * from JCR_MITEM where ID=?";
+ FIND_NODE_BY_ID =
+ "select I.*, P.DATA from JCR_MITEM I, (select I2.PARENT_ID, V.DATA from
JCR_MITEM I2, JCR_MVALUE V where I2.I_CLASS=2 and I2.PARENT_ID=?"
+ + " and
I2.NAME='[http://www.jcp.org/jcr/1.0]primaryType' and
I2.ID=V.PROPERTY_ID) P"
+ + " where I.ID=P.PARENT_ID";
FIND_ITEM_BY_NAME =
"select * from JCR_MITEM" + " where PARENT_ID=? and NAME=? and
I_INDEX=? order by I_CLASS, VERSION DESC";
@@ -187,7 +193,7 @@
FIND_VALUE_BY_PROPERTYID_OREDERNUMB = "select DATA from JCR_MVALUE where
PROPERTY_ID=? and ORDER_NUM=?";
FIND_NODES_BY_PARENTID = "select * from JCR_MITEM" + " where
I_CLASS=1 and PARENT_ID=?" + " order by N_ORDER_NUM";
-
+
FIND_NODES_COUNT_BY_PARENTID = "select count(ID) from JCR_MITEM" + "
where I_CLASS=1 and PARENT_ID=?";
FIND_PROPERTIES_BY_PARENTID = "select * from JCR_MITEM" + " where
I_CLASS=2 and PARENT_ID=?" + " order by ID";
@@ -568,4 +574,15 @@
findValuesStorageDescriptorsByPropertyId.setString(1, cid);
return findValuesStorageDescriptorsByPropertyId.executeQuery();
}
+
+ @Override
+ protected ResultSet findNodeByIdentifier(String identifier) throws SQLException
+ {
+ if (findNodeById == null)
+ findNodeById = dbConnection.prepareStatement(FIND_NODE_BY_ID);
+ else
+ findNodeById.clearParameters();
+ findNodeById.setString(1, identifier);
+ return findNodeById.executeQuery();
+ }
}