Search in sources :

Example 6 with SchemaIndicator

use of org.talend.dataquality.indicators.schema.SchemaIndicator in project tdq-studio-se by Talend.

the class ConnectionEvaluator method addToConnectionIndicator.

@Override
protected void addToConnectionIndicator(Indicator indicator) {
    final ConnectionIndicator connectionIndicator = getConnectionIndicator();
    if (connectionIndicator == null) {
        return;
    }
    SchemaSwitch<Boolean> schemaSwitch = new SchemaSwitch<Boolean>() {

        /*
             * (non-Javadoc)
             * 
             * @see
             * org.talend.dataquality.indicators.schema.util.SchemaSwitch#caseCatalogIndicator(org.talend.dataquality
             * .indicators.schema.CatalogIndicator)
             */
        @Override
        public Boolean caseCatalogIndicator(CatalogIndicator object) {
            connectionIndicator.addCatalogIndicator(object);
            connectionIndicator.setCatalogCount(connectionIndicator.getCatalogCount() + 1);
            // increment schema count
            connectionIndicator.setSchemaCount(connectionIndicator.getSchemaCount() + object.getSchemaCount());
            // MOD scorreia 2009-01-16 increment other counts
            incrementCounts(connectionIndicator, object);
            return true;
        }

        private void incrementCounts(final ConnectionIndicator connIndicator, SchemaIndicator childIndicator) {
            connIndicator.setTableCount(connIndicator.getTableCount() + childIndicator.getTableCount());
            connIndicator.setTableRowCount(connIndicator.getTableRowCount() + childIndicator.getTableRowCount());
            // MOD klliu 2011-12-26 bug TDQ-4235
            connIndicator.setViewCount(connIndicator.getViewCount() + childIndicator.getViewCount());
            connIndicator.setViewRowCount(connIndicator.getViewRowCount() + childIndicator.getViewRowCount());
            connIndicator.setKeyCount(connIndicator.getKeyCount() + childIndicator.getKeyCount());
            connIndicator.setIndexCount(connIndicator.getIndexCount() + childIndicator.getIndexCount());
        }

        /*
             * (non-Javadoc)
             * 
             * @see
             * org.talend.dataquality.indicators.schema.util.SchemaSwitch#caseSchemaIndicator(org.talend.dataquality
             * .indicators.schema.SchemaIndicator)
             */
        @Override
        public Boolean caseSchemaIndicator(SchemaIndicator object) {
            connectionIndicator.addSchemaIndicator(object);
            connectionIndicator.setSchemaCount(connectionIndicator.getSchemaCount() + 1);
            // MOD scorreia 2009-01-16 increment other counts
            incrementCounts(connectionIndicator, object);
            return true;
        }
    };
    schemaSwitch.doSwitch(indicator);
}
Also used : SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) SchemaSwitch(org.talend.dataquality.indicators.schema.util.SchemaSwitch) ConnectionIndicator(org.talend.dataquality.indicators.schema.ConnectionIndicator)

Example 7 with SchemaIndicator

use of org.talend.dataquality.indicators.schema.SchemaIndicator in project tdq-studio-se by Talend.

the class SchemaAnalysisWizard method initCWMResourceBuilder.

@Override
public ModelElement initCWMResourceBuilder() {
    Analysis analysis = (Analysis) super.initCWMResourceBuilder();
    if (getAnalysisBuilder() != null) {
        // MOD klliu 15750 2011-1-05 add the repnode on parameter
        PackagesAnalyisParameter packageParameter = getParameter();
        IRepositoryNode connectionRepNode = getParameter().getConnectionRepNode();
        ConnectionItem item = (ConnectionItem) connectionRepNode.getObject().getProperty().getItem();
        Connection tdProvider = item.getConnection();
        // Connection tdProvider = packageParameter.getTdDataProvider();
        getAnalysisBuilder().setAnalysisConnection(tdProvider);
        Indicator[] indicators = new Indicator[packageParameter.getPackages().size()];
        ModelElement[] modelElement = new ModelElement[packageParameter.getPackages().size()];
        int i = 0;
        for (IRepositoryNode node : packageParameter.getPackages()) {
            SchemaIndicator createSchemaIndicator = SchemaFactory.eINSTANCE.createSchemaIndicator();
            DBSchemaRepNode catalogNode = (DBSchemaRepNode) node;
            Schema schema = ((MetadataSchemaRepositoryObject) catalogNode.getObject()).getSchema();
            modelElement[i] = schema;
            DefinitionHandler.getInstance().setDefaultIndicatorDefinition(createSchemaIndicator);
            createSchemaIndicator.setAnalyzedElement(schema);
            indicators[i] = createSchemaIndicator;
            i++;
        }
        getAnalysisBuilder().addElementsToAnalyze(modelElement, indicators);
    }
    return analysis;
}
Also used : SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) DBSchemaRepNode(org.talend.dq.nodes.DBSchemaRepNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Schema(orgomg.cwm.resource.relational.Schema) Connection(org.talend.core.model.metadata.builder.connection.Connection) SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) Indicator(org.talend.dataquality.indicators.Indicator) MetadataSchemaRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataSchemaRepositoryObject) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) PackagesAnalyisParameter(org.talend.dq.analysis.parameters.PackagesAnalyisParameter) Analysis(org.talend.dataquality.analysis.Analysis)

