use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.
the class EMFRepositoryNodeManager method parseSqlStatement.
@SuppressWarnings("unchecked")
public List<IRepositoryNode> parseSqlStatement(String sql, RepositoryNode currRoot) throws Exception {
// inital the quote depence on the dbtype
IRepositoryViewObject rObject = currRoot.getObject();
DatabaseConnectionItem item = (DatabaseConnectionItem) rObject.getProperty().getItem();
DatabaseConnection dbConnection = (DatabaseConnection) item.getConnection();
String dbType = dbConnection.getDatabaseType();
leftDbQuote = TalendTextUtils.getQuoteByDBType(dbType, true);
rightDbQuote = TalendTextUtils.getQuoteByDBType(dbType, false);
sql = initSqlStatement(sql);
if (sql == null || "".equals(sql) || !sql.startsWith("select ")) {
//$NON-NLS-1$ //$NON-NLS-2$
return Collections.EMPTY_LIST;
}
List<String> tableNames = new ArrayList<String>();
List<String> columnsNames = new ArrayList<String>();
String[] cols = parseSqlToNameList(sql, tableNames, columnsNames);
List<IRepositoryNode> nodes = new ArrayList<IRepositoryNode>();
for (IRepositoryNode tableNode : currRoot.getChildren()) {
for (int i = 0; i < tableNames.size(); i++) {
//$NON-NLS-1$
String tableLabel = "";
if (tableNode.getObject() instanceof MetadataTableRepositoryObject) {
MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) tableNode.getObject();
tableLabel = object.getSourceName();
} else {
tableLabel = tableNode.getObject().getLabel();
}
boolean isNeed = false;
if (cols.length == 1 && cols[0].equals("*")) {
//$NON-NLS-1$
for (String string : tableNames) {
if (string.equals(tableLabel.toLowerCase())) {
nodes.add(tableNode);
isNeed = true;
}
}
}
if (tableLabel != null) {
for (String string : tableNames) {
if (string.equals(tableLabel.toLowerCase())) {
isNeed = true;
}
}
}
if (isNeed) {
for (IRepositoryNode colNode : tableNode.getChildren()) {
//$NON-NLS-1$
String collabel = "";
if (colNode.getObject() instanceof MetadataColumnRepositoryObject) {
MetadataColumnRepositoryObject object2 = (MetadataColumnRepositoryObject) colNode.getObject();
collabel = object2.getSourceName();
} else {
collabel = colNode.getObject().getLabel();
}
if (collabel != null) {
for (String string : columnsNames) {
if ((string.replaceAll("\\" + leftDbQuote, "").replaceAll("\\" + rightDbQuote, "")).equals(//$NON-NLS-1$ //$NON-NLS-2$
collabel.toLowerCase())) {
nodes.add(colNode);
}
// right bracket
if ((string.replaceAll("\\" + leftDbQuote, "").replaceAll("\\" + rightDbQuote, "")).equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
for (int j = 0; j < relations.size(); j++) {
String[] pks = relations.get(j);
String pk = pks[0];
String fk = pks[1];
boolean isSet = false;
if (pk.equals(collabel.toLowerCase())) {
isSet = true;
//$NON-NLS-1$
pk = tableLabel.toLowerCase() + "." + collabel.toLowerCase();
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (fk.equals(collabel.toLowerCase())) {
isSet = true;
//$NON-NLS-1$
fk = tableLabel.toLowerCase() + "." + collabel.toLowerCase();
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (pk.equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
//$NON-NLS-1$
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (fk.equals(tableLabel.toLowerCase() + "." + collabel.toLowerCase())) {
//$NON-NLS-1$
if (!nodes.contains(colNode)) {
nodes.add(colNode);
}
}
if (isSet) {
relations.set(j, new String[] { pk, fk });
}
}
}
}
}
}
}
}
return nodes;
}
use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.
the class EMFRepositoryNodeManager method getTables.
@SuppressWarnings("unchecked")
public List<MetadataTable> getTables(List<IRepositoryNode> nodes, List<MetadataColumn> selectedColumns) {
List<MetadataTable> tables = new ArrayList<MetadataTable>();
for (IRepositoryNode node : nodes) {
RepositoryNodeType type = SQLBuilderRepositoryNodeManager.getRepositoryType((RepositoryNode) node);
if (type == RepositoryNodeType.DATABASE) {
root = (RepositoryNode) node;
DatabaseConnection connection = (DatabaseConnection) SQLBuilderRepositoryNodeManager.getItem((RepositoryNode) node).getConnection();
for (MetadataTable table : ConnectionHelper.getTables(connection)) {
if (!tables.contains(table)) {
tables.add(table);
selectedColumns.addAll(table.getColumns());
}
}
// if database is selected , It does not need to check others.
break;
} else if (type == RepositoryNodeType.TABLE) {
MetadataTable table = ((MetadataTableRepositoryObject) node.getObject()).getTable();
if (!tables.contains(table)) {
tables.add(table);
selectedColumns.addAll(table.getColumns());
}
root = SQLBuilderRepositoryNodeManager.getRoot((RepositoryNode) node);
} else if (type == RepositoryNodeType.COLUMN) {
MetadataColumn column = ((MetadataColumnRepositoryObject) node.getObject()).getColumn();
if (!selectedColumns.contains(column)) {
selectedColumns.add(column);
}
MetadataTable table = column.getTable();
if (!tables.contains(table)) {
tables.add(table);
}
root = SQLBuilderRepositoryNodeManager.getRoot((RepositoryNode) node);
}
setRoot(null);
}
return tables;
}
use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.
the class StatusManagerSettingPage method expandSomeNodes.
private void expandSomeNodes(IProjectRepositoryNode root) {
if (root instanceof IProjectRepositoryNode) {
final IProjectRepositoryNode rootNode = root;
// metadata
IRepositoryNode metadataConNode = rootNode.getRootRepositoryNode(ERepositoryObjectType.METADATA);
if (metadataConNode != null) {
treeViewer.expandToLevel(metadataConNode, 1);
}
// code
IRepositoryNode codeNode = rootNode.getRootRepositoryNode(ERepositoryObjectType.CODE);
if (codeNode != null) {
treeViewer.expandToLevel(codeNode, 1);
}
}
}
use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.
the class JobExportAction method getProcesses.
private static List<ExportFileResource> getProcesses(Collection<? extends IRepositoryNode> nodes, String path) {
List<ExportFileResource> value = new ArrayList<ExportFileResource>();
for (IRepositoryNode node : nodes) {
if (node.getType() == ENodeType.SYSTEM_FOLDER || node.getType() == ENodeType.SIMPLE_FOLDER) {
value.addAll(getProcesses(node.getChildren(), node.getProperties(EProperties.LABEL).toString() + '/'));
}
if (node.getType() == ENodeType.REPOSITORY_ELEMENT) {
IRepositoryViewObject repositoryObject = node.getObject();
if (repositoryObject.getProperty().getItem() instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) repositoryObject.getProperty().getItem();
ExportFileResource resource = new ExportFileResource(processItem, path + processItem.getProperty().getLabel());
resource.setNode(node);
value.add(resource);
}
}
}
return value;
}
use of org.talend.repository.model.IRepositoryNode in project tdi-studio-se by Talend.
the class BuildJobManager method getProcesses.
private List<ProcessItem> getProcesses(List<? extends IRepositoryNode> nodes) {
List<ProcessItem> value = new ArrayList<ProcessItem>();
for (IRepositoryNode node : nodes) {
if (node.getType() == ENodeType.SYSTEM_FOLDER || node.getType() == ENodeType.SIMPLE_FOLDER) {
value.addAll(getProcesses(node.getChildren()));
}
if (node.getType() == ENodeType.REPOSITORY_ELEMENT) {
IRepositoryViewObject repositoryObject = node.getObject();
if (repositoryObject.getProperty().getItem() instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) repositoryObject.getProperty().getItem();
value.add(processItem);
}
}
}
return value;
}
Aggregations