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;
}
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;
}
}
}
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();
}
}
}
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);
}
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);
}
}
Aggregations