Search in sources :

Example 11 with RolapConnection

use of mondrian.rolap.RolapConnection in project mondrian by pentaho.

the class AggSchemaScanTest method testAggScanPropertiesEmptySchema.

public void testAggScanPropertiesEmptySchema() throws Exception {
    final RolapConnection rolapConn = (RolapConnection) getConnection();
    final DataSource dataSource = rolapConn.getDataSource();
    Connection sqlConnection = null;
    try {
        sqlConnection = dataSource.getConnection();
        Util.PropertyList propertyList = new Util.PropertyList();
        propertyList.put(RolapConnectionProperties.AggregateScanCatalog.name(), "bogus");
        propertyList.put(RolapConnectionProperties.AggregateScanSchema.name(), "bogus");
        JdbcSchema jdbcSchema = JdbcSchema.makeDB(dataSource);
        jdbcSchema.resetAllTablesLoaded();
        jdbcSchema.getTablesMap().clear();
        jdbcSchema.loadTables(propertyList);
        Assert.assertEquals(0, jdbcSchema.getTablesMap().size());
    } finally {
        if (sqlConnection != null) {
            try {
                sqlConnection.close();
            } catch (SQLException e) {
            // ignore
            }
        }
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) SQLException(java.sql.SQLException) Connection(java.sql.Connection) RolapConnection(mondrian.rolap.RolapConnection) Util(mondrian.olap.Util) DataSource(javax.sql.DataSource)

Example 12 with RolapConnection

use of mondrian.rolap.RolapConnection in project mondrian by pentaho.

the class AggSchemaScanTest method testAggScanPropertiesPopulatedSchema.

public void testAggScanPropertiesPopulatedSchema() throws Exception {
    final RolapConnection rolapConn = (RolapConnection) getConnection();
    final DataSource dataSource = rolapConn.getDataSource();
    Connection sqlConnection = null;
    try {
        sqlConnection = dataSource.getConnection();
        DatabaseMetaData dbmeta = sqlConnection.getMetaData();
        if (!dbmeta.supportsSchemasInTableDefinitions() && !dbmeta.supportsCatalogsInTableDefinitions()) {
            System.out.println("Database does not support schema or catalog in table definitions.  Cannot run test.");
            return;
        }
        Util.PropertyList propertyList = new Util.PropertyList();
        boolean foundSchema = false;
        // Different databases treat catalogs and schemas differently.  Figure out whether foodmart is a schema or catalog in this database
        try {
            String schema = sqlConnection.getSchema();
            String catalog = sqlConnection.getCatalog();
            if (schema != null || catalog != null) {
                foundSchema = true;
                propertyList.put(RolapConnectionProperties.AggregateScanCatalog.name(), catalog);
                propertyList.put(RolapConnectionProperties.AggregateScanSchema.name(), schema);
            }
        } catch (AbstractMethodError | Exception ex) {
        // Catch if the JDBC client throws an exception.  Do nothing.
        }
        // Some databases like Oracle do not implement getSchema and getCatalog with the connection, so try the dbmeta instead
        if (!foundSchema && dbmeta.supportsSchemasInTableDefinitions()) {
            try (ResultSet resultSet = dbmeta.getSchemas()) {
                if (resultSet.getMetaData().getColumnCount() == 2) {
                    while (resultSet.next()) {
                        if (resultSet.getString(1).equalsIgnoreCase("foodmart")) {
                            propertyList.put(RolapConnectionProperties.AggregateScanSchema.name(), resultSet.getString(1));
                            propertyList.put(RolapConnectionProperties.AggregateScanCatalog.name(), resultSet.getString(2));
                            foundSchema = true;
                            break;
                        }
                    }
                }
            }
        }
        if (dbmeta.supportsCatalogsInTableDefinitions() && !foundSchema) {
            try (ResultSet resultSet = dbmeta.getCatalogs()) {
                if (resultSet.getMetaData().getColumnCount() == 1) {
                    while (resultSet.next()) {
                        if (resultSet.getString(1).equalsIgnoreCase("foodmart")) {
                            propertyList.put(RolapConnectionProperties.AggregateScanCatalog.name(), resultSet.getString(1));
                            foundSchema = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!foundSchema) {
            System.out.println("Cannot find foodmart schema or catalog in database.  Cannot run test.");
            return;
        }
        JdbcSchema jdbcSchema = JdbcSchema.makeDB(dataSource);
        // Have to clear the table list because creating the connection loads this
        jdbcSchema.resetAllTablesLoaded();
        jdbcSchema.getTablesMap().clear();
        jdbcSchema.loadTables(propertyList);
        // The foodmart schema has 37 tables.
        Assert.assertEquals(37, jdbcSchema.getTablesMap().size());
    } finally {
        if (sqlConnection != null) {
            try {
                sqlConnection.close();
            } catch (SQLException e) {
            // ignore
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) RolapConnection(mondrian.rolap.RolapConnection) Util(mondrian.olap.Util) DatabaseMetaData(java.sql.DatabaseMetaData) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource) RolapConnection(mondrian.rolap.RolapConnection) ResultSet(java.sql.ResultSet)

Example 13 with RolapConnection

use of mondrian.rolap.RolapConnection in project mondrian by pentaho.

the class DriverManager method getConnection.

/**
 * Creates a connection to a Mondrian OLAP Engine
 * using a list of connection properties,
 * a catalog locator,
 * and a JDBC data source.
 *
 * @param properties Collection of properties which define the location
 *   of the connection.
 *   See {@link mondrian.rolap.RolapConnection} for a list of allowed properties.
 * @param locator Use to locate real catalog url by a customized
 *   configuration value. If <code>null</code>, leave the catalog url
 *   unchanged.
 * @param dataSource - if not null an external DataSource to be used
 *        by Mondrian
 * @return A {@link Connection}, never null
 */
public static Connection getConnection(Util.PropertyList properties, CatalogLocator locator, DataSource dataSource) {
    String provider = properties.get("PROVIDER", "mondrian");
    if (!provider.equalsIgnoreCase("mondrian")) {
        throw Util.newError("Provider not recognized: " + provider);
    }
    final String instance = properties.get(RolapConnectionProperties.Instance.name());
    MondrianServer server = MondrianServer.forId(instance);
    if (server == null) {
        throw Util.newError("Unknown server instance: " + instance);
    }
    if (locator == null) {
        locator = server.getCatalogLocator();
    }
    if (locator != null) {
        String catalog = properties.get(RolapConnectionProperties.Catalog.name());
        properties.put(RolapConnectionProperties.Catalog.name(), locator.locate(catalog));
    }
    final RolapConnection connection = new RolapConnection(server, properties, dataSource);
    return connection;
}
Also used : RolapConnection(mondrian.rolap.RolapConnection)

Example 14 with RolapConnection

use of mondrian.rolap.RolapConnection in project mondrian by pentaho.

the class XmlaExtraTest method testGetDataSourceDoesntLeakPassword.

/**
 * This test makes sure that the value of
 * {@link RolapConnectionProperties#JdbcPassword} isn't leaked through
 * the XmlaExtra interface.
 */
public void testGetDataSourceDoesntLeakPassword() throws Exception {
    final List<Map<String, Object>> expectedList = new ArrayList<Map<String, Object>>();
    final Map<String, Object> expectedMap = new HashMap<String, Object>();
    expectedMap.put("DataSourceInfo", "Provider=Mondrian;Jdbc=foo;JdbcPassword=bar;JdbcUser=bacon");
    expectedList.add(expectedMap);
    final MondrianServer server = mock(MondrianServer.class);
    final RolapConnection rConn = mock(RolapConnection.class);
    final MondrianOlap4jConnection conn = mock(MondrianOlap4jConnection.class);
    final MondrianOlap4jExtra extra = mock(MondrianOlap4jExtra.class);
    doReturn(expectedList).when(server).getDatabases(rConn);
    doReturn(server).when(rConn).getServer();
    doReturn(rConn).when(conn).getMondrianConnection();
    doCallRealMethod().when(extra).getDataSources(conn);
    for (Map<String, Object> ds : extra.getDataSources(conn)) {
        final PropertyList props = Util.parseConnectString(String.valueOf(ds.get("DataSourceInfo")));
        assertNull(props.get(RolapConnectionProperties.Jdbc.name()));
        assertNull(props.get(RolapConnectionProperties.JdbcUser.name()));
        assertNull(props.get(RolapConnectionProperties.JdbcPassword.name()));
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) MondrianServer(mondrian.olap.MondrianServer) PropertyList(mondrian.olap.Util.PropertyList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with RolapConnection

use of mondrian.rolap.RolapConnection in project mondrian by pentaho.

the class NativizeSetFunDefTest method assertQueryIsReWritten.

private void assertQueryIsReWritten(TestContext testContext, final String query, final String expectedQuery) {
    final RolapConnection connection = (RolapConnection) testContext.getConnection();
    String actualOutput = Locus.execute(connection, NativizeSetFunDefTest.class.getName(), new Locus.Action<String>() {

        public String execute() {
            return connection.parseQuery(query).toString();
        }
    });
    if (!Util.nl.equals("\n")) {
        actualOutput = actualOutput.replace(Util.nl, "\n");
    }
    assertEquals(expectedQuery, actualOutput);
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) Locus(mondrian.server.Locus)

Aggregations

RolapConnection (mondrian.rolap.RolapConnection)19 Locus (mondrian.server.Locus)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 DataSource (javax.sql.DataSource)3 ArrayList (java.util.ArrayList)2 MondrianException (mondrian.olap.MondrianException)2 Util (mondrian.olap.Util)2 RolapCube (mondrian.rolap.RolapCube)2 RolapSchema (mondrian.rolap.RolapSchema)2 Logger (org.apache.logging.log4j.Logger)2 Appender (org.apache.logging.log4j.core.Appender)2 OlapConnection (org.olap4j.OlapConnection)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1