Search in sources :

Example 1 with DatabaseDialectService

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

the class JcrBackedDatasourceMgmtServiceTest method testDeleteDatasourceWithName.

@Test
public void testDeleteDatasourceWithName() throws Exception {
    final String fileId = "456";
    final String databasesFolderPath = "/etc/pdi/databases";
    final String dotKdb = ".kdb";
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    // stub out get parent folder
    doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
    doReturn(reservedChars).when(repo).getReservedChars();
    // stub out get file to delete
    doReturn(new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).build()).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    datasourceMgmtService.deleteDatasourceByName(EXP_DBMETA_NAME);
    verify(repo).deleteFile(eq(fileId), eq(true), anyString());
}
Also used : DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Test(org.junit.Test)

Example 2 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 3 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 4 with DatabaseDialectService

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

the class JcrBackedDatasourceMgmtServiceTest method testDeleteDatasourceWithId.

private void testDeleteDatasourceWithId(boolean throwException) throws Exception {
    final String dotKdb = ".kdb";
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    // stub out get parent folder
    doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFileById(EXP_FILE_ID);
    doReturn(reservedChars).when(repo).getReservedChars();
    // stub out get file to delete
    doReturn(new RepositoryFile.Builder(EXP_FILE_ID, EXP_DBMETA_NAME + dotKdb).build()).when(repo).getFileById(EXP_FILE_ID);
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    if (throwException) {
        deleteDatasourceWithIdThrowException(repo);
    }
    datasourceMgmtService.deleteDatasourceById(EXP_FILE_ID);
    verify(repo).deleteFile(eq(EXP_FILE_ID), eq(true), nullable(String.class));
}
Also used : DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)

Example 5 with DatabaseDialectService

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

the class JcrBackedDatasourceMgmtServiceTest method testCreateDatasource.

@Test
public void testCreateDatasource() throws Exception {
    final String parentFolderId = "123";
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    // stub out get parent folder
    doReturn(new RepositoryFile.Builder(parentFolderId, "databases").folder(true).build()).when(repo).getFile("/etc/pdi/databases");
    doReturn(reservedChars).when(repo).getReservedChars();
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    IDatabaseConnection databaseConnection = createDatabaseConnection(EXP_DBMETA_NAME);
    datasourceMgmtService.createDatasource(databaseConnection);
    verify(repo).createFile(eq(parentFolderId), argThat(isLikeFile(new RepositoryFile.Builder(EXP_DBMETA_NAME + ".kdb").build())), argThat(hasData(pathPropertyPair("/databaseMeta/HOST_NAME", EXP_DBMETA_HOSTNAME))), nullable(String.class));
}
Also used : DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Test(org.junit.Test)

Aggregations

DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)20 Test (org.junit.Test)10 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)10 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)10 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)10 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)8 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 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 IDatabaseDialect (org.pentaho.database.IDatabaseDialect)4 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)4 DatabaseDialectException (org.pentaho.database.DatabaseDialectException)3 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)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