Search in sources :

Example 31 with Connection

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();
}
Also used : Connection(mondrian.olap.Connection) Util(mondrian.olap.Util)

Example 32 with Connection

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;
}
Also used : Connection(mondrian.olap.Connection)

Example 33 with Connection

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();
}
Also used : Connection(mondrian.olap.Connection)

Example 34 with Connection

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;
}
Also used : Connection(mondrian.olap.Connection)

Example 35 with Connection

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;
}
Also used : Connection(mondrian.olap.Connection)

Aggregations

Connection (mondrian.olap.Connection)38 RolapConnection (mondrian.rolap.RolapConnection)8 Util (mondrian.olap.Util)5 MondrianException (mondrian.olap.MondrianException)4 Result (mondrian.olap.Result)4 Member (mondrian.olap.Member)3 Query (mondrian.olap.Query)3 MDXConnection (org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection)3 MemberExpr (mondrian.mdx.MemberExpr)2 Cube (mondrian.olap.Cube)2 QueryAxis (mondrian.olap.QueryAxis)2 TestMember (mondrian.olap.fun.TestMember)2 Execution (mondrian.server.Execution)2 FoodMartTestCase (mondrian.test.FoodMartTestCase)2 TestContext (mondrian.test.TestContext)2 OlapConnection (org.olap4j.OlapConnection)2 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)2 MondrianCatalog (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog)2 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1