use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class MetadataColumnComparator method saveEMFMetadataColumn.
@SuppressWarnings("unchecked")
private static void saveEMFMetadataColumn(String id, List<MetadataColumn> columnNodes) {
DatabaseConnectionItem item = getEMFItem(id);
final DatabaseConnection connection = (DatabaseConnection) item.getConnection();
IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
List<MetadataTable> tables = new ArrayList<MetadataTable>();
tables.addAll(tableset);
List<MetadataColumn> emfCols = new ArrayList<MetadataColumn>();
List<MetadataColumn> dbCols = new ArrayList<MetadataColumn>();
for (MetadataColumn col : columnNodes) {
for (MetadataTable table : tables) {
if (table.getLabel().equals(col.getTable().getLabel())) {
List<TdColumn> returnCols = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, table.getSourceName());
for (MetadataColumn emfcolumn : table.getColumns()) {
for (MetadataColumn column : returnCols) {
if (emfcolumn.getLabel().equals(col.getLabel()) && column.getLabel().equals(col.getOriginalField())) {
emfCols.add(emfcolumn);
dbCols.add(column);
}
}
}
}
}
}
saveOneMetadataColumn(emfCols, columnNodes, dbCols);
saveMetaData(item);
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class MetadataColumnComparator method isChangeElementColor.
/**
* dev Comment method "isChangeElementColor".
*
* @param node
* @return
*/
public boolean isChangeElementColor(RepositoryNode node) {
boolean flag = false;
Object type = node.getProperties(EProperties.CONTENT_TYPE);
if (type.equals(RepositoryNodeType.DATABASE)) {
return getItem(node).getConnection().isDivergency();
}
if (type.equals(RepositoryNodeType.TABLE)) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
MetadataTable table = object.getTable();
flag = table.getSourceName().equals(table.getLabel());
flag = flag && table.isDivergency();
}
return flag;
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable 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 org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class MetadataColumnComparator method isDiff.
/**
* dev Comment method "isDiff".
*
* @param node
* @return
*/
@SuppressWarnings("unchecked")
public boolean[] isDiff(RepositoryNode node) {
boolean isDiffDivergency = false;
boolean isDiffSyschronize = false;
boolean isDiffGray = false;
Object type = node.getProperties(EProperties.CONTENT_TYPE);
if (type.equals(RepositoryNodeType.DATABASE)) {
DatabaseConnection connection = (DatabaseConnection) getItem(node).getConnection();
Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
for (MetadataTable table : tables) {
List<MetadataColumn> columns = table.getColumns();
for (MetadataColumn column : columns) {
if (column.isDivergency()) {
isDiffDivergency = true;
}
if (column.isSynchronised()) {
isDiffSyschronize = true;
}
if (column.getLabel() == null || "".equals(column.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
if (table.isDivergency()) {
isDiffDivergency = true;
}
if (table.getLabel() == null || "".equals(table.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
} else if (type.equals(RepositoryNodeType.TABLE)) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
MetadataTable table = object.getTable();
List<MetadataColumn> columns = table.getColumns();
for (MetadataColumn column : columns) {
if (column.isDivergency()) {
isDiffDivergency = true;
}
if (column.isSynchronised()) {
isDiffSyschronize = true;
}
if (column.getLabel() == null || "".equals(column.getLabel())) {
//$NON-NLS-1$
isDiffGray = true;
}
}
if (table.isDivergency()) {
isDiffDivergency = true;
}
}
return new boolean[] { isDiffGray, isDiffDivergency, isDiffSyschronize };
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable 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;
}
Aggregations