Skip to content

Commit

Permalink
MONDRIAN: [MONDRIAN-507]
Browse files Browse the repository at this point in the history
Adds a CatalogLocator parameter to the FileRepository for proper embedding. 

Also reverts an edit from MROSSI in XmlaHandler. The confusion between the concepts of "catalog" and "schemas" had him make a change to the handler and prevented it from resolving datasources and catalogs correctly by name. I've also renamed the parameter names in the mondrian.server package so that this confusion disapears. We should do this throughout all of the code some day.

[git-p4: depot-paths = "//open/mondrian/": change = 14601]
  • Loading branch information
lucboudreau committed Sep 8, 2011
1 parent 437b2ac commit 380241c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 49 deletions.
66 changes: 39 additions & 27 deletions src/main/mondrian/server/FileRepository.java
Expand Up @@ -13,6 +13,7 @@
import mondrian.olap.DriverManager;
import mondrian.olap4j.MondrianOlap4jDriver;
import mondrian.rolap.*;
import mondrian.spi.CatalogLocator;
import mondrian.tui.XmlaSupport;
import mondrian.xmla.*;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -48,9 +49,14 @@ public class FileRepository implements Repository {
"mondrian.server.DynamicContentFinder$executorService");

private final ScheduledFuture<?> scheduledFuture;
private final CatalogLocator locator;

