001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2010-2011 Pentaho
008// All Rights Reserved.
009*/
010package mondrian.server;
011
012import mondrian.olap.MondrianServer;
013import mondrian.rolap.RolapConnection;
014import mondrian.rolap.RolapSchema;
015
016import org.olap4j.OlapConnection;
017import org.olap4j.impl.Olap4jUtil;
018
019import java.util.*;
020
021/**
022 * Implementation of {@link Repository} for
023 * a server that doesn't have a repository: each connection in the server
024 * has its own catalog (specified in the connect string) and therefore the
025 * catalog and schema metadata will be whatever pertains to that connection.
026 * (That's why the methods have a connection parameter.)
027 *
028 * @author Julian Hyde
029 */
030public class ImplicitRepository implements Repository {
031    public ImplicitRepository() {
032        super();
033    }
034
035    public List<String> getCatalogNames(
036        RolapConnection connection,
037        String databaseName)
038    {
039        // In an implicit repository, we assume that there is a single
040        // database, a single catalog and a single schema.
041        return
042            Collections.singletonList(
043                connection.getSchema().getName());
044    }
045
046    public List<String> getDatabaseNames(RolapConnection connection)
047    {
048        // In an implicit repository, we assume that there is a single
049        // database, a single catalog and a single schema.
050        return
051            Collections.singletonList(
052                connection.getSchema().getName());
053    }
054
055    public Map<String, RolapSchema> getRolapSchemas(
056        RolapConnection connection,
057        String databaseName,
058        String catalogName)
059    {
060        final RolapSchema schema = connection.getSchema();
061        assert schema.getName().equals(catalogName);
062        return Collections.singletonMap(schema.getName(), schema);
063    }
064
065    public OlapConnection getConnection(
066        MondrianServer server,
067        String databaseName,
068        String catalogName,
069        String roleName,
070        Properties props)
071    {
072        // This method does not make sense in an ImplicitRepository. The
073        // catalog and schema are gleaned from the connection, not vice
074        // versa.
075        throw new UnsupportedOperationException();
076    }
077
078    public List<Map<String, Object>> getDatabases(
079        RolapConnection connection)
080    {
081        return Collections.singletonList(
082            Olap4jUtil.<String, Object>mapOf(
083                "DataSourceName", connection.getSchema().getName(),
084                "DataSourceDescription", null,
085                "URL", null,
086                "DataSourceInfo", connection.getSchema().getName(),
087                "ProviderName", "Mondrian",
088                "ProviderType", "MDP",
089                "AuthenticationMode", "Unauthenticated"));
090    }
091
092    public void shutdown() {
093        // ignore.
094    }
095}
096
097// End ImplicitRepository.java