Search in sources :

Example 1 with SQLExplorerPlugin

use of net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin in project tdq-studio-se by Talend.

the class SqlexplorerService method removeAliasInSQLExplorer.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataprofiler.service.ISqlexplorerService#removeAliasInSQLExplorer(orgomg.cwm.foundation.softwaredeployment
     * .DataProvider[])
     */
@Override
public void removeAliasInSQLExplorer(DataProvider... dataproviders) {
    SQLExplorerPlugin sqlPlugin = SQLExplorerPlugin.getDefault();
    AliasManager aliasManager = sqlPlugin.getAliasManager();
    DatabaseStructureView dsView = sqlPlugin.findDatabaseStructureView();
    // alias from propertyFile map at the same time.
    try {
        Collection<Alias> aliases = aliasManager.getAliases();
        if (aliases.isEmpty()) {
            return;
        }
        for (DataProvider dataProvider : dataproviders) {
            String aliasName = dataProvider.getName();
            if (null == aliasName) {
                continue;
            }
            Alias alias = aliasManager.getAlias(aliasName);
            if (alias != null) {
                sqlPlugin.getPropertyFile().remove(alias);
                aliasManager.removeAlias(aliasName);
            }
            // if the ctabItem is open,close it.
            if (dsView != null) {
                dsView.closeCurrentCabItem(aliasName);
            }
        }
    } catch (Exception e) {
        log.error(e, e);
    }
    aliasManager.modelChanged();
}
Also used : DataProvider(orgomg.cwm.foundation.softwaredeployment.DataProvider) AliasManager(net.sourceforge.sqlexplorer.dbproduct.AliasManager) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SQLExplorerPlugin(net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException)

Example 2 with SQLExplorerPlugin

use of net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin in project tdq-studio-se by Talend.

the class SqlexplorerService method updateDriverIfClassNotLoad.

/**
 * if the sqlexplorer driver is unRegisted,load the driver jar by lib manage system.
 *
 * @param sqlPlugin
 * @param connection
 * @param databaseConnection
 */
public void updateDriverIfClassNotLoad(DatabaseConnection databaseConnection) {
    SQLExplorerPlugin sqlPlugin = SQLExplorerPlugin.getDefault();
    DriverManager driverManager = sqlPlugin.getDriverModel();
    String driverClassName = JavaSqlFactory.getDriverClass(databaseConnection);
    if (driverClassName != null) {
        String id = AliasAndManaDriverHelper.getInstance().joinManagedDriverId(databaseConnection);
        ManagedDriver manDr = driverManager.getDriver(id);
        if (manDr != null && !manDr.isDriverClassLoaded()) {
            loadDriverByLibManageSystem(databaseConnection);
        }
    }
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) SQLExplorerPlugin(net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)

Example 3 with SQLExplorerPlugin

use of net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin in project tdq-studio-se by Talend.

the class SqlexplorerService method updateConnetionAliasByName.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.dataprofiler.service.ISqlexplorerService#updateConnetionAliasByName(org.talend.core.model.metadata.
     * builder.connection.Connection, java.lang.String)
     */
@Override
public void updateConnetionAliasByName(Connection connection, String aliasName) {
    if (connection == null || aliasName == null) {
        return;
    }
    SQLExplorerPlugin sqlPlugin = SQLExplorerPlugin.getDefault();
    // if the ctabItem is open,close it.
    DatabaseStructureView view = sqlPlugin.findDatabaseStructureView();
    if (view != null) {
        view.closeCurrentCabItem(aliasName);
    }
    AliasManager aliasManager = sqlPlugin.getAliasManager();
    Alias alias = aliasManager.getAlias(aliasName);
    if (alias != null) {
        try {
            aliasManager.removeAlias(aliasName);
            addConnetionAliasToSQLPlugin(connection);
        } catch (Exception e) {
            log.error(e, e);
        }
    }
}
Also used : AliasManager(net.sourceforge.sqlexplorer.dbproduct.AliasManager) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SQLExplorerPlugin(net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException)

Example 4 with SQLExplorerPlugin

use of net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin in project tdq-studio-se by Talend.

the class URLUtil method init.

private static void init() {
    SQLExplorerPlugin defaultPlugin = SQLExplorerPlugin.getDefault();
    baseURL = defaultPlugin.getBundle().getEntry("/");
    initialized = true;
}
Also used : SQLExplorerPlugin(net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)

Example 5 with SQLExplorerPlugin

use of net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin in project tdq-studio-se by Talend.

the class SqlexplorerService method getDriver.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.service.ISqlexplorerService#getDriver(java.lang.String, java.lang.String)
     */
@Override
public Driver getDriver(String driverClassName, String jarsPath) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    Driver driver = null;
    if (StringUtils.isNotEmpty(jarsPath)) {
        try {
            driver = this.createGenericJDBC(jarsPath, driverClassName);
        } catch (Exception e) {
            log.error(e, e);
        }
        return driver;
    }
    SQLExplorerPlugin sqlExplorerPlugin = SQLExplorerPlugin.getDefault();
    if (sqlExplorerPlugin != null) {
        net.sourceforge.sqlexplorer.dbproduct.DriverManager driverModel = sqlExplorerPlugin.getDriverModel();
        try {
            Collection<ManagedDriver> drivers = driverModel.getDrivers();
            for (ManagedDriver managedDriver : drivers) {
                LinkedList<String> jars = managedDriver.getJars();
                List<URL> urls = new ArrayList<URL>();
                for (int i = 0; i < jars.size(); i++) {
                    File file = new File(jars.get(i));
                    if (file.exists()) {
                        urls.add(file.toURI().toURL());
                    }
                }
                if (!urls.isEmpty()) {
                    try {
                        MyURLClassLoader cl;
                        cl = new MyURLClassLoader(urls.toArray(new URL[0]));
                        Class<?> clazz = cl.findClass(driverClassName);
                        if (clazz != null) {
                            driver = (Driver) clazz.newInstance();
                            if (driver != null) {
                                return driver;
                            }
                        }
                    } catch (ClassNotFoundException e) {
                    // do nothings
                    }
                }
            }
        } catch (MalformedURLException e) {
        // do nothings
        }
    }
    if (driver == null) {
        driver = (Driver) Class.forName(driverClassName).newInstance();
    }
    return driver;
}
Also used : MalformedURLException(java.net.MalformedURLException) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) ArrayList(java.util.ArrayList) MyURLClassLoader(net.sourceforge.sqlexplorer.util.MyURLClassLoader) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) Driver(java.sql.Driver) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SQLExplorerPlugin(net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)

Aggregations

SQLExplorerPlugin (net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)7 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)4 AliasManager (net.sourceforge.sqlexplorer.dbproduct.AliasManager)4 MalformedURLException (java.net.MalformedURLException)3 DriverManager (net.sourceforge.sqlexplorer.dbproduct.DriverManager)3 ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)3 PartInitException (org.eclipse.ui.PartInitException)3 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)2 File (java.io.File)1 URL (java.net.URL)1 Driver (java.sql.Driver)1 ArrayList (java.util.ArrayList)1 User (net.sourceforge.sqlexplorer.dbproduct.User)1 AliasAndManaDriverHelper (net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper)1 MyURLClassLoader (net.sourceforge.sqlexplorer.util.MyURLClassLoader)1 IFile (org.eclipse.core.resources.IFile)1 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 DataProvider (orgomg.cwm.foundation.softwaredeployment.DataProvider)1