Example 8 with SchemaIndicator

use of org.talend.dataquality.indicators.schema.SchemaIndicator in project tdq-studio-se by Talend.

the class AbstractSchemaEvaluator method evalSchemaIndic.

/**
 * DOC scorreia Comment method "evalSchemaIndic".
 *
 * @param tdSchema
 * @param tableBuilder
 * @param tablePattern
 * @param ok
 * @throws SQLException
 */
protected void evalSchemaIndic(Schema tdSchema, ReturnCode ok) throws SQLException {
    // --- create SchemaIndicator for each catalog
    SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
    // MOD xqliu 2009-1-21 feature 4715
    DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
    this.evalSchemaIndicLow(null, schemaIndic, null, tdSchema, ok);
}
Also used : SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator)

Example 9 with SchemaIndicator

use of org.talend.dataquality.indicators.schema.SchemaIndicator in project tdq-studio-se by Talend.

the class ConnectionEvaluator method executeSqlQuery.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.indicators.Evaluator#executeSqlQuery(java.lang.String)
     * 
     * Note that the given statement is not used.
     */
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
    // assert this.getAnalyzedElements().size() == 1 : "Invalid number of analyzed elements: "
    // + this.getAnalyzedElements().size();
    ReturnCode ok = new ReturnCode(true);
    dataProvider = this.getDataManager();
    if (this.elementToIndicators.values().isEmpty()) {
        // $NON-NLS-1$
        String msg = Messages.getString("Evaluator.NoInidcator1");
        log.error(msg);
        ok.setReturnCode(msg, false);
        return ok;
    }
    elementIndics = this.elementToIndicators.values().iterator().next();
    if (elementIndics.isEmpty()) {
        // $NON-NLS-1$
        String msg = Messages.getString("Evaluator.NoInidcator2", dataProvider);
        log.error(msg);
        ok.setReturnCode(msg, false);
        return ok;
    }
    ConnectionIndicator connectionIndicator = getConnectionIndicator();
    this.resetCounts(connectionIndicator);
    List<Catalog> catalogs = ConnectionHelper.getCatalogs(dataProvider);
    if (isTos(dataProvider)) {
        cleanUpCatalog(catalogs);
    }
    if (this.getMonitor() != null) {
        this.getMonitor().beginTask("Analyze catalogs", 100);
    }
    int temp = 0;
    if (catalogs.isEmpty()) {
        // no catalog, only schemata
        List<Schema> schemata = ConnectionHelper.getSchema(dataProvider);
        // MOD yyi 2009-11-30 10187
        for (Schema tdSchema : schemata) {
            if (!checkSchema(tdSchema)) {
                // $NON-NLS-1$
                ok.setReturnCode(Messages.getString("Evaluator.schemaNotExist", tdSchema.getName()), false);
                return ok;
            }
        }
        // for (Schema tdSchema : schemata) {
        for (int i = 0; i < schemata.size(); i++) {
            Schema tdSchema = schemata.get(i);
            if (this.getMonitor() != null) {
                this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
            }
            evalSchemaIndic(tdSchema, ok);
            if (this.getMonitor() != null) {
                int current = (i + 1) * 100 / schemata.size();
                if (current > temp) {
                    this.getMonitor().worked(current - temp);
                    temp = current;
                }
            }
        }
    } else {
        // MOD yyi 2009-11-30 10187
        for (Catalog tdCatalog : catalogs) {
            if (!checkCatalog(tdCatalog.getName())) {
                // $NON-NLS-1$
                ok.setReturnCode(Messages.getString("Evaluator.catalogNotExist", tdCatalog.getName()), false);
                return ok;
            }
        }
        // for (Catalog tdCatalog : catalogs) {
        for (int i = 0; i < catalogs.size(); i++) {
            if (this.continueRun()) {
                Catalog tdCatalog = catalogs.get(i);
                String catName = tdCatalog.getName();
                if (this.getMonitor() != null) {
                    this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName)));
                }
                if (dbms().supportCatalogSelection()) {
                    try {
                        connection.setCatalog(catName);
                    } catch (SQLException e) {
                        // $NON-NLS-1$
                        log.warn("Exception while executing SQL query " + sqlStatement, e);
                    }
                }
                CatalogIndicator catalogIndic = SchemaFactory.eINSTANCE.createCatalogIndicator();
                // MOD xqliu 2009-1-21 feature 4715
                DefinitionHandler.getInstance().setDefaultIndicatorDefinition(catalogIndic);
                List<Schema> schemas = CatalogHelper.getSchemas(tdCatalog);
                if (schemas.isEmpty()) {
                    // no schema
                    evalCatalogIndic(catalogIndic, tdCatalog, ok);
                } else {
                    catalogIndic.setAnalyzedElement(tdCatalog);
                    // --- create SchemaIndicator for each pair of catalog schema
                    for (Schema tdSchema : schemas) {
                        if (this.continueRun()) {
                            if (this.getMonitor() != null) {
                                this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName) + ", " + Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
                            }
                            // --- create SchemaIndicator for each catalog
                            SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
                            // MOD xqliu 2009-1-21 feature 4715
                            DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
                            evalSchemaIndicLow(catalogIndic, schemaIndic, tdCatalog, tdSchema, ok);
                        }
                    }
                    catalogIndic.setSchemaCount(schemas.size());
                }
                if (this.getMonitor() != null) {
                    int current = (i + 1) * 100 / catalogs.size();
                    if (current > temp) {
                        this.getMonitor().worked(current - temp);
                        temp = current;
                    }
                }
            }
        }
        if (this.getMonitor() != null) {
            this.getMonitor().done();
        }
    }
    if (log.isDebugEnabled()) {
        printCounts(connectionIndicator);
    }
    return ok;
}
Also used : SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) Schema(orgomg.cwm.resource.relational.Schema) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) ConnectionIndicator(org.talend.dataquality.indicators.schema.ConnectionIndicator) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 10 with SchemaIndicator

