Search in sources :

Example 11 with DataManager

use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.

the class ColumnSetAnalysisHandler method addIndicator.

/**
 * The resources that are connected to this analysis and that are potentially modified.
 */
// private Collection<Resource> modifiedResources = new HashSet<Resource>();
/**
 * Method "addColumnToAnalyze".
 *
 * @param column
 * @return
 */
public boolean addIndicator(List<ModelElement> columns, Indicator indicator) {
    for (ModelElement tdColumn : columns) {
        if (!analysis.getContext().getAnalysedElements().contains(tdColumn)) {
            analysis.getContext().getAnalysedElements().add(tdColumn);
        }
    }
    // store first level of indicators in result.
    analysis.getResults().getIndicators().add(indicator);
    initializeIndicator(indicator);
    DataManager connection = analysis.getContext().getConnection();
    if (connection == null) {
        // try to get one
        for (ModelElement element : columns) {
            TdColumn tdColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(element);
            // $NON-NLS-1$
            log.error(Messages.getString("ColumnCorrelationAnalysisHandler.CONNNOTBEENSETINANALYSIS"));
            connection = ConnectionHelper.getTdDataProvider(tdColumn);
            if (connection != null) {
                analysis.getContext().setConnection(connection);
                break;
            }
        }
    }
    TypedReturnCode<Dependency> rc = DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
    return rc.isOk();
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Dependency(orgomg.cwm.objectmodel.core.Dependency)

Example 12 with DataManager

use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.

the class DQReferenceMerger method addInTarget.

/*
     * override this method to fix a specail case: when add a catalog on database server,this new one can't be added in
     * local db connection
     */
@Override
protected void addInTarget(ReferenceChange diff, boolean rightToLeft) {
    final Match match = diff.getMatch();
    final EObject expectedContainer;
    if (rightToLeft) {
        expectedContainer = match.getLeft();
    } else {
        expectedContainer = match.getRight();
    }
    if (expectedContainer == null) {
        // one of the "required" diffs should have created our container.
        return;
    }
    final Comparison comparison = match.getComparison();
    final EReference reference = diff.getReference();
    final EObject expectedValue;
    final Match valueMatch = comparison.getMatch(diff.getValue());
    if (valueMatch == null) {
        // This is an out of scope value.
        if (diff.getValue().eIsProxy()) {
            // Copy the proxy
            expectedValue = EcoreUtil.copy(diff.getValue());
        } else {
            // Use the same value.
            expectedValue = diff.getValue();
        }
    } else if (rightToLeft) {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setLeft(expectedValue);
        } else {
            // qiongli: when I add catalog on remote server,test on reload, should replace "valueMatch.getLeft()"
            // with "valueMatch.getRight()" at here.
            // expectedValue = valueMatch.getLeft();
            expectedValue = valueMatch.getRight();
            // qiongli: remove the newest DataManage from the right Catalog or Schema,avoid a missing
            // "datamanage herf=" "
            Catalog catlog = SwitchHelpers.CATALOG_SWITCH.doSwitch(expectedValue);
            Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(expectedValue);
            if (catlog != null) {
                EList<DataManager> dataManager = catlog.getDataManager();
                dataManager.clear();
            } else if (schema != null) {
                EList<DataManager> dataManager = schema.getDataManager();
                dataManager.clear();
            }
        }
    } else {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setRight(expectedValue);
        } else {
            expectedValue = valueMatch.getLeft();
        }
    }
    // We have the container, reference and value. We need to know the insertion index.
    if (reference.isMany()) {
        final int insertionIndex = findInsertionIndex(comparison, diff, rightToLeft);
        final List<EObject> targetList = (List<EObject>) safeEGet(expectedContainer, reference);
        addAt(targetList, expectedValue, insertionIndex);
    } else {
        safeESet(expectedContainer, reference, expectedValue);
    }
    if (reference.isContainment()) {
        // Copy XMI ID when applicable.
        final Resource initialResource = diff.getValue().eResource();
        final Resource targetResource = expectedValue.eResource();
        if (initialResource instanceof XMIResource && targetResource instanceof XMIResource) {
            ((XMIResource) targetResource).setID(expectedValue, ((XMIResource) initialResource).getID(diff.getValue()));
        }
    }
// no need to check this for DQ items,
// checkImpliedDiffsOrdering(diff, rightToLeft);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Catalog(orgomg.cwm.resource.relational.Catalog) Match(org.eclipse.emf.compare.Match) EList(org.eclipse.emf.common.util.EList) Comparison(org.eclipse.emf.compare.Comparison) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) EReference(org.eclipse.emf.ecore.EReference)

Example 13 with DataManager

use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.

the class AnalysisExecutor method getConnection.

/**
 * DOC scorreia Comment method "getConnection".
 *
 * @param analysis
 * @param schema
 * @return
 */
