Search in sources :

Example 46 with DatabaseConnectionItem

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

the class MetadataColumnComparator method getAllNamesByRepositoryNode.

/**
     * method "getTableNamesByRepositoryNode" get All Table Names in current RepositoryNode's DatabaseConnectionItem.
     * 
     * @param node current RepositoryNode
     * @return List :all Table Names.
     */
@SuppressWarnings("unchecked")
public static Map<String, List<String>> getAllNamesByRepositoryNode(RepositoryNode node) {
    Map<String, List<String>> allNames = new HashMap<String, List<String>>();
    DatabaseConnectionItem item = getItem(getRoot(node));
    DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    Set<MetadataTable> tablesFromEMF = ConnectionHelper.getTables(connection);
    boolean isOdbc = connection.getSID() == null || connection.getSID().length() == 0;
    String sid = isOdbc ? connection.getDatasourceName() : connection.getSID();
    for (MetadataTable table : tablesFromEMF) {
        String tableName = table.getSourceName();
        if (tableName != null && !"".equals(tableName)) {
            //$NON-NLS-1$
            List<String> columnNames = new ArrayList<String>();
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            tableName = "\"" + sid + "\".\"" + tableName + "\"";
            List<MetadataColumn> columns = table.getColumns();
            for (MetadataColumn column : columns) {
                String columnName = column.getOriginalField();
                if (columnName != null && !"".equals(columnName)) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$
                    columnName = tableName + ".\"" + columnName + "\"";
                    columnNames.add(columnName);
                }
            }
            allNames.put(tableName, columnNames);
        }
    }
    return allNames;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 47 with DatabaseConnectionItem

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

the class DBStructureComposite method updateStructureView.

/**
     * Updates the structure view to reflect the change of Repository View.
     * 
     * @see SQLBuilderDialog.repositoryChanged(RepositoryChangedEvent event)
     * @param event
     */
protected void updateStructureView(RepositoryChangedEvent event) {
    if (!isShowAllConnections) {
        DatabaseConnectionItem originalConnection = getDisplayedConnection();
        IRepositoryViewObject repositoryObject = event.getDelta().getRepositoryObject();
        if (repositoryObject != null) {
            DatabaseConnectionItem newConnection = (DatabaseConnectionItem) repositoryObject.getProperty().getItem();
            if (!originalConnection.getProperty().getId().equals(newConnection.getProperty().getId())) {
                return;
            }
            if (!originalConnection.getProperty().getLabel().equals(newConnection.getProperty().getLabel())) {
                String newRepositoryName = newConnection.getProperty().getLabel();
                this.builderDialog.getConnParameters().setRepositoryName(newRepositoryName);
                this.builderDialog.getConnParameters().setRepositoryId(newConnection.getProperty().getId());
            }
        }
    }
    ((DBTreeProvider) treeViewer.getContentProvider()).setInitialized(false);
    treeViewer.setInput(new RepositoryNode(null, null, ENodeType.SYSTEM_FOLDER));
    doExpand();
}
Also used : DBTreeProvider(org.talend.sqlbuilder.dbstructure.DBTreeProvider) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 48 with DatabaseConnectionItem

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

the class MetadataColumnComparator method getALLQueryLabels.

/**
     * dev Comment method "getALLQueryLabels".
     * 
     * @param repositoryNode current RepositoryNode.
     * @return all QueryLabels in Emf.
     */
@SuppressWarnings("unchecked")
public List<String> getALLQueryLabels(RepositoryNode repositoryNode) {
    List<String> allQueries = new ArrayList<String>();
    DatabaseConnectionItem item = getEMFItem(repositoryNode.getObject().getId());
    DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    QueriesConnection queriesConnection = connection.getQueries();
    if (queriesConnection != null) {
        List<Query> qs = queriesConnection.getQuery();
        for (Query q1 : qs) {
            allQueries.add(q1.getLabel());
        }
    }
    return allQueries;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 49 with DatabaseConnectionItem

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

the class RenameDriverJarPathForDBConnectionMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        Connection connection = ((DatabaseConnectionItem) item).getConnection();
        if (connection instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) connection;
            String oldJarPath = dbConn.getDriverJarPath();
            String newJarPath = null;
            try {
                if (oldJarPath != null && !"".equals(oldJarPath.trim())) {
                    //$NON-NLS-1$
                    IPath path = Path.fromOSString(oldJarPath);
                    if (path.isAbsolute()) {
                        newJarPath = path.lastSegment();
                    }
                }
                if (newJarPath != null) {
                    dbConn.setDriverJarPath(newJarPath);
                    ProxyRepositoryFactory.getInstance().save(item, true);
                    return ExecutionResult.SUCCESS_NO_ALERT;
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : IPath(org.eclipse.core.runtime.IPath) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 50 with DatabaseConnectionItem

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

the class RenameAccessDbVersionInConnection method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof DatabaseConnectionItem) {
        DatabaseConnectionItem connectionItem = (DatabaseConnectionItem) item;
        DatabaseConnection connection = (DatabaseConnection) connectionItem.getConnection();
        if (connection instanceof DatabaseConnection) {
            DatabaseConnection dbConnection = (DatabaseConnection) connection;
            if (EDatabaseTypeName.ACCESS.equals(EDatabaseTypeName.getTypeFromDbType(dbConnection.getDatabaseType()))) {
                boolean modified = false;
                if (EDatabaseVersion4Drivers.ACCESS_2003.getVersionValue().toUpperCase().equals(dbConnection.getDbVersionString())) {
                    dbConnection.setDbVersionString(EDatabaseVersion4Drivers.ACCESS_2003.getVersionValue());
                    modified = true;
                } else if (EDatabaseVersion4Drivers.ACCESS_2007.getVersionValue().toUpperCase().equals(dbConnection.getDbVersionString())) {
                    dbConnection.setDbVersionString(EDatabaseVersion4Drivers.ACCESS_2007.getVersionValue());
                    modified = true;
                }
                if (modified) {
                    try {
                        factory.save(item, true);
                        return ExecutionResult.SUCCESS_WITH_ALERT;
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    }
                }
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) 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