use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataColumnComparator method fixedColumns.
/**
* fixed Column from EMF use Column From DataBase .
*
* @param columnsFromDB MetadataColumn from Database
* @param cloumnsFromEMF MetadataColumn from Emf
*/
private void fixedColumns(List<MetadataColumn> columnsFromDB, List<MetadataColumn> cloumnsFromEMF) {
for (MetadataColumn emf : cloumnsFromEMF) {
modifyOldOneColumnFromDB(columnsFromDB, emf);
}
while (!columnsFromDB.isEmpty()) {
MetadataColumn db = columnsFromDB.remove(0);
modifyOldOneColumnFromEMF(cloumnsFromEMF, db);
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataColumnComparator method getAllNamesByRepositoryNode.
/**
* method "getTableNamesByRepositoryNode" get All Table Names in current RepositoryNode's DatabaseConnectionItem.
*
* @param node current RepositoryNode
* @return List :all Table Names.
*/
@SuppressWarnings("unchecked")
public static Map<String, List<String>> getAllNamesByRepositoryNode(RepositoryNode node) {
Map<String, List<String>> allNames = new HashMap<String, List<String>>();
DatabaseConnectionItem item = getItem(getRoot(node));
DatabaseConnection connection = (DatabaseConnection) item.getConnection();
Set<MetadataTable> tablesFromEMF = ConnectionHelper.getTables(connection);
boolean isOdbc = connection.getSID() == null || connection.getSID().length() == 0;
String sid = isOdbc ? connection.getDatasourceName() : connection.getSID();
for (MetadataTable table : tablesFromEMF) {
String tableName = table.getSourceName();
if (tableName != null && !"".equals(tableName)) {
//$NON-NLS-1$
List<String> columnNames = new ArrayList<String>();
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
tableName = "\"" + sid + "\".\"" + tableName + "\"";
List<MetadataColumn> columns = table.getColumns();
for (MetadataColumn column : columns) {
String columnName = column.getOriginalField();
if (columnName != null && !"".equals(columnName)) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$
columnName = tableName + ".\"" + columnName + "\"";
columnNames.add(columnName);
}
}
allNames.put(tableName, columnNames);
}
}
return allNames;
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataColumnComparator method modifyOldRepositoryNode.
/**
* dev Comment method "modifyOldRepositoryNode".
*
* @param connection
* @param iMetadataConnection
*/
@SuppressWarnings("unchecked")
public void modifyOldRepositoryNode(DatabaseConnection connection, IMetadataConnection iMetadataConnection, RepositoryNode oldNode) throws Exception {
boolean status = new ManagerConnection().check(iMetadataConnection);
connection.setDivergency(!status);
if (status) {
// /Get MetadataTable From DB
List<MetadataTable> tablesFromDB = ExtractMetaDataFromDataBase.returnMetaTablesFormConnection(iMetadataConnection);
ExtractMetaDataUtils.getInstance().setReconnect(false);
// Get MetadataTable From EMF(Old RepositoryNode)
Set<MetadataTable> tablesetFromEMF = ConnectionHelper.getTables(connection);
List<MetadataTable> tablesFromEMF = new ArrayList<MetadataTable>();
tablesFromEMF.addAll(tablesetFromEMF);
if (oldNode.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.DATABASE) {
if (tablesFromEMF.size() < tablesFromDB.size()) {
modifyOldConnection(tablesFromEMF, iMetadataConnection, tablesFromDB, oldNode);
}
restoreConnection(connection, tablesFromEMF);
} else if (oldNode.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.TABLE) {
MetadataTable metadataTable = ((MetadataTableRepositoryObject) oldNode.getObject()).getTable();
modifyOldOneTableFromDB(tablesFromDB, metadataTable);
MetadataTable tableFromDB = null;
for (MetadataTable table : tablesFromDB) {
if (table.getSourceName().equals(metadataTable.getSourceName())) {
tableFromDB = table;
}
}
if (tableFromDB != null) {
List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, tableFromDB.getSourceName()));
fixedColumns(columnsFromDB, metadataTable.getColumns());
}
// for (MetadataColumn metadataColumn : (List<MetadataColumn>) metadataTable.getColumns()) {
// modifyOneColumnFromDB(iMetadataConnection, tablesFromDB, metadataColumn);
// }
restoreConnection(connection, tablesFromEMF);
} else if (oldNode.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.COLUMN) {
MetadataColumn metadataColumn = ((MetadataColumnRepositoryObject) oldNode.getObject()).getColumn();
modifyOneColumnFromDB(iMetadataConnection, tablesFromDB, metadataColumn);
}
} else {
Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
List<MetadataTable> tablesFromEMF = new ArrayList<MetadataTable>();
tablesFromEMF.addAll(tableset);
for (MetadataTable tableFromEMF : tablesFromEMF) {
List<MetadataColumn> columnsFromEMF = tableFromEMF.getColumns();
for (MetadataColumn column : columnsFromEMF) {
//$NON-NLS-1$
column.setOriginalField(" ");
column.setDivergency(true);
column.setSynchronised(false);
}
//$NON-NLS-1$
tableFromEMF.setSourceName(" ");
tableFromEMF.setDivergency(true);
}
}
ExtractMetaDataUtils.getInstance().setReconnect(true);
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataColumnComparator method modifyOneColumnFromDB.
/**
* dev Comment method "modifyOneColumnFromDB".
*
* @param iMetadataConnection
* @param tablesFromDB
* @param metadataColumn
*/
private void modifyOneColumnFromDB(IMetadataConnection iMetadataConnection, List<MetadataTable> tablesFromDB, MetadataColumn metadataColumn) {
MetadataTable tableFromDB = null;
for (MetadataTable table : tablesFromDB) {
if (table.getSourceName().equals(metadataColumn.getTable().getSourceName())) {
tableFromDB = table;
}
}
if (tableFromDB != null) {
List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, tableFromDB.getSourceName()));
modifyOldOneColumnFromDB(columnsFromDB, metadataColumn);
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tdi-studio-se by Talend.
the class MetadataColumnComparator method modifyOldConnection.
/**
* dev Comment method "ModifyOldConnection".
*
* @param tablesFromEMF
* @param iMetadataConnection
* @param tablesFromDB
*/
@SuppressWarnings("unchecked")
private void modifyOldConnection(List<MetadataTable> tablesFromEMF, IMetadataConnection iMetadataConnection, List<MetadataTable> tablesFromDB, RepositoryNode oldNode) {
for (MetadataTable tableFromDB : tablesFromDB) {
MetadataTable tableFromModel = null;
for (MetadataTable tableFromEMF : tablesFromEMF) {
// /Get MetadataColumn From EMF
if (tableFromDB.getSourceName().equals(tableFromEMF.getSourceName())) {
tableFromModel = tableFromEMF;
break;
}
}
if (tableFromModel != null) {
// /Get MetadataColumn from DB
List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, tableFromDB.getSourceName()));
List<MetadataColumn> columnsFromEMF = tableFromModel.getColumns();
fixedColumns(columnsFromDB, columnsFromEMF);
}
}
fixedTables(tablesFromDB, tablesFromEMF, iMetadataConnection, oldNode);
}
Aggregations