Skip to content

Commit

Permalink
MONDRIAN: Oops, forgot some files. Data source change listener plugin…
Browse files Browse the repository at this point in the history
…. Using this plugin, mondrian can check if the data source has changed and flush the cache. Currently only flushing of hierarchy cache is provided.

[git-p4: depot-paths = "//open/mondrian/": change = 8483]
  • Loading branch information
Bart Pappyn committed Jan 8, 2007
1 parent 39bc261 commit d2c2e8f
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/main/mondrian/spi/DataSourceChangeListener.java
@@ -0,0 +1,57 @@
/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2005-2005 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.spi;


import mondrian.rolap.RolapHierarchy;


/**
* Definition of a data source change listener.
*
* A change listener can be specified in the connection string. It is used
* to ask what is changed in the datasource (e.g. database).
*
* Everytime mondrian has to decide whether it will use data from cache, it
* will call the change listener. When the change listener tells mondrian
* the datasource has changed for a dimension, cube, ... then mondrian will
* flush the cache and read from database again.
*
* It is specified in the connection string, like this :
*
* <blockquote><code>
* Jdbc=jdbc:odbc:MondrianFoodMart; JdbcUser=ziggy; JdbcPassword=stardust; DataSourceChangeListener=com.acme.MyChangeListener;
* </code></blockquote>
*
* This class should be called in mondrian before any data is read, so
* even before cache is build. This way, the plugin is able to register
* the first timestamp mondrian tries to read the datasource.
*
* @author Bart Pappyn
* @version $Id$
* @since Dec 12, 2006
*/

public interface DataSourceChangeListener {

/**
* Checks if the given hierarchy has changed since the previous
* time this function was called.
*
* The first time, this function will be called when the cache
* is still empty. This is because the plugin is able to register
* the first timestamp the function was accessed.
*
* It is highly recommended to optimize the plugin and minimize
* the time needed to evaluate this function, because this plugin
* is called many times for each mondrian query.
*/
public boolean isHierarchyChanged(RolapHierarchy hierarchy);
}
65 changes: 65 additions & 0 deletions src/main/mondrian/spi/impl/DataSourceChangeListenerImpl.java
@@ -0,0 +1,65 @@
/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2005-2005 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.spi.impl;

import mondrian.spi.DataSourceChangeListener;
import mondrian.olap.MondrianDef;
import mondrian.rolap.RolapHierarchy;


/**
* Default implementation of a data source change listener
* that always returns that the datasource is unchanged.
*
* A change listener can be specified in the connection string. It is used
* to ask what is changed in the datasource (e.g. database).
*
* Everytime mondrian has to decide whether it will use data from cache, it
* will call the change listener. When the change listener tells mondrian
* the datasource has changed for a dimension, cube, ... then mondrian will
* flush the cache and read from database again.
*
* It is specified in the connection string, like this :
*
* <blockquote><code>
* Jdbc=jdbc:odbc:MondrianFoodMart; JdbcUser=ziggy; JdbcPassword=stardust; DataSourceChangeListener=com.acme.MyChangeListener;
* </code></blockquote>
*
* This class should be called in mondrian before any data is read, so
* even before cache is build. This way, the plugin is able to register
* the first timestamp mondrian tries to read the datasource.
*
* @author Bart Pappyn
* @version $Id$
* @since Dec 12, 2006
*/

public class DataSourceChangeListenerImpl implements DataSourceChangeListener {

/** Creates a new instance of DataSourceChangeListenerImpl */
public DataSourceChangeListenerImpl() {
}


public synchronized boolean isHierarchyChanged(RolapHierarchy hierarchy) {
return false;
}

String getTableName(RolapHierarchy hierarchy) {
MondrianDef.Relation relation = hierarchy.getRelation();
if (relation instanceof MondrianDef.Table) {
MondrianDef.Table tableRelation = (MondrianDef.Table)relation;

return tableRelation.name;
} else {
return null;
}
}
}
64 changes: 64 additions & 0 deletions src/main/mondrian/spi/impl/DataSourceChangeListenerImpl2.java
@@ -0,0 +1,64 @@
/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2005-2005 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.spi.impl;

import mondrian.spi.DataSourceChangeListener;
import mondrian.olap.MondrianDef;
import mondrian.rolap.RolapHierarchy;


/**
* Default implementation of a data source change listener
* that always returns that the datasource is changed.
*
* A change listener can be specified in the connection string. It is used
* to ask what is changed in the datasource (e.g. database).
*
* Everytime mondrian has to decide whether it will use data from cache, it
* will call the change listener. When the change listener tells mondrian
* the datasource has changed for a dimension, cube, ... then mondrian will
* flush the cache and read from database again.
*
* It is specified in the connection string, like this :
*
* <blockquote><code>
* Jdbc=jdbc:odbc:MondrianFoodMart; JdbcUser=ziggy; JdbcPassword=stardust; DataSourceChangeListener=com.acme.MyChangeListener;
* </code></blockquote>
*
* This class should be called in mondrian before any data is read, so
* even before cache is build. This way, the plugin is able to register
* the first timestamp mondrian tries to read the datasource.
*
* @author Bart Pappyn
* @version $Id$
* @since Dec 12, 2006
*/

public class DataSourceChangeListenerImpl2 implements DataSourceChangeListener {

/** Creates a new instance of DataSourceChangeListenerImpl2 */
public DataSourceChangeListenerImpl2() {
}


public synchronized boolean isHierarchyChanged(RolapHierarchy hierarchy) {
return true;
}
String getTableName(RolapHierarchy hierarchy) {
MondrianDef.Relation relation = hierarchy.getRelation();
if (relation instanceof MondrianDef.Table) {
MondrianDef.Table tableRelation = (MondrianDef.Table)relation;

return tableRelation.name;
} else {
return null;
}
}
}

0 comments on commit d2c2e8f

Please sign in to comment.