use of mondrian.rolap.agg.SegmentCacheManager.AbortException in project mondrian by pentaho.
the class SegmentLoader method createExecuteSql.
/**
* Creates and executes a SQL statement to retrieve the set of cells
* specified by a GroupingSetsList.
*
* <p>This method may be overridden in tests.
*
* @param cellRequestCount Number of missed cells that led to this request
* @param groupingSetsList Grouping
* @param compoundPredicateList Compound predicate list
* @return An executed SQL statement, or null
*/
SqlStatement createExecuteSql(int cellRequestCount, final GroupingSetsList groupingSetsList, List<StarPredicate> compoundPredicateList) {
RolapStar star = groupingSetsList.getStar();
Pair<String, List<SqlStatement.Type>> pair = AggregationManager.generateSql(groupingSetsList, compoundPredicateList);
final Locus locus = new SqlStatement.StatementLocus(Locus.peek().execution, "Segment.load", "Error while loading segment", SqlStatementEvent.Purpose.CELL_SEGMENT, cellRequestCount);
// When caching is enabled, we must register the SQL statement
// in the index. We don't want to cancel SQL statements that are shared
// across threads unless it is safe.
final Util.Functor1<Void, Statement> callbackWithCaching = new Util.Functor1<Void, Statement>() {
public Void apply(final Statement stmt) {
cacheMgr.execute(new SegmentCacheManager.Command<Void>() {
public Void call() throws Exception {
boolean atLeastOneActive = false;
for (Segment seg : groupingSetsList.getDefaultSegments()) {
final SegmentCacheIndex index = cacheMgr.getIndexRegistry().getIndex(seg.star);
// then.
if (index.contains(seg.getHeader())) {
index.linkSqlStatement(seg.getHeader(), stmt);
atLeastOneActive = true;
}
if (!atLeastOneActive) {
// knows to stop.
throw new AbortException();
}
}
return null;
}
public Locus getLocus() {
return locus;
}
});
return null;
}
};
// When using no cache, we register the SQL statement directly
// with the execution instance for cleanup.
final Util.Functor1<Void, Statement> callbackNoCaching = new Util.Functor1<Void, Statement>() {
public Void apply(final Statement stmt) {
locus.execution.registerStatement(locus, stmt);
return null;
}
};
try {
return RolapUtil.executeQuery(star.getDataSource(), pair.left, pair.right, 0, 0, locus, -1, -1, // cache the segments or not.
MondrianProperties.instance().DisableCaching.get() ? callbackNoCaching : callbackWithCaching);
} catch (Throwable t) {
if (Util.getMatchingCause(t, AbortException.class) != null) {
return null;
} else {
throw new MondrianException("Failed to load segment form SQL", t);
}
}
}
Aggregations