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
}
}
}
}
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
}
}
}
}
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;
}
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()));
}
}
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);
}
Aggregations