Search in sources :

Example 1 with DataSource

use of org.kie.workbench.common.screens.datasource.management.backend.core.DataSource in project kie-wb-common by kiegroup.

the class WildflyDataSourceProvider method deploy.

@Override
public DataSourceDeploymentInfo deploy(DataSourceDef dataSourceDef) throws Exception {
    // This random identifiers calculation should be removed when WF supports deletion
    // of data sources without letting them published on server until next restart.
    String random = "_" + generateRandomUUID();
    String deploymentId = DeploymentIdGenerator.generateDeploymentId(dataSourceDef) + random;
    String kieJndi = JndiNameGenerator.generateJNDIName(dataSourceDef);
    String deploymentJndi = kieJndi + random;
    DataSourceDeploymentInfo deploymentInfo = deploy(dataSourceDef, deploymentJndi, deploymentId);
    javax.sql.DataSource dataSource = (javax.sql.DataSource) jndiLookupDataSource(deploymentJndi);
    WildlfyDataSource wfDataSource = new WildlfyDataSource(dataSource, deploymentJndi);
    managedDataSources.put(deploymentId, wfDataSource);
    return deploymentInfo;
}
Also used : DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) DataSource(org.kie.workbench.common.screens.datasource.management.backend.core.DataSource)

Example 2 with DataSource

use of org.kie.workbench.common.screens.datasource.management.backend.core.DataSource in project kie-wb-common by kiegroup.

the class WildflyDataSourceProvider method lookupDataSource.

@Override
public DataSource lookupDataSource(DataSourceDeploymentInfo deploymentInfo) throws Exception {
    WildlfyDataSource dataSource = managedDataSources.get(deploymentInfo.getDeploymentId());
    if (dataSource == null) {
        dataSource = unManagedDataSources.get(deploymentInfo.getDeploymentId());
    }
    if (dataSource == null) {
        DataSourceDeploymentInfo refreshedDeploymentInfo = getDeploymentInfo(deploymentInfo.getUuid());
        if (refreshedDeploymentInfo != null && refreshedDeploymentInfo.getJndi() != null) {
            javax.sql.DataSource sqlDataSource = (javax.sql.DataSource) jndiLookupDataSource(refreshedDeploymentInfo.getJndi());
            if (sqlDataSource != null) {
                dataSource = new WildlfyDataSource(sqlDataSource, refreshedDeploymentInfo.getJndi());
                unManagedDataSources.put(deploymentInfo.getDeploymentId(), dataSource);
                return dataSource;
            }
        }
    }
    if (dataSource != null) {
        if (dataSource.isNew()) {
            // first access to the data source
            dataSource.setStatus(DataSourceStatus.REFERENCED);
        }
        return dataSource;
    } else {
        throw new Exception("Data source for: " + deploymentInfo + " is not deployed in current system.");
    }
}
Also used : DataSourceDeploymentInfo(org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo) DataSource(org.kie.workbench.common.screens.datasource.management.backend.core.DataSource)

Example 3 with DataSource

use of org.kie.workbench.common.screens.datasource.management.backend.core.DataSource in project kie-wb-common by kiegroup.

the class DatabaseMetadataServiceImpl method findTables.

@Override
public List<TableMetadata> findTables(String dataSourceUuid, String schema, String tableNamePattern, DatabaseMetadata.TableType... types) {
    checkNotNull("dataSourceUuid", dataSourceUuid);
    checkNotNull("types", types);
    try {
        DataSource dataSource = dataSourceRuntimeManager.lookupDataSource(dataSourceUuid);
        return DatabaseMetadataUtil.findTables(dataSource.getConnection(), schema, tableNamePattern, types);
    } catch (Exception e) {
        logger.error("It was not possible to get database metadata for data source: " + dataSourceUuid, e);
        throw new GenericPortableException("It was not possible to get database metadata for data source: " + dataSourceUuid + ": " + e.getMessage(), e);
    }
}
Also used : GenericPortableException(org.guvnor.common.services.shared.exceptions.GenericPortableException) GenericPortableException(org.guvnor.common.services.shared.exceptions.GenericPortableException) DataSource(org.kie.workbench.common.screens.datasource.management.backend.core.DataSource)

Aggregations

DataSource (org.kie.workbench.common.screens.datasource.management.backend.core.DataSource)3 DataSourceDeploymentInfo (org.kie.workbench.common.screens.datasource.management.model.DataSourceDeploymentInfo)2 GenericPortableException (org.guvnor.common.services.shared.exceptions.GenericPortableException)1