[exo-jcr-commits] exo-jcr SVN: r853 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core/version and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Nov 25 05:44:59 EST 2009
Author: tolusha
Date: 2009-11-25 05:44:59 -0500 (Wed, 25 Nov 2009)
New Revision: 853
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestGetNodesPerf.java
Log:
EXOJRC-221: improvements with location & definitions
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2009-11-25 10:28:31 UTC (rev 852)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2009-11-25 10:44:59 UTC (rev 853)
@@ -23,6 +23,7 @@
import org.exoplatform.services.jcr.access.AccessManager;
import org.exoplatform.services.jcr.access.PermissionType;
import org.exoplatform.services.jcr.core.ExtendedPropertyType;
+import org.exoplatform.services.jcr.core.nodetype.ItemDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
@@ -97,6 +98,11 @@
*/
protected JCRPath location;
+ /**
+ * Item QPath.
+ */
+ protected QPath qpath;
+
protected SessionDataManager dataManager;
protected LocationFactory locationFactory;
@@ -157,7 +163,7 @@
/**
* {@inheritDoc}
*/
- public String getPath()
+ public String getPath() throws RepositoryException
{
return getLocation().getAsString(false);
}
@@ -165,7 +171,7 @@
/**
* {@inheritDoc}
*/
- public String getName()
+ public String getName() throws RepositoryException
{
return getLocation().getName().getAsString();
}
@@ -231,7 +237,7 @@
*/
public int getDepth()
{
- return getLocation().getDepth();
+ return qpath.getDepth();
}
/**
@@ -741,8 +747,11 @@
*
* @return item JCRPath
*/
- public JCRPath getLocation()
+ public JCRPath getLocation() throws RepositoryException
{
+ if (this.location == null)
+ this.location = session.getLocationFactory().createJCRPath(qpath);
+
return this.location;
}
@@ -758,6 +767,15 @@
abstract void loadData(ItemData data) throws RepositoryException;
+ abstract void loadData(ItemData data, ItemDefinitionData itemDefinitionData) throws RepositoryException;
+
+ /**
+ * Returns Item definition data.
+ *
+ * @return
+ */
+ abstract ItemDefinitionData getItemDefinitionData();
+
public boolean hasPermission(String action) throws RepositoryException
{
NodeData ndata;
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2009-11-25 10:28:31 UTC (rev 852)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2009-11-25 10:44:59 UTC (rev 853)
@@ -24,6 +24,7 @@
import org.exoplatform.services.jcr.access.SystemIdentity;
import org.exoplatform.services.jcr.core.ExtendedNode;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
+import org.exoplatform.services.jcr.core.nodetype.ItemDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
@@ -137,7 +138,7 @@
*
* @param data
* Node data
- * @param session
+ * @param session
* Session
* @throws RepositoryException
* if error occurs during the Node data loading
@@ -150,6 +151,25 @@
}
/**
+ * NodeImpl constructor.
+ *
+ * @param data
+ * Node data
+ * @param parent
+ * Parent node data
+ * @param session
+ * Session
+ * @throws RepositoryException
+ * if error occurs during the Node data loading
+ */
+ public NodeImpl(NodeData data, NodeData parent, SessionImpl session) throws RepositoryException
+ {
+ super(data, session);
+ this.sysLocFactory = session.getSystemLocationFactory();
+ loadData(data, parent);
+ }
+
+ /**
* {@inheritDoc}
*/
public void accept(ItemVisitor visitor) throws RepositoryException
@@ -1357,7 +1377,8 @@
throw new RepositoryException("ACL is NULL " + nodeData.getQPath().getAsString());
this.data = nodeData;
- this.location = session.getLocationFactory().createJCRPath(getData().getQPath());
+ this.qpath = nodeData.getQPath();
+ this.location = null;
initDefinition();
}
@@ -1365,6 +1386,84 @@
/**
* {@inheritDoc}
*/
+ private void loadData(ItemData data, NodeData parent) throws RepositoryException, InvalidItemStateException,
+ ConstraintViolationException
+ {
+
+ if (data == null)
+ throw new InvalidItemStateException("Data is null for " + this.getPath()
+ + " Probably was deleted by another session and can not be loaded from container ");
+
+ if (!data.isNode())
+ throw new RepositoryException("Load data failed: Node expected");
+
+ NodeData nodeData = (NodeData)data;
+
+ // TODO do we need this three checks here?
+ if (nodeData.getPrimaryTypeName() == null)
+ throw new RepositoryException("Load data: NodeData has no primaryTypeName. Null value found. "
+ + (nodeData.getQPath() != null ? nodeData.getQPath().getAsString() : "[null path node]") + " " + nodeData);
+
+ if (nodeData.getMixinTypeNames() == null)
+ throw new RepositoryException("Load data: NodeData has no mixinTypeNames. Null value found. "
+ + (nodeData.getQPath() != null ? nodeData.getQPath().getAsString() : "[null path node]"));
+
+ if (nodeData.getACL() == null)
+ throw new RepositoryException("ACL is NULL " + nodeData.getQPath().getAsString());
+
+ this.data = nodeData;
+ this.qpath = nodeData.getQPath();
+ this.location = null;
+
+ initDefinition(parent);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void loadData(ItemData data, ItemDefinitionData itemDefinitionData) throws RepositoryException,
+ InvalidItemStateException, ConstraintViolationException
+ {
+
+ if (data == null)
+ throw new InvalidItemStateException("Data is null for " + this.getPath()
+ + " Probably was deleted by another session and can not be loaded from container ");
+
+ if (!data.isNode())
+ throw new RepositoryException("Load data failed: Node expected");
+
+ NodeData nodeData = (NodeData)data;
+
+ // TODO do we need this three checks here?
+ if (nodeData.getPrimaryTypeName() == null)
+ throw new RepositoryException("Load data: NodeData has no primaryTypeName. Null value found. "
+ + (nodeData.getQPath() != null ? nodeData.getQPath().getAsString() : "[null path node]") + " " + nodeData);
+
+ if (nodeData.getMixinTypeNames() == null)
+ throw new RepositoryException("Load data: NodeData has no mixinTypeNames. Null value found. "
+ + (nodeData.getQPath() != null ? nodeData.getQPath().getAsString() : "[null path node]"));
+
+ if (nodeData.getACL() == null)
+ throw new RepositoryException("ACL is NULL " + nodeData.getQPath().getAsString());
+
+ this.data = nodeData;
+ this.location = null;
+ this.qpath = nodeData.getQPath();
+ this.definition = (NodeDefinitionData)itemDefinitionData;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ItemDefinitionData getItemDefinitionData()
+ {
+ return definition;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Lock lock(boolean isDeep, boolean isSessionScoped) throws UnsupportedRepositoryOperationException,
LockException, AccessDeniedException, RepositoryException
{
@@ -2685,6 +2784,33 @@
throw new ConstraintViolationException("Node definition not found for " + getPath());
}
+ /**
+ * Init NodeDefinition.
+ *
+ * @throws RepositoryException
+ * if error occurs
+ * @throws ConstraintViolationException
+ * if definition not found
+ */
+ private void initDefinition(NodeData parent) throws RepositoryException, ConstraintViolationException
+ {
+
+ if (this.isRoot())
+ { // root - no parent
+ this.definition =
+ new NodeDefinitionData(null, null, true, true, OnParentVersionAction.ABORT, true,
+ new InternalQName[]{Constants.NT_BASE}, null, false);
+ return;
+ }
+
+ this.definition =
+ session.getWorkspace().getNodeTypesHolder().getChildNodeDefinition(getInternalName(),
+ parent.getPrimaryTypeName(), parent.getMixinTypeNames());
+
+ if (definition == null)
+ throw new ConstraintViolationException("Node definition not found for " + getPath());
+ }
+
private void removeMergeFailed(Version version, PlainChangesLog changesLog) throws RepositoryException
{
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2009-11-25 10:28:31 UTC (rev 852)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/PropertyImpl.java 2009-11-25 10:44:59 UTC (rev 853)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.impl.core;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
+import org.exoplatform.services.jcr.core.nodetype.ItemDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionData;
import org.exoplatform.services.jcr.core.nodetype.PropertyDefinitionDatas;
import org.exoplatform.services.jcr.datamodel.InternalQName;
@@ -93,14 +94,42 @@
this.propertyData = (TransientPropertyData)data;
this.type = propertyData.getType();
- this.location = session.getLocationFactory().createJCRPath(getData().getQPath());
- this.propertyDef = null;
+ this.qpath = data.getQPath();
+ this.location = null;
+
initDefinitions(this.propertyData.isMultiValued());
}
/**
* {@inheritDoc}
*/
+ void loadData(ItemData data, ItemDefinitionData itemDefinitionData) throws RepositoryException,
+ ConstraintViolationException
+ {
+
+ if (!(data instanceof TransientPropertyData))
+ throw new RepositoryException("Load data: TransientPropertyData is expected, but have " + data);
+
+ this.data = data;
+ this.propertyData = (TransientPropertyData)data;
+ this.type = propertyData.getType();
+
+ this.location = null;
+ this.qpath = data.getQPath();
+ this.propertyDef = (PropertyDefinitionData)itemDefinitionData;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ItemDefinitionData getItemDefinitionData()
+ {
+ return propertyDef;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Value getValue() throws ValueFormatException, RepositoryException
{
@@ -526,9 +555,10 @@
*/
public String dump()
{
- String vals = "Property " + getPath() + " values: ";
+ String vals = "Property ";
try
{
+ vals = getPath() + " values: ";
for (int i = 0; i < getValueArray().length; i++)
{
vals += new String(((BaseValue)getValueArray()[i]).getInternalData().getAsByteArray()) + ";";
@@ -564,19 +594,4 @@
return false;
}
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
- {
- try
- {
- return getLocation().getAsString(false).hashCode();
- }
- catch (Exception e)
- {
- return super.hashCode();
- }
- }
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2009-11-25 10:28:31 UTC (rev 852)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2009-11-25 10:44:59 UTC (rev 853)
@@ -578,7 +578,7 @@
for (NodeData data : nodeDatas)
{
- NodeImpl item = itemFactory.createNode(data);
+ NodeImpl item = itemFactory.createNode(data, parent);
session.getActionHandler().postRead(item);
@@ -1729,7 +1729,7 @@
}
else
{
- item.loadData(newItem.getData());
+ item.loadData(newItem.getData(), newItem.getItemDefinitionData());
return item;
}
}
@@ -1839,12 +1839,19 @@
String dump()
{
String str = "Items Pool: \n";
- for (ItemImpl item : items.values())
+ try
{
- str +=
- (item.isNode() ? "Node\t\t" : "Property\t") + "\t" + item.isValid() + "\t" + item.isNew() + "\t"
- + item.getInternalIdentifier() + "\t" + item.getPath() + "\n";
+ for (ItemImpl item : items.values())
+ {
+ str +=
+ (item.isNode() ? "Node\t\t" : "Property\t") + "\t" + item.isValid() + "\t" + item.isNew() + "\t"
+ + item.getInternalIdentifier() + "\t" + item.getPath() + "\n";
+ }
}
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
return str;
}
@@ -1880,10 +1887,26 @@
return node;
}
+ private NodeImpl createNode(NodeData data, NodeData parent) throws RepositoryException
+ {
+ NodeImpl node = new NodeImpl(data, parent, session);
+ if (node.isNodeType(Constants.NT_VERSION))
+ {
+ return new VersionImpl(data, session);
+ }
+ else if (node.isNodeType(Constants.NT_VERSIONHISTORY))
+ {
+ return new VersionHistoryImpl(data, session);
+ }
+ else
+ return node;
+ }
+
private PropertyImpl createProperty(ItemData data) throws RepositoryException
{
return new PropertyImpl(data, session);
}
+
}
/**
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java 2009-11-25 10:28:31 UTC (rev 852)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/version/VersionHistoryImpl.java 2009-11-25 10:44:59 UTC (rev 853)
@@ -629,7 +629,7 @@
}
- public boolean isVersionBelongToThis(Version version)
+ public boolean isVersionBelongToThis(Version version) throws RepositoryException
{
return ((VersionImpl)version).getLocation().isDescendantOf(getLocation(), false);
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java 2009-11-25 10:28:31 UTC (rev 852)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java 2009-11-25 10:44:59 UTC (rev 853)
@@ -387,7 +387,7 @@
return testFile;
}
- protected void checkMixins(String[] mixins, NodeImpl node)
+ protected void checkMixins(String[] mixins, NodeImpl node) throws RepositoryException
{
try
{
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestGetNodesPerf.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestGetNodesPerf.java 2009-11-25 10:28:31 UTC (rev 852)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestGetNodesPerf.java 2009-11-25 10:44:59 UTC (rev 853)
@@ -19,11 +19,7 @@
import org.exoplatform.services.jcr.JcrAPIBaseTest;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
-import java.io.File;
-import java.io.PrintWriter;
-
import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -39,14 +35,17 @@
{
private static final String testName = "testRoot";
- private static final int sessionCount = 20;
+ private static final int sessionCount = 1;
+ private static final int tryCount = 10;
+
private Session[] sessions = new Session[sessionCount];
private GetNodesThread[] threads = new GetNodesThread[sessionCount];
public void testGetNodes() throws Exception
{
+
for (int i = 0; i < sessionCount; i++)
{
sessions[i] = (SessionImpl)repository.login(credentials, "ws");
@@ -67,6 +66,10 @@
log.info("waiting for 10 seconds...");
Thread.sleep(10000);
+ System.gc();
+ Runtime rt = Runtime.getRuntime();
+ long usedMemory = rt.totalMemory() - rt.freeMemory();
+
log.info("getting nodes...");
for (int i = 0; i < sessionCount; i++)
{
@@ -87,8 +90,7 @@
break;
}
-
- log.info("Test finished");
+ log.info("Memory used: " + (rt.totalMemory() - rt.freeMemory() - usedMemory) / 1024 + "Kb");
}
private class GetNodesThread extends Thread
@@ -107,9 +109,12 @@
{
Node testRoot = curSession.getRootNode().getNode(testName);
- long startTime = System.currentTimeMillis();
- testRoot.getNodes();
- log.info("Total time: " + (System.currentTimeMillis() - startTime) / 1000 + "s");
+ for (int k = 0; k < tryCount; k++)
+ {
+ long startTime = System.currentTimeMillis();
+ testRoot.getNodes();
+ log.info("Total time: " + (System.currentTimeMillis() - startTime) / 1000 + "s");
+ }
}
catch (RepositoryException e)
{
More information about the exo-jcr-commits
mailing list