Search in sources :

Example 1 with RolapConnection

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

the class AggGenTest method testCallingLoadColumnsInAddCollapsedColumnOrAddzSpecialCollapsedColumn.

public void testCallingLoadColumnsInAddCollapsedColumnOrAddzSpecialCollapsedColumn() throws Exception {
    Logger logger = LogManager.getLogger(AggGen.class);
    StringWriter writer = new StringWriter();
    final Appender appender = Util.makeAppender("testMdcContext", writer, null);
    Util.addAppender(appender, logger, org.apache.logging.log4j.Level.DEBUG);
    MondrianProperties props = MondrianProperties.instance();
    // If run in Ant and with mondrian.jar, please comment out this line:
    propSaver.set(props.AggregateRules, "DefaultRules.xml");
    propSaver.set(props.UseAggregates, true);
    propSaver.set(props.ReadAggregates, true);
    propSaver.set(props.GenerateAggregateSql, true);
    final RolapConnection rolapConn = (RolapConnection) getConnection();
    Query query = rolapConn.parseQuery("select {[Measures].[Count]} on columns from [HR]");
    rolapConn.execute(query);
    Util.removeAppender(appender, logger);
    final DataSource dataSource = rolapConn.getDataSource();
    Connection sqlConnection = null;
    try {
        sqlConnection = dataSource.getConnection();
        DatabaseMetaData dbmeta = sqlConnection.getMetaData();
        JdbcSchema jdbcSchema = JdbcSchema.makeDB(dataSource);
        final String catalogName = jdbcSchema.getCatalogName();
        final String schemaName = jdbcSchema.getSchemaName();
        String log = writer.toString();
        Pattern p = Pattern.compile("DEBUG - Init: Column: [^:]+: `(\\w+)`.`(\\w+)`" + Util.nl + "WARN - Can not find column: \\2");
        Matcher m = p.matcher(log);
        while (m.find()) {
            ResultSet rs = dbmeta.getColumns(catalogName, schemaName, m.group(1), m.group(2));
            assertTrue(!rs.next());
        }
    } finally {
        if (sqlConnection != null) {
            try {
                sqlConnection.close();
            } catch (SQLException e) {
            // ignore
            }
        }
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Connection(java.sql.Connection) RolapConnection(mondrian.rolap.RolapConnection) Logger(org.apache.logging.log4j.Logger) DataSource(javax.sql.DataSource) RolapConnection(mondrian.rolap.RolapConnection) StringWriter(java.io.StringWriter)

Example 2 with RolapConnection

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

the class SchemaTest method testMondrian1275.

public void testMondrian1275() throws Exception {
    final TestContext tc = getTestContext().withSchema("<?xml version=\"1.0\"?>\n" + "<Schema name=\"FoodMart\">\n" + "  <Dimension name=\"Store Type\">\n" + "    <Annotations>\n" + "      <Annotation name=\"foo\">bar</Annotation>\n" + "    </Annotations>\n" + "    <Hierarchy hasAll=\"true\" primaryKey=\"store_id\">\n" + "      <Table name=\"store\"/>\n" + "      <Level name=\"Store Type\" column=\"store_type\" uniqueMembers=\"true\"/>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "<Cube name=\"Sales\" defaultMeasure=\"Unit Sales\">\n" + "  <Table name=\"sales_fact_1997\">\n" + "    <AggExclude name=\"agg_c_special_sales_fact_1997\" />\n" + "    <AggExclude name=\"agg_lc_100_sales_fact_1997\" />\n" + "    <AggExclude name=\"agg_lc_10_sales_fact_1997\" />\n" + "    <AggExclude name=\"agg_pc_10_sales_fact_1997\" />\n" + "  </Table>\n" + "  <DimensionUsage name=\"Store Type\" source=\"Store Type\" foreignKey=\"store_id\"/>\n" + "  <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n" + "      formatString=\"Standard\"/>\n" + "</Cube>\n" + "</Schema>\n");
    final RolapConnection rolapConn = tc.getOlap4jConnection().unwrap(RolapConnection.class);
    final SchemaReader schemaReader = rolapConn.getSchemaReader();
    final RolapSchema schema = schemaReader.getSchema();
    for (RolapCube cube : schema.getCubeList()) {
        Dimension dim = cube.getDimensions()[1];
        final Map<String, Annotation> annotations = dim.getAnnotationMap();
        Assert.assertEquals(1, annotations.size());
        Assert.assertEquals("bar", annotations.get("foo").getValue());
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) RolapSchema(mondrian.rolap.RolapSchema) RolapCube(mondrian.rolap.RolapCube)

Example 3 with RolapConnection

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

the class Execution method fireExecutionEndEvent.

private void fireExecutionEndEvent() {
    final RolapConnection connection = statement.getMondrianConnection();
    final MondrianServer server = connection.getServer();
    server.getMonitor().sendEvent(new ExecutionEndEvent(this.startTimeMillis, server.getId(), connection.getId(), this.statement.getId(), this.id, this.phase, this.state, this.cellCacheHitCount, this.cellCacheMissCount, this.cellCachePendingCount, expCacheHitCount, expCacheMissCount));
}
Also used : RolapConnection(mondrian.rolap.RolapConnection)

Example 4 with RolapConnection

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

the class OlapServiceImplTest method flushSingleSchemaCache.

@Test
public void flushSingleSchemaCache() throws Exception {
    OlapConnection connection = mock(OlapConnection.class);
    doReturn(connection).when(olapService).getConnection("schemaX", session);
    RolapConnection rc = mock(RolapConnection.class);
    doReturn(rc).when(connection).unwrap(RolapConnection.class);
    doReturn(cacheControl).when(rc).getCacheControl(any(PrintWriter.class));
    RolapSchema schema = mock(RolapSchema.class);
    doReturn(schema).when(rc).getSchema();
    olapService.flush(session, "schemaX");
    verify(cacheControl, times(1)).flushSchema(schema);
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) RolapSchema(mondrian.rolap.RolapSchema) OlapConnection(org.olap4j.OlapConnection) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with RolapConnection

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

the class OlapServiceImplTest method testFlushProceedsOnException.

@Test
public void testFlushProceedsOnException() throws Exception {
    stubHostedServer();
    final Properties properties = new Properties();
    properties.put(RolapConnectionProperties.Locale.name(), getLocale().toString());
    OlapConnection conn = mock(OlapConnection.class);
    when(server.getConnection("Pentaho", "myHostedServer", null, properties)).thenReturn(conn);
    when(conn.isWrapperFor(any(Class.class))).thenReturn(true);
    final RolapConnection rolapConn = mock(RolapConnection.class);
    when(conn.unwrap(any(Class.class))).thenReturn(rolapConn);
    when(rolapConn.getCacheControl(any(PrintWriter.class))).thenThrow(new RuntimeException("something happend"));
    try {
        olapService.flushAll(session);
    } catch (IOlapServiceException e) {
        fail("Exception shouldn't have made it this far.");
    }
}
Also used : RolapConnection(mondrian.rolap.RolapConnection) OlapConnection(org.olap4j.OlapConnection) IOlapServiceException(org.pentaho.platform.plugin.action.olap.IOlapServiceException) RolapConnectionProperties(mondrian.rolap.RolapConnectionProperties) Properties(java.util.Properties) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

RolapConnection (mondrian.rolap.RolapConnection)20 Locus (mondrian.server.Locus)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 DataSource (javax.sql.DataSource)3 OlapConnection (org.olap4j.OlapConnection)3 PrintWriter (java.io.PrintWriter)2 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 Test (org.junit.Test)2 IOlapServiceException (org.pentaho.platform.plugin.action.olap.IOlapServiceException)2 StringWriter (java.io.StringWriter)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1