Search in sources :

Example 1 with SimpleLogger

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;
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) SimpleLogger(org.pentaho.platform.util.logging.SimpleLogger) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with SimpleLogger

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);
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) FilterPanelException(org.pentaho.platform.uifoundation.component.xml.FilterPanelException) Document(org.dom4j.Document) SimpleLogger(org.pentaho.platform.util.logging.SimpleLogger) FilterPanelException(org.pentaho.platform.uifoundation.component.xml.FilterPanelException) FilterPanel(org.pentaho.platform.uifoundation.component.xml.FilterPanel) FilterDefinition(org.pentaho.platform.uifoundation.component.FilterDefinition) ILogger(org.pentaho.platform.api.engine.ILogger) List(java.util.List) LinkedList(java.util.LinkedList) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with SimpleLogger

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);
}
Also used : SimpleLogger(org.pentaho.platform.util.logging.SimpleLogger)

Example 4 with SimpleLogger

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();
        }
    }
}
Also used : QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SQLException(java.sql.SQLException) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) SimpleLogger(org.pentaho.platform.util.logging.SimpleLogger) ModelerException(org.pentaho.agilebi.modeler.ModelerException) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) SQLException(java.sql.SQLException) SqlQueriesNotSupportedException(org.pentaho.platform.dataaccess.datasource.wizard.service.SqlQueriesNotSupportedException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)

Aggregations

SimpleLogger (org.pentaho.platform.util.logging.SimpleLogger)4 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 SQLConnection (org.pentaho.platform.plugin.services.connections.sql.SQLConnection)2 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Document (org.dom4j.Document)1 ModelerException (org.pentaho.agilebi.modeler.ModelerException)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)1 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)1 SQLModelGeneratorException (org.pentaho.metadata.util.SQLModelGeneratorException)1 ILogger (org.pentaho.platform.api.engine.ILogger)1 CsvTransformGeneratorException (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)1 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)1 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)1