More NodeService.getChildAssocsByPropertyValue (incl. PostgreSQL fix)

- Boolean *must* be passed as a parameter (PostgreSQL only accepts 'TRUE' or 'FALSE')
 - Moved code next to ChildAssoc-related code
 - Tested on MySQL and PostgreSQL


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21893 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-08-20 09:51:52 +00:00
parent 1fb2270a24
commit a0e426f85c
3 changed files with 81 additions and 83 deletions

View File

@@ -787,6 +787,20 @@
a.child_node_id IS NULL a.child_node_id IS NULL
</select> </select>
<select id="select_ChildAssocsByPropertyValue" parameterClass="ChildProperty" resultMap="result_ChildAssoc">
<include refid="alfresco.node.select_ChildAssoc_Results"/>
<include refid="alfresco.node.select_ChildAssoc_FromSimple"/>
join alf_node_properties prop on (childNode.id = prop.node_id)
where
parentNode.id = #parentNodeId#
and prop.qname_id = #propertyQNameId#
<isEqual property="value.persistedType" compareValue="6">and prop.string_value = #value.stringValue#</isEqual>
<isEqual property="value.persistedType" compareValue="5">and prop.double_value = #value.doubleValue#</isEqual>
<isEqual property="value.persistedType" compareValue="3">and prop.long_value = #value.longValue#</isEqual>
<isEqual property="value.persistedType" compareValue="1">and prop.boolean_value = #value.booleanValue#</isEqual>
<include refid="alfresco.node.select_ChildAssoc_OrderBy"/>
</select>
<select id="select_NodePrimaryChildAcls" parameterClass="ChildAssoc" resultMap="result_NodeAcl"> <select id="select_NodePrimaryChildAcls" parameterClass="ChildAssoc" resultMap="result_NodeAcl">
select select
node.id as id, node.id as id,
@@ -922,22 +936,4 @@
alf_transaction alf_transaction
</select> </select>
<select id="select_ChildAssocsByPropertyValue" parameterClass="ChildProperty" resultMap="result_ChildAssoc">
<include refid="alfresco.node.select_ChildAssoc_Results"/>
<include refid="alfresco.node.select_ChildAssoc_FromSimple"/>
join alf_node_properties prop on (childNode.id = prop.node_id)
where
parentNode.id = #parentNodeId#
and prop.qname_id = #propertyQNameId#
<isEqual property="value.persistedType" compareValue="6"> and prop.string_value = #value.stringValue#</isEqual>
<isEqual property="value.persistedType" compareValue="5"> and prop.double_value = #value.doubleValue#</isEqual>
<isEqual property="value.persistedType" compareValue="3"> and prop.long_value = #value.longValue#</isEqual>
<isEqual property="value.persistedType" compareValue="1" >
<isEqual property="value.booleanValue" compareValue="true" >and prop.boolean_value = 1</isEqual>
<isEqual property="value.booleanValue" compareValue="false" >and prop.boolean_value = 0</isEqual>
</isEqual>
<include refid="alfresco.node.select_ChildAssoc_OrderBy"/>
</select>
</sqlMap> </sqlMap>

View File

@@ -1783,6 +1783,72 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return results; return results;
} }
/**
* Specific properties <b>not</b> supported by {@link #getChildAssocsByPropertyValue(NodeRef, QName, Serializable)}
*/
private static List<QName> getChildAssocsByPropertyValueBannedProps = new ArrayList<QName>();
static
{
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_NODE_DBID);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_NODE_UUID);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_NAME);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_MODIFIED);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_MODIFIER);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_CREATED);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_CREATOR);
}
@Override
public List<ChildAssociationRef> getChildAssocsByPropertyValue(
NodeRef nodeRef,
QName propertyQName,
Serializable value)
{
// Get the node
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
// Check the QName is not one of the "special" system maintained ones.
if (getChildAssocsByPropertyValueBannedProps.contains(propertyQName))
{
throw new IllegalArgumentException(
"getChildAssocsByPropertyValue does not allow search of system maintaied properties: " + propertyQName);
}
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback()
{
public boolean preLoadNodes()
{
return false;
}
public boolean handle(
Pair<Long, ChildAssociationRef> childAssocPair,
Pair<Long, NodeRef> parentNodePair,
Pair<Long, NodeRef> childNodePair)
{
results.add(childAssocPair.getSecond());
return true;
}
public void done()
{
}
};
// Get the assocs pointing to it
nodeDAO.getChildAssocsByPropertyValue(nodeId, propertyQName, value, callback);
// sort the results
List<ChildAssociationRef> orderedList = reorderChildAssocs(results);
// Done
return orderedList;
}
public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
throws InvalidNodeRefException throws InvalidNodeRefException
{ {
@@ -2221,66 +2287,4 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return true; return true;
} }
} }
private static List<QName> getChildAssocsByPropertyValueBannedProps = new ArrayList<QName>();
static
{
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_NODE_DBID);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_NODE_UUID);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_NAME);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_MODIFIED);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_MODIFIER);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_CREATED);
getChildAssocsByPropertyValueBannedProps.add(ContentModel.PROP_CREATOR);
}
@Override
public List<ChildAssociationRef> getChildAssocsByPropertyValue(NodeRef nodeRef,
QName propertyQName,
Serializable value)
{
// Get the node
Pair<Long, NodeRef> nodePair = getNodePairNotNull(nodeRef);
Long nodeId = nodePair.getFirst();
// Check the QName is not one of the "special" system maintained ones.
if(getChildAssocsByPropertyValueBannedProps.contains(propertyQName))
{
throw new IllegalArgumentException("getChildAssocsByPropertyValue does not allow search of system maintaied properties: " + propertyQName);
}
final List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(10);
// We have a callback handler to filter results
ChildAssocRefQueryCallback callback = new ChildAssocRefQueryCallback()
{
public boolean preLoadNodes()
{
return false;
}
public boolean handle(
Pair<Long, ChildAssociationRef> childAssocPair,
Pair<Long, NodeRef> parentNodePair,
Pair<Long, NodeRef> childNodePair)
{
results.add(childAssocPair.getSecond());
return true;
}
public void done()
{
}
};
// Get the assocs pointing to it
nodeDAO.getChildAssocsByPropertyValue(nodeId, propertyQName, value, callback);
// sort the results
List<ChildAssociationRef> orderedList = reorderChildAssocs(results);
// Done
return orderedList;
}
} }

View File

@@ -539,7 +539,5 @@ public class DbNodeServiceImplTest extends BaseNodeServiceTest
{ {
// expect to go here // expect to go here
} }
} }
} }