Search in sources :

Example 41 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.

the class DatabaseHelper method databaseMetaToDatabaseConnection.

public IDatabaseConnection databaseMetaToDatabaseConnection(final DatabaseMeta databaseMeta) {
    IDatabaseConnection databaseConnection = new DatabaseConnection();
    databaseConnection.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName(databaseMeta.getDatabaseTypeDesc()));
    databaseConnection.setName(databaseMeta.getName());
    if (databaseMeta.getObjectId() != null) {
        databaseConnection.setId(databaseMeta.getObjectId().getId());
    }
    String accessType = databaseMeta.getAccessTypeDesc();
    // This is a special case with some PDI connections
    if (accessType != null && accessType.contains("Native")) {
        accessType = DatabaseAccessType.NATIVE.getName();
    } else if (accessType != null && accessType.equals(", ")) {
        accessType = DatabaseAccessType.JNDI.getName();
    }
    databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
    databaseConnection.setHostname(databaseMeta.getHostname());
    databaseConnection.setDatabaseName(databaseMeta.getDatabaseName());
    databaseConnection.setDatabasePort(databaseMeta.getDatabasePortNumberString());
    databaseConnection.setUsername(databaseMeta.getUsername());
    databaseConnection.setPassword(databaseMeta.getPassword());
    databaseConnection.setInformixServername(databaseMeta.getServername());
    databaseConnection.setDataTablespace(databaseMeta.getDataTablespace());
    databaseConnection.setIndexTablespace(databaseMeta.getIndexTablespace());
    databaseConnection.setConnectSql(databaseMeta.getConnectSQL());
    databaseConnection.setInitialPoolSize(databaseMeta.getInitialPoolSize());
    databaseConnection.setMaximumPoolSize(databaseMeta.getMaximumPoolSize());
    databaseConnection.setUsingConnectionPool(databaseMeta.isUsingConnectionPool());
    databaseConnection.setForcingIdentifiersToLowerCase(databaseMeta.isForcingIdentifiersToLowerCase());
    databaseConnection.setForcingIdentifiersToUpperCase(databaseMeta.isForcingIdentifiersToUpperCase());
    databaseConnection.setQuoteAllFields(databaseMeta.isQuoteAllFields());
    databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(databaseMeta.isUsingDoubleDecimalAsSchemaTableSeparator());
    Map<String, String> attributeMap = new HashMap<String, String>();
    for (Entry<Object, Object> entry : databaseMeta.getAttributes().entrySet()) {
        attributeMap.put((String) entry.getKey(), (String) entry.getValue());
    }
    databaseConnection.setAttributes(attributeMap);
    Map<String, String> connectionPoolingMap = new HashMap<String, String>();
    for (Entry<Object, Object> entry : databaseMeta.getConnectionPoolingProperties().entrySet()) {
        connectionPoolingMap.put((String) entry.getKey(), (String) entry.getValue());
    }
    databaseConnection.setConnectionPoolingProperties(connectionPoolingMap);
    databaseConnection.setExtraOptions(databaseMeta.getExtraOptions());
    return databaseConnection;
}
Also used : HashMap(java.util.HashMap) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 42 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.

the class DatabaseHelper method dataNodeToDatabaseConnection.

