Search in sources :

Example 1 with BooleanProperty

use of org.eigenbase.util.property.BooleanProperty in project mondrian by pentaho.

the class CacheControlImpl method execute.

public void execute(MemberEditCommand cmd) {
    final BooleanProperty prop = MondrianProperties.instance().EnableRolapCubeMemberCache;
    if (prop.get()) {
        throw new IllegalArgumentException("Member cache control operations are not allowed unless " + "property " + prop.getPath() + " is false");
    }
    synchronized (MEMBER_CACHE_LOCK) {
        // Make sure that a Locus is in the Execution stack,
        // since some operations might require DB access.
        Execution execution;
        try {
            execution = Locus.peek().execution;
        } catch (EmptyStackException e) {
            if (connection == null) {
                throw new IllegalArgumentException("Connection required");
            }
            execution = new Execution(connection.getInternalStatement(), 0);
        }
        final Locus locus = new Locus(execution, "CacheControlImpl.execute", "when modifying the member cache.");
        Locus.push(locus);
        try {
            // Execute the command
            final List<CellRegion> cellRegionList = new ArrayList<CellRegion>();
            ((MemberEditCommandPlus) cmd).execute(cellRegionList);
            // Flush the cells touched by the regions
            for (CellRegion memberRegion : cellRegionList) {
                // Iterate over the cubes, create a cross region with
                // its measures, and flush the data cells.
                // It is possible that some regions don't intersect
                // with a cube. We will intercept the exceptions and
                // skip to the next cube if necessary.
                final List<Dimension> dimensions = memberRegion.getDimensionality();
                if (dimensions.size() > 0) {
                    for (Cube cube : dimensions.get(0).getSchema().getCubes()) {
                        try {
                            final List<CellRegionImpl> crossList = new ArrayList<CellRegionImpl>();
                            crossList.add((CellRegionImpl) createMeasuresRegion(cube));
                            crossList.add((CellRegionImpl) memberRegion);
                            final CellRegion crossRegion = new CrossjoinCellRegion(crossList);
                            flush(crossRegion);
                        } catch (UndeclaredThrowableException e) {
                            if (e.getCause() instanceof InvocationTargetException) {
                                final InvocationTargetException ite = (InvocationTargetException) e.getCause();
                                if (ite.getTargetException() instanceof MondrianException) {
                                    final MondrianException me = (MondrianException) ite.getTargetException();
                                    if (me.getMessage().matches("^Mondrian Error:Member " + "'\\[.*\\]' not found$")) {
                                        continue;
                                    }
                                }
                            }
                            throw new MondrianException(e);
                        } catch (MondrianException e) {
                            if (e.getMessage().matches("^Mondrian Error:Member " + "'\\[.*\\]' not found$")) {
                                continue;
                            }
                            throw e;
                        }
                    }
                }
            }
            // Apply it all.
            ((MemberEditCommandPlus) cmd).commit();
        } finally {
            Locus.pop(locus);
        }
    }
}
Also used : BooleanProperty(org.eigenbase.util.property.BooleanProperty) InvocationTargetException(java.lang.reflect.InvocationTargetException) Execution(mondrian.server.Execution) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Locus(mondrian.server.Locus)

Example 2 with BooleanProperty

use of org.eigenbase.util.property.BooleanProperty in project mondrian by pentaho.

the class NonEmptyTest method testNotNativeVirtualCubeCrossJoinUnsupported.

