Search in sources :

Example 1 with DatabaseTypeHelper

use of org.pentaho.database.util.DatabaseTypeHelper in project pentaho-platform by pentaho.

the class PooledDatasourceHelperTest method testCreatePoolNoClassName.

@Test
public void testCreatePoolNoClassName() throws Exception {
    DatabaseDialectService dialectService = new DatabaseDialectService(false);
    final DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(dialectService.getDatabaseTypes());
    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.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.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) 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)

Example 2 with DatabaseTypeHelper

use of org.pentaho.database.util.DatabaseTypeHelper 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);
    }
}
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 3 with DatabaseTypeHelper

use of org.pentaho.database.util.DatabaseTypeHelper in project data-access by pentaho.

the class DatabaseConnectionConverterTest method testConvertToXml.

@Test
public void testConvertToXml() {
    DatabaseConnection dbConnection = new DatabaseConnection();
    dbConnection.setId("my id");
    dbConnection.setAccessType(DatabaseAccessType.NATIVE);
    List<DatabaseAccessType> accessTypes = new LinkedList<DatabaseAccessType>();
    accessTypes.add(DatabaseAccessType.NATIVE);
    DatabaseType dbType = new DatabaseType("name", "short name", accessTypes, 100500, "helpUri");
    dbConnection.setDatabaseType(dbType);
    Map<String, String> extraOptions = new HashMap<String, String>();
    extraOptions.put("opt", "value");
    dbConnection.setExtraOptions(extraOptions);
    dbConnection.setName("Best name");
    dbConnection.setHostname("localhost");
    dbConnection.setDatabaseName("foodmart");
    dbConnection.setDatabasePort("2233");
    dbConnection.setUsername("username");
    dbConnection.setPassword("password");
    dbConnection.setStreamingResults(true);
    dbConnection.setDataTablespace("tables");
    dbConnection.setIndexTablespace("indexes");
    dbConnection.setSQLServerInstance("INSTANCE_0");
    dbConnection.setUsingDoubleDecimalAsSchemaTableSeparator(true);
    dbConnection.setInformixServername("INFORM_1");
    dbConnection.addExtraOption("100", "option", "value");
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("attr1", "value");
    dbConnection.setAttributes(attributes);
    dbConnection.setChanged(true);
    dbConnection.setQuoteAllFields(true);
    dbConnection.setForcingIdentifiersToLowerCase(true);
    dbConnection.setForcingIdentifiersToUpperCase(true);
    dbConnection.setConnectSql("select * from 1");
    dbConnection.setUsingConnectionPool(true);
    dbConnection.setInitialPoolSize(3);
    dbConnection.setMaximumPoolSize(9);
    dbConnection.setPartitioned(true);
    Map<String, String> connectionPoolingProperties = new HashMap<String, String>();
    connectionPoolingProperties.put("pool", "abc");
    dbConnection.setConnectionPoolingProperties(connectionPoolingProperties);
    List<PartitionDatabaseMeta> partitioningInformation = new LinkedList<PartitionDatabaseMeta>();
    PartitionDatabaseMeta pdm = new PartitionDatabaseMeta();
    partitioningInformation.add(pdm);
    dbConnection.setPartitioningInformation(partitioningInformation);
    List<IDatabaseType> databaseTypes = new LinkedList<IDatabaseType>();
    databaseTypes.add(dbType);
    DatabaseTypeHelper dbh = new DatabaseTypeHelper(databaseTypes);
    DatabaseConnectionConverter dbcc = new DatabaseConnectionConverter(dbh);
    String xmlCOnnection = dbcc.convertToXml(dbConnection);
}
Also used : DatabaseType(org.pentaho.database.model.DatabaseType) IDatabaseType(org.pentaho.database.model.IDatabaseType) HashMap(java.util.HashMap) PartitionDatabaseMeta(org.pentaho.database.model.PartitionDatabaseMeta) LinkedList(java.util.LinkedList) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatabaseAccessType(org.pentaho.database.model.DatabaseAccessType) DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) Test(org.junit.Test)

Example 4 with DatabaseTypeHelper

use of org.pentaho.database.util.DatabaseTypeHelper in project data-access by pentaho.

the class ConnectionController method init.

@Bindable
public void init() {
    XulServiceCallback<List<IDatabaseType>> callback = new XulServiceCallback<List<IDatabaseType>>() {

        public void error(String message, Throwable error) {
            error.printStackTrace();
        }

        public void success(List<IDatabaseType> retVal) {
            databaseTypeHelper = new DatabaseTypeHelper(retVal);
        }
    };
    dialectService.getDatabaseTypes(callback);
    saveConnectionConfirmationDialog = // $NON-NLS-1$
    (XulDialog) document.getElementById("saveConnectionConfirmationDialogConnectionController");
    overwriteConnectionConfirmationDialog = (XulDialog) document.getElementById("overwriteConnectionConfirmationDialogConnectionController");
    renameConnectionConfirmationDialog = (XulDialog) document.getElementById("renameConnectionConfirmationDialogConnectionController");
    // $NON-NLS-1$
    errorDialog = (XulDialog) document.getElementById("errorDialog");
    // $NON-NLS-1$
    errorLabel = (XulLabel) document.getElementById("errorLabel");
    // $NON-NLS-1$
    successDialog = (XulDialog) document.getElementById("successDialog");
    // $NON-NLS-1$
    successLabel = (XulLabel) document.getElementById("successLabel");
    // $NON-NLS-1$
    removeConfirmationDialog = (XulDialog) document.getElementById("removeConfirmationDialogConnectionController");
    // $NON-NLS-1$
    successDetailsDialog = (XulDialog) document.getElementById("successDetailsDialogConnectionController");
}
Also used : XulServiceCallback(org.pentaho.ui.xul.XulServiceCallback) IDatabaseType(org.pentaho.database.model.IDatabaseType) DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) ArrayList(java.util.ArrayList) IDatabaseConnectionList(org.pentaho.ui.database.event.IDatabaseConnectionList) List(java.util.List) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Example 5 with DatabaseTypeHelper

