Search in sources :

Example 26 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class DatabaseTypeFilter method isSupportNode.

private boolean isSupportNode(IRepositoryNode node, String[] items) {
    if (filterItems == null) {
        return true;
    }
    List<String> asList = Arrays.asList(items);
    if (node.getObject() == null) {
        if (node.getType() == ENodeType.REFERENCED_PROJECT || node.getType() == ENodeType.SYSTEM_FOLDER) {
            return true;
        }
        if (node.getContentType() != null && node.getContentType().equals(ERepositoryObjectType.METADATA)) {
            return true;
        }
    } else {
        Item item = node.getObject().getProperty().getItem();
        if (item instanceof DatabaseConnectionItem) {
            DatabaseConnectionItem connItem = (DatabaseConnectionItem) item;
            DatabaseConnection connection = (DatabaseConnection) connItem.getConnection();
            if (connection != null) {
                String databaseType = connection.getDatabaseType();
                if (databaseType.equals(EDatabaseTypeName.ORACLEFORSID.getDisplayName())) {
                    databaseType = EDatabaseTypeName.ORACLEFORSID.getXmlName();
                } else if (databaseType.equals(EDatabaseTypeName.ORACLESN.getDisplayName())) {
                    databaseType = EDatabaseTypeName.ORACLESN.getXmlName();
                } else if (databaseType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
                    databaseType = EDatabaseTypeName.ORACLE_OCI.getXmlName();
                } else if (databaseType.equals(EDatabaseTypeName.MSSQL.getDisplayName())) {
                    // for component
                    databaseType = EDatabaseTypeName.MSSQL.getXmlName();
                } else {
                    databaseType = EDatabaseTypeName.getTypeFromDbType(databaseType).getProduct();
                }
                if (asList.contains(databaseType)) {
                    return true;
                }
            }
        } else if (item instanceof FolderItem) {
            return true;
        }
    }
    return false;
}
Also used : Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 27 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class EMFRepositoryNodeManager method getQueryByLabel.

/**
     * dev Comment method "getQueryByLabel".
     * 
     * @param node all repository node Type
     * @param label search query label
     * @return
     */
@SuppressWarnings("unchecked")
public Query getQueryByLabel(RepositoryNode node, String label) {
    root = null;
    if (node.getObjectType().equals(ERepositoryObjectType.METADATA_CON_QUERY)) {
        root = node.getParent().getParent();
    } else {
        root = SQLBuilderRepositoryNodeManager.getRoot(node);
    }
    if (root == null) {
        return null;
    }
    DatabaseConnectionItem item = SQLBuilderRepositoryNodeManager.getItem(root);
    DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    QueriesConnection queriesConnection = connection.getQueries();
    if (queriesConnection != null) {
        List<Query> queries = queriesConnection.getQuery();
        for (Query query : queries) {
            if (query.getLabel().equals(label)) {
                return query;
            }
        }
    }
    return null;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 28 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem 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;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject)

Example 29 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class MetadataColumnComparator method getEMFItem.

public static DatabaseConnectionItem getEMFItem(String id) {
    IRepositoryViewObject repositoryObject = DBTreeProvider.getMaps().get(id);
    DatabaseConnectionItem item = (DatabaseConnectionItem) repositoryObject.getProperty().getItem();
    return item;
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 30 with DatabaseConnectionItem

use of org.talend.core.model.properties.DatabaseConnectionItem in project tdi-studio-se by Talend.

the class MetadataColumnComparator method createNewRepositoryNode.

/**
     * dev Comment method "createNewRepositoryNode".
     * 
     * @param node
     * @param parameters
     * @param connection
     * @param iMetadataConnection
     * @return
     */
@SuppressWarnings("unchecked")
private RepositoryNode createNewRepositoryNode(RepositoryNode node, ConnectionParameters parameters, DatabaseConnection connection, IMetadataConnection iMetadataConnection) {
    ManagerConnection managerConnection = new ManagerConnection();
    boolean status = managerConnection.check(iMetadataConnection);
    connection.setDivergency(!status);
    ConnectionHelper.getTables(connection).clear();
    if (status) {
    // try {
    // List<MetadataTable> tablesFromDB = ExtractMetaDataFromDataBase.returnMetaTablesFormConnection(
    // iMetadataConnection, 500);
    // ExtractMetaDataUtils.getInstance().setReconnect(false);
    // for (MetadataTable table : tablesFromDB) {
    // List<MetadataColumn> columnsFromDB = new ArrayList<MetadataColumn>();
    // columnsFromDB.addAll(ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection,
    // table.getSourceName()));
    // table.getColumns().clear();
    // for (MetadataColumn column : columnsFromDB) {
    // column.setLabel(""); //$NON-NLS-1$
    // table.getColumns().add(column);
    // }
    // table.setLabel(""); //$NON-NLS-1$
    // ConnectionHelper.getTables(connection).add(table);
    // }
    // ExtractMetaDataUtils.getInstance().setReconnect(true);
    // } catch (Exception e) {
    // if (parameters != null) {
    // parameters.setConnectionComment(e.getMessage());
    // }
    // return null;
    // }
    } else {
        if (parameters != null) {
            parameters.setConnectionComment(managerConnection.getMessageException() == null ? "" : //$NON-NLS-1$
            managerConnection.getMessageException());
        }
    }
    DatabaseConnectionItem item = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
    Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
    connectionProperty.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
    connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
    //$NON-NLS-1$
    connectionProperty.setStatusCode("");
    item.setProperty(connectionProperty);
    // TDI-18665
    updatePackage(iMetadataConnection);
    DatabaseConnection dbConn = (DatabaseConnection) iMetadataConnection.getCurrentConnection();
    item.setConnection(dbConn);
    RepositoryObject object = new RepositoryObject(connectionProperty);
    //$NON-NLS-1$
    object.setLabel("");
    ItemState state = PropertiesFactory.eINSTANCE.createItemState();
    state.setDeleted(false);
    item.setState(state);
    if (node == null) {
        node = new RepositoryNode(null, null, ENodeType.SYSTEM_FOLDER);
    }
    RepositoryNode newNode = new RepositoryNode(object, node, ENodeType.SYSTEM_FOLDER);
    return newNode;
}
Also used : ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) SqlBuilderRepositoryObject(org.talend.sqlbuilder.dbstructure.SqlBuilderRepositoryObject) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) MetadataColumnRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataColumnRepositoryObject) ItemState(org.talend.core.model.properties.ItemState) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Property(org.talend.core.model.properties.Property) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)50 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)40 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)23 PersistenceException (org.talend.commons.exception.PersistenceException)16 Connection (org.talend.core.model.metadata.builder.connection.Connection)13 Item (org.talend.core.model.properties.Item)13 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 ArrayList (java.util.ArrayList)11 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)11 IElementParameter (org.talend.core.model.process.IElementParameter)10 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)9 Query (org.talend.core.model.metadata.builder.connection.Query)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 INode (org.talend.core.model.process.INode)7 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)6 ContextItem (org.talend.core.model.properties.ContextItem)6 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)6 Node (org.talend.designer.core.ui.editor.nodes.Node)6 List (java.util.List)5 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)5