public void testNotNativeVirtualCubeCrossJoinUnsupported() {
    switch(getTestContext().getDialect().getDatabaseProduct()) {
        case INFOBRIGHT:
            // Hits same Infobright bug as NamedSetTest.testNamedSetOnMember.
            return;
    }
    final BooleanProperty enableProperty = MondrianProperties.instance().EnableNativeCrossJoin;
    final StringProperty alertProperty = MondrianProperties.instance().AlertNativeEvaluationUnsupported;
    if (!enableProperty.get()) {
        // are supposed to be raised.
        return;
    }
    String mdx = "select " + "{[Measures].AllMembers} on columns, " + "NonEmptyCrossJoin([Product].[All Products].children, " + "[Store].[All Stores].children) on rows " + "from [Warehouse and Sales]";
    final List<LoggingEvent> events = new ArrayList<LoggingEvent>();
    // set up log4j listener to detect alerts
    Appender alertListener = new AppenderSkeleton() {

        protected void append(LoggingEvent event) {
            events.add(event);
        }

        public void close() {
        }

        public boolean requiresLayout() {
            return false;
        }
    };
    final Logger rolapUtilLogger = Logger.getLogger(RolapUtil.class);
    propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    rolapUtilLogger.addAppender(alertListener);
    String expectedMessage = "Unable to use native SQL evaluation for 'NonEmptyCrossJoin'";
    // verify that exception is thrown if alerting is set to ERROR
    propSaver.set(alertProperty, org.apache.log4j.Level.ERROR.toString());
    try {
        checkNotNative(3, mdx);
        fail("Expected NativeEvaluationUnsupportedException");
    } catch (Exception ex) {
        Throwable t = ex;
        while (t.getCause() != null && t != t.getCause()) {
            t = t.getCause();
        }
        if (!(t instanceof NativeEvaluationUnsupportedException)) {
            fail();
        }
    // Expected
    } finally {
        propSaver.reset();
        propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    }
    // should have gotten one ERROR
    int nEvents = countFilteredEvents(events, org.apache.log4j.Level.ERROR, expectedMessage);
    assertEquals("logged error count check", 1, nEvents);
    events.clear();
    // verify that exactly one warning is posted but execution succeeds
    // if alerting is set to WARN
    propSaver.set(alertProperty, org.apache.log4j.Level.WARN.toString());
    try {
        checkNotNative(3, mdx);
    } finally {
        propSaver.reset();
        propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    }
    // should have gotten one WARN
    nEvents = countFilteredEvents(events, org.apache.log4j.Level.WARN, expectedMessage);
    assertEquals("logged warning count check", 1, nEvents);
    events.clear();
    // verify that no warning is posted if native evaluation is
    // explicitly disabled
    propSaver.set(alertProperty, org.apache.log4j.Level.WARN.toString());
    propSaver.set(enableProperty, false);
    try {
        checkNotNative(3, mdx);
    } finally {
        propSaver.reset();
        propSaver.setAtLeast(rolapUtilLogger, org.apache.log4j.Level.WARN);
    }
    // should have gotten no WARN
    nEvents = countFilteredEvents(events, org.apache.log4j.Level.WARN, expectedMessage);
    assertEquals("logged warning count check", 0, nEvents);
    events.clear();
    // no biggie if we don't get here for some reason; just being
    // half-heartedly clean
    rolapUtilLogger.removeAppender(alertListener);
}
Also used : Appender(org.apache.log4j.Appender) AppenderSkeleton(org.apache.log4j.AppenderSkeleton) BooleanProperty(org.eigenbase.util.property.BooleanProperty) ArrayList(java.util.ArrayList) StringProperty(org.eigenbase.util.property.StringProperty) Logger(org.apache.log4j.Logger) NativeEvaluationUnsupportedException(mondrian.olap.NativeEvaluationUnsupportedException) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) LoggingEvent(org.apache.log4j.spi.LoggingEvent) NativeEvaluationUnsupportedException(mondrian.olap.NativeEvaluationUnsupportedException)

Example 3 with BooleanProperty

use of org.eigenbase.util.property.BooleanProperty in project mondrian by pentaho.

the class XmlaCognosTest method testNonEmptyWithCognosCalcOneLiteral.

public void testNonEmptyWithCognosCalcOneLiteral() throws Exception {
    final BooleanProperty enableNonEmptyOnAllAxes = MondrianProperties.instance().EnableNonEmptyOnAllAxis;
    boolean nonEmptyAllAxesCurrentState = enableNonEmptyOnAllAxes.get();
    final BooleanProperty enableNativeNonEmpty = MondrianProperties.instance().EnableNativeNonEmpty;
    boolean nativeNonemptyCurrentState = enableNativeNonEmpty.get();
    try {
        enableNonEmptyOnAllAxes.set(true);
        enableNativeNonEmpty.set(false);
        executeMDX();
        if (Bug.BugMondrian446Fixed) {
            enableNativeNonEmpty.set(true);
            executeMDX();
        }
    } finally {
        enableNativeNonEmpty.set(nativeNonemptyCurrentState);
        enableNonEmptyOnAllAxes.set(nonEmptyAllAxesCurrentState);
    }
}
Also used : BooleanProperty(org.eigenbase.util.property.BooleanProperty)

Aggregations

BooleanProperty (org.eigenbase.util.property.BooleanProperty)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ArrayList (java.util.ArrayList)1 NativeEvaluationUnsupportedException (mondrian.olap.NativeEvaluationUnsupportedException)1 MemberChildrenConstraint (mondrian.rolap.sql.MemberChildrenConstraint)1 TupleConstraint (mondrian.rolap.sql.TupleConstraint)1 Execution (mondrian.server.Execution)1 Locus (mondrian.server.Locus)1 Appender (org.apache.log4j.Appender)1 AppenderSkeleton (org.apache.log4j.AppenderSkeleton)1 Logger (org.apache.log4j.Logger)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 StringProperty (org.eigenbase.util.property.StringProperty)1