use of org.pentaho.platform.util.logging.SimpleLogger in project pentaho-platform by pentaho.
the class SqlMetadataQueryExec method getConnection.
protected SQLConnection getConnection(DatabaseMeta databaseMeta) {
// use the connection specified in the query
SQLConnection localConnection = null;
try {
IPentahoSession session = PentahoSessionHolder.getSession();
if (databaseMeta.getAccessType() == DatabaseMeta.TYPE_ACCESS_JNDI) {
String jndiName = databaseMeta.getDatabaseName();
if (jndiName != null) {
SimpleLogger simpleLogger = new SimpleLogger(this);
localConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, jndiName, session, simpleLogger);
}
}
if (localConnection == null) {
String driver = databaseMeta.getDriverClass();
String userId = databaseMeta.getUsername();
String password = databaseMeta.getPassword();
String connectionInfo = databaseMeta.getURL();
if (StringUtils.isEmpty(databaseMeta.getDatabaseName())) {
String genericDBMetaDriver = databaseMeta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, "");
if (!StringUtils.isEmpty(genericDBMetaDriver)) {
driver = genericDBMetaDriver;
}
String genericDBMetaURL = databaseMeta.getAttributes().getProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, "");
if (!StringUtils.isEmpty(genericDBMetaURL)) {
connectionInfo = genericDBMetaURL;
}
}
SimpleLogger simpleLogger = new SimpleLogger(this);
localConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, driver, connectionInfo, userId, password, session, simpleLogger);
}
// localConnection = getConnection(localConnection);
return localConnection;
} catch (Exception e) {
// $NON-NLS-1$
logger.error(Messages.getInstance().getErrorString("MetadataQueryComponent.ERROR_0006_EXECUTE_FAILED"), e);
}
return null;
}
use of org.pentaho.platform.util.logging.SimpleLogger in project pentaho-platform by pentaho.
the class FilterDefinitionIT method testFilterCreation.
public void testFilterCreation() {
try {
// $NON-NLS-1$
Class.forName("net.sf.cglib.transform.ClassFilter");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ILogger l = new SimpleLogger(this);
IPentahoSession session = getSession();
setGlobalParams();
this.sessionStartup(session);
Document doc = null;
try {
// $NON-NLS-1$
doc = XmlDom4JHelper.getDocFromFile(new File(SOLUTION_PATH + "/test/filterPanel/test.filterpanel.xml"), null);
} catch (Exception ee) {
ee.printStackTrace();
// $NON-NLS-1$
assertTrue("Failed to get the document from a file.", false);
}
FilterPanel fp = null;
try {
fp = new FilterPanel(session, doc, l);
} catch (FilterPanelException e) {
e.printStackTrace();
// $NON-NLS-1$
assertTrue("Failed to create stream from document.", false);
}
Map parameterProviders = getParameterProviders();
boolean success = false;
List filters = fp.getFilters();
FilterDefinition fd = null;
fd = (FilterDefinition) filters.get(0);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter session-attribute failed", success);
fd = (FilterDefinition) filters.get(1);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter global-attribute failed", success);
fd = (FilterDefinition) filters.get(2);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter static-lov failed", success);
fd = (FilterDefinition) filters.get(3);
// $NON-NLS-1$
success = fd.populate(parameterProviders, new String[] { "huh" });
// $NON-NLS-1$
assertTrue("Populate on filter action sequence failed", success);
}
use of org.pentaho.platform.util.logging.SimpleLogger in project pentaho-platform by pentaho.
the class LogTest method testSimpleLogger.
public void testSimpleLogger() {
SimpleLogger logger = new SimpleLogger(LogTest.class);
logger.setLoggingLevel(ILogger.WARN);
int logLevel = logger.getLoggingLevel();
String logLevelName = logger.getLogLevelName(logLevel);
int logLevelWithParam = logger.getLogLevel(logLevelName);
Assert.assertEquals(logLevelWithParam, ILogger.WARN);
// $NON-NLS-1$
logger.warn("This is a warning with class as an object" + ILogger.WARN);
// $NON-NLS-1$
logger.warn("This is a warning with class as an object" + +ILogger.WARN, new Throwable());
// $NON-NLS-1$
logger.debug("This is a debug with class as an object" + ILogger.DEBUG);
// $NON-NLS-1$
logger.debug("This is a debug with class as an object" + ILogger.DEBUG, new Throwable());
// $NON-NLS-1$
logger.error("This is a error with class as an object" + ILogger.ERROR);
// $NON-NLS-1$
logger.error("This is a error with class as an object" + ILogger.ERROR, new Throwable());
// $NON-NLS-1$
logger.fatal("This is a fatal with class as an object" + ILogger.FATAL);
// $NON-NLS-1$
logger.fatal("This is a fatal with class as an object" + ILogger.FATAL, new Throwable());
// $NON-NLS-1$
logger.info("This is an info with class as an object" + ILogger.INFO);
// $NON-NLS-1$
logger.info("This is an info with class as an object" + ILogger.INFO, new Throwable());
// $NON-NLS-1$
logger.trace("This is a trace with class as an object" + ILogger.TRACE, new Throwable());
// $NON-NLS-1$
logger.trace("This is a trace with class as a string" + ILogger.TRACE, new Throwable());
// $NON-NLS-1$
logger.trace("This is a trace test");
Assert.assertTrue(true);
}
use of org.pentaho.platform.util.logging.SimpleLogger in project data-access by pentaho.
the class DSWDatasourceServiceImpl method executeQuery.
IPentahoResultSet executeQuery(String connectionName, String query, String previewLimit) throws QueryValidationException, SqlQueriesNotSupportedException {
SQLConnection sqlConnection = null;
try {
checkSqlQueriesSupported(connectionName);
int limit = (previewLimit != null && previewLimit.length() > 0) ? Integer.parseInt(previewLimit) : -1;
sqlConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connectionName, PentahoSessionHolder.getSession(), new SimpleLogger(DatasourceServiceHelper.class.getName()));
sqlConnection.setMaxRows(limit);
sqlConnection.setReadOnly(true);
return sqlConnection.executeQuery(BEFORE_QUERY + query + AFTER_QUERY);
} catch (SqlQueriesNotSupportedException e) {
logger.error(e.getLocalizedMessage());
throw e;
} catch (SQLException e) {
String error = "DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED";
if (e.getSQLState().equals("S0021")) {
// Column already exists
error = "DatasourceServiceImpl.ERROR_0021_DUPLICATE_COLUMN_NAMES";
}
logger.error(Messages.getErrorString(error, e.getLocalizedMessage()));
throw new QueryValidationException(Messages.getString(error, e.getLocalizedMessage()));
} catch (Exception e) {
logger.error(Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), e);
throw new QueryValidationException(e.getLocalizedMessage(), e);
} finally {
if (sqlConnection != null) {
sqlConnection.close();
}
}
}
Aggregations