Search in sources :

Example 16 with Connection

use of mondrian.olap.Connection in project pentaho-platform by pentaho.

the class MondrianFlushCacheComponent method executeAction.

public boolean executeAction() {
    MDXLookupRule mdxLookupRule = getLookupRule();
    Connection conn = ((MDXConnection) mdxLookupRule.shareConnection()).getConnection();
    CacheControl cacheControl = conn.getCacheControl(null);
    Cube[] cubes = conn.getSchema().getCubes();
    for (Cube cube : cubes) {
        cacheControl.flush(cacheControl.createMeasuresRegion(cube));
    }
    cacheControl.flushSchema(conn.getSchema());
    return true;
}
Also used : MDXLookupRule(org.pentaho.platform.plugin.action.mdx.MDXLookupRule) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) Cube(mondrian.olap.Cube) Connection(mondrian.olap.Connection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) CacheControl(mondrian.olap.CacheControl)

Example 17 with Connection

use of mondrian.olap.Connection in project pentaho-platform by pentaho.

the class MondrianModelComponent method getInitialQuery.

public static String getInitialQuery(final Properties properties, final String cubeName, IPentahoSession session) throws Throwable {
    // Apply any properties for this catalog specified in datasource.xml
    IMondrianCatalogService mondrianCatalogService = PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder.getSession());
    List<MondrianCatalog> catalogs = mondrianCatalogService.listCatalogs(PentahoSessionHolder.getSession(), true);
    String propCat = properties.getProperty(RolapConnectionProperties.Catalog.name());
    for (MondrianCatalog cat : catalogs) {
        if (cat.getDefinition().equalsIgnoreCase(propCat)) {
            Util.PropertyList connectProperties = Util.parseConnectString(cat.getDataSourceInfo());
            Iterator<Pair<String, String>> iter = connectProperties.iterator();
            while (iter.hasNext()) {
                Pair<String, String> pair = iter.next();
                if (// Only set if not set already
                !properties.containsKey(pair.getKey())) {
                    properties.put(pair.getKey(), pair.getValue());
                }
            }
            break;
        }
    }
    MDXConnection mdxConnection = (MDXConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, properties, session, null);
    // mdxConnection.setProperties( properties );
    Connection connection = mdxConnection.getConnection();
    if (connection == null) {
        Logger.error("MondrianModelComponent", Messages.getInstance().getErrorString("MondrianModel.ERROR_0001_INVALID_CONNECTION", // $NON-NLS-1$ //$NON-NLS-2$
        properties.toString()));
        return null;
    }
    try {
        return MondrianModelComponent.getInitialQuery(connection, cubeName);
    } catch (Throwable t) {
        if (t instanceof MondrianException) {
            // pull the cause out, otherwise it never gets logged
            Throwable cause = ((MondrianException) t).getCause();
            if (cause != null) {
                throw cause;
            } else {
                throw t;
            }
        } else {
            throw t;
        }
    }
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) Connection(mondrian.olap.Connection) RolapConnection(mondrian.rolap.RolapConnection) Util(mondrian.olap.Util) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) MondrianException(mondrian.olap.MondrianException) Pair(mondrian.util.Pair)

Example 18 with Connection

use of mondrian.olap.Connection in project pentaho-platform by pentaho.

the class MondrianCatalogHelper method flushCacheForCatalog.

