KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > spi > impl > DataSourceChangeListenerImpl4


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/spi/impl/DataSourceChangeListenerImpl4.java#3 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2007 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.spi.impl;
11
12 import java.util.Random JavaDoc;
13
14 import mondrian.spi.DataSourceChangeListener;
15 import mondrian.olap.MondrianDef;
16 import mondrian.rolap.RolapHierarchy;
17 import mondrian.rolap.agg.Aggregation;
18
19
20 /**
21  * Default implementation of a data source change listener
22  * that always returns that the datasource is changed.
23  *
24  * A change listener can be specified in the connection string. It is used
25  * to ask what is changed in the datasource (e.g. database).
26  *
27  * Everytime mondrian has to decide whether it will use data from cache, it
28  * will call the change listener. When the change listener tells mondrian
29  * the datasource has changed for a dimension, cube, ... then mondrian will
30  * flush the cache and read from database again.
31  *
32  * It is specified in the connection string, like this :
33  *
34  * <blockquote><code>
35  * Jdbc=jdbc:odbc:MondrianFoodMart; JdbcUser=ziggy; JdbcPassword=stardust; DataSourceChangeListener=com.acme.MyChangeListener;
36  * </code></blockquote>
37  *
38  * This class should be called in mondrian before any data is read, so
39  * even before cache is build. This way, the plugin is able to register
40  * the first timestamp mondrian tries to read the datasource.
41  *
42  * @author Bart Pappyn
43  * @version $Id: //open/mondrian/src/main/mondrian/spi/impl/DataSourceChangeListenerImpl4.java#3 $
44  * @since Dec 12, 2006
45  */

46
47 public class DataSourceChangeListenerImpl4 implements DataSourceChangeListener {
48     private int flushInverseFrequencyHierarchy;
49     private int flushInverseFrequencyAggregation;
50     final Random JavaDoc random = new Random JavaDoc(123456);
51     
52     /** Creates a new instance of DataSourceChangeListenerImpl2 */
53     public DataSourceChangeListenerImpl4() {
54         this(0,0);
55     }
56     public DataSourceChangeListenerImpl4(int flushInverseFrequencyHierarchy,
57             int flushInverseFrequencyAggregation) {
58         this.flushInverseFrequencyHierarchy = flushInverseFrequencyHierarchy;
59         this.flushInverseFrequencyAggregation = flushInverseFrequencyAggregation;
60     }
61
62     public synchronized boolean isHierarchyChanged(RolapHierarchy hierarchy) {
63         if (flushInverseFrequencyHierarchy != 0) {
64             if (random.nextInt(flushInverseFrequencyHierarchy) == 0) {
65                 return true;
66             }
67             else {
68                 return false;
69             }
70         } else {
71             return true;
72         }
73     }
74
75     public synchronized boolean isAggregationChanged(Aggregation aggregation) {
76         if (flushInverseFrequencyAggregation != 0) {
77             if (random.nextInt(flushInverseFrequencyAggregation) == 0) {
78                 return true;
79             }
80             else {
81                 return false;
82             }
83         } else {
84             return true;
85         }
86     }
87
88     public String JavaDoc getTableName(RolapHierarchy hierarchy) {
89         MondrianDef.Relation relation = hierarchy.getRelation();
90         if (relation instanceof MondrianDef.Table) {
91             MondrianDef.Table tableRelation = (MondrianDef.Table)relation;
92
93             return tableRelation.name;
94         } else {
95             return null;
96         }
97     }
98 }
99
Popular Tags