- add TenantService hooks to (Db)NodeService

- add deleteStore to NodeService (not yet exposed via public API)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6391 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2007-08-01 16:30:28 +00:00
parent 0c6e62605d
commit f75175cbd3
6 changed files with 239 additions and 21 deletions

View File

@@ -158,6 +158,9 @@
<property name="avmNodeService"> <property name="avmNodeService">
<ref bean="avmNodeService"/> <ref bean="avmNodeService"/>
</property> </property>
<property name="tenantService">
<ref bean="tenantService"/>
</property>
</bean> </bean>
<bean id="sessionSizeResourceInterceptor" class="org.alfresco.repo.transaction.TransactionResourceInterceptor" > <bean id="sessionSizeResourceInterceptor" class="org.alfresco.repo.transaction.TransactionResourceInterceptor" >
<property name="methodResourceManagers"> <property name="methodResourceManagers">

View File

@@ -450,4 +450,46 @@
]]> ]]>
</query> </query>
<query name="node.GetNodeStatusesForStore">
select
status
from
org.alfresco.repo.domain.hibernate.NodeStatusImpl as status
where
status.key.protocol = :protocol and
status.key.identifier = :identifier
</query>
<query name="node.GetChildAssocsForStore">
select
assoc
from
org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc
where
assoc.parent.id in (select
node.id
from
org.alfresco.repo.domain.hibernate.NodeImpl node
where
node.store.key.protocol = :protocol and
node.store.key.identifier = :identifier)
</query>
<query name="node.GetNodesExceptRootForStore">
select
node
from
org.alfresco.repo.domain.hibernate.NodeImpl as node
where
node.store.key.protocol = :nodeProtocol and
node.store.key.identifier = :nodeIdentifier and
node.id != (select
rootNode.id
from
org.alfresco.repo.domain.hibernate.StoreImpl store
where
store.key.protocol = :storeProtocol and
store.key.identifier = :storeIdentifier)
</query>
</hibernate-mapping> </hibernate-mapping>

View File

