use of mondrian.olap.Connection in project mondrian by pentaho.
the class SchemaVersionTest method testSchema3noVersion.
public void testSchema3noVersion() {
TestContext testContext = TestContext.instance().withSchema(SCHEMA_3_HEADER + SCHEMA_3_BODY);
Util.PropertyList connectInfo = testContext.getConnectionProperties();
Connection conn = DriverManager.getConnection(connectInfo, null);
assertNotNull(conn);
conn.close();
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class TestContext method executeQuery.
/**
* Executes a query.
*
* @param queryString Query string
*/
public Result executeQuery(String queryString) {
Connection connection = getConnection();
queryString = upgradeQuery(queryString);
Query query = connection.parseQuery(queryString);
final Result result = connection.execute(query);
// switch to enable this, but it will do for now.
if (MondrianProperties.instance().TestExpDependencies.booleanValue()) {
assertResultValid(result);
}
return result;
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class TestContext method compileExpression.
/**
* Compiles a scalar expression in the context of the default cube.
*
* @param expression The expression to evaluate
* @param scalar Whether the expression is scalar
* @return String form of the program
*/
public String compileExpression(String expression, final boolean scalar) {
String cubeName = getDefaultCubeName();
if (cubeName.indexOf(' ') >= 0) {
cubeName = Util.quoteMdxIdentifier(cubeName);
}
final String queryString;
if (scalar) {
queryString = "with member [Measures].[Foo] as " + Util.singleQuoteString(expression) + " select {[Measures].[Foo]} on columns from " + cubeName;
} else {
queryString = "SELECT {" + expression + "} ON COLUMNS FROM " + cubeName;
}
Connection connection = getConnection();
Query query = connection.parseQuery(queryString);
final Exp exp;
if (scalar) {
exp = query.getFormulas()[0].getExpression();
} else {
exp = query.getAxes()[0].getSet();
}
final Calc calc = query.compileExpression(exp, scalar, null);
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
final CalcWriter calcWriter = new CalcWriter(pw, false);
calc.accept(calcWriter);
pw.flush();
return sw.toString();
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class TestContext method getRawSchema.
/**
* Returns the definition of the schema.
*
* @return XML definition of the FoodMart schema
*/
public String getRawSchema() {
final Connection connection = withSchemaProcessor(SnoopingSchemaProcessor.class).getConnection();
connection.close();
String schema = SnoopingSchemaProcessor.THREAD_RESULT.get();
Util.threadLocalRemove(SnoopingSchemaProcessor.THREAD_RESULT);
return schema;
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class TestContext method getConnection.
/**
* Returns the connection to run queries.
*
* <p>When invoked on the default TestContext instance, returns a connection
* to the FoodMart database.
*/
public synchronized Connection getConnection() {
if (connectionRef != null) {
Connection connection = connectionRef.get();
if (connection != null) {
return connection;
}
}
final Connection connection = DriverManager.getConnection(getConnectionProperties(), null, null);
connectionRef = new SoftReference<Connection>(connection);
return connection;
}
Aggregations