Skip to content

Commit

Permalink
MONDRIAN: Making the XmlaServlet.server property class-protected so s…
Browse files Browse the repository at this point in the history
…ubclasses can access it. Also adding a lockbox for java.sql.DataSource

[git-p4: depot-paths = "//open/mondrian-release/3.2/": change = 13962]
  • Loading branch information
lucboudreau committed Dec 7, 2010
1 parent fc002c7 commit aab5192
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 8 deletions.
29 changes: 29 additions & 0 deletions src/main/mondrian/olap/MondrianServer.java
Expand Up @@ -18,6 +18,7 @@
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
* Interface by which to control an instance of Mondrian.
Expand Down Expand Up @@ -124,6 +125,34 @@ public abstract OlapConnection getConnection(
String roleName)
throws SQLException, SecurityException;

/**
* Extended version of
* {@link MondrianServer#getConnection(String, String, String)}
* taking a list of properties to pass down to the native connection.
*
* <p>Gets a Connection given a catalog (and implicitly the catalog's data
* source) and the name of a user role.
*
* <p>If you want to pass in a role object, and you are making the call
* within the same JVM (i.e. not RPC), register the role using
* {@link MondrianServer#getLockBox()} and pass in the moniker
* for the generated lock box entry. The server will retrieve the role from
* the moniker.
*
* @param catalogName Catalog name
* @param schemaName Schema name
* @param roleName User role name
* @param props Properties to pass down to the native driver.
* @return Connection
* @throws SQLException If error occurs
*/
public abstract OlapConnection getConnection(
String catalogName,
String schemaName,
String roleName,
Properties props)
throws SQLException, SecurityException;

/**
* Returns a list of the data sources in this server. One element
* per data source, each element a map whose keys are the XMLA fields
Expand Down
47 changes: 46 additions & 1 deletion src/main/mondrian/olap4j/MondrianOlap4jDriver.java
Expand Up @@ -10,10 +10,13 @@
package mondrian.olap4j;

import mondrian.rolap.RolapConnectionProperties;
import mondrian.util.LockBox;

import java.sql.*;
import java.util.*;

import org.olap4j.impl.Olap4jUtil;

/**
* Olap4j driver for Mondrian.
*
Expand Down Expand Up @@ -63,6 +66,12 @@
public class MondrianOlap4jDriver implements Driver {
protected final Factory factory;

/**
* Lockbox containing the datasources and other objects to pass
* statically through the JVM.
*/
private final static LockBox lockbox = new LockBox();

static {
try {
register();
Expand All @@ -89,7 +98,7 @@ protected Factory createFactory() {
factoryClassName = "mondrian.olap4j.FactoryJdbc3Impl";
}
try {
final Class clazz = Class.forName(factoryClassName);
final Class<?> clazz = Class.forName(factoryClassName);
return (Factory) clazz.newInstance();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
Expand All @@ -100,6 +109,17 @@ protected Factory createFactory() {
}
}

/**
* Provides access to the driver's lockbox. Used to
* pass Java objects to the driver through the JDBC
* API. It is usually used in combinaison with the
* driver JDBC properties.
* @return A lockbox in which to store objects
*/
public static LockBox getLockBox() {
return lockbox;
}

/**
* Registers an instance of MondrianOlap4jDriver.
*
Expand Down Expand Up @@ -145,6 +165,13 @@ public DriverPropertyInfo[] getPropertyInfo(
p.name(),
null));
}
// Next add all LockBox moniker properties.
for (Moniker mon : Moniker.values()) {
list.add(
new DriverPropertyInfo(
mon.name(),
null));
}
return list.toArray(new DriverPropertyInfo[list.size()]);
}

Expand Down Expand Up @@ -175,6 +202,24 @@ public int getMinorVersion() {
public boolean jdbcCompliant() {
return false;
}

/**
* Properties supported by this driver
*/
public enum Moniker {
/**
* Moniker token of a java.sql.DataSource object placed in the
* driver's LockBox. This DataSource will be used internally
* by Mondrian to establish a connection to the backend RDBMS.
*/
SharedDataSource(),
/**
* Moniker token of a mondrian.spi.CatalogLocator object placed in the
* driver's LockBox. This CatalogLocator will be used internally by
* Mondrian to seek the catalog.
*/
SharedCatalogLocator();
}
}

// End MondrianOlap4jDriver.java
4 changes: 3 additions & 1 deletion src/main/mondrian/server/FileRepository.java
Expand Up @@ -52,7 +52,8 @@ public OlapConnection getConnection(
MondrianServer server,
String catalogName,
String schemaName,
String roleName)
String roleName,
Properties props)
throws SQLException
{
final CatalogInfo catalogInfo;
Expand Down Expand Up @@ -96,6 +97,7 @@ public OlapConnection getConnection(
RolapConnectionProperties.Role.name(),
roleName);
}
properties.putAll(props);
final java.sql.Connection connection =
java.sql.DriverManager.getConnection(connectString, properties);
return ((OlapWrapper) connection).unwrap(OlapConnection.class);
Expand Down
3 changes: 2 additions & 1 deletion src/main/mondrian/server/ImplicitRepository.java
Expand Up @@ -52,7 +52,8 @@ public OlapConnection getConnection(
MondrianServer server,
String catalogName,
String schemaName,
String roleName)
String roleName,
Properties props)
{
// This method does not make sense in an ImplicitRepository. The
// catalog and schema are gleaned from the connection, not vice
Expand Down
15 changes: 14 additions & 1 deletion src/main/mondrian/server/MondrianServerImpl.java
Expand Up @@ -151,9 +151,22 @@ public OlapConnection getConnection(
String schemaName,
String roleName)
throws SQLException
{
return this.getConnection(
catalogName, schemaName, roleName,
new Properties());
}

@Override
public OlapConnection getConnection(
String catalogName,
String schemaName,
String roleName,
Properties props)
throws SQLException
{
return repository.getConnection(
this, catalogName, schemaName, roleName);
this, catalogName, schemaName, roleName, props);
}

