Search in sources :

Example 26 with DatabaseConnection

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

Example 27 with DatabaseConnection

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;
}
Also used : DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 28 with DatabaseConnection

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());
}
Also used : DatabaseConnection(org.pentaho.database.model.DatabaseConnection) Test(org.junit.Test)

Example 29 with DatabaseConnection

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);
    }
}
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 30 with DatabaseConnection

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);
    }
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) HashMap(java.util.HashMap) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) 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)

Aggregations

DatabaseConnection (org.pentaho.database.model.DatabaseConnection)56 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)48 Test (org.junit.Test)36 HashMap (java.util.HashMap)10 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)7 DatabaseType (org.pentaho.database.model.DatabaseType)6 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)6 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)6 ArrayList (java.util.ArrayList)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IDatabaseType (org.pentaho.database.model.IDatabaseType)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)5 Response (javax.ws.rs.core.Response)4 List (java.util.List)3 LinkedList (java.util.LinkedList)2 Mockito.anyString (org.mockito.Mockito.anyString)2 DatabaseAccessType (org.pentaho.database.model.DatabaseAccessType)2 PartitionDatabaseMeta (org.pentaho.database.model.PartitionDatabaseMeta)2 Category (org.pentaho.metadata.model.Category)2