use of org.pentaho.database.model.DatabaseConnection 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;
}
}
use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method createDatabaseConnection.
private IDatabaseConnection createDatabaseConnection(final String dbName) throws Exception {
IDatabaseConnection dbConnection = new DatabaseConnection();
dbConnection.setName(dbName);
dbConnection.setHostname(EXP_DBMETA_HOSTNAME);
dbConnection.setDatabaseType(mockDatabaseType("Hypersonic"));
dbConnection.setAccessType(DatabaseAccessType.NATIVE);
dbConnection.setDatabasePort(EXP_DBMETA_PORT);
return dbConnection;
}
use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class DefaultDatasourceMgmtWebServiceTest method testEverything.
@Test
public void testEverything() throws Exception {
DatabaseConnection databaseConnection = createDatabaseConnection("testDatabase");
String id = datasourceMgmtWebService.createDatasource(dbConnectionAdapter.marshal(databaseConnection));
assertNotNull(id);
DatabaseConnectionDto databaseConnectionDto = datasourceMgmtWebService.getDatasourceByName("testDatabase");
assertNotNull(databaseConnectionDto);
assertEquals(EXP_DBMETA_HOSTNAME, databaseConnectionDto.getHostname());
DatabaseConnectionDto databaseConnectionDto1 = datasourceMgmtWebService.getDatasourceById(id);
assertNotNull(databaseConnectionDto1);
assertEquals(EXP_DBMETA_HOSTNAME, databaseConnectionDto1.getHostname());
DatabaseConnection databaseConnection1 = createDatabaseConnection("testDatabase1");
String id1 = datasourceMgmtWebService.createDatasource(dbConnectionAdapter.marshal(databaseConnection1));
assertNotNull(id1);
DatabaseConnectionDto databaseConnectionDto2 = datasourceMgmtWebService.getDatasourceByName("testDatabase1");
assertNotNull(databaseConnectionDto2);
assertEquals(EXP_DBMETA_HOSTNAME, databaseConnectionDto2.getHostname());
DatabaseConnectionDto databaseConnectionDto3 = datasourceMgmtWebService.getDatasourceById(id1);
assertNotNull(databaseConnectionDto3);
assertEquals(EXP_DBMETA_HOSTNAME, databaseConnectionDto3.getHostname());
List<DatabaseConnectionDto> databaseConnectionDtos = datasourceMgmtWebService.getDatasources();
assertEquals(2, databaseConnectionDtos.size());
List<String> ids = datasourceMgmtWebService.getDatasourceIds();
assertEquals(2, ids.size());
databaseConnection = dbConnectionAdapter.unmarshal(databaseConnectionDto);
updateDatabaseConnection(databaseConnection);
String id2 = datasourceMgmtWebService.updateDatasourceByName("testDatabase", dbConnectionAdapter.marshal(databaseConnection));
assertNotNull(id2);
DatabaseConnectionDto updatedDatabaseConnectionDto = datasourceMgmtWebService.getDatasourceByName("testDatabase");
assertNotNull(updatedDatabaseConnectionDto);
assertEquals(EXP_UPDATED_DBMETA_HOSTNAME, updatedDatabaseConnectionDto.getHostname());
databaseConnection1 = dbConnectionAdapter.unmarshal(databaseConnectionDto2);
updateDatabaseConnection(databaseConnection1);
String id3 = datasourceMgmtWebService.updateDatasourceById(id1, dbConnectionAdapter.marshal(databaseConnection1));
assertNotNull(id3);
DatabaseConnectionDto updatedDatabaseConnectionDto1 = datasourceMgmtWebService.getDatasourceById(id3);
assertNotNull(updatedDatabaseConnectionDto1);
assertEquals(EXP_UPDATED_DBMETA_HOSTNAME, updatedDatabaseConnectionDto1.getHostname());
datasourceMgmtWebService.deleteDatasourceByName("testDatabase");
DatabaseConnectionDto deletedDatabaseConnectionDto = datasourceMgmtWebService.getDatasourceByName("testDatabase");
assertNull(deletedDatabaseConnectionDto);
datasourceMgmtWebService.deleteDatasourceById(id3);
DatabaseConnectionDto deletedDatabaseConnectionDto2 = datasourceMgmtWebService.getDatasourceById(id3);
assertNull(deletedDatabaseConnectionDto2);
ids = datasourceMgmtWebService.getDatasourceIds();
assertEquals(0, ids.size());
}
use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreatePoolNoDialectService.
@Test
public void testCreatePoolNoDialectService() 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, "org.postgresql.Driver");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.setupPooledDataSource(con);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
use of org.pentaho.database.model.DatabaseConnection in project pentaho-platform by pentaho.
the class PooledDatasourceHelperTest method testCreatePoolNoDialect.
@Test
public void testCreatePoolNoDialect() throws Exception {
DatabaseDialectService dialectService = new DatabaseDialectService(false);
mp = new MicroPlatform(SOLUTION_PATH);
mp.defineInstance(IDatabaseDialectService.class, dialectService);
mp.start();
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, "");
attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
con.setAttributes(attrs);
try {
PooledDatasourceHelper.setupPooledDataSource(con);
fail("Expecting the exception to be thrown");
} catch (DBDatasourceServiceException ex) {
assertNotNull(ex);
}
}
Aggregations