KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > cache > BasicReleaseStrategy


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.cache;
11
12 import java.util.*;
13
14 import org.mmbase.core.event.*;
15 import org.mmbase.module.core.*;
16 import org.mmbase.storage.search.SearchQuery;
17 import org.mmbase.storage.search.Step;
18 import org.mmbase.util.logging.Logger;
19 import org.mmbase.util.logging.Logging;
20
21
22 /**
23  * This class provides a very basic release strategy. In fact it will release
24  * the cache in nearly every instance, except when the event is for a step in
25  * the <code>SearchQuery</code> that has 'nodes' set for it and the changed
26  * node is not one of those. This release strategy is in fact the original one
27  * and will allways be the first in the hierarchy of the
28  * <code>ChainedReleaseStrategy</code>.
29  *
30  * @author Ernst Bunders
31  * @since MMBase-1.8
32  * @version $Id: BasicReleaseStrategy.java,v 1.13 2006/06/27 07:31:45 michiel Exp $
33  */

34 public class BasicReleaseStrategy extends ReleaseStrategy {
35
36     private static final Logger log = Logging.getLoggerInstance(BasicReleaseStrategy.class);
37
38
39     public BasicReleaseStrategy(){
40     }
41
42     public String JavaDoc getName() {
43         return "Basic release strategy";
44     }
45
46
47     /* (non-Javadoc)
48      * @see org.mmbase.cache.QueryResultCacheReleaseStrategy#getDescription()
49      */

50     public String JavaDoc getDescription() {
51         return "This strategy does exactly what the original cache release "+
52             "implementation did. It checks if the step of the query that maches the "+
53             "type of the changed node has 'nodes' set. if it does, and the changed "+
54             "node is not one of them, the query should not be flushed from cache";
55     }
56
57     /* (non-Javadoc)
58      * @see org.mmbase.cache.ReleaseStrategy#doEvaluate(org.mmbase.module.core.NodeEvent, org.mmbase.storage.search.SearchQuery, java.util.List)
59      */

60     protected final boolean doEvaluate(NodeEvent event, SearchQuery query, List cachedResult) {
61         //this simple optimization only works for nodeEvents
62
MMBase mmb = MMBase.getMMBase();
63         String JavaDoc eventTable = event.getBuilderName();
64         MMObjectBuilder eventBuilder = mmb.getBuilder(eventTable);
65         Iterator i = query.getSteps().iterator();
66         while (i.hasNext()) {
67             Step step = (Step) i.next();
68             String JavaDoc table = step.getTableName();
69             if (! (table.equals(eventTable) ||
70                    eventBuilder.isExtensionOf(mmb.getBuilder(table)))) continue;
71             Set nodes = step.getNodes();
72             if (nodes == null || nodes.size() == 0 || nodes.contains(new Integer JavaDoc(event.getNodeNumber()))) {
73                 return true;
74             }
75         }
76         return false;
77     }
78
79     protected boolean doEvaluate(RelationEvent event, SearchQuery query, List cachedResult) {
80         // no strategy for relation events
81
log.debug("basic strategy: flush: relation event");
82         return true;
83     }
84
85 }
86
Popular Tags