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