@@ -533,7 +533,10 @@ public abstract class AbstractNodeServiceImpl implements NodeService
try try
{ {
Set<QName> aspectQNames = getAspects(nodeRef); Set<QName> aspectQNames = getAspects(nodeRef);
QName typeQName = getType(nodeRef);
// special case, e.g. when onAuditAspect runs as System
QName typeQName = getTypeInternal(nodeRef);
qnames = new HashSet<QName>(aspectQNames.size() + 1); qnames = new HashSet<QName>(aspectQNames.size() + 1);
qnames.addAll(aspectQNames); qnames.addAll(aspectQNames);
qnames.add(typeQName); qnames.add(typeQName);
@@ -546,6 +549,12 @@ public abstract class AbstractNodeServiceImpl implements NodeService
return qnames; return qnames;
} }
// default implementation, should be overridden to support MT
protected QName getTypeInternal(NodeRef nodeRef)
{
return getType(nodeRef);
}
/** /**
* Generates a GUID for the node using either the creation properties or just by * Generates a GUID for the node using either the creation properties or just by
* generating a value randomly. * generating a value randomly.

View File

@@ -48,6 +48,7 @@ import org.alfresco.repo.domain.Store;
import org.alfresco.repo.node.AbstractNodeServiceImpl; import org.alfresco.repo.node.AbstractNodeServiceImpl;
import org.alfresco.repo.node.StoreArchiveMap; import org.alfresco.repo.node.StoreArchiveMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition; import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition;
@@ -93,6 +94,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
private NodeDaoService nodeDaoService; private NodeDaoService nodeDaoService;
private StoreArchiveMap storeArchiveMap; private StoreArchiveMap storeArchiveMap;
private NodeService avmNodeService; private NodeService avmNodeService;
private TenantService tenantService;
public DbNodeServiceImpl() public DbNodeServiceImpl()
{ {
@@ -114,6 +116,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
this.avmNodeService = avmNodeService; this.avmNodeService = avmNodeService;
} }
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/** /**
* Performs a null-safe get of the node * Performs a null-safe get of the node
* *
@@ -125,7 +132,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
ParameterCheck.mandatory("nodeRef", nodeRef); ParameterCheck.mandatory("nodeRef", nodeRef);
Node unchecked = nodeDaoService.getNode(nodeRef); Node unchecked = nodeDaoService.getNode(tenantService.getName(nodeRef));
if (unchecked == null) if (unchecked == null)
{ {
throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef); throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef);
@@ -143,7 +150,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
ParameterCheck.mandatory("nodeRef", nodeRef); ParameterCheck.mandatory("nodeRef", nodeRef);
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, false); NodeStatus nodeStatus = nodeDaoService.getNodeStatus(tenantService.getName(nodeRef), false);
if (nodeStatus == null || nodeStatus.getNode() == null) if (nodeStatus == null || nodeStatus.getNode() == null)
{ {
throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef); throw new InvalidNodeRefException("Node does not exist: " + nodeRef, nodeRef);
@@ -153,6 +160,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public boolean exists(StoreRef storeRef) public boolean exists(StoreRef storeRef)
{ {
storeRef = tenantService.getName(storeRef);
Store store = nodeDaoService.getStore(storeRef.getProtocol(), storeRef.getIdentifier()); Store store = nodeDaoService.getStore(storeRef.getProtocol(), storeRef.getIdentifier());
boolean exists = (store != null); boolean exists = (store != null);
// done // done
@@ -163,6 +171,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
ParameterCheck.mandatory("nodeRef", nodeRef); ParameterCheck.mandatory("nodeRef", nodeRef);
nodeRef = tenantService.getName(nodeRef);
Node node = nodeDaoService.getNode(nodeRef); Node node = nodeDaoService.getNode(nodeRef);
boolean exists = (node != null); boolean exists = (node != null);
// done // done
@@ -173,6 +182,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
ParameterCheck.mandatory("nodeRef", nodeRef); ParameterCheck.mandatory("nodeRef", nodeRef);
nodeRef = tenantService.getName(nodeRef);
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, false); NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, false);
if (nodeStatus == null) // node never existed if (nodeStatus == null) // node never existed
{ {
@@ -195,7 +205,21 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
List<StoreRef> storeRefs = new ArrayList<StoreRef>(stores.size()); List<StoreRef> storeRefs = new ArrayList<StoreRef>(stores.size());
for (Store store : stores) for (Store store : stores)
{ {
storeRefs.add(store.getStoreRef()); StoreRef storeRef = store.getStoreRef();
try
{
if (tenantService.isTenantUser())
{
tenantService.checkDomain(storeRef.getIdentifier());
storeRef = tenantService.getBaseName(storeRef);
}
storeRefs.add(storeRef);
}
catch (RuntimeException re)
{
// deliberately ignore - stores in different domain will not be listed
}
} }
// Now get the AVMStores. // Now get the AVMStores.
List<StoreRef> avmStores = avmNodeService.getStores(); List<StoreRef> avmStores = avmNodeService.getStores();
@@ -210,7 +234,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
*/ */
public StoreRef createStore(String protocol, String identifier) public StoreRef createStore(String protocol, String identifier)
{ {
StoreRef storeRef = new StoreRef(protocol, identifier); StoreRef storeRef = tenantService.getName(new StoreRef(protocol, identifier));
identifier = storeRef.getIdentifier();
// check that the store does not already exist // check that the store does not already exist
Store store = nodeDaoService.getStore(protocol, identifier); Store store = nodeDaoService.getStore(protocol, identifier);
if (store != null) if (store != null)
@@ -238,11 +263,40 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
throw new RuntimeException("Incorrect store reference"); throw new RuntimeException("Incorrect store reference");
} }
storeRef = tenantService.getBaseName(storeRef);
return storeRef; return storeRef;
} }
/**
* @see NodeDaoService#deleteStore(String, String)
*/
public void deleteStore(StoreRef storeRef)
{
storeRef = tenantService.getName(storeRef);
String protocol = storeRef.getProtocol();
String identifier = storeRef.getIdentifier();
// check that the store does exist
Store store = nodeDaoService.getStore(protocol, identifier);
if (store == null)
{
throw new InvalidStoreRefException("Unable to delete a store that does not exist: " + storeRef, storeRef);
}
// TODO invoke policies - e.g. tell indexer to delete index
//invokeBeforeDeleteStore(ContentModel.TYPE_STOREROOT, storeRef);
// (hard) delete store
nodeDaoService.deleteStore(protocol, identifier);
// done
return;
}
public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException
{ {
storeRef = tenantService.getName(storeRef);
Store store = nodeDaoService.getStore(storeRef.getProtocol(), storeRef.getIdentifier()); Store store = nodeDaoService.getStore(storeRef.getProtocol(), storeRef.getIdentifier());
if (store == null) if (store == null)
{ {
@@ -255,6 +309,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
throw new InvalidStoreRefException("Store does not have a root node: " + storeRef, storeRef); throw new InvalidStoreRefException("Store does not have a root node: " + storeRef, storeRef);
} }
NodeRef nodeRef = node.getNodeRef(); NodeRef nodeRef = node.getNodeRef();
nodeRef = tenantService.getBaseName(nodeRef);
// done // done
return nodeRef; return nodeRef;
} }
@@ -286,6 +341,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Assert.notNull(assocQName); Assert.notNull(assocQName);
// Get the parent node // Get the parent node
parentRef = tenantService.getName(parentRef);
Node parentNode = getNodeNotNull(parentRef); Node parentNode = getNodeNotNull(parentRef);
// null property map is allowed // null property map is allowed
@@ -381,10 +437,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Set<QName> nodeAspects = node.getAspects(); Set<QName> nodeAspects = node.getAspects();
for (AspectDefinition defaultAspectDef : defaultAspectDefs) for (AspectDefinition defaultAspectDef : defaultAspectDefs)
{ {
invokeBeforeAddAspect(nodeRef, defaultAspectDef.getName()); QName aspectTypeQName = defaultAspectDef.getName();
nodeAspects.add(defaultAspectDef.getName()); invokeBeforeAddAspect(nodeRef, aspectTypeQName);
nodeAspects.add(aspectTypeQName);
addDefaultPropertyValues(defaultAspectDef, properties); addDefaultPropertyValues(defaultAspectDef, properties);
invokeOnAddAspect(nodeRef, defaultAspectDef.getName()); invokeOnAddAspect(nodeRef, aspectTypeQName);
// Now add any default aspects for this aspect // Now add any default aspects for this aspect
addDefaultAspects(defaultAspectDef, node, properties); addDefaultAspects(defaultAspectDef, node, properties);
@@ -510,6 +567,15 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return node.getTypeQName(); return node.getTypeQName();
} }
@Override
protected QName getTypeInternal(NodeRef nodeRef)
{
Node node = getNodeNotNull(nodeRef);
// special case, e.g. when onAuditAspect runs as System
return tenantService.getName(nodeRef, node.getTypeQName());
}
/** /**
* @see org.alfresco.service.cmr.repository.NodeService#setType(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) * @see org.alfresco.service.cmr.repository.NodeService#setType(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/ */
@@ -547,6 +613,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Map<QName, Serializable> aspectProperties) Map<QName, Serializable> aspectProperties)
throws InvalidNodeRefException, InvalidAspectException throws InvalidNodeRefException, InvalidAspectException
{ {
nodeRef = tenantService.getName(nodeRef);
// check that the aspect is legal // check that the aspect is legal
AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName); AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName);
if (aspectDef == null) if (aspectDef == null)
@@ -571,7 +638,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Set any default property values that appear on the aspect // Set any default property values that appear on the aspect
addDefaultPropertyValues(aspectDef, nodeProperties); addDefaultPropertyValues(aspectDef, nodeProperties);
// Add any dependant aspect // Add any dependent aspect
addDefaultAspects(aspectDef, node, nodeProperties); addDefaultAspects(aspectDef, node, nodeProperties);
// Set the property values back on the node // Set the property values back on the node
@@ -690,6 +757,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public void deleteNode(NodeRef nodeRef) public void deleteNode(NodeRef nodeRef)
{ {
nodeRef = tenantService.getName(nodeRef);
// First get the node to ensure that it exists // First get the node to ensure that it exists
Node node = getNodeNotNull(nodeRef); Node node = getNodeNotNull(nodeRef);
@@ -715,6 +783,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
else else
{ {
StoreRef storeRef = nodeRef.getStoreRef(); StoreRef storeRef = nodeRef.getStoreRef();
// remove tenant domain - to retrieve archive store from map
storeRef = tenantService.getBaseName(storeRef);
archiveStoreRef = storeArchiveMap.getArchiveMap().get(storeRef); archiveStoreRef = storeArchiveMap.getArchiveMap().get(storeRef);
// get the type and check if we need archiving // get the type and check if we need archiving
TypeDefinition typeDef = dictionaryService.getType(node.getTypeQName()); TypeDefinition typeDef = dictionaryService.getType(node.getTypeQName());
@@ -733,6 +805,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
} }
else else
{ {
archiveStoreRef = tenantService.getName(archiveStoreRef);
// archive it // archive it
archiveNode(nodeRef, archiveStoreRef); archiveNode(nodeRef, archiveStoreRef);
// The archive performs a move, which will fire the appropriate OnDeleteNode // The archive performs a move, which will fire the appropriate OnDeleteNode
@@ -884,7 +957,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
*/ */
private void addIntrinsicProperties(Node node, Map<QName, Serializable> properties) private void addIntrinsicProperties(Node node, Map<QName, Serializable> properties)
{ {
NodeRef nodeRef = node.getNodeRef(); NodeRef nodeRef = tenantService.getBaseName(node.getNodeRef());
properties.put(ContentModel.PROP_STORE_PROTOCOL, nodeRef.getStoreRef().getProtocol()); properties.put(ContentModel.PROP_STORE_PROTOCOL, nodeRef.getStoreRef().getProtocol());
properties.put(ContentModel.PROP_STORE_IDENTIFIER, nodeRef.getStoreRef().getIdentifier()); properties.put(ContentModel.PROP_STORE_IDENTIFIER, nodeRef.getStoreRef().getIdentifier());
properties.put(ContentModel.PROP_NODE_UUID, nodeRef.getId()); properties.put(ContentModel.PROP_NODE_UUID, nodeRef.getId());
@@ -898,6 +971,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public Map<QName, Serializable> getProperties(NodeRef nodeRef) throws InvalidNodeRefException public Map<QName, Serializable> getProperties(NodeRef nodeRef) throws InvalidNodeRefException
{ {
nodeRef = tenantService.getName(nodeRef);
Node node = getNodeNotNull(nodeRef); Node node = getNodeNotNull(nodeRef);
return getPropertiesImpl(node); return getPropertiesImpl(node);
} }
@@ -1043,6 +1117,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
Assert.notNull(qname); Assert.notNull(qname);
nodeRef = tenantService.getName(nodeRef);
// get the node // get the node
Node node = getNodeNotNull(nodeRef); Node node = getNodeNotNull(nodeRef);
@@ -1096,6 +1171,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
throw new UnsupportedOperationException("The property " + qname + " may not be removed individually"); throw new UnsupportedOperationException("The property " + qname + " may not be removed individually");
} }
nodeRef = tenantService.getName(nodeRef);
// Get the node // Get the node
Node node = getNodeNotNull(nodeRef); Node node = getNodeNotNull(nodeRef);
@@ -1128,8 +1204,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
for (ChildAssoc assoc : parentAssocs) for (ChildAssoc assoc : parentAssocs)
{ {
// get the parent // get the parent
Node parentNode = assoc.getParent(); results.add(tenantService.getBaseName(assoc.getParent().getNodeRef()));
results.add(parentNode.getNodeRef());
} }
// done // done
return results; return results;
@@ -1158,7 +1233,14 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// no match - ignore // no match - ignore
continue; continue;
} }
results.add(assoc.getChildAssocRef()); ChildAssociationRef childAssocRef = new ChildAssociationRef(
assoc.getChildAssocRef().getTypeQName(),
tenantService.getBaseName(assoc.getChildAssocRef().getParentRef()),
assoc.getChildAssocRef().getQName(),
tenantService.getBaseName(assoc.getChildAssocRef().getChildRef()),
assoc.getChildAssocRef().isPrimary(),
assoc.getChildAssocRef().getNthSibling());
results.add(childAssocRef);
} }
// done // done
return results; return results;
@@ -1231,7 +1313,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
ChildAssoc childAssoc = nodeDaoService.getChildAssoc(node, assocTypeQName, childName); ChildAssoc childAssoc = nodeDaoService.getChildAssoc(node, assocTypeQName, childName);
if (childAssoc != null) if (childAssoc != null)
{ {
return childAssoc.getChild().getNodeRef(); return tenantService.getBaseName(childAssoc.getChild().getNodeRef());
} }
else else
{ {
@@ -1443,9 +1525,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
continue; continue;
} }
// build a path element // build a path element
NodeRef parentRef = assoc.getParent().getNodeRef(); NodeRef parentRef = tenantService.getBaseName(assoc.getParent().getNodeRef());
QName qname = assoc.getQname(); QName qname = assoc.getQname();
NodeRef childRef = assoc.getChild().getNodeRef(); NodeRef childRef = tenantService.getBaseName(assoc.getChild().getNodeRef());
boolean isPrimary = assoc.getIsPrimary(); boolean isPrimary = assoc.getIsPrimary();
// build a real association reference // build a real association reference
ChildAssociationRef assocRef = new ChildAssociationRef(assoc.getTypeQName(), parentRef, qname, childRef, isPrimary, -1); ChildAssociationRef assocRef = new ChildAssociationRef(assoc.getTypeQName(), parentRef, qname, childRef, isPrimary, -1);
@@ -1789,6 +1871,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public NodeRef getStoreArchiveNode(StoreRef storeRef) public NodeRef getStoreArchiveNode(StoreRef storeRef)
{ {
storeRef = tenantService.getBaseName(storeRef);
StoreRef archiveStoreRef = storeArchiveMap.getArchiveMap().get(storeRef); StoreRef archiveStoreRef = storeArchiveMap.getArchiveMap().get(storeRef);
if (archiveStoreRef == null) if (archiveStoreRef == null)
{ {

View File

@@ -76,6 +76,15 @@ public interface NodeDaoService
*/ */
public Store createStore(String protocol, String identifier); public Store createStore(String protocol, String identifier);
/**
* Deletes the unique store for the given protocol and identifier combination
*
* @param protocol a protocol, e.g. {@link org.alfresco.service.cmr.repository.StoreRef#PROTOCOL_WORKSPACE}
* @param identifier a protocol-specific identifier
*/
public void deleteStore(String protocol, String identifier);
/** /**
* @param protocol the protocol that the store serves * @param protocol the protocol that the store serves
* @param identifier the protocol-specific identifer * @param identifier the protocol-specific identifer

View File

@@ -56,6 +56,7 @@ import org.alfresco.repo.domain.hibernate.ServerImpl;
import org.alfresco.repo.domain.hibernate.StoreImpl; import org.alfresco.repo.domain.hibernate.StoreImpl;
import org.alfresco.repo.domain.hibernate.TransactionImpl; import org.alfresco.repo.domain.hibernate.TransactionImpl;
import org.alfresco.repo.node.db.NodeDaoService; import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionAwareSingleton; import org.alfresco.repo.transaction.TransactionAwareSingleton;
import org.alfresco.repo.transaction.TransactionalDao; import org.alfresco.repo.transaction.TransactionalDao;
@@ -105,6 +106,10 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
private static final String QUERY_GET_NODES_WITH_PROPERTY_VALUES_BY_ACTUAL_TYPE = "node.GetNodesWithPropertyValuesByActualType"; private static final String QUERY_GET_NODES_WITH_PROPERTY_VALUES_BY_ACTUAL_TYPE = "node.GetNodesWithPropertyValuesByActualType";
private static final String QUERY_GET_SERVER_BY_IPADDRESS = "server.getServerByIpAddress"; private static final String QUERY_GET_SERVER_BY_IPADDRESS = "server.getServerByIpAddress";
private static final String QUERY_GET_NODE_STATUSES_FOR_STORE = "node.GetNodeStatusesForStore";
private static final String QUERY_GET_CHILD_ASSOCS_FOR_STORE = "node.GetChildAssocsForStore";
private static final String QUERY_GET_NODES_EXCEPT_ROOT_FOR_STORE = "node.GetNodesExceptRootForStore";
private static Log logger = LogFactory.getLog(HibernateNodeDaoServiceImpl.class); private static Log logger = LogFactory.getLog(HibernateNodeDaoServiceImpl.class);
/** Log to trace parent association caching: <b>classname + .ParentAssocsCache</b> */ /** Log to trace parent association caching: <b>classname + .ParentAssocsCache</b> */
private static Log loggerParentAssocsCache = LogFactory.getLog(HibernateNodeDaoServiceImpl.class.getName() + ".ParentAssocsCache"); private static Log loggerParentAssocsCache = LogFactory.getLog(HibernateNodeDaoServiceImpl.class.getName() + ".ParentAssocsCache");
@@ -123,6 +128,14 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
/** used for debugging */ /** used for debugging */
private Set<String> changeTxnIdSet; private Set<String> changeTxnIdSet;
TenantService tenantService;
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
/** /**
* *
*/ */
@@ -348,6 +361,65 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
return store; return store;
} }
/**
* Delete store - this is a hard delete.
*
* @param protocol the store protocol
* @param identifier the store identifier
*/
public void deleteStore(final String protocol, final String identifier)
{
// ensure that the store exists
Store store = getStore(protocol, identifier);
if (store == null)
{
throw new RuntimeException("Store does not exist: \n" +
" protocol: " + protocol + "\n" +
" identifier: " + identifier);
}
Node rootNode = store.getRootNode();
// TODO - convert queries to deletes ?
// delete node status
Query query = getSession().getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_NODE_STATUSES_FOR_STORE);
query.setParameter("protocol", protocol);
query.setParameter("identifier", identifier);
List<NodeImpl> list = (List<NodeImpl>)query.list();
getHibernateTemplate().deleteAll(list);
// delete child assocs
query = getSession().getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOCS_FOR_STORE);
query.setParameter("protocol", protocol);
query.setParameter("identifier", identifier);
list = (List<NodeImpl>)query.list();
getHibernateTemplate().deleteAll(list);
// delete nodes (except root node)
query = getSession().getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_NODES_EXCEPT_ROOT_FOR_STORE);
query.setParameter("nodeProtocol", protocol);
query.setParameter("nodeIdentifier", identifier);
query.setParameter("storeProtocol", protocol);
query.setParameter("storeIdentifier", identifier);
list = (List<NodeImpl>)query.list();
getHibernateTemplate().deleteAll(list);
// delete root node and store
getHibernateTemplate().delete(rootNode);
getHibernateTemplate().delete(store);
// done
return;
}
public Store getStore(String protocol, String identifier) public Store getStore(String protocol, String identifier)
{ {
StoreKey storeKey = new StoreKey(protocol, identifier); StoreKey storeKey = new StoreKey(protocol, identifier);
@@ -796,13 +868,13 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
private Collection<ChildAssociationRef> convertToChildAssocRefs(Node parentNode, List<Object[]> queryResults) private Collection<ChildAssociationRef> convertToChildAssocRefs(Node parentNode, List<Object[]> queryResults)
{ {
Collection<ChildAssociationRef> refs = new ArrayList<ChildAssociationRef>(queryResults.size()); Collection<ChildAssociationRef> refs = new ArrayList<ChildAssociationRef>(queryResults.size());
NodeRef parentNodeRef = parentNode.getNodeRef(); NodeRef parentNodeRef = tenantService.getBaseName(parentNode.getNodeRef());
for (Object[] row : queryResults) for (Object[] row : queryResults)
{ {
String childProtocol = (String) row[5]; String childProtocol = (String) row[5];
String childIdentifier = (String) row[6]; String childIdentifier = (String) row[6];
String childUuid = (String) row[7]; String childUuid = (String) row[7];
NodeRef childNodeRef = new NodeRef(new StoreRef(childProtocol, childIdentifier), childUuid); NodeRef childNodeRef = tenantService.getBaseName(new NodeRef(new StoreRef(childProtocol, childIdentifier), childUuid));
QName assocTypeQName = (QName) row[0]; QName assocTypeQName = (QName) row[0];
QName assocQName = (QName) row[1]; QName assocQName = (QName) row[1];
Boolean assocIsPrimary = (Boolean) row[2]; Boolean assocIsPrimary = (Boolean) row[2];