public List<Map<String, Object>> getDataSources(
Expand Down
4 changes: 3 additions & 1 deletion src/main/mondrian/server/Repository.java
Expand Up @@ -17,6 +17,7 @@
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
* Callback by which a {@link mondrian.olap.MondrianServer} finds its catalogs
Expand Down Expand Up @@ -47,7 +48,8 @@ OlapConnection getConnection(
MondrianServer server,
String catalogName,
String schemaName,
String roleName)
String roleName,
Properties props)
throws SQLException;
}

Expand Down
52 changes: 51 additions & 1 deletion src/main/mondrian/xmla/XmlaHandler.java
Expand Up @@ -2792,9 +2792,40 @@ protected OlapConnection getConnection(
String schema,
final String role)
throws XmlaException
{
return this.getConnection(
catalog, schema, role,
new Properties());
}

/**
* Gets a Connection given a catalog (and implicitly the catalog's data
* source) and the name of a user role.
*
* <p>If you want to pass in a role object, and you are making the call
* within the same JVM (i.e. not RPC), register the role using
* {@link mondrian.olap.MondrianServer#getLockBox()} and pass in the moniker
* for the generated lock box entry. The server will retrieve the role from
* the moniker.
*
* @param catalog Catalog name
* @param schema Schema name
* @param role User role name
* @param props Properties to pass down to the native driver.
* @return Connection
* @throws XmlaException If error occurs
*/
protected OlapConnection getConnection(
String catalog,
String schema,
final String role,
Properties props)
throws XmlaException
{
try {
return connectionFactory.getConnection(catalog, schema, role);
return
connectionFactory.getConnection(
catalog, schema, role, props);
} catch (SecurityException e) {
throw new XmlaException(
CLIENT_FAULT_FC,
Expand Down Expand Up @@ -3113,6 +3144,25 @@ OlapConnection getConnection(
String schema,
String roleName)
throws SQLException;
/**
* Extended version of
* {@link ConnectionFactory#getConnection(String, String, String)}
* which takes a properties list as a supplemental argument.
* The properties must be passed to the underlying driver.
* @param catalog The name of the catalog to use.
* @param schema The name of the schema to use.
* @param roleName The name of the role to use, or NULL.
* @param props Properties to be passed to the underlying
* native driver.
* @return An OlapConnection object.
* @throws SQLException If the you know what hits the fan.
*/
OlapConnection getConnection(
String catalog,
String schema,
String roleName,
Properties props)
throws SQLException;
}

public static void main(String[] args) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/xmla/XmlaServlet.java
Expand Up @@ -54,7 +54,7 @@ public abstract class XmlaServlet

public static final String DEFAULT_DATASOURCE_FILE = "datasources.xml";

private MondrianServer server;
protected MondrianServer server;
protected RepositoryContentFinder contentFinder;

public enum Phase {
Expand Down
9 changes: 8 additions & 1 deletion src/main/mondrian/xmla/XmlaUtil.java
Expand Up @@ -309,12 +309,19 @@ public static MetadataRowset getMetadataRowset(

final XmlaHandler.ConnectionFactory connectionFactory =
new XmlaHandler.ConnectionFactory() {
public OlapConnection getConnection(
public OlapConnection getConnection(
String catalog, String schema, String roleName)
throws SQLException
{
return connection;
}
public OlapConnection getConnection(
String catalog, String schema, String roleName,
Properties props)
throws SQLException
{
return connection;
}
};
final XmlaRequest request = new XmlaRequest() {
public Method getMethod() {
Expand Down

0 comments on commit aab5192

Please sign in to comment.