Search in sources :

Example 16 with IDatabaseConnection

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

the class ConnectionController method createIDatabaseConnectionBean.

protected AutoBean<IDatabaseConnection> createIDatabaseConnectionBean(IDatabaseConnection connection) {
    AutoBean<IDatabaseConnection> bean = connectionAutoBeanFactory.iDatabaseConnection();
    IDatabaseConnection connectionBean = bean.as();
    copyDatabaseConnectionProperties(connection, connectionBean);
    return AutoBeanUtils.getAutoBean(connectionBean);
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 17 with IDatabaseConnection

use of org.pentaho.database.model.IDatabaseConnection 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)

Example 18 with IDatabaseConnection

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

the class ConnectionService method getConnectionIdByNameWithResponse.

/**
 * Returns a response with id of a database connection
 *
 * @param name
 *          String representing the name of the database to search
 * @return Response based on the string value of the connection id
 *
 * @throws ConnectionServiceException
 */
@GET
@Path("/getid")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response getConnectionIdByNameWithResponse(@QueryParam("name") String name) throws ConnectionServiceException {
    IDatabaseConnection conn = null;
    Response response;
    try {
        conn = connectionService.getConnectionByName(name);
        if (conn != null) {
            response = Response.ok().entity(conn.getId()).build();
        } else {
            response = Response.notModified().build();
        }
    } catch (Exception ex) {
        response = Response.serverError().entity(ex.getMessage()).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 19 with IDatabaseConnection

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

the class ConnectionService method getConnectionByNameWithResponse.

/**
 * this is a method to return a response object with an error message use getEntity(Connection.class) and getStatus()
 * to determine success
 */
@GET
@Path("/getresponse")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public Response getConnectionByNameWithResponse(@QueryParam("name") String name) throws ConnectionServiceException {
    IDatabaseConnection conn = null;
    Response response;
    try {
        conn = connectionService.getConnectionByName(name);
        sanitizer.unsanitizeConnectionParameters(conn);
        hidePassword(conn);
        response = Response.ok().entity(conn).build();
    } catch (Exception ex) {
        response = Response.serverError().entity(ex.getMessage()).build();
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 20 with IDatabaseConnection

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

the class ConnectionService method getConnectionByName.

/**
 * Returns the list of database connections
 *
 * @param name
 *          String representing the name of the database to return
 * @return Database connection by name
 *
 * @throws ConnectionServiceException
 */
@GET
@Path("/get")
@Produces({ APPLICATION_JSON })
@Facet(name = "Unsupported")
public IDatabaseConnection getConnectionByName(@QueryParam("name") String name) throws ConnectionServiceException {
    IDatabaseConnection conn = connectionService.getConnectionByName(name);
    hidePassword(conn);
    return conn;
}
Also used : IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

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