Search in sources :

Example 1 with StringProperty

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

the class RolapConnection method getDataSourceResolver.

/**
 * Returns the instance of the {@link mondrian.spi.DataSourceResolver}
 * plugin.
 *
 * @return data source resolver
 */
private static synchronized DataSourceResolver getDataSourceResolver() {
    if (dataSourceResolver == null) {
        final StringProperty property = MondrianProperties.instance().DataSourceResolverClass;
        final String className = property.get(JndiDataSourceResolver.class.getName());
        try {
            dataSourceResolver = ClassResolver.INSTANCE.instantiateSafe(className);
        } catch (ClassCastException e) {
            throw Util.newInternal(e, "Plugin class specified by property " + property.getPath() + " must implement " + DataSourceResolver.class.getName());
        }
    }
    return dataSourceResolver;
}
Also used : StringProperty(org.eigenbase.util.property.StringProperty) JndiDataSourceResolver(mondrian.spi.impl.JndiDataSourceResolver) JndiDataSourceResolver(mondrian.spi.impl.JndiDataSourceResolver)

Example 2 with StringProperty

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

the class BasicQueryTest method testStatistics.

/**
 * Unit test for {@link StatisticsProvider} and implementations
 * {@link JdbcStatisticsProvider} and
 * {@link SqlStatisticsProvider}.
 */
public void testStatistics() {
    final String product = getTestContext().getDialect().getDatabaseProduct().name();
    final String dialectClassName = getTestContext().getDialect().getClass().getName();
    propSaver.set(new StringProperty(MondrianProperties.instance(), MondrianProperties.instance().StatisticsProviders.getPath() + "." + product, null), MyJdbcStatisticsProvider.class.getName() + "," + SqlStatisticsProvider.class.getName());
    final TestContext testContext = getTestContext().withFreshConnection();
    try {
        testContext.assertSimpleQuery();
        // bypass dialect cache and always get a fresh dialect instance
        // with our custom providers
        Dialect dialect = DialectManager.createDialect(testContext.getConnection().getDataSource(), null, dialectClassName);
        final List<StatisticsProvider> statisticsProviders = dialect.getStatisticsProviders();
        assertEquals(2, statisticsProviders.size());
        assertTrue(statisticsProviders.get(0) instanceof MyJdbcStatisticsProvider);
        assertTrue(statisticsProviders.get(1) instanceof SqlStatisticsProvider);
        for (StatisticsProvider statisticsProvider : statisticsProviders) {
            long rowCount = statisticsProvider.getTableCardinality(dialect, testContext.getConnection().getDataSource(), null, null, "customer", new Execution(((RolapSchema) testContext.getConnection().getSchema()).getInternalConnection().getInternalStatement(), 0));
            if (statisticsProvider instanceof SqlStatisticsProvider) {
                assertTrue("Row count estimate: " + rowCount + " (actual 10281)", rowCount > 10000 && rowCount < 15000);
            }
            long valueCount = statisticsProvider.getColumnCardinality(dialect, testContext.getConnection().getDataSource(), null, null, "customer", "gender", new Execution(((RolapSchema) testContext.getConnection().getSchema()).getInternalConnection().getInternalStatement(), 0));
            assertTrue("Value count estimate: " + valueCount + " (actual 2)", statisticsProvider instanceof JdbcStatisticsProvider ? valueCount == -1 : valueCount == 2);
        }
    } finally {
        testContext.close();
    }
}
Also used : SqlStatisticsProvider(mondrian.spi.impl.SqlStatisticsProvider) Execution(mondrian.server.Execution) JdbcStatisticsProvider(mondrian.spi.impl.JdbcStatisticsProvider) StringProperty(org.eigenbase.util.property.StringProperty) SqlStatisticsProvider(mondrian.spi.impl.SqlStatisticsProvider) JdbcStatisticsProvider(mondrian.spi.impl.JdbcStatisticsProvider)

Example 3 with StringProperty

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

the class ObjectFactory method getClassName.

/**
 * Returns the name of a class to use to create an object.
 * The factory's <code>StringProperty</code> is gotten and
 * if it has a non-null value, then that is returned. Otherwise,
 * the <code>StringProperty</code>'s name (path) is used as the
 * name to probe the <code>Properties</code> object for a value.
 * This method is allowed to return null.
 *
 * @return <code>null</code> or a class name
 */
protected String getClassName(final Properties props) {
    final StringProperty stringProp = getStringProperty();
    final String className = stringProp.get();
    return (className != null) ? className : (props == null) ? null : props.getProperty(stringProp.getPath());
}
Also used : StringProperty(org.eigenbase.util.property.StringProperty)

Example 4 with StringProperty

use of org.eigenbase.util.property.StringProperty 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 5 with StringProperty

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

the class RolapUtil method alertNonNative.

/**
 * Raises an alert that native SQL evaluation could not be used
 * in a case where it might have been beneficial, but some
 * limitation in Mondrian's implementation prevented it.
 * (Do not call this in cases where native evaluation would
 * have been wasted effort.)
 *
 * @param functionName name of function for which native evaluation
 * was skipped
 *
 * @param reason reason why native evaluation was skipped
 */
public static void alertNonNative(String functionName, String reason) throws NativeEvaluationUnsupportedException {
    // No i18n for log message, but yes for excn
    String alertMsg = "Unable to use native SQL evaluation for '" + functionName + "'; reason:  " + reason;
    StringProperty alertProperty = MondrianProperties.instance().AlertNativeEvaluationUnsupported;
    String alertValue = alertProperty.get();
    if (alertValue.equalsIgnoreCase(org.apache.log4j.Level.WARN.toString())) {
        LOGGER.warn(alertMsg);
    } else if (alertValue.equalsIgnoreCase(org.apache.log4j.Level.ERROR.toString())) {
        LOGGER.error(alertMsg);
        throw MondrianResource.instance().NativeEvaluationUnsupported.ex(functionName);
    }
}
Also used : StringProperty(org.eigenbase.util.property.StringProperty)

Aggregations

StringProperty (org.eigenbase.util.property.StringProperty)5 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 JdbcStatisticsProvider (mondrian.spi.impl.JdbcStatisticsProvider)1 JndiDataSourceResolver (mondrian.spi.impl.JndiDataSourceResolver)1 SqlStatisticsProvider (mondrian.spi.impl.SqlStatisticsProvider)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 BooleanProperty (org.eigenbase.util.property.BooleanProperty)1