Search in sources :

Example 1 with IDatabaseConnection

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

the class TestDataSourceResource method main.

public static void main(String[] args) {
    IDatabaseConnection conn = getConnectionByName(CONNECTION_NAME);
    if (conn == null)
        add();
    else
        update();
    conn = getConnectionByName(CONNECTION_NAME);
    if (conn != null) {
        System.out.println("GetConn " + conn.getName());
        delete();
    }
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 2 with IDatabaseConnection

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

the class TestDataSourceResource method update.

private static void update() {
    init();
    IDatabaseConnection connection = createConnectionObject();
    String conn = (new JSONObject(connection)).toString();
    System.out.println(conn);
    try {
        WebResource resource = client.resource(update_url);
        Response result = resource.accept(MediaType.APPLICATION_JSON).entity(conn).post(Response.class);
        System.out.println(result);
    } catch (Exception ex) {
        System.out.println("Error in update");
    }
}
Also used : Response(javax.ws.rs.core.Response) JSONObject(org.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 3 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection 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;
    }
}
Also used : ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) ConnectionServiceImpl(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) SQLConnection(org.pentaho.platform.plugin.services.connections.sql.SQLConnection) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialect(org.pentaho.database.IDatabaseDialect) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 4 with IDatabaseConnection

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

the class LegacyDatasourceConverter method unmarshal.

/**
 * Convert textual data back into an object.
 *
 * @param reader  The stream to read the text from.
 * @param context
 * @return The resulting object.
 */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    MultiTableDatasourceDTO resultDTO = new MultiTableDatasourceDTO();
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        String nodeName = reader.getNodeName();
        if (nodeName.equalsIgnoreCase("datasourceName")) {
            String value = reader.getValue();
            resultDTO.setDatasourceName(value);
        } else if (nodeName.equalsIgnoreCase("selectedConnection")) {
            String connectionClass = reader.getAttribute("class");
            if (connectionClass != null) {
                DatabaseConnection databaseConnection = new DatabaseConnection();
                if (connectionClass.equals("org.pentaho.platform.dataaccess.datasource.beans.Connection")) {
                    while (reader.hasMoreChildren()) {
                        reader.moveDown();
                        nodeName = reader.getNodeName();
                        if (reader.getNodeName().equalsIgnoreCase("name")) {
                            String databaseName = reader.getValue();
                            databaseConnection.setName(databaseName);
                            databaseConnection.setId(databaseName);
                        } else if (reader.getNodeName().equalsIgnoreCase("username")) {
                            databaseConnection.setUsername(reader.getValue());
                        } else if (reader.getNodeName().equalsIgnoreCase("password")) {
                            databaseConnection.setPassword(reader.getValue());
                        } else if (reader.getNodeName().equalsIgnoreCase("url")) {
                            ParsedJdbcUrl parsedJdbcUrl = new ParsedJdbcUrl(reader.getValue());
                            databaseConnection.setHostname(parsedJdbcUrl.getHostname());
                            databaseConnection.setDatabasePort(parsedJdbcUrl.getPort());
                            databaseConnection.setDatabaseName(parsedJdbcUrl.getDatabaseName());
                            databaseConnection.setDatabaseType(resolveDatabaseType(parsedJdbcUrl.getJdbcPrefix()));
                        }
                        reader.moveUp();
                    }
                    resultDTO.setSelectedConnection(databaseConnection);
                } else {
                    // instantiate the class specified
                    try {
                        Class databaseConnectionClass = Class.forName(connectionClass);
                        IDatabaseConnection databaseConnectionInstance = (IDatabaseConnection) context.convertAnother(resultDTO, databaseConnectionClass);
                        resultDTO.setSelectedConnection(databaseConnectionInstance);
                    } catch (ClassNotFoundException e) {
                        // not going to work anyway, set empty connection for now
                        resultDTO.setSelectedConnection(new DatabaseConnection());
                    }
                }
            }
        } else if (nodeName.equalsIgnoreCase("schemaModel")) {
            SchemaModel schemaModel = (SchemaModel) context.convertAnother(resultDTO, SchemaModel.class);
            if (schemaModel != null) {
                resultDTO.setSchemaModel(schemaModel);
            }
        } else if (nodeName.equalsIgnoreCase("selectedTables")) {
            List<String> selectedTables = (List<String>) context.convertAnother(resultDTO, ArrayList.class);
            if (selectedTables != null) {
                resultDTO.setSelectedTables(selectedTables);
            }
        } else if (nodeName.equalsIgnoreCase("doOlap")) {
            resultDTO.setDoOlap(Boolean.valueOf(reader.getValue()));
        }
        reader.moveUp();
    }
    return resultDTO;
}
Also used : MultiTableDatasourceDTO(org.pentaho.platform.dataaccess.datasource.wizard.service.impl.MultiTableDatasourceDTO) SchemaModel(org.pentaho.agilebi.modeler.models.SchemaModel) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 5 with IDatabaseConnection

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

the class JdbcDatasourceResourceTest method testGetConnectionIDs.

@Test
public void testGetConnectionIDs() throws Exception {
    IDatabaseConnection mockIDatabaseConnection = mock(IDatabaseConnection.class);
    List<IDatabaseConnection> conns = new ArrayList<IDatabaseConnection>();
    conns.add(mockIDatabaseConnection);
    List<String> connStrList = new ArrayList<String>();
    connStrList.add(conns.get(0).getName());
    doReturn(conns).when(jdbcDatasourceResource.service).getConnections();
    JaxbList<String> connections = jdbcDatasourceResource.getConnectionIDs();
    verify(jdbcDatasourceResource, times(1)).getConnectionIDs();
    assertEquals(connections.getList().get(0), connStrList.get(0));
}
Also used : ArrayList(java.util.ArrayList) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) 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