Search in sources :

Example 16 with IMetadataConnection

use of org.talend.core.model.metadata.IMetadataConnection 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 17 with IMetadataConnection

use of org.talend.core.model.metadata.IMetadataConnection 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)

Example 18 with IMetadataConnection

use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.

the class EMFRepositoryNodeManager method getPKFromTables.

public List<String[]> getPKFromTables(List<MetadataTable> tables, String selectedContext) {
    List<String[]> fks = new ArrayList<String[]>();
    //$NON-NLS-1$
    String fk = "";
    //$NON-NLS-1$
    String pk = "";
    IMetadataConnection iMetadataConnection = null;
    if (root != null) {
        try {
            DatabaseConnection databaseConnection = (DatabaseConnection) SQLBuilderRepositoryNodeManager.getItem(root).getConnection();
            iMetadataConnection = ConvertionHelper.convert(databaseConnection, false, selectedContext);
            dbMetaData = rnmanager.getDatabaseMetaData(iMetadataConnection);
        } catch (final Exception e) {
            //$NON-NLS-1$
            final String mainMsg = Messages.getString("EMFRepositoryNodeManager.DBConnection.Text");
            Display.getDefault().syncExec(new Runnable() {

                /*
                     * (non-Javadoc)
                     * 
                     * @see java.lang.Runnable#run()
                     */
                @Override
                public void run() {
                    new ErrorDialogWidthDetailArea(new Shell(), SqlBuilderPlugin.PLUGIN_ID, mainMsg, e.getMessage());
                }
            });
        }
    }
    for (MetadataTable table : tables) {
        try {
            if (dbMetaData != null && table.getSourceName() != null) {
                ResultSet resultSet;
                if (dbMetaData.supportsSchemasInDataManipulation() && !"".equals(iMetadataConnection.getSchema())) {
                    // bug 0006949 added
                    if (dbMetaData.getCatalogs() != null) {
                        resultSet = dbMetaData.getExportedKeys(null, iMetadataConnection.getSchema(), table.getSourceName());
                    } else {
                        //$NON-NLS-1$
                        resultSet = dbMetaData.getExportedKeys("", iMetadataConnection.getSchema(), table.getSourceName());
                    }
                } else {
                    if (dbMetaData.getCatalogs() != null) {
                        resultSet = dbMetaData.getExportedKeys(null, iMetadataConnection.getSchema(), table.getSourceName());
                    } else {
                        //$NON-NLS-1$
                        resultSet = dbMetaData.getExportedKeys("", iMetadataConnection.getSchema(), table.getSourceName());
                    }
                }
                if (resultSet != null) {
                    ResultSetMetaData metadata = resultSet.getMetaData();
                    int[] relevantIndeces = new int[metadata.getColumnCount()];
                    for (int i = 1; i <= metadata.getColumnCount(); i++) {
                        relevantIndeces[i - 1] = i;
                    }
                    while (resultSet.next()) {
                        for (int relevantIndece : relevantIndeces) {
                            String key = metadata.getColumnName(relevantIndece);
                            if (key.toUpperCase().equals("FKCOLUMN_NAME")) {
                                //$NON-NLS-1$
                                fk += resultSet.getString(relevantIndece);
                            } else if (key.toUpperCase().equals("FKTABLE_NAME")) {
                                //$NON-NLS-1$
                                //$NON-NLS-1$
                                fk = resultSet.getString(relevantIndece) + ".";
                            } else if (key.toUpperCase().equals("PKCOLUMN_NAME")) {
                                //$NON-NLS-1$
                                //$NON-NLS-1$
                                pk = table.getSourceName() + "." + resultSet.getString(relevantIndece);
                            }
                        }
                        if (!"".equals(fk) && !"".equals(pk)) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            String[] strs = new String[2];
                            strs[0] = pk;
                            strs[1] = fk;
                            fks.add(strs);
                            //$NON-NLS-1$
                            fk = "";
                            //$NON-NLS-1$
                            pk = "";
                        }
                    }
                    resultSet.close();
                }
            }
        } catch (Exception e) {
            //$NON-NLS-1$
            SqlBuilderPlugin.log(Messages.getString("EMFRepositoryNodeManager.logMessage"), e);
        }
    }
    if (!relations.isEmpty()) {
        fks.addAll(relations);
        relations.clear();
    }
    return fks;
}
Also used : ArrayList(java.util.ArrayList) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ResultSetMetaData(java.sql.ResultSetMetaData) Shell(org.eclipse.swt.widgets.Shell) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ResultSet(java.sql.ResultSet) ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 19 with IMetadataConnection

use of org.talend.core.model.metadata.IMetadataConnection in project tdi-studio-se by Talend.

the class MetadataColumnComparator method getRepositoryNodeByBuildIn.

/**
     * dev Comment method "getRepositoryNodeByBuildIn".
     * 
     * @param node
     * @param parameters
     * @return
     */
@SuppressWarnings("unchecked")
public RepositoryNode getRepositoryNodeByBuildIn(RepositoryNode node, ConnectionParameters parameters) {
    DatabaseConnection connection = createConnection(parameters);
    if (connection == null) {
        return null;
    }
    IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
    RepositoryNode newNode = createNewRepositoryNode(node, parameters, connection, iMetadataConnection);
    return newNode;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Aggregations

IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)19 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)17 ArrayList (java.util.ArrayList)9 SQLException (java.sql.SQLException)8 List (java.util.List)6 Connection (org.talend.core.model.metadata.builder.connection.Connection)5 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)5 Shell (org.eclipse.swt.widgets.Shell)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 ErrorDialogWithDetailAreaAndContinueButton (org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)3 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)3 SQLBuilderDialog (org.talend.sqlbuilder.ui.SQLBuilderDialog)3 ResultSet (java.sql.ResultSet)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2