protected TypedReturnCode<java.sql.Connection> getConnection(Analysis analysis) {
    // MODSCA 2008-03-25 scorreia schema is not used. removed (was used before to select the catalog of the db)
    // now it is done elsewhere
    TypedReturnCode<java.sql.Connection> rc = new TypedReturnCode<java.sql.Connection>();
    DataManager datamanager = analysis.getContext().getConnection();
    if (datamanager == null) {
        // $NON-NLS-1$
        rc.setReturnCode(Messages.getString("AnalysisExecutor.DataManagerNull", analysis.getName()), false);
        return rc;
    }
    if (datamanager != null && datamanager.eIsProxy()) {
        datamanager = (DataManager) EObjectHelper.resolveObject(datamanager);
    }
    Connection dataprovider = SwitchHelpers.CONNECTION_SWITCH.doSwitch(datamanager);
    if (dataprovider == null) {
        rc.setReturnCode(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "AnalysisExecutor.DataProviderNull", // $NON-NLS-1$
        datamanager.getName(), analysis.getName()), false);
        return rc;
    }
    // create hive connection
    IMetadataConnection metadataConnection = ConvertionHelper.convert(dataprovider);
    if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
        try {
            HiveConnectionHandler hiveConnHandler = HiveConnectionManager.getInstance().createHandler(metadataConnection);
            java.sql.Connection createConnection = hiveConnHandler.createHiveConnection();
            rc.setOk(true);
            rc.setObject(createConnection);
        } catch (ClassNotFoundException e) {
            log.error(e);
            rc.setOk(false);
        } catch (InstantiationException e) {
            log.error(e);
            rc.setOk(false);
        } catch (IllegalAccessException e) {
            log.error(e);
            rc.setOk(false);
        } catch (SQLException e) {
            log.error(e);
            rc.setOk(false);
        }
        return rc;
    } else {
        // create other type connection
        TypedReturnCode<java.sql.Connection> connection = JavaSqlFactory.createConnection(dataprovider);
        if (!connection.isOk()) {
            rc.setReturnCode(connection.getMessage(), false);
            return rc;
        }
        rc.setObject(connection.getObject());
        return rc;
    }
}
Also used : HiveConnectionHandler(org.talend.metadata.managment.hive.handler.HiveConnectionHandler) SQLException(java.sql.SQLException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode)

Example 14 with DataManager

use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.

the class TableAnalysisWizard method createAndSaveCWMFile.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataprofiler.core.ui.wizard.analysis.AbstractAnalysisWizard#createAndSaveCWMFile(orgomg.cwm.objectmodel
     * .core.ModelElement)
     */
@Override
public TypedReturnCode<Object> createAndSaveCWMFile(ModelElement cwmElement) {
    Analysis analysis = (Analysis) cwmElement;
    DataManager connection = analysis.getContext().getConnection();
    if (connection != null) {
        DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
    }
    // MOD by hcheng for 7173:Broken dependency between analyses and connection
    TypedReturnCode<Object> saveCWMFile = super.createAndSaveCWMFile(analysis);
    if (saveCWMFile.isOk() && connection != null) {
        ElementWriterFactory.getInstance().createDataProviderWriter().save(connection);
    }
    return saveCWMFile;
}
Also used : Analysis(org.talend.dataquality.analysis.Analysis) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager)

Example 15 with DataManager

use of orgomg.cwm.foundation.softwaredeployment.DataManager in project tdq-studio-se by Talend.

the class AnalysisFilterWizard method createAndSaveCWMFile.

@Override
public TypedReturnCode<Object> createAndSaveCWMFile(ModelElement cwmElement) {
    Analysis analysis = (Analysis) cwmElement;
    // MOD klliu feature 15750 connection property define
    // MOD qiongli 2011-2-24,bug 17588,add dependency.
    DataManager connection = analysis.getContext().getConnection();
    DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
    ConnectionItem connectionItem = (ConnectionItem) getParameter().getConnectionRepNode().getObject().getProperty().getItem();
    TypedReturnCode<Object> saveCWMFile = super.createAndSaveCWMFile(analysis);
    // MOD by hcheng for 7173:Broken dependency between analyses and connection
    if (saveCWMFile.isOk()) {
        // ProxyRepositoryViewObject.fetchAllRepositoryViewObjects(Boolean.TRUE, Boolean.TRUE);
        // MOD yyi 2012-02-08 TDQ-4621:Explicitly set true for updating dependencies.
        ElementWriterFactory.getInstance().createDataProviderWriter().save(connectionItem, true);
    }
    return saveCWMFile;
}
Also used : Analysis(org.talend.dataquality.analysis.Analysis) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager)

Aggregations

DataManager (orgomg.cwm.foundation.softwaredeployment.DataManager)37 Analysis (org.talend.dataquality.analysis.Analysis)8 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)7 IRepositoryNode (org.talend.repository.model.IRepositoryNode)6 ArrayList (java.util.ArrayList)5 Connection (org.talend.core.model.metadata.builder.connection.Connection)5 TdColumn (org.talend.cwm.relational.TdColumn)4 Indicator (org.talend.dataquality.indicators.Indicator)4 RepositoryNode (org.talend.repository.model.RepositoryNode)4 Dependency (orgomg.cwm.objectmodel.core.Dependency)4 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)4 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)3 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)3 CompositeIndicator (org.talend.dataquality.indicators.CompositeIndicator)3 SQLException (java.sql.SQLException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 EObject (org.eclipse.emf.ecore.EObject)2