use of orgomg.cwm.resource.relational.Catalog in project tdi-studio-se by Talend.
the class MetadataColumnComparator method restoreConnection.
/**
* dev Comment method "restoreConnection".
*
* @param connection
* @param tablesFromEMF
*/
@SuppressWarnings("unchecked")
private void restoreConnection(DatabaseConnection connection, List<MetadataTable> tablesFromEMF) {
tablesFromEMF = sortTableColumn(tablesFromEMF);
// bug when do refresh twice it will add all tables
if (tList == null) {
tList = new ArrayList<MetadataTable>();
tList.addAll(ConnectionHelper.getTables(connection));
}
Catalog c = (Catalog) ConnectionHelper.getPackage(connection.getSID(), connection, Catalog.class);
Schema s = (Schema) ConnectionHelper.getPackage(connection.getSID(), connection, Schema.class);
Schema schema = (Schema) ConnectionHelper.getPackage(connection.getUiSchema(), connection, Schema.class);
if (c != null) {
PackageHelper.addMetadataTable(tablesFromEMF, c);
} else if (s != null) {
PackageHelper.addMetadataTable(tablesFromEMF, s);
} else if (schema != null) {
PackageHelper.addMetadataTable(tablesFromEMF, schema);
} else {
Schema defaultSchema = null;
List<Schema> schemas = ConnectionHelper.getSchema(connection);
if (schemas.size() > 0) {
for (Schema sch : schemas) {
if (" ".equals(sch.getName())) {
//$NON-NLS-1$
defaultSchema = sch;
break;
}
}
}
if (defaultSchema == null) {
//$NON-NLS-1$
defaultSchema = SchemaHelper.createSchema(" ");
ConnectionHelper.addSchema(defaultSchema, connection);
}
PackageHelper.addMetadataTable(tablesFromEMF, defaultSchema);
}
}
use of orgomg.cwm.resource.relational.Catalog in project tdi-studio-se by Talend.
the class MetadataColumnComparator method deleteNouseTables.
public void deleteNouseTables(Connection connection) {
if (!(connection instanceof DatabaseConnection)) {
return;
}
if (tList == null) {
return;
}
List<MetadataTable> tableList = new ArrayList<MetadataTable>(ConnectionHelper.getTables(connection));
tableList.removeAll(tList);
Catalog catalog = (Catalog) ConnectionHelper.getPackage(((DatabaseConnection) connection).getSID(), connection, Catalog.class);
Schema schema = (Schema) ConnectionHelper.getPackage(((DatabaseConnection) connection).getUiSchema(), connection, Schema.class);
String c = "";
String s = "";
if (catalog != null) {
c = catalog.getName();
}
if (schema != null) {
s = schema.getName();
}
ProjectNodeHelper.removeTablesFromCurrentCatalogOrSchema(c, s, (DatabaseConnection) connection, tableList);
tList = null;
}
use of orgomg.cwm.resource.relational.Catalog in project tdi-studio-se by Talend.
the class MergeTosMetadataMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ConnectionItem) {
try {
URI itemURI = getItemURI(item);
if (itemURI != null) {
URI itemResourceURI = getItemResourceURI(itemURI);
if (metadata400to410 == null) {
metadata400to410 = new TosMetadataMigrationFrom400to410();
}
Resource migratedResource = metadata400to410.migrate(itemResourceURI.toString(), new NullProgressMonitor());
HashMap<String, Object> xmlSaveOtions = XML_SAVE_OTIONS_1_0;
if (migratedResource != null) {
// check for DB connection caus we need to setup Schema and Catalog properly
EObject content = migratedResource.getContents().get(0);
if (content != null && "DatabaseConnection".equals(content.eClass().getName())) {
// resource is dynamic EMF so convert it to static model by serialising it and reloading it
ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
try {
// serialize into memory
try {
migratedResource.save(tempStream, XML_SAVE_OTIONS_1_0);
} catch (Exception e) {
// try with version 1.1
tempStream = new ByteArrayOutputStream();
xmlSaveOtions = XML_SAVE_OTIONS_1_1;
migratedResource.save(tempStream, xmlSaveOtions);
} finally {
tempStream.close();
}
// create a resource to laod the inmemory resource that should be a static EMF model
migratedResource = resourceSet.createResource(URI.createURI(//$NON-NLS-1$
"http://talend/dummy_static.metadata"));
migratedResource.load(new ByteArrayInputStream(tempStream.toByteArray()), xmlSaveOtions);
// check that DBConnection is firdt element
DatabaseConnection databaseConnection = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(migratedResource.getContents().get(0));
// do not check for null caus DB connection is already check above
String databaseType = databaseConnection.getDatabaseType();
databaseConnection.setDriverClass(ExtractMetaDataUtils.getInstance().getDriverClassByDbType(databaseType));
EDatabaseTypeName currentType = EDatabaseTypeName.getTypeFromDbType(databaseType);
EDatabaseSchemaOrCatalogMapping curCatalog = currentType.getCatalogMappingField();
EDatabaseSchemaOrCatalogMapping curSchema = currentType.getSchemaMappingField();
// all the DB connection are migrated with a Schema by default
if (!curCatalog.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
// we need to place the current schemas into a catalogs
ConnectionHelper.removeSchemas(schemas, databaseConnection);
for (Schema schema : schemas) {
// compute the name of the schema and the catalogs
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
String catalogName = computeCatalogName(databaseConnection, curCatalog);
schema.setName(schemaName);
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
// add the schema to the catalog and the the catalog to the connection
CatalogHelper.addSchemas(Collections.singleton(schema), catalog);
ConnectionHelper.addCatalog(catalog, databaseConnection);
}
} else {
// we need to replace the Schemas with a Catalogs
for (Schema schema : schemas) {
// compute the name the catalog
String catalogName = computeCatalogName(databaseConnection, curCatalog);
// use owned elements to get everything regardless of tables or views or
// else
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
catalog.getOwnedElement().addAll(schema.getOwnedElement());
ConnectionHelper.addCatalog(catalog, databaseConnection);
ConnectionHelper.removeSchemas(Collections.singleton(schema), databaseConnection);
}
}
} else if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
for (Schema schema : schemas) {
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
schema.setName(schemaName);
}
}
// else no catalog so we keep the schema as is
} catch (Exception e) {
// we have an exception finalising the migration but we trap it caus we still try to
// save it
log.error("Cannot complete merge metadata migration on file:" + itemResourceURI.toString(), e);
ExceptionHandler.process(e);
} finally {
tempStream.close();
}
}
// else not a DB connection so persist
OutputStream outputStream = item.eResource().getResourceSet().getURIConverter().createOutputStream(itemResourceURI, null);
try {
migratedResource.save(outputStream, xmlSaveOtions);
} finally {
outputStream.close();
}
}
return ExecutionResult.SUCCESS_WITH_ALERT;
}
} catch (ATLCoreException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (IOException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} finally {
resourceSet.getResources().clear();
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class OverviewResultPage method createResultSection.
@Override
protected void createResultSection(Composite parent) {
statisticalSection = this.createSection(form, parent, DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.statisticalinformations"), // $NON-NLS-1$
null);
Composite sectionClient = toolkit.createComposite(statisticalSection);
sectionClient.setLayout(new GridLayout());
catalogTableViewer = new TableViewer(sectionClient, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
Table catalogTable = catalogTableViewer.getTable();
TableUtils.addActionTooltip(catalogTable);
catalogTable.setHeaderVisible(true);
catalogTable.setBackgroundMode(SWT.INHERIT_FORCE);
catalogTable.setLinesVisible(true);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(catalogTable);
List<Catalog> catalogs = getCatalogs();
boolean containSubSchema = false;
for (Catalog catalog : catalogs) {
List<Schema> schemas = CatalogHelper.getSchemas(catalog);
if (schemas.size() > 0) {
containSubSchema = true;
break;
}
}
if (catalogs.size() > 0 && containSubSchema) {
createCatalogSchemaColumns(catalogTable);
provider = new CatalogSchemaViewerProvier();
addColumnSorters(catalogTableViewer, catalogTable.getColumns(), catalogWithSchemaSorters);
createSchemaTableViewer(sectionClient);
schemaTableViewer.addSelectionChangedListener(new DisplayTableAndViewListener());
catalogTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
StructuredSelection selection = (StructuredSelection) event.getSelection();
OverviewIndUIElement firstElement = (OverviewIndUIElement) selection.getFirstElement();
List<OverviewIndUIElement> cataUIEleList = new ArrayList<OverviewIndUIElement>();
if (firstElement != null) {
Indicator overviewIndicator = firstElement.getOverviewIndicator();
// selection.getFirstElement();
CatalogIndicator catalogIndicator = (CatalogIndicator) overviewIndicator;
// MOD qiongli bug 13093,2010-7-2,
// selection.getFirstElement();
currentCatalogIndicator = (SchemaIndicator) overviewIndicator;
// MOD xqliu 2009-11-30 bug 9114
if (catalogIndicator != null) {
EList<SchemaIndicator> schemaIndicators = catalogIndicator.getSchemaIndicators();
for (SchemaIndicator schemaIndicator : schemaIndicators) {
RepositoryNode schemaNode = RepositoryNodeHelper.recursiveFind(schemaIndicator.getAnalyzedElement());
OverviewIndUIElement cataUIEle = new OverviewIndUIElement();
cataUIEle.setNode(schemaNode);
cataUIEle.setOverviewIndicator(schemaIndicator);
cataUIEleList.add(cataUIEle);
}
schemaTableViewer.setInput(cataUIEleList);
schemaTableViewer.getTable().setVisible(true);
addColumnSorters(schemaTableViewer, schemaTableViewer.getTable().getColumns(), schemaSorters);
}
}
// ~
}
});
createContextMenuFor(schemaTableViewer);
} else {
if (catalogs.size() > 0) {
createCatalogTableColumns(catalogTable);
provider = new CatalogViewerProvier();
} else {
createSchemaTableColumns(catalogTable);
provider = new SchemaViewerProvier();
}
addColumnSorters(catalogTableViewer, catalogTable.getColumns(), schemaSorters);
catalogTableViewer.addSelectionChangedListener(new DisplayTableAndViewListener());
}
catalogTableViewer.setLabelProvider(provider);
catalogTableViewer.setContentProvider(provider);
doSetInput();
tableAndViewComposite = new Composite(sectionClient, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableAndViewComposite);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
layout.horizontalSpacing = 50;
tableAndViewComposite.setLayout(layout);
tableAndViewComposite.setVisible(false);
sectionClient.layout();
statisticalSection.setClient(sectionClient);
createContextMenuFor(catalogTableViewer);
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class OverviewResultPage method refreshSumSection.
/**
* DOC qzhang Comment method "refreshSumSection".
*
* @param summarySection
*/
private void refreshSumSection() {
fillDataProvider();
if (getTdDataProvider() == null) {
return;
}
if (sumSectionClient != null && !sumSectionClient.isDisposed()) {
Control[] children = sumSectionClient.getChildren();
for (Control control : children) {
control.dispose();
}
}
Composite leftComp = new Composite(sumSectionClient, SWT.NONE);
leftComp.setLayout(new GridLayout(2, false));
GridData subCompData = new GridData(GridData.FILL_HORIZONTAL);
subCompData.verticalAlignment = GridData.BEGINNING;
leftComp.setLayoutData(subCompData);
Composite rightComp = new Composite(sumSectionClient, SWT.NONE);
rightComp.setLayout(new GridLayout(2, false));
rightComp.setLayoutData(subCompData);
String connectionStr = JavaSqlFactory.getURL(getTdDataProvider());
Properties pameterProperties = SupportDBUrlStore.getInstance().getDBPameterProperties(connectionStr);
// $NON-NLS-1$
toolkit.createLabel(leftComp, DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.DBMS"));
// MOD TDQ-8539, find the db type from the connection, not from the properties file
toolkit.createLabel(leftComp, getDatabaseType(pameterProperties));
String serverName = JavaSqlFactory.getServerName(getTdDataProvider());
// $NON-NLS-1$
toolkit.createLabel(leftComp, DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.server"));
toolkit.createLabel(leftComp, serverName == null ? PluginConstant.EMPTY_STRING : serverName);
String port = JavaSqlFactory.getPort(getTdDataProvider());
// $NON-NLS-1$
toolkit.createLabel(leftComp, DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.port"));
toolkit.createLabel(leftComp, port == null ? PluginConstant.EMPTY_STRING : port);
String username = JavaSqlFactory.getUsername(getTdDataProvider());
// $NON-NLS-1$
toolkit.createLabel(leftComp, DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.connectAs"));
toolkit.createLabel(leftComp, username);
List<Catalog> tdCatalogs = getCatalogs();
// TDQ-6735 get the correct numbers of schema.
// MOD TDQ-8539 , get the schemas size
int schemaSize = masterPage.getSchamas(tdCatalogs);
toolkit.createLabel(leftComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.catalogs", PluginConstant.EMPTY_STRING));
toolkit.createLabel(leftComp, PluginConstant.EMPTY_STRING + tdCatalogs.size());
toolkit.createLabel(leftComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.schemata", PluginConstant.EMPTY_STRING));
toolkit.createLabel(leftComp, PluginConstant.EMPTY_STRING + schemaSize);
ExecutionInformations resultMetadata = masterPage.getCurrentModelElement().getResults().getResultMetadata();
toolkit.createLabel(rightComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.createionDate", PluginConstant.EMPTY_STRING));
toolkit.createLabel(rightComp, getFormatDateStr(masterPage.getCurrentModelElement().getCreationDate()));
toolkit.createLabel(rightComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("AbstractAnalysisResultPage.executionDate", PluginConstant.EMPTY_STRING));
toolkit.createLabel(rightComp, getFormatDateStr(resultMetadata.getExecutionDate()));
toolkit.createLabel(rightComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("AbstractAnalysisResultPage.executionDuration", PluginConstant.EMPTY_STRING));
// $NON-NLS-1$
toolkit.createLabel(rightComp, PluginConstant.EMPTY_STRING + resultMetadata.getExecutionDuration() / 1000.0d + "s");
String executeStatus = (resultMetadata.isLastRunOk() ? DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.success") : // $NON-NLS-1$ //$NON-NLS-2$
DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.failure", resultMetadata.getMessage()));
Label rightLabel = toolkit.createLabel(rightComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("AbstractAnalysisResultPage.executionStatus"));
int executionNumber = resultMetadata.getExecutionNumber();
if (!resultMetadata.isLastRunOk() && executionNumber != 0) {
rightLabel.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
}
rightLabel = toolkit.createLabel(rightComp, executionNumber == 0 ? PluginConstant.EMPTY_STRING : executeStatus);
toolkit.createLabel(rightComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("AbstractAnalysisResultPage.numberOfExecution", PluginConstant.EMPTY_STRING));
toolkit.createLabel(rightComp, PluginConstant.EMPTY_STRING + executionNumber);
toolkit.createLabel(rightComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("AbstractAnalysisResultPage.lastSucessfulExecution", PluginConstant.EMPTY_STRING));
toolkit.createLabel(rightComp, PluginConstant.EMPTY_STRING + resultMetadata.getLastExecutionNumberOk());
// MOD qiongli 2011-5-16
DataManager connection = masterPage.getCurrentModelElement().getContext().getConnection();
if (connection != null) {
RepositoryNode connNode = RepositoryNodeHelper.recursiveFind(connection);
if (connNode != null && connNode.getObject().isDeleted()) {
Label leftLabel = toolkit.createLabel(leftComp, // $NON-NLS-1$
DefaultMessagesImpl.getString("AbstractPagePart.LogicalDeleteWarn", connNode.getLabel()));
leftLabel.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
toolkit.createLabel(rightComp, PluginConstant.EMPTY_STRING);
toolkit.createLabel(rightComp, PluginConstant.EMPTY_STRING);
}
}
sumSectionClient.layout();
}
Aggregations