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);
}
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;
}
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);
}
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;
}
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);
}
Aggregations