use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class SelectedCompareUIProvider method fillContextMenu.
@Override
public void fillContextMenu(IMenuManager menu) {
// TDQ-9394 hide all "Reload" menu.
if (!isShowMenu()) {
return;
}
if (isShowMenu()) {
return;
}
Iterator<?> iter = ((TreeSelection) this.getContext().getSelection()).iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (!(obj instanceof RepositoryNode)) {
return;
}
}
TreeSelection treeSelection = (TreeSelection) getContext().getSelection();
if (treeSelection == null) {
return;
}
Object firstElement = treeSelection.getFirstElement();
RepositoryNode rNode = (RepositoryNode) firstElement;
IFolder folder = WorkbenchUtils.getFolder(rNode);
IFolder metadataFolder = ResourceManager.getMetadataFolder();
if (!folder.getFullPath().toOSString().startsWith(metadataFolder.getFullPath().toOSString())) {
return;
}
Object[] selectedObj = treeSelection.toArray();
if (selectedObj.length < 2) {
return;
}
List<Object> objects = new ArrayList<Object>();
for (Object obj : selectedObj) {
Connection conn = getConnection(obj);
if (!MetadataConnectionUtils.isTDQSupportDBTemplate(conn)) {
return;
}
RepositoryNode node = (RepositoryNode) obj;
if (node instanceof DBConnectionRepNode) {
Property property = ((DBConnectionRepNode) node).getObject().getProperty();
DatabaseConnectionItem databaseConnectionItem = (DatabaseConnectionItem) property.getItem();
Connection databaseConnection = databaseConnectionItem.getConnection();
objects.add(databaseConnection);
} else if (node instanceof DBCatalogRepNode) {
Catalog catalog = ((DBCatalogRepNode) node).getCatalog();
objects.add(catalog);
} else if (node instanceof DBSchemaRepNode) {
Schema schema = ((DBSchemaRepNode) node).getSchema();
objects.add(schema);
} else if (node instanceof DBTableRepNode) {
TdTable tdTable = ((DBTableRepNode) node).getTdTable();
objects.add(tdTable);
} else if (node instanceof DBColumnRepNode) {
TdColumn tdColumn = ((DBColumnRepNode) node).getTdColumn();
objects.add(tdColumn);
}
}
// MOD yyi 2011-03-22 17871:hide compare action for flat file column
if (2 == objects.size()) {
selectionCompareAction.refreshSelectedObj(objects.get(0), objects.get(1));
menu.add(selectionCompareAction);
}
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class SubelementCompareAction method findMatchedModelElement.
/**
* DOC klliu Comment method "findMatchedModelElement". don't understand this method!!!
*
* @param parent
* @param similarElement
* @return
*/
private ModelElement findMatchedModelElement(EObject parent, EObject similarElement) {
if (parent instanceof Connection) {
if (similarElement instanceof Schema) {
Schema schema = (Schema) similarElement;
// Case of MS SQL Server.
if (selectedOjbect instanceof Catalog) {
// ??????
List<Schema> schemas = CatalogHelper.getSchemas((Catalog) selectedOjbect);
if (schemas != null && schemas.size() > 0) {
for (Schema tdSchema : schemas) {
if (tdSchema.getName().equalsIgnoreCase((schema).getName())) {
return tdSchema;
}
}
}
}
// case of MS SQL Server, Postgresql......
EObject eContainer = schema.eContainer();
if (eContainer != null && eContainer instanceof Catalog) {
List<Catalog> catalogs = ConnectionHelper.getCatalogs((Connection) parent);
for (Catalog catalog : catalogs) {
if (((Catalog) eContainer).getName().equals(catalog.getName())) {
List<Schema> schemas = CatalogHelper.getSchemas(catalog);
if (schemas != null && schemas.size() > 0) {
for (Schema tdSchema : schemas) {
if (tdSchema.getName().equalsIgnoreCase((schema).getName())) {
return tdSchema;
}
}
}
}
}
}
// Case of Oracle
List<Schema> schames = ConnectionHelper.getSchema((Connection) parent);
for (Schema schame : schames) {
if (schame.getName().equalsIgnoreCase((schema).getName())) {
return schame;
}
}
}
// Case of Mysql
if (similarElement instanceof Catalog) {
List<Catalog> catalogs = ConnectionHelper.getCatalogs((Connection) parent);
for (Catalog catalog : catalogs) {
if (catalog.getName().equalsIgnoreCase(((Catalog) similarElement).getName())) {
return catalog;
}
}
}
} else if (parent instanceof Package) {
// MOD klliu bug 15822 resolve proxy caused two Instance,so we must use one Instance
if (parent != null && parent.eIsProxy()) {
parent = EObjectHelper.resolveObject(parent);
}
// MOD mzhao bug 8581 2009-08-05
List<ColumnSet> columnSets = new ArrayList<ColumnSet>();
columnSets.addAll(PackageHelper.getTables((Package) parent));
columnSets.addAll(PackageHelper.getViews((Package) parent));
for (ModelElement columnSet : columnSets) {
if (((ColumnSet) columnSet).getName().equalsIgnoreCase(((ColumnSet) similarElement).getName())) {
return columnSet;
}
}
}
return null;
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class ModelElementEditonDistance method distance.
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.compare.match.eobject.EditionDistance#distance(org.eclipse.emf.compare.Comparison,
* org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
*/
@Override
public double distance(Comparison inProgress, EObject a, EObject b) {
boolean isSame = false;
if (a instanceof DatabaseConnection) {
return 0;
}
if (a instanceof Catalog && b instanceof Catalog) {
Catalog catalog1 = (Catalog) a;
Catalog catalog2 = (Catalog) b;
isSame = StringUtils.equalsIgnoreCase(catalog1.getName(), catalog2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof Schema && b instanceof Schema) {
Schema schema1 = (Schema) a;
Schema schema2 = (Schema) b;
isSame = StringUtils.equalsIgnoreCase(schema1.getName(), schema2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdTable && b instanceof TdTable) {
TdTable tdTable1 = (TdTable) a;
TdTable tdTable2 = (TdTable) b;
isSame = StringUtils.equalsIgnoreCase(tdTable1.getName(), tdTable2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdView && b instanceof TdView) {
TdView tdView1 = (TdView) a;
TdView tdView2 = (TdView) b;
isSame = StringUtils.equalsIgnoreCase(tdView1.getName(), tdView2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdColumn && b instanceof TdColumn) {
TdColumn tdColumn1 = (TdColumn) a;
TdColumn tdColumn2 = (TdColumn) b;
isSame = StringUtils.equalsIgnoreCase(tdColumn1.getName(), tdColumn2.getName()) && distance(inProgress, tdColumn1.getSqlDataType(), tdColumn2.getSqlDataType()) == 0;
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TaggedValue && b instanceof TaggedValue) {
TaggedValue taggedValue1 = (TaggedValue) a;
TaggedValue taggedValue2 = (TaggedValue) b;
isSame = StringUtils.equalsIgnoreCase(taggedValue1.getTag(), taggedValue2.getTag()) && StringUtils.equalsIgnoreCase(taggedValue1.getValue(), taggedValue2.getValue());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdExpression && b instanceof TdExpression) {
TdExpression tdExpression1 = (TdExpression) a;
TdExpression tdExpression2 = (TdExpression) b;
isSame = StringUtils.equalsIgnoreCase(tdExpression1.getLanguage(), tdExpression2.getLanguage()) && StringUtils.equalsIgnoreCase(tdExpression1.getBody(), tdExpression2.getBody());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdSqlDataType && b instanceof TdSqlDataType) {
TdSqlDataType tdExpression1 = (TdSqlDataType) a;
TdSqlDataType tdExpression2 = (TdSqlDataType) b;
isSame = StringUtils.equalsIgnoreCase(tdExpression1.getName(), tdExpression2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof MetadataColumn && b instanceof MetadataColumn) {
// Added yyin TDQ-8360
MetadataColumn metaColumn1 = (MetadataColumn) a;
MetadataColumn metaColumn2 = (MetadataColumn) b;
isSame = StringUtils.equalsIgnoreCase(metaColumn1.getLabel(), metaColumn2.getLabel());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof MetadataTable && b instanceof MetadataTable) {
MetadataTable mTable1 = (MetadataTable) a;
MetadataTable mTable2 = (MetadataTable) b;
isSame = StringUtils.equalsIgnoreCase(mTable1.getLabel(), mTable2.getLabel());
return isSame ? 0 : Double.MAX_VALUE;
}
return super.distance(inProgress, a, b);
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class RepositoryNodeHelper method getAnalyzeDataNames.
/**
* Get selected names and split with "/". .e.g,onnection/catalog/schema/table.
*
* @param columnNode
* @return
*/
public static String getAnalyzeDataNames(IRepositoryNode columnNode) {
ModelElement mod = RepositoryNodeHelper.getModelElementFromRepositoryNode(columnNode);
if (mod == null) {
return PluginConstant.EMPTY_STRING;
}
MetadataColumn metadataColumn = SwitchHelpers.METADATA_COLUMN_SWITCH.doSwitch(mod);
if (metadataColumn == null) {
return PluginConstant.EMPTY_STRING;
}
List<String> nameLs = new ArrayList<String>();
EObject eContainer = metadataColumn.eContainer();
MetadataTable mdTable = SwitchHelpers.METADATA_TABLE_SWITCH.doSwitch(eContainer);
if (mdTable != null) {
nameLs.add(mdTable.getLabel());
Package parentCatalogOrSchema = ColumnSetHelper.getParentCatalogOrSchema(mdTable);
Connection conn = null;
// DelimitedFile conn doesn't have Catalog and Schema.
if (parentCatalogOrSchema == null) {
conn = ConnectionHelper.getTdDataProvider(mdTable);
} else {
conn = ConnectionHelper.getTdDataProvider(parentCatalogOrSchema);
Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(parentCatalogOrSchema);
Catalog catalog = SwitchHelpers.CATALOG_SWITCH.doSwitch(parentCatalogOrSchema);
if (schema != null) {
nameLs.add(schema.getName());
catalog = CatalogHelper.getParentCatalog(schema);
if (catalog != null) {
nameLs.add(catalog.getName());
}
} else if (catalog != null) {
nameLs.add(catalog.getName());
}
}
if (conn != null) {
nameLs.add(conn.getName());
}
}
return sortNames(nameLs, PluginConstant.SLASH_STRING);
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class CatalogEvaluator method executeSqlQuery.
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
ReturnCode ok = new ReturnCode(true);
// --- preconditions
DataProvider 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;
}
Indicator[] indics = this.getAllIndicators();
if (indics.length == 0) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator2", dataProvider);
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
for (Indicator indicator : indics) {
CatalogIndicator catalogIndicator = DataqualitySwitchHelper.CATALOG_SWITCH.doSwitch(indicator);
if (catalogIndicator == null) {
continue;
}
Catalog catalog = (Catalog) catalogIndicator.getAnalyzedElement();
String catName = catalog.getName();
// MOD yyi 2009-11-30 10187
if (!checkCatalog(catName)) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.catalogNotExist", catName), false);
return ok;
}
// MOD qiongli 2012-8-9,Method 'Method not supported' not supported for HiveConnection
if (dbms().supportCatalogSelection()) {
connection.setCatalog(catName);
}
List<Schema> schemas = CatalogHelper.getSchemas(catalog);
if (schemas.isEmpty()) {
// no schema
evalCatalogIndic(catalogIndicator, catalog, ok);
} else {
catalogIndicator.setAnalyzedElement(catalog);
catalogIndicator.setSchemaCount(schemas.size());
// --- create SchemaIndicator for each pair of catalog schema
for (Schema tdSchema : schemas) {
// --- create SchemaIndicator for each catalog
SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
evalSchemaIndicLow(catalogIndicator, schemaIndic, catalog, tdSchema, ok);
}
}
}
return ok;
}
Aggregations