Search in sources :

Example 6 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class PooledDatasourceHelperTest method testCreateDatasourceNoClassName.

@Test
public void testCreateDatasourceNoClassName() throws Exception {
    DatabaseDialectService dialectService = new DatabaseDialectService(false);
    final DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(dialectService.getDatabaseTypes());
    final DatabaseConnection con = new DatabaseConnection();
    con.setId("Postgres");
    con.setName("Postgres");
    con.setAccessType(DatabaseAccessType.NATIVE);
    con.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName("GENERIC"));
    con.setUsername("pentaho_user");
    con.setPassword("password");
    final HashMap<String, String> attrs = new HashMap<>();
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "");
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
    con.setAttributes(attrs);
    try {
        PooledDatasourceHelper.convert(con, () -> dialectService);
        fail("Expecting the exception to be thrown");
    } catch (DBDatasourceServiceException ex) {
        assertNotNull(ex);
    }
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) HashMap(java.util.HashMap) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 7 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class PooledDatasourceHelperTest method testCreateDatasourceNoDialect.

@Test
public void testCreateDatasourceNoDialect() throws Exception {
    DatabaseDialectService dialectService = new DatabaseDialectService(false);
    final DatabaseConnection con = new DatabaseConnection();
    con.setId("Postgres");
    con.setName("Postgres");
    con.setAccessType(DatabaseAccessType.NATIVE);
    con.setUsername("pentaho_user");
    con.setPassword("password");
    final HashMap<String, String> attrs = new HashMap<>();
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.postgresql.Driver");
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
    con.setAttributes(attrs);
    try {
        PooledDatasourceHelper.convert(con, () -> dialectService);
        fail("Expecting the exception to be thrown");
    } catch (DBDatasourceServiceException ex) {
        assertNotNull(ex);
    }
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) HashMap(java.util.HashMap) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 8 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project data-access by pentaho.

the class DatasourceInMemoryServiceHelper method getConnection.

public static SQLConnection getConnection(String connectionName) throws DatasourceServiceException {
    IDatabaseConnection connection = null;
    try {
        ConnectionServiceImpl service = new ConnectionServiceImpl();
        connection = service.getConnectionByName(connectionName);
        DatabaseDialectService dialectService = new DatabaseDialectService();
        IDatabaseDialect dialect = dialectService.getDialect(connection);
        String driverClass = null;
        if (connection.getDatabaseType().getShortName().equals("GENERIC")) {
            driverClass = connection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS);
        } else {
            driverClass = dialect.getNativeDriver();
        }
        return new SQLConnection(driverClass, dialect.getURLWithExtraOptions(connection), connection.getUsername(), connection.getPassword(), null);
    } catch (ConnectionServiceException e1) {
        return null;
    } catch (DatabaseDialectException e) {
        return null;
    }
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) ConnectionServiceImpl(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialect(org.pentaho.database.IDatabaseDialect) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 9 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project data-access by pentaho.

the class LegacyDatasourceConverter method resolveDatabaseType.

/**
 * Will resolve a database type based on the prefix of the jdbc URL, which we assume originated from one of these
 * classes
 *
 * @param urlPrefix
 * @return
 */
private IDatabaseType resolveDatabaseType(String urlPrefix) {
    DatabaseDialectService databaseDialectService = new DatabaseDialectService(false);
    List<IDatabaseDialect> databaseDialects = databaseDialectService.getDatabaseDialects();
    String nativePre = null;
    for (IDatabaseDialect databaseDialect : databaseDialects) {
        // 
        // NOTE - The GenericDatabaseDialect and the AccessDatabaseDialect
        // both return null for the value of getNativeJdbcPre - so - this
        // requires a null-check.
        // 
        // MB
        // 
        nativePre = databaseDialect.getNativeJdbcPre();
        if ((nativePre != null) && (nativePre.startsWith(urlPrefix))) {
            return databaseDialect.getDatabaseType();
        }
    }
    return null;
}
Also used : DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialect(org.pentaho.database.IDatabaseDialect)

Example 10 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class DatabaseConnectionAdapter method unmarshal.

@Override
public DatabaseConnection unmarshal(DatabaseConnectionDto dbConnDto) throws Exception {
    if (dbConnDto != null) {
        IDatabaseDialectService databaseDialectService = new DatabaseDialectService();
        DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(databaseDialectService.getDatabaseTypes());
        DatabaseConnection dbConn = new DatabaseConnection();
        dbConn.setId(dbConnDto.getId());
        dbConn.setAccessType(dbConnDto.getAccessType());
        dbConn.setAccessTypeValue(dbConnDto.getAccessTypeValue());
        dbConn.setChanged(dbConnDto.getChanged());
        dbConn.setConnectionPoolingProperties(dbConnDto.getConnectionPoolingProperties());
        dbConn.setConnectSql(dbConnDto.getConnectSql());
        dbConn.setDatabaseName(dbConnDto.getDatabaseName());
        dbConn.setDatabasePort(dbConnDto.getDatabasePort());
        if (dbConnDto.getDatabaseType() != null) {
            dbConn.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName(dbConnDto.getDatabaseType()));
        }
        dbConn.setDataTablespace(dbConnDto.getDataTablespace());
        dbConn.setForcingIdentifiersToLowerCase(dbConnDto.isForcingIdentifiersToLowerCase());
        dbConn.setForcingIdentifiersToUpperCase(dbConnDto.isForcingIdentifiersToUpperCase());
        dbConn.setHostname(dbConnDto.getHostname());
        dbConn.setIndexTablespace(dbConnDto.getIndexTablespace());
        dbConn.setInformixServername(dbConnDto.getInformixServername());
        dbConn.setInitialPoolSize(dbConnDto.getInitialPoolSize());
        dbConn.setMaximumPoolSize(dbConnDto.getMaximumPoolSize());
        dbConn.setName(dbConnDto.getName());
        dbConn.setPartitioned(dbConnDto.isPartitioned());
        dbConn.setPartitioningInformation(dbConnDto.getPartitioningInformation());
        dbConn.setPassword(dbConnDto.getPassword());
        dbConn.setQuoteAllFields(dbConnDto.isQuoteAllFields());
        dbConn.setSQLServerInstance(dbConnDto.getSQLServerInstance());
        dbConn.setStreamingResults(dbConnDto.isStreamingResults());
        dbConn.setUsername(dbConnDto.getUsername());
        dbConn.setUsingConnectionPool(dbConnDto.isUsingConnectionPool());
        dbConn.setUsingDoubleDecimalAsSchemaTableSeparator(dbConnDto.isUsingDoubleDecimalAsSchemaTableSeparator());
        return dbConn;
    } else {
        return null;
    }
}
Also used : DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService)

Aggregations

DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)17 Test (org.junit.Test)10 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)10 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)7 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)7 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)6 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)6 HashMap (java.util.HashMap)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 IDatabaseDialect (org.pentaho.database.IDatabaseDialect)4 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)4 DatabaseDialectException (org.pentaho.database.DatabaseDialectException)3 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)3 Driver (java.sql.Driver)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)2