Search in sources :

Example 1 with SqlBuilderRepositoryObject

use of org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject in project tdi-studio-se by Talend.

the class GenerateSelectSQLAction method createColumnSelect.

/**
     * @return query string for full table select
     */
protected String createColumnSelect() {
    //$NON-NLS-1$
    StringBuffer query = new StringBuffer("select ");
    String fix = getPrePostfix(selectedNodes.get(0));
    String tablePrefix = getTablePrefix(selectedNodes.get(0));
    //$NON-NLS-1$
    String sep = "";
    //$NON-NLS-1$
    String table = "";
    for (int i = 0; i < selectedNodes.size(); i++) {
        RepositoryNode node = (RepositoryNode) selectedNodes.get(i);
        if (node.getParent() != ((RepositoryNode) selectedNodes.get(0)).getParent()) {
            continue;
        }
        if ((RepositoryNodeType) selectedNodes.get(0).getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.COLUMN) {
            if (table.length() == 0) {
                table = ((SqlBuilderRepositoryObject) node.getParent().getObject()).getSourceName();
            }
            String column = ((SqlBuilderRepositoryObject) node.getObject()).getSourceName();
            if (column == null || column.trim().equals("")) {
                //$NON-NLS-1$
                continue;
            }
            query.append(sep);
            query.append(fix + column + fix);
            //$NON-NLS-1$
            sep = ", ";
        }
    }
    //$NON-NLS-1$
    query.append(" from ");
    if (fix != null && !fix.trim().equals("")) {
        //$NON-NLS-1$
        if (tablePrefix == null || tablePrefix.equals("")) {
            //$NON-NLS-1$
            query.append(fix + table + fix);
        } else {
            //$NON-NLS-1$
            query.append(fix + tablePrefix + fix + "." + fix + table + fix);
        }
    } else {
        if (tablePrefix == null || tablePrefix.equals("")) {
            //$NON-NLS-1$
            query.append(table);
        } else {
            //$NON-NLS-1$
            query.append(tablePrefix + "." + table);
        }
    }
    return query.toString();
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject)

Example 2 with SqlBuilderRepositoryObject

use of org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject in project tdi-studio-se by Talend.

the class GenerateSelectSQLAction method createTableSelect.

/**
     * @return query string for full table select
     */
protected String createTableSelect() {
    RepositoryNode node = (RepositoryNode) selectedNodes.get(0);
    String fix = getPrePostfix(node);
    String tablePrefix = getTablePrefix(node);
    //$NON-NLS-1$
    StringBuffer query = new StringBuffer("select ");
    //$NON-NLS-1$
    String sep = "";
    EList columns = ((MetadataTableRepositoryObject) node.getObject()).getTable().getColumns();
    Iterator it = columns.iterator();
    if (columns.isEmpty()) {
        //$NON-NLS-1$
        query.append("*");
    }
    while (it.hasNext()) {
        String column = ((MetadataColumn) it.next()).getOriginalField();
        if (column == null || column.trim().equals("")) {
            //$NON-NLS-1$
            continue;
        }
        query.append(sep);
        query.append(fix + column + fix);
        //$NON-NLS-1$
        sep = ", ";
    }
    //$NON-NLS-1$
    query.append(" from ");
    if (fix != null && !fix.trim().equals("")) {
        //$NON-NLS-1$
        if (tablePrefix == null || tablePrefix.equals("")) {
            //$NON-NLS-1$
            query.append(fix + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName() + fix);
        } else {
            query.append(//$NON-NLS-1$
            fix + tablePrefix + fix + "." + fix + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName() + fix);
        }
    } else {
        if (tablePrefix == null || tablePrefix.equals("")) {
            //$NON-NLS-1$
            query.append(((SqlBuilderRepositoryObject) node.getObject()).getSourceName());
        } else {
            //$NON-NLS-1$
            query.append(tablePrefix + "." + ((SqlBuilderRepositoryObject) node.getObject()).getSourceName());
        }
    }
    return query.toString();
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject)

Aggregations

IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 RepositoryNode (org.talend.repository.model.RepositoryNode)2 SqlBuilderRepositoryObject (org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject)2 Iterator (java.util.Iterator)1 EList (org.eclipse.emf.common.util.EList)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1