Search in sources :

Example 1 with DriverShim

use of org.talend.core.model.metadata.builder.database.DriverShim 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 2 with DriverShim

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

the class SQLExecution method doExecution.

protected void doExecution() throws Exception {
    final long startTime = System.currentTimeMillis();
    try {
        stmt = connection.createStatement();
        //$NON-NLS-1$
        setProgressMessage(Messages.getString("SQLResultsView.Executing"));
        stmt.setMaxRows(maxRows);
        if (isCancelled) {
            return;
        }
        boolean b = stmt.execute(sqlStatement);
        if (isCancelled) {
            closeStatement();
            return;
        }
        if (b) {
            final ResultSet rs = stmt.getResultSet();
            if (rs != null) {
                if (isCancelled) {
                    closeStatement();
                    return;
                }
                // create new dataset from results
                DataSet dataSet = new DataSet(null, rs, null);
                final long endTime = System.currentTimeMillis();
                // update sql result
                sqlResult.setDataSet(dataSet);
                sqlResult.setExecutionTimeMillis(endTime - startTime);
                closeStatement();
                if (isCancelled) {
                    return;
                }
                // show results..
                displayResults();
                // update text on editor
                composite.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                    }
                });
            }
        } else {
            // update text on editor
            composite.getDisplay().asyncExec(new Runnable() {

                public void run() {
                    // close tab
                    parentTab.dispose();
                }
            });
            closeStatement();
            if (isCancelled) {
                return;
            }
        }
        stmt = null;
    } catch (Exception e) {
        closeStatement();
        throw e;
    } finally {
        // bug 17980
        DriverShim wapperDriver = session.getWapperDriver();
        if (wapperDriver != null) {
            try {
                //$NON-NLS-1$
                wapperDriver.connect("jdbc:derby:;shutdown=true", null);
            } catch (SQLException e) {
            // exception of shutdown success. no need to catch.
            }
        }
    }
}
Also used : DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DriverShim(org.talend.core.model.metadata.builder.database.DriverShim) SQLException(java.sql.SQLException)

Example 3 with DriverShim

use of org.talend.core.model.metadata.builder.database.DriverShim in project tdq-studio-se by Talend.

the class ManagedDriver method instanceMSSqlJdbcDriver.

/**
 * use jtds SSO mode to connect sqlserver database, only allow to instance driver once.
 *
 * @param dbType
 * @param dbVersion
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
private void instanceMSSqlJdbcDriver(String dbType, String dbVersion) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    Map<String, DriverShim> driverCache = ExtractMetaDataUtils.getInstance().getDriverCache();
    if (driverCache.containsKey(EDatabase4DriverClassName.MSSQL.getDriverClass())) {
        DriverShim driverShim = driverCache.get(EDatabase4DriverClassName.MSSQL.getDriverClass());
        jdbcDriver = driverShim;
    } else {
        instanceJdbcDriver(dbType, dbVersion);
        if (jdbcDriver != null) {
            DriverShim driverShim = new DriverShim(jdbcDriver);
            ExtractMetaDataUtils.getInstance().setDriverCache(driverShim);
        }
    }
}
Also used : DriverShim(org.talend.core.model.metadata.builder.database.DriverShim)

Example 4 with DriverShim

use of org.talend.core.model.metadata.builder.database.DriverShim 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 5 with DriverShim

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

the class DbInfo method getConnFromNode.

private void getConnFromNode() {
    DriverShim wapperDriver = null;
    ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
    try {
        List list = null;
        if (dbType.equals(EDatabaseTypeName.GENERAL_JDBC.getDisplayName())) {
            list = extractMeta.connect(trueDBTypeForJDBC, url, username, pwd, driverClassName, driverJarPath, dbVersion, additionalParams);
        } else {
            // driverJarPath set to null,to reget driverJarPath
            driverJarPath = "";
            list = extractMeta.connect(dbType, url, username, pwd, driverClassName, driverJarPath, dbVersion, additionalParams);
        }
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i) instanceof Connection) {
                    conn = (Connection) list.get(i);
                }
                if (list.get(i) instanceof DriverShim) {
                    wapperDriver = (DriverShim) list.get(i);
                }
            }
        }
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    } finally {
        // bug 9162
        try {
            // if HSQLDB_IN_PROGRESS connection is not closed,HSQLDB_IN_PROGRESS can't open
            if (conn != null) {
                ConnectionUtils.closeConnection(conn);
            }
            if (wapperDriver != null && isJavaDB()) {
                //$NON-NLS-1$
                wapperDriver.connect("jdbc:derby:;shutdown=true", null);
            }
        } catch (SQLException e) {
        // exception of shutdown success. no need to catch.
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ExtractMetaDataUtils(org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils) List(java.util.List) DriverShim(org.talend.core.model.metadata.builder.database.DriverShim) SQLException(java.sql.SQLException)

Aggregations

DriverShim (org.talend.core.model.metadata.builder.database.DriverShim)5 SQLException (java.sql.SQLException)3 List (java.util.List)3 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 ISQLAlias (net.sourceforge.squirrel_sql.fw.sql.ISQLAlias)1 SQLConnection (net.sourceforge.squirrel_sql.fw.sql.SQLConnection)1 Point (org.eclipse.swt.graphics.Point)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 ExtractMetaDataUtils (org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils)1 DataSet (org.talend.sqlbuilder.dataset.dataset.DataSet)1 SessionTreeModel (org.talend.sqlbuilder.sessiontree.model.SessionTreeModel)1 SessionTreeNode (org.talend.sqlbuilder.sessiontree.model.SessionTreeNode)1