Search in sources :

Example 1 with IMetadataConnection

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

the class MetadataColumnComparator method updatePackage.

private void updatePackage(IMetadataConnection metadataConnectionTemp) {
    if (metadataConnectionTemp == null) {
        return;
    }
    Driver derbyDriver = null;
    java.sql.Connection sqlConn = null;
    ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
    // get dbType before get connection so that the dbtype won't be null.TDI-18366
    String dbType = metadataConnectionTemp.getDbType();
    DatabaseConnection dbConn = (DatabaseConnection) metadataConnectionTemp.getCurrentConnection();
    List list = MetadataConnectionUtils.getConnection(metadataConnectionTemp);
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i) instanceof Driver) {
            String driverClass = metadataConnectionTemp.getDriverClass();
            if (MetadataConnectionUtils.isDerbyRelatedDb(driverClass, dbType)) {
                derbyDriver = (Driver) list.get(i);
            }
        }
        if (list.get(i) instanceof java.sql.Connection) {
            sqlConn = (java.sql.Connection) list.get(i);
        }
    }
    try {
        if (sqlConn != null) {
            DatabaseMetaData dm = null;
            // Added by Marvin Wang on Mar. 13, 2013 for loading hive jars dynamically, refer to TDI-25072.
            if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(dbType)) {
                dm = HiveConnectionManager.getInstance().extractDatabaseMetaData(metadataConnectionTemp);
            } else {
                dm = extractMeta.getDatabaseMetaData(sqlConn, dbType, false, metadataConnectionTemp.getDatabase());
            }
            MetadataFillFactory.getDBInstance().fillCatalogs(dbConn, dm, MetadataConnectionUtils.getPackageFilter(dbConn, dm, true));
            MetadataFillFactory.getDBInstance().fillSchemas(dbConn, dm, MetadataConnectionUtils.getPackageFilter(dbConn, dm, false));
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        if (sqlConn != null) {
            ConnectionUtils.closeConnection(sqlConn);
        }
        if (derbyDriver != null) {
            try {
                //$NON-NLS-1$
                derbyDriver.connect("jdbc:derby:;shutdown=true", null);
            } catch (SQLException e) {
            // exception of shutdown success. no need to catch.
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) Driver(java.sql.Driver) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) DatabaseMetaData(java.sql.DatabaseMetaData) SQLException(java.sql.SQLException) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with IMetadataConnection

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

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

Example 4 with IMetadataConnection

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

the class MetadataColumnComparator method getRepositoryNodeFromDB.

/**
     * method "getRepositoryNodeFromDB".
     * 
     * @param oldNode
     * @return
     */
@SuppressWarnings("unchecked")
public RepositoryNode getRepositoryNodeFromDB(RepositoryNode oldNode, String selectedContext) {
    DatabaseConnectionItem item = getItem(getRoot(oldNode));
    DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection, false, selectedContext);
    try {
        modifyOldRepositoryNode(connection, iMetadataConnection, oldNode);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return oldNode;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) SQLException(java.sql.SQLException) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 5 with IMetadataConnection

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

the class AbstractElementPropertySectionController method isConnectionExist.

protected boolean isConnectionExist() {
    ISQLBuilderService service = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ISQLBuilderService.class)) {
        service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
    }
    if (service == null) {
        return false;
    }
    if (contextManager != null && contextManager.getDefaultContext().getContextParameterList().size() != 0) {
        initConnectionParametersWithContext(elem, contextManager.getDefaultContext());
    }
    DatabaseConnection connection = service.createConnection(connParameters);
    if (connection != null) {
        IMetadataConnection metadataConnection = null;
        metadataConnection = ConvertionHelper.convert(connection);
        return checkExistConnections(metadataConnection);
    }
    return false;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService)

Aggregations

IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)38 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)27 SQLException (java.sql.SQLException)18 Connection (org.talend.core.model.metadata.builder.connection.Connection)14 ArrayList (java.util.ArrayList)12 List (java.util.List)7 MetadataFillFactory (org.talend.metadata.managment.model.MetadataFillFactory)7 ReturnCode (org.talend.utils.sugars.ReturnCode)7 Properties (java.util.Properties)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)6 DatabaseMetaData (java.sql.DatabaseMetaData)5 DBConnectionParameter (org.talend.dq.analysis.parameters.DBConnectionParameter)5 Shell (org.eclipse.swt.widgets.Shell)4 ErrorDialogWithDetailAreaAndContinueButton (org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton)4 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)4 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)3