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