Search in sources :

Example 11 with DatabaseConnection

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

the class SessionTreeNodeManager method getSessionTreeNode.

/**
     * Converts the DatabaseConnection to SessionTreeNode, and stores the SessionTreeNode.
     * 
     * @param repositoryNode RepositoryNode
     * @param selectedContext
     * @return SessionTreeNode
     */
public SessionTreeNode getSessionTreeNode(RepositoryNode repositoryNode, String selectedContext) throws Exception {
    // Gets the root RepositoryNode
    RepositoryNode root = getRoot(repositoryNode);
    // Gets the DatabaseConnection
    DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) root.getObject().getProperty().getItem()).getConnection();
    if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connection.getDatabaseType())) {
        if (connection.getURL().lastIndexOf("=") != connection.getURL().length() - 1) {
            //$NON-NLS-1$
            connection.setDatasourceName(connection.getURL().substring(connection.getURL().lastIndexOf(File.separator) + 1, connection.getURL().length()));
            connection.setSID(connection.getURL().substring(connection.getURL().lastIndexOf(File.separator) + 1, connection.getURL().length()));
        }
    }
    SessionTreeNode sessionTreeNode = map.get(connection);
    // hyWang modified for bug 0007062
    if (sessionTreeNode != null && !sessionTreeNode.isConnectionClosed()) {
        return sessionTreeNode;
    }
    // If the node is not existent,creates one and cache it.
    sessionTreeNode = SessionTreeNodeUtils.getSessionTreeNode(connection, root, selectedContext);
    map.put(connection, sessionTreeNode);
    return sessionTreeNode;
}
Also used : SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 12 with DatabaseConnection

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

the class CatalogNode method getSchemaName.

/**
     * @return SchemaName.
     */
public String getSchemaName() {
    DatabaseConnection databaseConnection = getSession().getDatabaseConnection();
    if (databaseConnection == null) {
        return null;
    }
    String schema = databaseConnection.getUiSchema();
    if (schema != null && schema.length() == 0) {
        return null;
    }
    return ExtractMetaDataUtils.getInstance().getSchema();
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 13 with DatabaseConnection

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

the class SQLBuilderDialog method shutDownDb.

private void shutDownDb(DatabaseConnection databaseConnection) {
    IMetadataConnection iMetadataConnection = null;
    if (selectedContext == null) {
        selectedContext = databaseConnection.getContextName();
    }
    iMetadataConnection = ConvertionHelper.convert(databaseConnection, false, selectedContext);
    String dbType = iMetadataConnection.getDbType();
    String driverClassName = iMetadataConnection.getDriverClass();
    if (driverClassName.equals(EDatabase4DriverClassName.JAVADB_EMBEDED.getDriverClass()) || dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_DERBYCLIENT.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_JCCJDBC.getDisplayName()) || dbType.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName())) {
        String username = iMetadataConnection.getUsername();
        String pwd = iMetadataConnection.getPassword();
        String dbVersion = iMetadataConnection.getDbVersionString();
        String url = iMetadataConnection.getUrl();
        Connection connection = null;
        DriverShim wapperDriver = null;
        try {
            List list = ExtractMetaDataUtils.getInstance().connect(dbType, url, username, pwd, driverClassName, iMetadataConnection.getDriverJarPath(), dbVersion, iMetadataConnection.getAdditionalParams());
            if (list != null && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i) instanceof Connection) {
                        connection = (Connection) list.get(i);
                    }
                    if (list.get(i) instanceof DriverShim) {
                        wapperDriver = (DriverShim) list.get(i);
                    }
                }
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        } finally {
            try {
                // for derby
                if (wapperDriver != null) {
                    //$NON-NLS-1$
                    wapperDriver.connect("jdbc:derby:;shutdown=true", null);
                }
                if (connection != null) {
                    // for hsqldb in-process
                    ConnectionUtils.closeConnection(connection);
                }
            } catch (SQLException e) {
            // exception of shutdown success. no need to catch.
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) List(java.util.List) ArrayList(java.util.ArrayList) DriverShim(org.talend.core.model.metadata.builder.database.DriverShim) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException)

Example 14 with DatabaseConnection

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

the class SQLBuilderDialog method close.

@Override
public boolean close() {
    try {
        SqlBuilderPlugin.getDefault().getRepositoryService().removeRepositoryChangedListener(this);
        if (this.nodeInEditor != null) {
            RepositoryNode root = SQLBuilderRepositoryNodeManager.getRoot(this.nodeInEditor);
            if (root != null) {
                DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) root.getObject().getProperty().getItem()).getConnection();
                shutDownDb(connection);
            }
        }
        clean();
        SQLBuilderRepositoryNodeManager.removeAllRepositoryNodes();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        super.close();
    }
    return true;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException)

Example 15 with DatabaseConnection

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

the class MetadataColumnComparator method saveEMFMetadataColumn.

@SuppressWarnings("unchecked")
private static void saveEMFMetadataColumn(String id, List<MetadataColumn> columnNodes) {
    DatabaseConnectionItem item = getEMFItem(id);
    final DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
    Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
    List<MetadataTable> tables = new ArrayList<MetadataTable>();
    tables.addAll(tableset);
    List<MetadataColumn> emfCols = new ArrayList<MetadataColumn>();
    List<MetadataColumn> dbCols = new ArrayList<MetadataColumn>();
    for (MetadataColumn col : columnNodes) {
        for (MetadataTable table : tables) {
            if (table.getLabel().equals(col.getTable().getLabel())) {
                List<TdColumn> returnCols = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, table.getSourceName());
                for (MetadataColumn emfcolumn : table.getColumns()) {
                    for (MetadataColumn column : returnCols) {
                        if (emfcolumn.getLabel().equals(col.getLabel()) && column.getLabel().equals(col.getOriginalField())) {
                            emfCols.add(emfcolumn);
                            dbCols.add(column);
                        }
                    }
                }
            }
        }
    }
    saveOneMetadataColumn(emfCols, columnNodes, dbCols);
    saveMetaData(item);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14