private void flushCacheForCatalog(String catalogName, IPentahoSession pentahoSession) {
    IOlapService olapService = PentahoSystem.get(IOlapService.class, "IOlapService", pentahoSession);
    Connection unwrap = null;
    try {
        OlapConnection connection = olapService.getConnection(catalogName, pentahoSession);
        unwrap = connection.unwrap(Connection.class);
        unwrap.getCacheControl(null).flushSchema(unwrap.getSchema());
    } catch (Throwable e) {
        MondrianCatalogHelper.logger.warn(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0019_FAILED_TO_FLUSH", catalogName), e);
    } finally {
        if (unwrap != null) {
            unwrap.close();
        }
    }
}
Also used : IOlapService(org.pentaho.platform.plugin.action.olap.IOlapService) OlapConnection(org.olap4j.OlapConnection) OlapConnection(org.olap4j.OlapConnection) Connection(mondrian.olap.Connection)

Example 19 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testReplaceCompoundSlicerPlaceholder.

public void testReplaceCompoundSlicerPlaceholder() {
    final TestContext testContext = TestContext.instance();
    final Connection connection = testContext.getConnection();
    final String queryText = "SELECT {[Measures].[Customer Count]} ON 0 " + "FROM [Sales] " + "WHERE [Time].[1997]";
    final Query query = connection.parseQuery(queryText);
    final QueryAxis querySlicerAxis = query.getSlicerAxis();
    final Member slicerMember = ((MemberExpr) querySlicerAxis.getSet()).getMember();
    final RolapHierarchy slicerHierarchy = ((RolapCube) query.getCube()).getTimeHierarchy(null);
    final Execution execution = new Execution(query.getStatement(), 0L);
    final RolapEvaluatorRoot rolapEvaluatorRoot = new RolapEvaluatorRoot(execution);
    final RolapEvaluator rolapEvaluator = new RolapEvaluator(rolapEvaluatorRoot);
    final Member expectedMember = slicerMember;
    rolapEvaluator.setSlicerContext(expectedMember);
    RolapResult.CompoundSlicerRolapMember placeHolderMember = Mockito.mock(RolapResult.CompoundSlicerRolapMember.class);
    Mockito.doReturn(slicerHierarchy).when(placeHolderMember).getHierarchy();
    // tested call
    Member r = SqlConstraintUtils.replaceCompoundSlicerPlaceholder(placeHolderMember, rolapEvaluator);
    // test
    Assert.assertSame(expectedMember, r);
}
Also used : Query(mondrian.olap.Query) TestContext(mondrian.test.TestContext) Connection(mondrian.olap.Connection) Execution(mondrian.server.Execution) MemberExpr(mondrian.mdx.MemberExpr) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember) QueryAxis(mondrian.olap.QueryAxis)

Example 20 with Connection

use of mondrian.olap.Connection in project mondrian by pentaho.

the class NonEmptyTest method testNonEmptyDescendants.

/**
 * Ensures that NON EMPTY Descendants is optimized.
 * Ensures that Descendants as a side effect collects MemberChildren that
 * may be looked up in the cache.
 */
public void testNonEmptyDescendants() {
    // 'level.getMembers()' which create false negatives in this test.
    if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
        return;
    }
    Connection con = getTestContext().withSchemaPool(false).getConnection();
    SmartMemberReader smr = getSmartMemberReader(con, "Customers");
    MemberCacheHelper smrch = smr.cacheHelper;
    clearAndHardenCache(smrch);
    SmartMemberReader ssmr = getSmartMemberReader(con, "Customers");
    MemberCacheHelper ssmrch = ssmr.cacheHelper;
    clearAndHardenCache(ssmrch);
    TestCase c = new TestCase(con, 45, 21, "select \n" + "{[Measures].[Unit Sales]} ON columns, " + "NON EMPTY {[Customers].[All Customers], Descendants([Customers].[All Customers].[USA].[CA], [Customers].[Name])} on rows " + "from [Sales] " + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
    Result result = c.run();
    // [Customers].[All Customers].[USA].[CA].[Burlingame].[Peggy Justice]
    RolapMember peggy = (RolapMember) result.getAxes()[1].getPositions().get(1).get(0);
    RolapMember burlingame = peggy.getParentMember();
    peggy = ((RolapCubeMember) peggy).getRolapMember();
    burlingame = ((RolapCubeMember) burlingame).getRolapMember();
    // all children of burlingame are not in cache
    MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
    assertNull(ssmrch.mapMemberToChildren.get(burlingame, mcc));
    // but non empty children is
    Evaluator evaluator = getEvaluator(result, new int[] { 0, 0 });
    evaluator.setNonEmpty(true);
    mcc = scf.getMemberChildrenConstraint(evaluator);
    List<RolapMember> list = ssmrch.mapMemberToChildren.get(burlingame, mcc);
    assertNotNull(list);
    assertTrue(list.contains(peggy));
    // now we run the same query again, this time everything must come out
    // of the cache
    RolapNativeRegistry reg = getRegistry(con);
    reg.setListener(new Listener() {

        public void foundEvaluator(NativeEvent e) {
        }

        public void foundInCache(TupleEvent e) {
        }

        public void executingSql(TupleEvent e) {
            fail("expected caching");
        }
    });
    try {
        c.run();
    } finally {
        reg.setListener(null);
    }
}
Also used : Listener(mondrian.rolap.RolapNative.Listener) Connection(mondrian.olap.Connection) Evaluator(mondrian.olap.Evaluator) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) TupleEvent(mondrian.rolap.RolapNative.TupleEvent) NativeEvent(mondrian.rolap.RolapNative.NativeEvent)

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