KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > RolapNative


1 /*
2 // This software is subject to the terms of the Common Public License
3 // Agreement, available at the following URL:
4 // http://www.opensource.org/licenses/cpl.html.
5 // Copyright (C) 2003-2005 Julian Hyde
6 // Copyright (C) 2004-2005 TONBELLER AG
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.rolap;
11
12 import java.util.EventObject JavaDoc;
13
14 import mondrian.olap.Exp;
15 import mondrian.olap.FunDef;
16 import mondrian.olap.NativeEvaluator;
17
18 /**
19  * a factory for {@link mondrian.olap.NativeEvaluator}. If the instance returns null,
20  * then the interpreter must compute the result itself. If it returns a NativeEvaluator
21  * the interpreter may choose to let the NativeEvaluator compute the result.
22  * <p>
23  * There exist multiple RolapNative implementations, e.g. for CrossJoin, TopCount,
24  * Filter etc. If the arguments of these functions are simple enough to be evaluated
25  * in SQL then a NativeEvaluator will be returned that performs the computations
26  * in SQL. Otherwise null will be returned.
27  */

28 public abstract class RolapNative {
29
30     private boolean enabled;
31     
32     class NativeEvent extends EventObject JavaDoc {
33         NativeEvaluator neval;
34         public NativeEvent(Object JavaDoc source, NativeEvaluator neval) {
35             super(source);
36             this.neval = neval;
37         }
38         NativeEvaluator getNativeEvaluator() {
39             return neval;
40         }
41     }
42     
43     class TupleEvent extends EventObject JavaDoc {
44         private TupleReader tupleReader;
45
46         public TupleEvent(Object JavaDoc source, TupleReader tupleReader) {
47             super(source);
48             this.tupleReader = tupleReader;
49         }
50
51         TupleReader getTupleReader() {
52             return tupleReader;
53         }
54         
55     }
56     
57     interface Listener {
58         void foundEvaluator(NativeEvent e);
59         void foundInCache(TupleEvent e);
60         void excutingSql(TupleEvent e);
61     }
62
63     protected Listener listener;
64     
65     /**
66      * If function can be implemented in SQL, returns a NativeEvaluator that
67      * computes the result; otherwise returns null.
68      */

69     abstract NativeEvaluator createEvaluator(RolapEvaluator evaluator, FunDef fun, Exp[] args);
70
71     /**
72      * if enabled == false, then createEvaluator will always return null
73      */

74     boolean isEnabled() {
75         return enabled;
76     }
77
78     void setEnabled(boolean enabled) {
79         this.enabled = enabled;
80     }
81
82     Listener getListener() {
83         return listener;
84     }
85
86     void setListener(Listener listener) {
87         this.listener = listener;
88     }
89
90     /**
91      * use hard caching for testing. When using soft references, we can not test caching
92      * because things may be garbage collected during the tests.
93      */

94     abstract void useHardCache(boolean hard);
95 }
96
97 // End RolapNative.java
98
Popular Tags