Skip to content

Commit

Permalink
MONDRIAN: added "DynamicSchemaProcessor" so that a schema can be modi…
Browse files Browse the repository at this point in the history
…fied at runtime.

[git-p4: depot-paths = "//open/mondrian/": change = 2805]
  • Loading branch information
hhaas committed Oct 28, 2004
1 parent 18e9aca commit ef67f97
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
27 changes: 27 additions & 0 deletions src/main/mondrian/rolap/DynamicSchemaProcessor.java
@@ -0,0 +1,27 @@
/*
//$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) 2004-2004 TONBELLER AG
//All Rights Reserved.
//You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap;

import java.net.URL;

/**
* A dynamic schema processor is used to dynamically change
* a Mondrian schema at runtime.
*/
public interface DynamicSchemaProcessor{

/**
* modify a Mondrian schema
* @param schemaUrl - the catalog URL
* @return the modified schema
*/
public String processSchema(URL schemaUrl) throws Exception ;

} // DynamicSchemaProcessor
9 changes: 8 additions & 1 deletion src/main/mondrian/rolap/RolapConnectionProperties.java
Expand Up @@ -23,7 +23,7 @@ public class RolapConnectionProperties extends EnumeratedValues {
private RolapConnectionProperties() {
super(new String[] {
Provider, Jdbc, JdbcDrivers, JdbcUser, JdbcPassword, Catalog,
CatalogContent, CatalogName, DataSource, PoolNeeded, Role});
CatalogContent, CatalogName, DataSource, PoolNeeded, Role, DynamicSchemaProcessor});
}
/**
* @{value} must equal <code>"Mondrian"</code>.
Expand Down Expand Up @@ -98,6 +98,13 @@ private RolapConnectionProperties() {
* after removing this prefix. This allows you to specify connection properties without a URL.
*/
public static final String JdbcPropertyPrefix = "jdbc.";
/**
* The name of a class implementing mondrian.rolap.DynamicSchemaProcessor.
* A dynamic schema prozessor is called at runtime in order to modify the
* schema content.
*/
public static final String DynamicSchemaProcessor = "DynamicSchemaProcessor";

}

// End RolapConnectionProperties.java
28 changes: 21 additions & 7 deletions src/main/mondrian/rolap/RolapSchema.java
Expand Up @@ -90,8 +90,22 @@ private RolapSchema(String catalogName, Util.PropertyList connectInfo) {
String schema = connectInfo.get(RolapConnectionProperties.CatalogContent);
final DOMWrapper def;
if (schema == null) {
String dynProcName = connectInfo.get(RolapConnectionProperties.DynamicSchemaProcessor);
java.net.URL url = new java.net.URL(catalogName);
if ( dynProcName != null && dynProcName.length() >0 ) {
try {
Class clazz = Class.forName(dynProcName);
Constructor ctor = clazz.getConstructor(new Class[0]);
DynamicSchemaProcessor dynProc =
(DynamicSchemaProcessor) ctor.newInstance(new Object[0]);
schema = dynProc.processSchema(url);
} catch (Exception e) {
throw Util.newError(e, "loading DynamicSchemaProcessor " + dynProcName);
}
def = xmlParser.parse(schema);
} else {
def = xmlParser.parse(url);
}
} else {
def = xmlParser.parse(schema);
}
Expand Down Expand Up @@ -296,18 +310,18 @@ static Pool instance() {
synchronized RolapSchema get(
String catalogName, String jdbcConnectString,
String jdbcUser, String dataSource, Util.PropertyList connectInfo) {
// if a schema will be dynamically processed, caching is not possible
// a "http" URL schema is assumed to be dynamic and will not be cached either
String dynProc = connectInfo.get(RolapConnectionProperties.DynamicSchemaProcessor);
if ( (dynProc != null && dynProc.length() == 0) || catalogName.toLowerCase().startsWith("http") ) {
// no caching
return new RolapSchema(catalogName, connectInfo);
}
final String key = makeKey(catalogName, jdbcConnectString, jdbcUser, dataSource);
RolapSchema schema = (RolapSchema) mapUrlToSchema.get(key);
if (schema == null) {
schema = new RolapSchema(catalogName, connectInfo);
// do not chache the schema, if it dynamic
// .i.e created from an http URL.
if (!catalogName.toLowerCase().startsWith("http"))
mapUrlToSchema.put(key, schema);
// Must create RolapConnection after we add to map, otherwise
// we will loop.
// no, this is redundant - its set in the ctor of RolapSchema
// schema.internalConnection = new RolapConnection(connectInfo, schema);
}
return schema;
}
Expand Down

0 comments on commit ef67f97

Please sign in to comment.