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());
}
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;
}
}
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;
}
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));
}
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));
}
Aggregations