public IDatabaseConnection dataNodeToDatabaseConnection(final Serializable id, final String name, final DataNode rootNode) {
    IDatabaseConnection databaseConnection = new DatabaseConnection();
    String databaseType = getString(rootNode, PROP_TYPE);
    databaseConnection.setDatabaseType(databaseType != null ? databaseTypeHelper.getDatabaseTypeByShortName(databaseType) : null);
    databaseConnection.setName(name);
    if (id != null) {
        databaseConnection.setId(id.toString());
    }
    String accessType = getString(rootNode, PROP_CONTYPE);
    // This is a special case with some PDI connections
    if (accessType != null && accessType.contains("Native")) {
        accessType = DatabaseAccessType.NATIVE.getName();
    } else if (accessType != null && accessType.equals(", ")) {
        accessType = DatabaseAccessType.JNDI.getName();
    }
    databaseConnection.setAccessType(accessType != null ? DatabaseAccessType.getAccessTypeByName(accessType) : null);
    databaseConnection.setHostname(getString(rootNode, PROP_HOST_NAME));
    databaseConnection.setDatabaseName(getString(rootNode, PROP_DATABASE_NAME));
    databaseConnection.setDatabasePort(getString(rootNode, PROP_PORT));
    databaseConnection.setUsername(getString(rootNode, PROP_USERNAME));
    databaseConnection.setPassword(decryptPassword(getString(rootNode, PROP_PASSWORD)));
    databaseConnection.setInformixServername(getString(rootNode, PROP_SERVERNAME));
    databaseConnection.setDataTablespace(getString(rootNode, PROP_DATA_TBS));
    databaseConnection.setIndexTablespace(getString(rootNode, PROP_INDEX_TBS));
    databaseConnection.setConnectSql(getString(rootNode, PROP_CONNECT_SQL));
    databaseConnection.setInitialPoolSize(getInt(rootNode, PROP_INITIAL_POOL_SIZE));
    databaseConnection.setMaximumPoolSize(getInt(rootNode, PROP_MAX_POOL_SIZE));
    databaseConnection.setUsingConnectionPool(getBoolean(rootNode, PROP_IS_POOLING));
    databaseConnection.setForcingIdentifiersToLowerCase(getBoolean(rootNode, PROP_IS_FORCING_TO_LOWER));
    databaseConnection.setForcingIdentifiersToUpperCase(getBoolean(rootNode, PROP_IS_FORCING_TO_UPPER));
    databaseConnection.setQuoteAllFields(getBoolean(rootNode, PROP_IS_QUOTE_FIELDS));
    databaseConnection.setUsingDoubleDecimalAsSchemaTableSeparator(getBoolean(rootNode, PROP_IS_DECIMAL_SEPERATOR));
    // Also, load all the properties we can find...
    DataNode attrNode = rootNode.getNode(NODE_ATTRIBUTES);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getAttributes().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    // Also, load any pooling params
    attrNode = rootNode.getNode(NODE_POOLING_PROPS);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getConnectionPoolingProperties().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    // Load extra options
    attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getExtraOptions().put(code, // $NON-NLS-1$
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    attrNode = rootNode.getNode(NODE_EXTRA_OPTIONS_ORDER);
    if (attrNode != null) {
        for (DataProperty property : attrNode.getProperties()) {
            String code = property.getName();
            String attribute = property.getString();
            databaseConnection.getExtraOptionsOrder().put(code, // $NON
            (attribute == null || attribute.length() == 0) ? "" : attribute);
        }
    }
    return databaseConnection;
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 43 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method getDatasource.

private IDatabaseConnection getDatasource(RepositoryFile file) throws DatasourceMgmtServiceException {
    try {
        if (file != null) {
            NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
            IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
            // databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
            return databaseConnection;
        } else {
            throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            ""));
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance()
    // .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", file.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 44 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.

the class JNDIDatasourceServiceTest method setUp.

@Before
public void setUp() {
    IDatabaseConnection mockConnection = mock(IDatabaseConnection.class);
    // Set it up - this is a JNDI connection
    when(mockConnection.getAccessType()).thenReturn(DatabaseAccessType.JNDI);
    when(mockConnection.getDatabaseName()).thenReturn(dsName);
    DataSource mockDs = mock(DataSource.class);
    IDatasourceMgmtService mockMgmtService = mock(IDatasourceMgmtService.class);
    spyService = spy(service);
    try {
        when(mockMgmtService.getDatasourceByName(dsName)).thenReturn(mockConnection);
    } catch (DatasourceMgmtServiceException e) {
        e.printStackTrace();
    }
    try {
        doReturn(mockDs).when(spyService).getJndiDataSource(dsName);
    } catch (DBDatasourceServiceException e) {
        e.printStackTrace();
    }
    doReturn(mockMgmtService).when(spyService).getDatasourceMgmtService();
    service.clearCache();
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) Before(org.junit.Before)

Example 45 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.

the class PooledDatasourceHelperTest method testConnectionFactory_MariaDB.

@Test
public void testConnectionFactory_MariaDB() {
    IDatabaseConnection connection = mock(IDatabaseConnection.class);
    doReturn(StringEscapeUtils.escapeHtml(user)).when(connection).getUsername();
    doReturn(StringEscapeUtils.escapeHtml(password)).when(connection).getPassword();
    ConnectionFactory factory = PooledDatasourceHelper.getConnectionFactory(connection, "jdbc:mariadb://localhost");
    Properties props = (Properties) Whitebox.getInternalState(factory, "_props");
    assertEquals(user, props.getProperty("user"));
    assertEquals(password, props.getProperty("password"));
}
Also used : ConnectionFactory(org.apache.commons.dbcp.ConnectionFactory) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)102 Test (org.junit.Test)32 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)29 ArrayList (java.util.ArrayList)18 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 RequestException (com.google.gwt.http.client.RequestException)14 Request (com.google.gwt.http.client.Request)13 RequestBuilder (com.google.gwt.http.client.RequestBuilder)13 RequestCallback (com.google.gwt.http.client.RequestCallback)13 Response (com.google.gwt.http.client.Response)13 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)13 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)11 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)9 List (java.util.List)8 Response (javax.ws.rs.core.Response)8 Path (javax.ws.rs.Path)7 GET (javax.ws.rs.GET)6 Produces (javax.ws.rs.Produces)6 Facet (org.codehaus.enunciate.Facet)5 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)5