use of org.talend.core.model.metadata.builder.connection.MetadataTable 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.MetadataTable 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.MetadataTable 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);
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class MetadataColumnComparator method fixedTables.
/**
* fixed Table .
*
* @param metaFromDB MetadataTable from Database
* @param metaFromEMF MetadataTable from Emf
* @param iMetadataConnection contain Connection.
*/
@SuppressWarnings("unchecked")
private void fixedTables(List<MetadataTable> metaFromDB, List<MetadataTable> metaFromEMF, IMetadataConnection iMetadataConnection, RepositoryNode oldNode) {
List<MetadataTable> removeEmfDB = new ArrayList<MetadataTable>();
for (MetadataTable emf : metaFromEMF) {
boolean flag = modifyOldOneTableFromDB(metaFromDB, emf);
if (flag) {
removeEmfDB.add(emf);
}
}
for (MetadataTable metadataTable : removeEmfDB) {
if (metadataTable.getLabel() == null || "".equals(metadataTable.getLabel())) {
//$NON-NLS-1$
metaFromEMF.remove(metadataTable);
}
}
// }
int nbTables = 0;
while (!metaFromDB.isEmpty() && nbTables < 500) {
MetadataTable db = metaFromDB.remove(0);
modifyOldOneTableFromEMF(metaFromEMF, iMetadataConnection, db);
nbTables++;
}
}
use of org.talend.core.model.metadata.builder.connection.MetadataTable in project tdi-studio-se by Talend.
the class CreateJSONSchemaAction method doRun.
@Override
protected void doRun() {
if (repositoryNode == null) {
repositoryNode = getCurrentRepositoryNode();
}
JSONFileConnection connection = null;
MetadataTable metadataTable = null;
boolean creation = false;
if (repositoryNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
ERepositoryObjectType nodeType = (ERepositoryObjectType) repositoryNode.getProperties(EProperties.CONTENT_TYPE);
String metadataTableLabel = (String) repositoryNode.getProperties(EProperties.LABEL);
JSONFileConnectionItem item = null;
if (nodeType == ERepositoryObjectType.METADATA_CON_TABLE) {
item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
connection = (JSONFileConnection) item.getConnection();
metadataTable = TableHelper.findByLabel(connection, metadataTableLabel);
creation = false;
} else if (nodeType == JSONRepositoryNodeType.JSON) {
item = (JSONFileConnectionItem) repositoryNode.getObject().getProperty().getItem();
connection = (JSONFileConnection) item.getConnection();
metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
String nextId = ProxyRepositoryFactory.getInstance().getNextId();
metadataTable.setId(nextId);
metadataTable.setLabel(getStringIndexed(metadataTable.getLabel()));
RecordFile record = (RecordFile) ConnectionHelper.getPackage(connection.getName(), connection, RecordFile.class);
if (record != null) {
// hywang
PackageHelper.addMetadataTable(metadataTable, record);
} else {
RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
ConnectionHelper.addPackage(newrecord, connection);
PackageHelper.addMetadataTable(metadataTable, newrecord);
}
creation = true;
} else {
return;
}
initContextMode(item);
openJSONSchemaWizard(item, metadataTable, false, creation);
}
}
Aggregations