public FileRepository(RepositoryContentFinder repositoryContentFinder) {
public FileRepository(
RepositoryContentFinder repositoryContentFinder,
CatalogLocator locator)
{
this.repositoryContentFinder = repositoryContentFinder;
this.locator = locator;
assert repositoryContentFinder != null;
scheduledFuture = executorService.scheduleWithFixedDelay(
new Runnable() {
Expand All @@ -70,26 +76,26 @@ public List<Map<String, Object>> getDatabases(
{
final List<Map<String, Object>> propsList =
new ArrayList<Map<String, Object>>();
for (DatasourceInfo dsInfo : getServerInfo().datasourceMap.values()) {
for (DatabaseInfo dsInfo : getServerInfo().datasourceMap.values()) {
propsList.add(dsInfo.properties);
}
return propsList;
}

public OlapConnection getConnection(
MondrianServer server,
String datasourceName,
String databaseName,
String catalogName,
String roleName,
Properties props)
throws SQLException
{
final ServerInfo serverInfo = getServerInfo();
final DatasourceInfo datasourceInfo;
if (datasourceName == null) {
final DatabaseInfo datasourceInfo;
if (databaseName == null) {
if (serverInfo.datasourceMap.size() == 0) {
throw new OlapException(
"No datasources configured on this server");
"No databases configured on this server");
}
datasourceInfo =
serverInfo
Expand All @@ -99,17 +105,17 @@ public OlapConnection getConnection(
.next();
} else {
datasourceInfo =
serverInfo.datasourceMap.get(datasourceName);
serverInfo.datasourceMap.get(databaseName);
}
if (datasourceInfo == null) {
throw Util.newError("unknown catalog '" + datasourceName + "'");
throw Util.newError("Unknown database '" + databaseName + "'");
}

final CatalogInfo catalogInfo;
if (catalogName == null) {
if (datasourceInfo.catalogMap.size() == 0) {
throw new OlapException(
"No catalogs in the datasource named "
"No catalogs in the database named "
+ datasourceInfo.name);
}
catalogInfo =
Expand All @@ -123,7 +129,7 @@ public OlapConnection getConnection(
datasourceInfo.catalogMap.get(catalogName);
}
if (catalogInfo == null) {
throw Util.newError("unknown schema '" + catalogName + "'");
throw Util.newError("Unknown catalog '" + catalogName + "'");
}
String connectString = catalogInfo.olap4jConnectString;
final Properties properties = new Properties();
Expand Down Expand Up @@ -156,7 +162,6 @@ public void shutdown() {

private ServerInfo getServerInfo() {
synchronized (SERVER_INFO_LOCK) {

if (this.serverInfo != null) {
return this.serverInfo;
}
Expand Down Expand Up @@ -185,17 +190,17 @@ private ServerInfo getServerInfo() {
xmlDataSource.providerType,
"AuthenticationMode",
xmlDataSource.authenticationMode);
final DatasourceInfo catalogInfo =
new DatasourceInfo(
final DatabaseInfo databaseInfo =
new DatabaseInfo(
xmlDataSource.name,
dsPropsMap);
serverInfo.datasourceMap.put(
xmlDataSource.name,
catalogInfo);
databaseInfo);
for (DataSourcesConfig.Catalog xmlCatalog
: xmlDataSource.catalogs.catalogs)
{
if (catalogInfo.catalogMap.containsKey(xmlCatalog.name)) {
if (databaseInfo.catalogMap.containsKey(xmlCatalog.name)) {
throw Util.newError(
"more than one DataSource object has name '"
+ xmlCatalog.name + "'");
Expand All @@ -208,22 +213,23 @@ private ServerInfo getServerInfo() {
// string. If not, add it.
final Util.PropertyList connectProperties =
Util.parseConnectString(connectString);
if (connectProperties.get(
RolapConnectionProperties.Catalog.name()) == null)
if (connectProperties
.get(RolapConnectionProperties.Catalog.name()) == null)
{
connectString +=
";"
+ RolapConnectionProperties.Catalog.name()
+ "="
+ xmlCatalog.definition;
}
final CatalogInfo schemaInfo =
final CatalogInfo catalogInfo =
new CatalogInfo(
xmlCatalog.name,
connectString);
catalogInfo.catalogMap.put(
connectString,
locator);
databaseInfo.catalogMap.put(
xmlCatalog.name,
schemaInfo);
catalogInfo);
}
}
this.serverInfo = serverInfo;
Expand Down Expand Up @@ -263,17 +269,17 @@ public Map<String, RolapSchema> getRolapSchemas(
}

private static class ServerInfo {
private Map<String, DatasourceInfo> datasourceMap =
new HashMap<String, DatasourceInfo>();
private Map<String, DatabaseInfo> datasourceMap =
new HashMap<String, DatabaseInfo>();
}

private static class DatasourceInfo {
private static class DatabaseInfo {
private final String name;
private final Map<String, Object> properties;
private Map<String, CatalogInfo> catalogMap =
new HashMap<String, CatalogInfo>();

DatasourceInfo(String name, Map<String, Object> properties) {
DatabaseInfo(String name, Map<String, Object> properties) {
this.name = name;
this.properties = properties;
}
Expand All @@ -283,9 +289,15 @@ private static class CatalogInfo {
private final String connectString;
private RolapSchema rolapSchema; // populated on demand
private final String olap4jConnectString;
private final CatalogLocator locator;

CatalogInfo(String name, String connectString) {
CatalogInfo(
String name,
String connectString,
CatalogLocator locator)
{
this.connectString = connectString;
this.locator = locator;
this.olap4jConnectString =
connectString.startsWith("jdbc:")
? connectString
Expand All @@ -299,7 +311,7 @@ private RolapSchema getRolapSchema() {
rolapConnection =
(RolapConnection)
DriverManager.getConnection(
connectString, null);
connectString, this.locator);
rolapSchema = rolapConnection.getSchema();
} finally {
if (rolapConnection != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/server/ImplicitRepository.java
Expand Up @@ -64,8 +64,8 @@ public Map<String, RolapSchema> getRolapSchemas(

public OlapConnection getConnection(
MondrianServer server,
String databaseName,
String catalogName,
String schemaName,
String roleName,
Properties props)
{
Expand Down
8 changes: 4 additions & 4 deletions src/main/mondrian/server/MondrianServerImpl.java
Expand Up @@ -148,26 +148,26 @@ public LockBox getLockBox() {

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

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

public List<String> getCatalogNames(
Expand Down
8 changes: 4 additions & 4 deletions src/main/mondrian/server/MondrianServerRegistry.java
Expand Up @@ -166,6 +166,9 @@ public MondrianServer createWithRepository(
RepositoryContentFinder contentFinder,
CatalogLocator catalogLocator)
{
if (catalogLocator == null) {
catalogLocator = new IdentityCatalogLocator();
}
final Repository repository;
if (contentFinder == null) {
// NOTE: registry.staticServer is initialized by calling this
Expand All @@ -175,10 +178,7 @@ public MondrianServer createWithRepository(
}
repository = new ImplicitRepository();
} else {
repository = new FileRepository(contentFinder);
}
if (catalogLocator == null) {
catalogLocator = new IdentityCatalogLocator();
repository = new FileRepository(contentFinder, catalogLocator);
}
return new MondrianServerImpl(this, repository, catalogLocator);
}
Expand Down
19 changes: 15 additions & 4 deletions src/main/mondrian/server/Repository.java
Expand Up @@ -19,9 +19,9 @@
import java.util.Map;
import java.util.Properties;

/**
* Callback by which a {@link mondrian.olap.MondrianServer} finds its catalogs
* and schemas.
/**
* Callback by which a {@link mondrian.olap.MondrianServer} finds its
* databases, catalogs and schemas.
*
* <p>An important implementation is {@link ImplicitRepository}. This
* encapsulates the behavior of embedded mondrian: there is no repository,
Expand Down Expand Up @@ -86,10 +86,21 @@ Map<String, RolapSchema> getRolapSchemas(
List<Map<String, Object>> getDatabases(
RolapConnection connection);

/**
* Returns an OlapConnection object.
* @param server The MondrianServer to use.
* @param databaseName The database name. Can be null.
* @param catalogName The catalog name. Can be null.
* @param roleName The role name. Can be null.
* @param props Additional connection properties.
* @return An opened olap connection.
* @throws SQLException If an error is encountered while
* creating the connection.
*/
OlapConnection getConnection(
MondrianServer server,
String databaseName,
String catalogName,
String schemaName,
String roleName,
Properties props)
throws SQLException;
Expand Down
25 changes: 16 additions & 9 deletions src/main/mondrian/xmla/XmlaHandler.java
Expand Up @@ -141,15 +141,22 @@ public OlapConnection getConnection(
props.put(JDBC_PASSWORD, request.getPassword());
}

// [MROSSI] getConnection does not take a dataSourceInfo. I think
// it was a bug.
//
// String dataSourceInfo =
// properties.get(PropertyDefinition.DataSourceInfo.name());
//
final String catalog =
request.getProperties().get(PropertyDefinition.Catalog.name());
return getConnection(catalog, null, request.getRoleName(), props);
final String databaseName =
request
.getProperties()
.get(PropertyDefinition.DataSourceInfo.name());

final String catalogName =
request
.getProperties()
.get(PropertyDefinition.Catalog.name());

return
getConnection(
databaseName,
catalogName,
request.getRoleName(),
props);
}

private enum SetType {
Expand Down

0 comments on commit 380241c

Please sign in to comment.