Search in sources :

Example 1 with IPentahoLoggingConnection

use of org.pentaho.platform.engine.core.system.IPentahoLoggingConnection in project pentaho-platform by pentaho.

the class PentahoConnectionFactory method getConnection.

/**
 * @param datasourceType
 * @param properties
 *          can be null
 * @param session
 *          can be null
 * @param logger
 * @return
 */
public static IPentahoConnection getConnection(final String datasourceType, Properties properties, final IPentahoSession session, final ILogger logger) {
    /*
     * TODO - This is where the "connection factory" action occurs. Based on if the datasourceType, location,
     * username, or password have changed then we create a new one.
     */
    String key = CONNECTION_PREFIX + datasourceType;
    IPentahoConnection connection = null;
    try {
        connection = PentahoSystem.getObjectFactory().get(IPentahoConnection.class, key, session);
        if (connection instanceof IPentahoLoggingConnection) {
            ((IPentahoLoggingConnection) connection).setLogger(logger);
        }
        connection.setProperties(properties);
    } catch (ObjectFactoryException e) {
        Logger.error(PentahoSystem.class.getName(), Messages.getInstance().getErrorString("PentahoConnectionFactory.ERROR_0001_COULD_NOT_CREATE_CONNECTION", key), // $NON-NLS-1$
        e);
    }
    return connection;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IPentahoLoggingConnection(org.pentaho.platform.engine.core.system.IPentahoLoggingConnection)

Aggregations

IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)1 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)1 IPentahoLoggingConnection (org.pentaho.platform.engine.core.system.IPentahoLoggingConnection)1