use of org.olap4j.OlapWrapper in project pentaho-kettle by pentaho.
the class OlapHelper method openQuery.
public void openQuery() throws Exception {
Class.forName(olap4jDriver);
OlapConnection connection = null;
if (Utils.isEmpty(username) && Utils.isEmpty(password)) {
connection = (OlapConnection) DriverManager.getConnection(olap4jUrl);
} else {
connection = (OlapConnection) DriverManager.getConnection(olap4jUrl, username, password);
}
OlapWrapper wrapper = connection;
olapConnection = wrapper.unwrap(OlapConnection.class);
try {
if (!Utils.isEmpty(catalogName)) {
olapConnection.setCatalog(catalogName);
}
} catch (SQLException e) {
throw new OlapException("Error setting catalog for MDX statement: '" + catalogName + "'");
}
OlapStatement stmt = olapConnection.createStatement();
if (!Utils.isEmpty(mdx)) {
CellSet tmp = stmt.executeOlapQuery(mdx);
result = tmp;
} else {
throw new Exception("Error executing empty MDX query");
}
}
use of org.olap4j.OlapWrapper in project mondrian by pentaho.
the class FileRepository method getConnection.
OlapConnection getConnection(CatalogInfo catalogInfo, MondrianServer server, String roleName, Properties props) throws SQLException {
String connectString = catalogInfo.olap4jConnectString;
// Save the server for the duration of the call to 'getConnection'.
final LockBox.Entry entry = MondrianServerRegistry.INSTANCE.lockBox.register(server);
final Properties properties = new Properties();
properties.setProperty(RolapConnectionProperties.Instance.name(), entry.getMoniker());
if (roleName != null) {
properties.setProperty(RolapConnectionProperties.Role.name(), roleName);
}
properties.putAll(props);
// the ClassLoader.
try {
ClassResolver.INSTANCE.forName(MondrianOlap4jDriver.class.getName(), true);
} catch (ClassNotFoundException e) {
throw new OlapException("Cannot find mondrian olap4j driver.");
}
final java.sql.Connection connection = java.sql.DriverManager.getConnection(connectString, properties);
return ((OlapWrapper) connection).unwrap(OlapConnection.class);
}
use of org.olap4j.OlapWrapper in project teiid by teiid.
the class OlapExecutionFactory method unwrap.
private OlapConnection unwrap(Connection conn) throws TranslatorException {
try {
OlapWrapper wrapper = conn.unwrap(OlapWrapper.class);
OlapConnection olapConn = wrapper.unwrap(OlapConnection.class);
return olapConn;
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
use of org.olap4j.OlapWrapper in project teiid by teiid.
the class TestOlapTranslator method testCannedProcedure.
@Test
public void testCannedProcedure() throws Exception {
String ddl = "create foreign procedure proc(arg integer, arg1 date) returns table (x string) options (\"teiid_rel:native-query\" '$2 $1 something')";
String query = "exec proc(2, {d'1970-01-01'})";
TransformationMetadata tm = RealMetadataFactory.fromDDL(ddl, "x", "phy");
CommandBuilder commandBuilder = new CommandBuilder(tm);
Command obj = commandBuilder.getCommand(query);
OlapExecutionFactory oef = new OlapExecutionFactory();
Connection mock = Mockito.mock(java.sql.Connection.class);
OlapWrapper mock2 = Mockito.mock(OlapWrapper.class);
OlapConnection mock3 = Mockito.mock(OlapConnection.class);
OlapStatement mock4 = Mockito.mock(OlapStatement.class);
Mockito.stub(mock4.executeOlapQuery(Mockito.anyString())).toThrow(new TeiidRuntimeException());
Mockito.stub(mock3.createStatement()).toReturn(mock4);
Mockito.stub(mock2.unwrap(OlapConnection.class)).toReturn(mock3);
Mockito.stub(mock.unwrap(OlapWrapper.class)).toReturn(mock2);
ProcedureExecution pe = oef.createProcedureExecution((Call) obj, Mockito.mock(ExecutionContext.class), new RuntimeMetadataImpl(tm), mock);
try {
pe.execute();
fail();
} catch (TeiidRuntimeException e) {
Mockito.verify(mock4).executeOlapQuery("'1970-01-01' 2 something");
}
}
Aggregations