Update of /var/cvs/src/org/mmbase/bridge/util
In directory james.mmbase.org:/tmp/cvs-serv13128
Modified Files:
Tag: MMBase-1_8
Queries.java
Log Message:
added a utility method I'll use in 'search&related' functionality
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/bridge/util
Index: Queries.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/bridge/util/Queries.java,v
retrieving revision 1.77.2.6
retrieving revision 1.77.2.7
diff -u -b -r1.77.2.6 -r1.77.2.7
--- Queries.java 29 Feb 2008 10:58:42 -0000 1.77.2.6
+++ Queries.java 25 Mar 2008 16:48:00 -0000 1.77.2.7
@@ -27,7 +27,7 @@
* methods are put here.
*
* @author Michiel Meeuwissen
- * @version $Id: Queries.java,v 1.77.2.6 2008/02/29 10:58:42 michiel Exp $
+ * @version $Id: Queries.java,v 1.77.2.7 2008/03/25 16:48:00 michiel Exp $
* @see org.mmbase.bridge.Query
* @since MMBase-1.7
*/
@@ -1292,6 +1292,46 @@
return result;
}
+ /**
+ * Explores a query object, and creates a certain new relation object,
which would make the
+ * given node appear in the query's result.
+ *
+ * You can read this as 'the query object is a related nodes query, and is
used to contain information
+ * about the relation (role, startnodes)'. This currently is also the only
implemented part of
+ * this method.
+
+ * @throw UnsupportedOperationException If it cannot be determined how the
node should be related.
+ *
+ * @since MMBase-1.8.6
+ */
+ public static void addToResult(Query q, Node n) {
+ List steps = q.getSteps();
+
+ if (steps.size() < 3) throw new UnsupportedOperationException();
+
+ // First, try if the node can be related to a startNode.
+ int start = 0;
+ Step startStep = (Step) steps.get(start);
+ Cloud cloud = n.getCloud();
+ SortedSet startNodes = startStep.getNodes();
+ NodeManager nextManager = cloud.getNodeManager(((Step) steps.get(start
+ 2)).getTableName());
+ if (startNodes.size() > 0 && (nextManager.equals(n.getNodeManager())
|| nextManager.getDescendants().contains(nextManager))) {
+ Node startNode = cloud.getNode(((Integer)
startNodes.iterator().next()).intValue());
+ RelationStep rel = (RelationStep) steps.get(start + 1);
+ String role =
cloud.getNode(rel.getRole().intValue()).getStringValue("sname");
+ switch(rel.getDirectionality()) {
+ case RelationStep.DIRECTIONS_SOURCE:
+ cloud.getRelationManager(n.getNodeManager(),
startNode.getNodeManager(), role).createRelation(startNode, n);
+ break;
+ default:
+ cloud.getRelationManager(startNode.getNodeManager(),
n.getNodeManager(), role).createRelation(startNode, n);
+ }
+ return;
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
public static void main(String[] argv) {
System.out.println(ConstraintParser.convertClauseToDBS("(([cpsettings.status]='[A]'
OR [cpsettings.status]='I') AND [users.account] != '') and
(lower([users.account]) LIKE '%t[est%' OR lower([users.email]) LIKE '%te]st%'
OR lower([users.firstname]) LIKE '%t[e]st%' OR lower([users.lastname]) LIKE
'%]test%')"));
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs