Search in sources :

Example 6 with SessionTreeNode

use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.

the class ExportedKeysTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table.
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getExportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getExportedKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 7, 8, 9, 10, 11, 12, 13, 14 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 7 with SessionTreeNode

use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.

the class SessionTreeNodeUtils method getSessionTreeNode.

public static SessionTreeNode getSessionTreeNode(DatabaseConnection dbconnection, RepositoryNode repositoryNode, String selectedContext) throws Exception {
    // hyWang add for bug 0007014
    IMetadataConnection iMetadataConnection = null;
    iMetadataConnection = ConvertionHelper.convert(dbconnection, false, selectedContext);
    String url = dbconnection.getURL();
    if (url == null || url.equals("")) {
        url = iMetadataConnection.getUrl();
    }
    // bug 17980
    SQLConnection connection = null;
    DriverShim wapperDriver = null;
    List list = createSQLConnection(dbconnection, selectedContext, iMetadataConnection);
    if (list != null && list.size() > 0) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) instanceof SQLConnection) {
                connection = (SQLConnection) list.get(i);
            }
            if (list.get(i) instanceof DriverShim) {
                wapperDriver = (DriverShim) list.get(i);
            }
        }
    }
    ISQLAlias alias = createSQLAlias("Repository Name", url, dbconnection.getUsername(), //$NON-NLS-1$
    dbconnection.getRawPassword(), // fix bug for 7014,added by hyWang
    dbconnection.getSID() == null || dbconnection.getSID().length() == 0 ? (dbconnection.getDatasourceName() == null || //$NON-NLS-1$  
    dbconnection.getDatasourceName().length() == 0 ? //$NON-NLS-1$  
    "Database" : dbconnection.getDatasourceName()) : dbconnection.getSID());
    SessionTreeModel stm = new SessionTreeModel();
    SessionTreeNode session;
    if (wapperDriver != null && (iMetadataConnection.getDriverClass().equals(EDatabase4DriverClassName.JAVADB_EMBEDED.getDriverClass()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_DERBYCLIENT.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.JAVADB_JCCJDBC.getDisplayName()) || iMetadataConnection.getDbType().equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName()))) {
        session = stm.createSessionTreeNode(new SQLConnection[] { connection, connection }, alias, null, dbconnection.getRawPassword(), repositoryNode, wapperDriver);
    } else {
        session = stm.createSessionTreeNode(new SQLConnection[] { connection, connection }, alias, null, dbconnection.getRawPassword(), repositoryNode);
    }
    return session;
}
Also used : SQLConnection(net.sourceforge.squirrel_sql.fw.sql.SQLConnection) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ArrayList(java.util.ArrayList) List(java.util.List) DriverShim(org.talend.core.model.metadata.builder.database.DriverShim) SessionTreeModel(org.talend.sqlbuilder.sessiontree.model.SessionTreeModel) ISQLAlias(net.sourceforge.squirrel_sql.fw.sql.ISQLAlias)

Example 8 with SessionTreeNode

use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.

the class ColumnInfoTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table.
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getColumns(ti.getCatalogName(), ti.getSchemaName(), realTableName, //$NON-NLS-1$
            "%");
        } else {
            // https://jira.talendforge.org/browse/TDI-28578
            String tableName = ti.getSimpleName();
            if (tableName.contains("/")) {
                tableName = tableName.replaceAll("/", "//");
            }
            resultSet = node.getSession().getMetaData().getJDBCMetaData().getColumns(ti.getCatalogName(), ti.getSchemaName(), tableName, "%");
        // resultSet = node.getSession().getMetaData().getColumns(tableNode.getTableInfo());
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 9 with SessionTreeNode

use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.

the class IndexesTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table.
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getIndexInfo(ti.getCatalogName(), ti.getSchemaName(), realTableName, true, true);
        } else {
            resultSet = node.getSession().getMetaData().getIndexInfo((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 10 with SessionTreeNode

use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.

the class TableNode method isNodeSameToColumn.

/**
     * Check if ColumnNode and Column are the same.
     * 
     * @param node ColumnNode
     * @param column MetadataColumnImpl
     * @return isNodeSameToColumn
     * @exception
     */
private boolean isNodeSameToColumn(ColumnNode node, MetadataColumnImpl column) {
    SessionTreeNode sessionTreeNode = node.getSession();
    TableColumnInfo[] tableColumnInfo = null;
    try {
        tableColumnInfo = sessionTreeNode.getMetaData().getColumnInfo(ptableInfo);
    } catch (SQLException e) {
        SqlBuilderPlugin.log(e.getMessage(), e);
        return false;
    }
    // Retrive metadataColumns from Database
    IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
    List<TdColumn> metadataColumns = new ArrayList<TdColumn>();
    metadataColumns = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, getLabelText());
    Iterator iterate = metadataColumns.iterator();
    while (iterate.hasNext()) {
        MetadataColumn metadataColumn = (MetadataColumn) iterate.next();
        for (TableColumnInfo info : tableColumnInfo) {
            if (metadataColumn.getLabel().equals(node.getLabelText()) && info.getColumnName().equals(node.getLabelText())) {
                boolean divergency = isEquivalent(metadataColumn, column);
                metadataColumn.setDivergency(divergency);
                return divergency;
            }
        }
    }
    return true;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn) SQLException(java.sql.SQLException) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableColumnInfo(net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection)

Aggregations

SessionTreeNode (org.talend.sqlbuilder.sessiontree.model.SessionTreeNode)11 ResultSet (java.sql.ResultSet)7 ArrayList (java.util.ArrayList)5 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)5 DataSet (org.talend.sqlbuilder.dataset.dataset.DataSet)5 INode (org.talend.sqlbuilder.dbstructure.nodes.INode)5 TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)5 RepositoryNode (org.talend.repository.model.RepositoryNode)4 List (java.util.List)3 SQLConnection (net.sourceforge.squirrel_sql.fw.sql.SQLConnection)3 SessionTreeNodeManager (org.talend.sqlbuilder.dbstructure.SessionTreeNodeManager)3 QueryTokenizer (org.talend.sqlbuilder.util.QueryTokenizer)3 Statement (java.sql.Statement)2 Preferences (org.eclipse.core.runtime.Preferences)2 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)2 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 ISQLAlias (net.sourceforge.squirrel_sql.fw.sql.ISQLAlias)1 TableColumnInfo (net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1