use of org.pentaho.database.util.DatabaseTypeHelper in project data-access by pentaho.

the class AgileMartDatasourceHelper method getAgileMartDatasource.

private IDatabaseConnection getAgileMartDatasource(Boolean useDefault, Properties agileMartDatasourceProperties) {
    IDatabaseConnection databaseConnection = new DatabaseConnection();
    IDatabaseDialectService databaseDialectService = PentahoSystem.get(IDatabaseDialectService.class);
    DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(databaseDialectService.getDatabaseTypes());
    databaseConnection.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASETYPESHORTNAME_VALUE) : agileMartDatasourceProperties.getProperty(DATABASETYPESHORTNAME)));
    String accessType = useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_ACCESS_TYPE_VALUE) : agileMartDatasourceProperties.getProperty(ACCESS_TYPE);
    // This is a special case with some PDI connections
    if (accessType != null && accessType.contains("Native") || accessType.equals("NATIVE")) {
        accessType = DatabaseAccessType.NATIVE.getName();
    } else if (accessType != null && accessType.equals(", ")) {
        accessType = DatabaseAccessType.JNDI.getName();
    }
    databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
    databaseConnection.setName(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_NAME_VALUE) : agileMartDatasourceProperties.getProperty(NAME));
    databaseConnection.setChanged(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_CHANGED_VALUE) : agileMartDatasourceProperties.getProperty(CHANGED)));
    databaseConnection.setDatabaseName(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASENAME_VALUE) : agileMartDatasourceProperties.getProperty(DATABASENAME));
    databaseConnection.setDatabasePort(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASEPORT_VALUE) : agileMartDatasourceProperties.getProperty(DATABASEPORT));
    databaseConnection.setForcingIdentifiersToLowerCase(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_FORCINGIDENTIFIERSTOLOWERCASE_VALUE) : agileMartDatasourceProperties.getProperty(FORCINGIDENTIFIERSTOLOWERCASE)));
    databaseConnection.setForcingIdentifiersToUpperCase(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_FORCINGIDENTIFIERSTOUPPERCASE_VALUE) : agileMartDatasourceProperties.getProperty(FORCINGIDENTIFIERSTOUPPERCASE)));
    databaseConnection.setHostname(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_HOSTNAME_VALUE) : agileMartDatasourceProperties.getProperty(HOSTNAME));
    databaseConnection.setInitialPoolSize(Integer.valueOf(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_INITIALPOOLSIZE_VALUE) : agileMartDatasourceProperties.getProperty(INITIALPOOLSIZE)));
    databaseConnection.setMaximumPoolSize(Integer.valueOf(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_MAXIMUMPOOLSIZE_VALUE) : agileMartDatasourceProperties.getProperty(MAXIMUMPOOLSIZE)));
    databaseConnection.setPartitioned(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_PARTITIONED_VALUE) : agileMartDatasourceProperties.getProperty(PARTITIONED)));
    databaseConnection.setPassword(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_PASSWORD_VALUE) : agileMartDatasourceProperties.getProperty(PASSWORD));
    databaseConnection.setUsername(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_USERNAME_VALUE) : agileMartDatasourceProperties.getProperty(USERNAME));
    databaseConnection.setUsingConnectionPool(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_USECONNECTIONPOOL_VALUE) : agileMartDatasourceProperties.getProperty(USECONNECTIONPOOL)));
    databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(Boolean.getBoolean(useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_USINGDOUBLEDECIMALASSCHEMATABLESEPERATOR_VALUE) : agileMartDatasourceProperties.getProperty(USINGDOUBLEDECIMALASSCHEMATABLESEPERATOR)));
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put(ATTRIBUTE_PORT_NUMBER, useDefault ? agileMartDatasourceProperties.getProperty(DEFAULT_DATABASEPORT_VALUE) : agileMartDatasourceProperties.getProperty(DATABASEPORT));
    attributes.put(ATTRIBUTE_STANDARD_CONNECTION, Boolean.FALSE.toString());
    attributes.put(ATTRIBUTE_AGILE_MART_CONNECTION, Boolean.TRUE.toString());
    databaseConnection.setAttributes(attributes);
    return databaseConnection;
}
Also used : DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) HashMap(java.util.HashMap) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService)

Aggregations

DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)10 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)6 HashMap (java.util.HashMap)5 IDatabaseType (org.pentaho.database.model.IDatabaseType)5 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)5 List (java.util.List)4 Test (org.junit.Test)4 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)4 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)4 XulServiceCallback (org.pentaho.ui.xul.XulServiceCallback)4 ArrayList (java.util.ArrayList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)3 IDatabaseConnectionList (org.pentaho.ui.database.event.IDatabaseConnectionList)2 Bindable (org.pentaho.ui.xul.stereotype.Bindable)2 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1