use of org.talend.dataquality.indicators.schema.SchemaIndicator in project tdq-studio-se by Talend.

the class AbstractSchemaEvaluatorTest method testAddToConnectionIndicator2Parameters.

@Test
public /**
 * No mock. using  java reflect mechanism to set private variable.
 * @throws SQLException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws NoSuchMethodException
 * @throws IllegalArgumentException
 * @throws InvocationTargetException
 */
void testAddToConnectionIndicator2Parameters() throws SQLException, InstantiationException, IllegalAccessException, NoSuchFieldException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
    // 
    Connection dataProvider = ConnectionFactory.eINSTANCE.createConnection();
    ConnectionIndicator connectionIndicator = SchemaFactory.eINSTANCE.createConnectionIndicator();
    List<Indicator> indicators = new ArrayList<Indicator>();
    indicators.add(connectionIndicator);
    Class<ConnectionEvaluator> connEval = ConnectionEvaluator.class;
    ConnectionEvaluator instance = connEval.newInstance();
    // $NON-NLS-1$
    Field field = connEval.getDeclaredField("dataProvider");
    field.setAccessible(true);
    field.set(instance, dataProvider);
    // $NON-NLS-1$
    Field field2 = connEval.getDeclaredField("elementIndics");
    field2.setAccessible(true);
    field2.set(instance, indicators);
    SchemaIndicator schemaIndic1 = SchemaFactory.eINSTANCE.createSchemaIndicator();
    schemaIndic1.setTableCount(3);
    schemaIndic1.setViewCount(1);
    schemaIndic1.setTableRowCount(100L);
    SchemaIndicator schemaIndic2 = SchemaFactory.eINSTANCE.createSchemaIndicator();
    schemaIndic2.setTableCount(2);
    schemaIndic2.setViewCount(2);
    schemaIndic2.setTableRowCount(95L);
    CatalogIndicator catalogIndic = SchemaFactory.eINSTANCE.createCatalogIndicator();
    catalogIndic.setSchemaCount(2);
    for (int i = 0; i < 2; i++) {
        if (i == 0) {
            instance.addToConnectionIndicator(catalogIndic, schemaIndic1);
        } else {
            instance.addToConnectionIndicator(catalogIndic, schemaIndic2);
        }
    }
    assertEquals(connectionIndicator.getCatalogCount(), 1);
    assertEquals(connectionIndicator.getSchemaCount(), 2);
    assertEquals(connectionIndicator.getTableCount(), 5);
    assertEquals(connectionIndicator.getViewCount(), 3);
    assertEquals(connectionIndicator.getTableRowCount(), 195);
}
Also used : Field(java.lang.reflect.Field) SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) ConnectionIndicator(org.talend.dataquality.indicators.schema.ConnectionIndicator) CatalogIndicator(org.talend.dataquality.indicators.schema.CatalogIndicator) ConnectionIndicator(org.talend.dataquality.indicators.schema.ConnectionIndicator) SchemaIndicator(org.talend.dataquality.indicators.schema.SchemaIndicator) Indicator(org.talend.dataquality.indicators.Indicator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SchemaIndicator (org.talend.dataquality.indicators.schema.SchemaIndicator)12 Indicator (org.talend.dataquality.indicators.Indicator)6 CatalogIndicator (org.talend.dataquality.indicators.schema.CatalogIndicator)6 Schema (orgomg.cwm.resource.relational.Schema)6 ConnectionIndicator (org.talend.dataquality.indicators.schema.ConnectionIndicator)4 Catalog (orgomg.cwm.resource.relational.Catalog)4 ArrayList (java.util.ArrayList)3 Connection (org.talend.core.model.metadata.builder.connection.Connection)3 OverviewIndUIElement (org.talend.dataprofiler.core.model.OverviewIndUIElement)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)3 ReturnCode (org.talend.utils.sugars.ReturnCode)3 RepositoryNode (org.talend.repository.model.RepositoryNode)2 DataProvider (orgomg.cwm.foundation.softwaredeployment.DataProvider)2 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)2 Field (java.lang.reflect.Field)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1