01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.datatypes.processors;
11:
12: import org.mmbase.bridge.*;
13: import org.mmbase.bridge.util.Queries;
14: import org.mmbase.storage.search.*;
15: import org.mmbase.util.logging.*;
16:
17: /**
18: * Used as 'commitprocessor' on the 'pos' field of a posrel object, this guesses a nice default if
19: * you left the value empty on commit.
20: *
21: * @author Michiel Meeuwissen
22: * @version $Id: PosrelCommitProcessor.java,v 1.2 2008/02/29 14:47:07 michiel Exp $
23: * @since MMBase-1.8.6
24: */
25:
26: public class PosrelCommitProcessor implements CommitProcessor {
27:
28: private static final Logger log = Logging
29: .getLoggerInstance(PosrelCommitProcessor.class);
30:
31: private static final long serialVersionUID = 1L;
32:
33: public void commit(Node node, Field field) {
34: if (log.isDebugEnabled()) {
35: log.debug("Committing" + node);
36: }
37: if (node.getValue(field.getName()) == null
38: || "".equals(node.getStringValue(field.getName()))) {
39: Node source = node.getNodeValue("snumber");
40: NodeQuery q = Queries.createNodeQuery(source);
41: String role = node.getNodeValue("rnumber").getStringValue(
42: "sname");
43: Step relationStep = q.addRelationStep(node.getCloud()
44: .getNodeManager("object"), role, "destination");
45: q.setNodeStep(relationStep);
46: Integer max = (Integer) Queries.max(q, q.getStepField(q
47: .getNodeManager().getField(field.getName())));
48: log.debug("max now " + max);
49: if (max == null)
50: max = 0;
51: node.setValueWithoutProcess(field.getName(), max + 1);
52: }
53: }
54:
55: }
|