Extended Properties to batch updates. This is really a salvage

from an aborted attempt to make basic attributes 
(creator, modifier, owner, modtime etc.) plain Properties.  This resulted
in a 30% performance hit.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3362 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-07-21 08:37:05 +00:00
parent e2eec832f1
commit 2e3e8f4ad2
12 changed files with 130 additions and 5 deletions

View File

@@ -142,6 +142,12 @@ public interface AVMNode
*/
public void setProperty(QName name, PropertyValue value);
/**
* Set a collection of properties on this node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(Map<QName, PropertyValue> properties);
/**
* Get a property by name.
* @param name The name of the property to get.

View File

@@ -306,6 +306,18 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
AVMContext.fgInstance.fAVMNodePropertyDAO.save(prop);
}
/**
* Set a collection of properties on this node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(Map<QName, PropertyValue> properties)
{
for (QName name : properties.keySet())
{
setProperty(name, properties.get(name));
}
}
/**
* Get a property by name.
* @param name The name of the property.

View File

@@ -53,4 +53,10 @@ public interface AVMNodePropertyDAO
* @param prop The property.
*/
public void update(AVMNodeProperty prop);
/**
* Delete all properties associated with a node.
* @param node The AVMNode whose properties should be deleted.
*/
public void deleteAll(AVMNode node);
}

View File

@@ -879,6 +879,19 @@ class AVMRepository
store.setProperty(pathParts[1], name, value);
}
/**
* Set a collection of properties at once.
* @param path The path to the node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(String path, Map<QName, PropertyValue> properties)
{
fLookupCount.set(1);
String [] pathParts = SplitPath(path);
AVMStore store = getAVMStoreByName(pathParts[0], true);
store.setProperties(pathParts[1], properties);
}
/**
* Get a property by name for a node.
* @param version The version to look under.

View File

@@ -319,6 +319,13 @@ public interface AVMService
*/
public void setProperty(String path, QName name, PropertyValue value);
/**
* Set a collection of properties on a node.
* @param path The path to the node.
* @param properties The Map of properties to set.
*/
public void setProperties(String path, Map<QName, PropertyValue> properties);
/**
* Get a property of a node by QName.
* @param version The version to look under.

View File

@@ -1053,7 +1053,29 @@ public class AVMServiceImpl implements AVMService
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/**
* Set a collection of properties on a node.
* @param path The path to the node.
* @param properties The Map of properties to set.
*/
public void setProperties(final String path, final Map<QName, PropertyValue> properties)
{
if (path == null || properties == null)
{
throw new AVMBadArgumentException("Illegal null argument.");
}
class TxnCallback implements RetryingTransactionCallback
{
public void perform()
{
fAVMRepository.setProperties(path, properties);
}
}
TxnCallback doit = new TxnCallback();
fTransaction.perform(doit, true);
}
/**
* Get a property of a node by QName.
* @param version The version to look under.

View File

@@ -24,6 +24,7 @@ import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -2038,6 +2039,22 @@ public class AVMServiceTest extends AVMServiceTestBase
Map<QName, PropertyValue> props = fService.getProperties(-1, "main:/a/b/c/foo");
assertEquals(1, props.size());
assertEquals(value.toString(), props.get(name).toString());
props = new HashMap<QName, PropertyValue>();
QName n1 = QName.createQName("silly.uri", "Prop1");
PropertyValue p1 = new PropertyValue(null, new Date(System.currentTimeMillis()));
props.put(n1, p1);
QName n2 = QName.createQName("silly.uri", "Prop2");
PropertyValue p2 = new PropertyValue(null, "A String Property.");
props.put(n2, p2);
QName n3 = QName.createQName("silly.uri", "Prop3");
PropertyValue p3 = new PropertyValue(null, 42);
props.put(n3, p3);
fService.setProperties("main:/a/b/c/bar", props);
fService.createSnapshot("main");
props = fService.getProperties(-1, "main:/a/b/c/bar");
assertEquals(p1.toString(), props.get(n1).toString());
assertEquals(p2.toString(), props.get(n2).toString());
assertEquals(p3.toString(), props.get(n3).toString());
}
catch (Exception e)
{

View File

@@ -276,6 +276,13 @@ public interface AVMStore
*/
public void setProperty(String path, QName name, PropertyValue value);
/**
* Set a collection of properties on a node.
* @param path The path to the node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(String path, Map<QName, PropertyValue> properties);
/**
* Get a property by name.
* @param version The version to look under.

View File

@@ -840,6 +840,18 @@ public class AVMStoreImpl implements AVMStore, Serializable
node.setProperty(name, value);
}
/**
* Set a collection of properties on a node.
* @param path The path to the node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(String path, Map<QName, PropertyValue> properties)
{
Lookup lPath = lookup(-1, path, true);
AVMNode node = lPath.getCurrentNode();
node.setProperties(properties);
}
/**
* Get a property by name.
* @param version The version to lookup.

View File

@@ -238,8 +238,8 @@ public class OrphanReaper implements Runnable
{
AVMContext.fgInstance.fNewInAVMStoreDAO.delete(newInRep);
}
// TODO What to do about such Hibernate wackiness: session.flush();
// TODO More of the same: node = AVMNodeUnwrapper.Unwrap(node);
// Get rid of all properties belonging to this node.
AVMContext.fgInstance.fAVMNodePropertyDAO.deleteAll(node);
// Extra work for directories.
if (node.getType() == AVMNodeType.PLAIN_DIRECTORY ||
node.getType() == AVMNodeType.LAYERED_DIRECTORY)

View File

@@ -29,6 +29,8 @@ public class AVMNodePropertyDAOHibernate extends HibernateDaoSupport
"from AVMNodePropertyImpl anp where anp.node = :node and anp.name = :name");
query.setEntity("node", node);
query.setParameter("name", name);
query.setCacheable(true);
query.setCacheRegion("Property.Lookup");
return (AVMNodeProperty)query.uniqueResult();
}
@@ -44,6 +46,8 @@ public class AVMNodePropertyDAOHibernate extends HibernateDaoSupport
getSession().createQuery(
"from AVMNodePropertyImpl anp where anp.node = :node");
query.setEntity("node", node);
query.setCacheable(true);
query.setCacheRegion("Properties.Lookup");
return (List<AVMNodeProperty>)query.list();
}
@@ -64,4 +68,16 @@ public class AVMNodePropertyDAOHibernate extends HibernateDaoSupport
{
// Do nothing for Hibernate.
}
/**
* Delete all properties associated with a node.
* @param node The AVMNode whose properties should be deleted.
*/
public void deleteAll(AVMNode node)
{
Query delete =
getSession().createQuery("delete from AVMNodePropertyImpl anp where anp.node = :node");
delete.setEntity("node", node);
delete.executeUpdate();
}
}