Author: pnedonosko
Date: 2009-11-17 11:14:29 -0500 (Tue, 17 Nov 2009)
New Revision: 722
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/inmemory/InmemoryStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLExceptionHandler.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
Log:
EXOJCR-203: JDBC loader get(Fqn), getChildrenNames(Fqn); WS connection rework
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/inmemory/InmemoryStorageConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/inmemory/InmemoryStorageConnection.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/inmemory/InmemoryStorageConnection.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -276,24 +276,4 @@
return null;
}
- /**
- * {@inheritDoc}
- */
- public void deleteNode(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void deleteProperty(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -379,26 +379,6 @@
/**
* {@inheritDoc}
*/
- public void deleteNode(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void deleteProperty(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- */
public ItemData getItemData(String identifier) throws RepositoryException,
IllegalStateException
{
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheTreeStorageConnection.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -436,24 +436,4 @@
throw new UnsupportedOperationException();
}
- /**
- * {@inheritDoc}
- */
- public void deleteNode(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void deleteProperty(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -25,14 +26,17 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import javax.jcr.InvalidItemStateException;
import javax.jcr.RepositoryException;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.dataflow.ItemState;
import org.exoplatform.services.jcr.datamodel.IllegalNameException;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
@@ -77,7 +81,7 @@
* @param dataContainer WorkspaceDataContainer
*/
@Inject
- public void injectDependencies(WorkspaceDataContainer dataContainer) throws
RepositoryConfigurationException
+ public void init(WorkspaceDataContainer dataContainer) throws
RepositoryConfigurationException
{
if (this.dataContainer != null)
{
@@ -96,11 +100,6 @@
*/
protected void apply(WorkspaceStorageConnection conn, List<Modification>
modifications) throws RepositoryException
{
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Modifications list size = " + modifications.size());
- }
-
// Prepare modifications list.
// Will be added oldValueData to modification for UPDATE.
//prepareModifications(modifications);
@@ -153,10 +152,6 @@
LOG.debug("Modifications list size = " + modifications.size());
}
- // Prepare modifications list.
- // Will be added oldValueData to modification for UPDATE.
- //prepareModifications(modifications);
-
WorkspaceStorageConnection conn = dataContainer.openConnection();
try
{
@@ -165,12 +160,12 @@
}
catch (RepositoryException e)
{
- LOG.error("RepositoryException: ", e); // TODO cleanup
+ LOG.error("RepositoryException: ", e); // TODO don't catch
throw new RepositoryException(e);
}
catch (IllegalStateException e)
{
- LOG.error("IllegalStateException: ", e); // TODO cleanup
+ LOG.error("IllegalStateException: ", e); // TODO don't catch
throw new IllegalStateException(e);
}
finally
@@ -268,173 +263,129 @@
}
/**
- * Prepare list of modifications.
- *
- * Will be checked the UPDATE, ADD, REMOVE.
- *
- * @param modifications
- * @throws RepositoryException
- */
- @Deprecated
- private void prepareModifications(List<Modification> modifications) throws
RepositoryException
- {
- WorkspaceStorageConnection conn = dataContainer.openConnection();
-
- try
- {
- for (int i = 0; i < modifications.size(); i++)
- {
- Modification m = modifications.get(i);
- if (m.getType() == ModificationType.PUT_KEY_VALUE)
- {
- ItemData itemData = null;
-
- //Check add or update node data.
- if (m.getValue() instanceof NodeData)
- {
- NodeData nodeData = (NodeData)m.getValue();
- itemData = conn.getItemData(nodeData.getIdentifier());
-
- // Set oldValueData for update node.
- if (itemData != null)
- modifications.get(i).setOldValue(itemData);
- }
- else if (m.getValue() instanceof PropertyData)
- {
- PropertyData propertyData = (PropertyData)m.getValue();
- itemData = conn.getItemData(propertyData.getIdentifier());
-
- // Set oldValueData for update property.
- if (itemData != null)
- modifications.get(i).setOldValue(itemData);
- }
- }
- else if (m.getType() == ModificationType.REMOVE_NODE)
- {
- if (m.getFqn().size() == 2
- && (m.getFqn().get(0).equals(JBossCacheStorage.NODES) ||
m.getFqn().get(0).equals(
- JBossCacheStorage.PROPS)))
- {
- String id = (String)m.getFqn().get(1);
- ItemData removedItemData = conn.getItemData(id);
-
- // Set valueData for update property or node.
- if (removedItemData != null)
- modifications.get(i).setValue(removedItemData);
- }
- }
- }
- }
- finally
- {
- conn.close();
- }
- }
-
- protected QPathEntry[] makeNodePath(Fqn<String> nodeFqn) throws
NumberFormatException, IllegalNameException
- {
- List<String> elements = nodeFqn.peekElements();
- QPathEntry[] path = new QPathEntry[elements.size()];
-
- for (int i = 0; i < elements.size(); i++)
- {
- path[i] = QPathEntry.parse(elements.get(i));
- }
-
- return path;
- }
-
- /**
* {@inheritDoc}
*/
public Map<Object, Object> get(Fqn name) throws Exception
{
- Map<Object, Object> attrs = new LinkedHashMap<Object, Object>();
+ Map<Object, Object> attrs;
- if (name.size() > 1)
+ WorkspaceStorageConnection conn = dataContainer.openConnection();
+ try
{
- if (name.get(0).equals(JBossCacheStorage.NODES))
+
+ if (name.size() > 1)
{
- // /$NODES/<NODE_ID>
- if (name.size() == 2)
+ if (name.get(0).equals(JBossCacheStorage.NODES))
{
- // return NodeData [ITEM_DATA : NodeData]
- WorkspaceStorageConnection conn = dataContainer.openConnection();
-
- try
+ // /$NODES/<NODE_ID>
+ if (name.size() == 2)
{
- NodeData nodeData =
(NodeData)conn.getItemData(name.getLastElementAsString());
-
+ String nodeId = name.getLastElementAsString();
+ NodeData nodeData = (NodeData)conn.getItemData(nodeId);
if (nodeData != null)
{
+ // TODO use dedicated select, not child datas
+ List<PropertyData> childProps =
conn.getChildPropertiesData(nodeData);
+ if (childProps.size() <= 0)
+ {
+ throw new JDBCCacheLoaderException("FATAL Empty attributes
for Node " + nodeId + " '" + name
+ + "'");
+ }
+
+ attrs = new LinkedHashMap<Object, Object>();
attrs.put(JBossCacheStorage.ITEM_DATA, nodeData);
-
- // put [PROPERTY_NAME : propertyData_ID]
- for (PropertyData prop : conn.getChildPropertiesData(nodeData))
+ for (PropertyData prop : childProps)
{
attrs.put(prop.getQPath().getName().getAsString(),
prop.getIdentifier());
}
}
+ else
+ {
+ attrs = null;
+ }
}
- finally
+ // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
+ else if (name.size() == 3)
{
- conn.close();
- }
- }
- // /$NODES/<NODE_ID>/<SUB_NODE_NAME>
- else if (name.size() == 3)
- {
- QPathEntry nodeName = QPathEntry.parse(name.getLastElementAsString());
+ QPathEntry childNodeName =
QPathEntry.parse(name.getLastElementAsString());
+ String parentId = (String)name.get(1);
- // return [ITEM_Id : nodeData_ID]
- WorkspaceStorageConnection conn = dataContainer.openConnection();
-
- try
- {
- NodeData parentNodeData =
(NodeData)conn.getItemData((String)name.get(1));
-
- //TODO We do not throw exception if parentNodeData not exists in DB,
because we use that method (get(Fqn name)) in exists(Fqn name).
- /*if (parentNodeData == null)
- throw new JDBCCacheLoaderException("The parent node with ID =
" + (String)name.get(1) + " not exis, FQN = '" + name +
"'.");*/
-
- if (parentNodeData != null)
+ // TODO use non-data method, check ACL creation
+ NodeData parentData = (NodeData)conn.getItemData(parentId);
+ if (parentData != null)
{
- NodeData nodeData = (NodeData)conn.getItemData(parentNodeData,
nodeName);
+ NodeData nodeData = (NodeData)conn.getItemData(parentData,
childNodeName);
if (nodeData != null)
+ {
+ attrs = new LinkedHashMap<Object, Object>();
attrs.put(JBossCacheStorage.ITEM_ID, nodeData.getIdentifier());
+ }
+ else
+ {
+ throw new JDBCCacheLoaderException("FATAL Child Node data
not found "
+ + parentData.getQPath().getAsString() +
childNodeName.getAsString(true) + " for '" + name
+ + "'");
+ }
}
+ else
+ {
+ throw new JDBCCacheLoaderException("FATAL Parent not found
" + parentId + " for '" + name + "'");
+ }
}
- finally
+ else
{
- conn.close();
+ attrs = null;
+ LOG.warn("Unexpected Fqn asked " + name);
}
}
- }
- // /$PROPS/<PROPERTY_ID>
- else if (name.get(0).equals(JBossCacheStorage.PROPS))
- {
- if (name.size() == 2)
+ // /$PROPS/<PROPERTY_ID>
+ else if (name.get(0).equals(JBossCacheStorage.PROPS))
{
- // return PropertyData [ITEM_DATA : PropertyData]
- WorkspaceStorageConnection conn = dataContainer.openConnection();
-
- try
+ if (name.size() == 2)
{
- PropertyData propertyData =
(PropertyData)conn.getItemData(name.getLastElementAsString());
-
+ String propertyId = name.getLastElementAsString();
+ PropertyData propertyData =
(PropertyData)conn.getItemData(propertyId);
if (propertyData != null)
+ {
+ attrs = new LinkedHashMap<Object, Object>();
attrs.put(JBossCacheStorage.ITEM_DATA, propertyData);
+ }
+ else
+ {
+ attrs = null;
+ }
}
- finally
+ else
{
- conn.close();
+ attrs = null;
+ LOG.warn("Unexpected Fqn asked " + name);
}
}
+ else
+ {
+ attrs = null;
+ LOG.warn("Unexpected Fqn asked " + name);
+ }
}
+ else if (name.equals(Fqn.ROOT) || name.equals(JBossCacheStorage.PROPS) ||
name.equals(JBossCacheStorage.NODES)
+ || name.equals(JBossCacheStorage.LOCKS))
+ {
+ // roots, like NODES, PROPS etc
+ attrs = new LinkedHashMap<Object, Object>();
+ }
+ else
+ {
+ LOG.warn("Unexpected Fqn asked " + name);
+ attrs = null;
+ }
}
+ finally
+ {
+ conn.close();
+ }
- return (attrs.size() == 0 ? null : attrs);
+ return attrs;
}
/**
@@ -453,7 +404,7 @@
{
// return child nodes names
- Set<String> childs = new LinkedHashSet<String>();
+ Set<String> childs;
// /$NODES/<NODE_ID>
if (name.size() == 2)
@@ -461,25 +412,54 @@
WorkspaceStorageConnection conn = dataContainer.openConnection();
try
{
- NodeData parentNodeData = (NodeData)conn.getItemData((String)name.get(1));
-
- if (parentNodeData == null)
- throw new JDBCCacheLoaderException("The parent node with ID = "
+ (String)name.get(1)
- + " not exis, FQN = '" + name + "'.");
-
- // get child nodes by parent Id
- for (NodeData node : conn.getChildNodesData(parentNodeData))
+ String nodeId = (String)name.get(1);
+ NodeData parentData = (NodeData)conn.getItemData(nodeId);
+ if (parentData != null)
{
-
childs.add(node.getQPath().getEntries()[node.getQPath().getEntries().length -
1].getAsString(true));
+ childs = new LinkedHashSet<String>();
+ // TODO get child nodes by parent Id, we need only id and name
+ for (NodeData node : conn.getChildNodesData(parentData))
+ {
+
childs.add(node.getQPath().getEntries()[node.getQPath().getEntries().length -
1].getAsString(true));
+ }
}
+ else
+ {
+ // TODO by JBC API we can just retur null, but it will not be normal for
this loader contract
+ throw new JDBCCacheLoaderException("FATAL Parent not found " +
nodeId + " '" + name + "'");
+ }
}
finally
{
conn.close();
}
}
+ else if (name.equals(JBossCacheStorage.NODES))
+ {
+ // TODO return all Nodes in workspace
+ childs = new LinkedHashSet<String>();
+ }
+ else if (name.equals(JBossCacheStorage.PROPS))
+ {
+ // TODO return all Properties in workspace
+ childs = new LinkedHashSet<String>();
+ }
+ else if (name.equals(JBossCacheStorage.LOCKS))
+ {
+ // TODO return all Locks in workspace
+ childs = new LinkedHashSet<String>();
+ }
+ else if (name.equals(Fqn.ROOT))
+ {
+ childs = new LinkedHashSet<String>();
+ childs.add(JBossCacheStorage.NODES);
+ childs.add(JBossCacheStorage.PROPS);
+ childs.add(JBossCacheStorage.LOCKS);
+ } else {
+ childs = null;
+ }
- return (childs.size() == 0 ? null : childs);
+ return childs;
}
/**
@@ -618,4 +598,82 @@
// etc.
-}
+ /**
+ * Prepare list of modifications.
+ *
+ * Will be checked the UPDATE, ADD, REMOVE.
+ *
+ * @param modifications
+ * @throws RepositoryException
+ */
+ @Deprecated
+ private void prepareModifications(List<Modification> modifications) throws
RepositoryException
+ {
+ WorkspaceStorageConnection conn = dataContainer.openConnection();
+
+ try
+ {
+ for (int i = 0; i < modifications.size(); i++)
+ {
+ Modification m = modifications.get(i);
+ if (m.getType() == ModificationType.PUT_KEY_VALUE)
+ {
+ ItemData itemData = null;
+
+ //Check add or update node data.
+ if (m.getValue() instanceof NodeData)
+ {
+ NodeData nodeData = (NodeData)m.getValue();
+ itemData = conn.getItemData(nodeData.getIdentifier());
+
+ // Set oldValueData for update node.
+ if (itemData != null)
+ modifications.get(i).setOldValue(itemData);
+ }
+ else if (m.getValue() instanceof PropertyData)
+ {
+ PropertyData propertyData = (PropertyData)m.getValue();
+ itemData = conn.getItemData(propertyData.getIdentifier());
+
+ // Set oldValueData for update property.
+ if (itemData != null)
+ modifications.get(i).setOldValue(itemData);
+ }
+ }
+ else if (m.getType() == ModificationType.REMOVE_NODE)
+ {
+ if (m.getFqn().size() == 2
+ && (m.getFqn().get(0).equals(JBossCacheStorage.NODES) ||
m.getFqn().get(0).equals(
+ JBossCacheStorage.PROPS)))
+ {
+ String id = (String)m.getFqn().get(1);
+ ItemData removedItemData = conn.getItemData(id);
+
+ // Set valueData for update property or node.
+ if (removedItemData != null)
+ modifications.get(i).setValue(removedItemData);
+ }
+ }
+ }
+ }
+ finally
+ {
+ conn.close();
+ }
+ }
+
+ @Deprecated
+ private QPathEntry[] makeNodePath(Fqn<String> nodeFqn) throws
NumberFormatException, IllegalNameException
+ {
+ List<String> elements = nodeFqn.peekElements();
+ QPathEntry[] path = new QPathEntry[elements.size()];
+
+ for (int i = 0; i < elements.size(); i++)
+ {
+ path[i] = QPathEntry.parse(elements.get(i));
+ }
+
+ return path;
+ }
+
+}
\ No newline at end of file
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -456,7 +456,7 @@
try
{
- deleteValues(cid, data, false);
+ deleteValues(cid, data.getIdentifier(), false);
// delete references
deleteReference(cid);
@@ -490,30 +490,10 @@
exceptionHandler.handleDeleteException(e, data);
}
}
-
- /**
- * {@inheritDoc}
- */
- public void deleteNode(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
- }
-
/**
* {@inheritDoc}
*/
- public void deleteProperty(String identifier) throws RepositoryException,
- UnsupportedOperationException, InvalidItemStateException,
IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- */
public void update(NodeData data) throws RepositoryException,
UnsupportedOperationException,
InvalidItemStateException, IllegalStateException
{
@@ -575,7 +555,7 @@
}
// do Values update: delete all and add all
- deleteValues(cid, data, true);
+ deleteValues(cid, data.getIdentifier(), true);
addValues(cid, data);
if (LOG.isDebugEnabled())
@@ -1653,8 +1633,8 @@
*
* @param cid
* Property id
- * @param pdata
- * PropertyData
+ * @param propertyIdentifier
+ * the identifier the PropertyData
* @param update
* boolean true if it's delete-add sequence (update operation)
* @throws IOException
@@ -1664,7 +1644,7 @@
* @throws ValueStorageNotFoundException
* if no such storage found with Value storageId
*/
- private void deleteValues(String cid, PropertyData pdata, boolean update) throws
IOException, SQLException,
+ private void deleteValues(String cid, String propertyIdentifier, boolean update)
throws IOException, SQLException,
ValueStorageNotFoundException
{
@@ -1684,7 +1664,7 @@
final ValueIOChannel channel =
valueStorageProvider.getChannel(storageId);
try
{
- channel.delete(pdata.getIdentifier());
+ channel.delete(propertyIdentifier);
valueChanges.add(channel);
}
finally
@@ -1913,6 +1893,181 @@
}
}
+ // for JBC etc.
+
+ /**
+ * Deletes <code>NodeData</code> by identifier.
+ *
+ * @param identifier
+ * the identifier of NodeData to be deleted
+ *
+ * @throws InvalidItemStateException
+ * if the data is already deleted
+ * @throws UnsupportedOperationException
+ * if operation is not supported (it is container for level 1)
+ * @throws RepositoryException
+ * if some exception occured
+ * @throws IllegalStateException
+ * if connection is closed
+ */
+ public void deleteNode(String identifier) throws RepositoryException,
UnsupportedOperationException,
+ InvalidItemStateException, IllegalStateException
+ {
+ checkIfOpened();
+
+ final String cid = getInternalId(identifier);
+
+ try
+ {
+ int nc = deleteItemByIdentifier(cid);
+
+ if (nc <= 0)
+ {
+ throw new JCRInvalidItemStateException("(delete) Node not found "
+ identifier
+ + ". Probably was deleted by another session ", identifier,
ItemState.DELETED);
+ }
+
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Node deleted id " + identifier);
+ }
+
+ }
+ catch (SQLException e)
+ {
+ if (LOG.isDebugEnabled())
+ LOG.error("Node remove. Database error: " + e, e);
+ exceptionHandler.handleDeleteException(e, identifier, true, "");
+ }
+
+ }
+
+ /**
+ * Deletes <code>PropertyData</code> by identifier.
+ *
+ * @param identifier
+ * the identifier of PropertyData to be deleted
+ *
+ * @throws InvalidItemStateException
+ * if the data is already deleted
+ * @throws UnsupportedOperationException
+ * if operation is not supported (it is container for level 1)
+ * @throws RepositoryException
+ * if some exception occured
+ * @throws IllegalStateException
+ * if connection is closed
+ */
+ public void deleteProperty(String identifier) throws RepositoryException,
UnsupportedOperationException,
+ InvalidItemStateException, IllegalStateException
+ {
+ checkIfOpened();
+
+ final String cid = getInternalId(identifier);
+
+ try
+ {
+ deleteValues(cid, identifier, false);
+
+ // delete references
+ deleteReference(cid);
+
+ // delete item
+ int nc = deleteItemByIdentifier(cid);
+ if (nc <= 0)
+ throw new JCRInvalidItemStateException("(delete) Property not found ID
= " + identifier
+ + ". Probably was deleted by another session ", identifier,
ItemState.DELETED);
+
+ if (LOG.isDebugEnabled())
+ LOG.debug("Property deleted ID = " + identifier);
+
+ }
+ 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, identifier, true, "");
+ }
+ }
+
+ public String getItemIdentifier(String parentId, String name) throws
RepositoryException, IllegalStateException
+ {
+
+ return null; // TODO
+ }
+
+ class PropertyDataInfo {
+ String propertyId;
+ String propertyName;
+ }
+
+ public List<PropertyDataInfo> getChildProperties(String parentId) throws
RepositoryException, IllegalStateException
+ {
+
+ return new ArrayList<PropertyDataInfo>(); // TODO
+ }
+
+ public List<String> getChildNodeNames(String parentId) throws
RepositoryException, IllegalStateException
+ {
+ checkIfOpened();
+ try
+ {
+ ResultSet node = findChildNodesByParentIdentifier(getInternalId(parentId));
+ List<String> childrens = new ArrayList<String>();
+ //while (node.next())
+ //childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE,
parent.getACL()));
+
+ return childrens;
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public List<String> getAllPropertyIdentifiers() throws RepositoryException,
IllegalStateException
+ {
+ checkIfOpened();
+ try
+ {
+ ResultSet node =
findChildNodesByParentIdentifier(getInternalId("???"));
+ List<String> childrens = new ArrayList<String>();
+ //while (node.next())
+ //childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE,
parent.getACL()));
+
+ return childrens;
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ public List<String> getAllNodeIdentifiers() throws RepositoryException,
IllegalStateException
+ {
+ checkIfOpened();
+ try
+ {
+ ResultSet node =
findChildNodesByParentIdentifier(getInternalId("???"));
+ List<String> childrens = new ArrayList<String>();
+ //while (node.next())
+ //childrens.add((NodeData)itemData(parent.getQPath(), node, I_CLASS_NODE,
parent.getACL()));
+
+ return childrens;
+ }
+ catch (SQLException e)
+ {
+ throw new RepositoryException(e);
+ }
+ }
+
+ // abstract to be impl
+
protected abstract int addNodeRecord(NodeData data) throws SQLException;
protected abstract int addPropertyRecord(PropertyData prop) throws SQLException;
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLExceptionHandler.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLExceptionHandler.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/SQLExceptionHandler.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -332,7 +332,50 @@
message += "Error of item delete " + itemInfo;
throw new RepositoryException(message, 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, String itemId, boolean isNode,
String path ) throws RepositoryException,
+ InvalidItemStateException
+ {
+ String message = "[" + containerName + "] DELETE " + (isNode ?
"NODE. " : "PROPERTY. ");
+ String errMessage = e.getMessage();
+ String itemInfo =
+ path + " " + itemId
+ + (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, itemId, 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.
*
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/storage/WorkspaceStorageConnection.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -261,42 +261,6 @@
IllegalStateException;
/**
- * Deletes <code>NodeData</code> by identifier.
- *
- * @param identifier
- * the identifier of NodeData to be deleted
- *
- * @throws InvalidItemStateException
- * if the data is already deleted
- * @throws UnsupportedOperationException
- * if operation is not supported (it is container for level 1)
- * @throws RepositoryException
- * if some exception occured
- * @throws IllegalStateException
- * if connection is closed
- */
- void deleteNode(String identifier) throws RepositoryException,
UnsupportedOperationException, InvalidItemStateException,
- IllegalStateException;
-
- /**
- * Deletes <code>PropertyData</code> by identifier.
- *
- * @param identifier
- * the identifier of PropertyData to be deleted
- *
- * @throws InvalidItemStateException
- * if the data is already deleted
- * @throws UnsupportedOperationException
- * if operation is not supported (it is container for level 1)
- * @throws RepositoryException
- * if some exception occured
- * @throws IllegalStateException
- * if connection is closed
- */
- void deleteProperty(String identifier) throws RepositoryException,
UnsupportedOperationException, InvalidItemStateException,
- IllegalStateException;
-
- /**
* Deletes <code>PropertyData</code>.
*
* @param data
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -82,7 +82,7 @@
initPersistence();
loader = new JDBCCacheLoader();
- loader.injectDependencies(persistentContainer);
+ loader.init(persistentContainer);
initJCRRoot();
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java 2009-11-17
16:08:08 UTC (rev 721)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java 2009-11-17
16:14:29 UTC (rev 722)
@@ -572,26 +572,6 @@
return null;
}
- /**
- * {@inheritDoc}
- */
- public void deleteNode(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void deleteProperty(String identifier) throws RepositoryException,
UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
- {
- // TODO Auto-generated method stub
-
- }
-
}
}