Search in sources :

Example 1 with DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager in project tdq-studio-se by Talend.

the class SQLExplorerPlugin method start.

/**
 * Initialises the Plugin
 */
@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    this.bundleContext = context;
    try {
        getLog().addLogListener(new ILogListener() {

            @Override
            public void logging(IStatus status, String plugin) {
                Throwable t = status.getException();
                if (t != null) {
                    System.err.println(t.getMessage());
                    t.printStackTrace(System.err);
                }
            }
        });
        driverManager = new DriverManager();
        // MOD qiongli TDQ-8893.we will don't use the xml file to maintain the ManagedDrivers later.so no need to
        // laod or save the xml files.
        // driverManager.loadDrivers();
        aliasManager = new AliasManager();
        try {
            // $NON-NLS-1$
            resourceBundle = ResourceBundle.getBundle("net.sourceforge.sqlexplorer.test");
        } catch (MissingResourceException x) {
            resourceBundle = null;
        }
        // load SQL History from previous sessions
        _history = new SQLHistory();
    } catch (Exception e) {
        error("Exception during start", e);
        throw e;
    }
}
Also used : AliasManager(net.sourceforge.sqlexplorer.dbproduct.AliasManager) IStatus(org.eclipse.core.runtime.IStatus) MissingResourceException(java.util.MissingResourceException) ILogListener(org.eclipse.core.runtime.ILogListener) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) SQLHistory(net.sourceforge.sqlexplorer.history.SQLHistory) PartInitException(org.eclipse.ui.PartInitException) MissingResourceException(java.util.MissingResourceException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 2 with DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager 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 DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager in project tdq-studio-se by Talend.

the class SqlexplorerService method loadManagedDriver.

/**
 * Load the driver by lib management system , which will configure the SQL Explorer driver classpath from xml.
 *
 * @param dbType
 * @param dbVersion
 * @param driverClassName
 * @param userName. the userName is used a special case :it MSSQL with empty userName.
 */
private void loadManagedDriver(DatabaseConnection dbConn) {
    String dbType = dbConn.getDatabaseType();
    String dbVersion = dbConn.getDbVersionString();
    String driverClassName = JavaSqlFactory.getDriverClass(dbConn);
    if (dbType == null || driverClassName == null) {
        return;
    }
    DriverManager driverManager = SQLExplorerPlugin.getDefault().getDriverModel();
    AliasAndManaDriverHelper aliasManaHelper = AliasAndManaDriverHelper.getInstance();
    String manaDriverId = aliasManaHelper.joinManagedDriverId(dbType, driverClassName, dbVersion);
    ManagedDriver manDr = driverManager.getDriver(manaDriverId);
    if (manDr != null && !manDr.isDriverClassLoaded()) {
        // "librariesIndex.xml".
        try {
            List<String> jarNames = EDatabaseVersion4Drivers.getDrivers(dbType, dbVersion);
            if (jarNames.isEmpty() && "JDBC".equals(dbType)) {
                jarNames.add(dbConn.getDriverJarPath());
            }
            LinkedList<String> driverJarRealPaths = aliasManaHelper.getDriverJarRealPaths(jarNames);
            if (!driverJarRealPaths.isEmpty()) {
                manDr.getJars().clear();
                manDr.getJars().addAll(driverJarRealPaths);
            }
            manDr.registerSQLDriver(dbConn);
        } catch (Exception e) {
            log.error(e);
        }
    }
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) AliasAndManaDriverHelper(net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException)

Example 4 with DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager in project tdq-studio-se by Talend.

the class SqlexplorerService method needAddDriverConnection.

@Override
public boolean needAddDriverConnection(DatabaseConnection dbConn) {
    boolean isNeed = false;
    DriverManager driverManager = SQLExplorerPlugin.getDefault().getDriverModel();
    String id = AliasAndManaDriverHelper.getInstance().joinManagedDriverId(dbConn);
    ManagedDriver manDr = driverManager.getDriver(id);
    if (manDr == null) {
        isNeed = true;
    } else if (!manDr.isDriverClassLoaded()) {
        loadDriverByLibManageSystem(dbConn);
        if (!manDr.isDriverClassLoaded()) {
            isNeed = true;
        }
    }
    return isNeed;
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager)

Example 5 with DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager in project tdq-studio-se by Talend.

the class SqlexplorerService method addConnetionAliasToSQLPlugin.

@Override
public void addConnetionAliasToSQLPlugin(ModelElement... dataproviders) {
    SQLExplorerPlugin sqlPlugin = SQLExplorerPlugin.getDefault();
    AliasManager aliasManager = sqlPlugin.getAliasManager();
    DriverManager driverManager = sqlPlugin.getDriverModel();
    List<String> tdqSupportDBType = MetadataConnectionUtils.getTDQSupportDBTemplate();
    // if all dataproviders are not supported on DQ side,don't save files SQLAliases.xml and
    // SQLDrivers.xml.Otherwise,save it.
    AliasAndManaDriverHelper aliasManaDriverHelper = AliasAndManaDriverHelper.getInstance();
    for (ModelElement dataProvider : dataproviders) {
        try {
            Connection connection = SwitchHelpers.CONNECTION_SWITCH.doSwitch(dataProvider);
            // MOD bug mzhao filter the other connections except database connection.
            if (connection != null && connection instanceof DatabaseConnection) {
                // TDQ-8379 do nothing if the database type isn't supproted on DQ side.
                DatabaseConnection dbConn = ((DatabaseConnection) connection);
                String databaseType = dbConn.getDatabaseType();
                if (!tdqSupportDBType.contains(databaseType)) {
                    continue;
                }
                // only new Alias when it is not in aliasManager
                Alias alias = aliasManager.getAlias(dataProvider.getName());
                String url = JavaSqlFactory.getURL(connection);
                // if the alias is not null and the url is same with the connection, this means the alias is already
                // exist; if the alias is not null but hte url is not same with the connection, this means the
                // connection has been overwrite , need to rebuild the alias
                boolean aliasExist = alias != null && StringUtils.equals(url, alias.getUrl());
                if (!aliasExist) {
                    if (alias == null) {
                        alias = new Alias(dataProvider.getName());
                    }
                    String user = JavaSqlFactory.getUsername(connection);
                    // MOD gdbu 2011-3-17 bug 19539
                    String password = JavaSqlFactory.getPassword(connection);
                    // ~19539
                    // user should not be null
                    // $NON-NLS-1$
                    user = user == null ? "" : user;
                    // password should not be null
                    // $NON-NLS-1$
                    password = password == null ? "" : password;
                    // is serialized correctly.
                    assert user != null;
                    assert password != null;
                    User previousUser = new User(user, password);
                    previousUser.setDatabaseConnection(dbConn);
                    alias.setDefaultUser(previousUser);
                    alias.setAutoLogon(false);
                    alias.setConnectAtStartup(true);
                    alias.setUrl(url);
                    ManagedDriver manDr = aliasManaDriverHelper.getManaDriverByConnection(dbConn);
                    if (manDr == null) {
                        manDr = aliasManaDriverHelper.createNewManagerDriver(dbConn);
                        driverManager.addDriver(manDr);
                    } else if (!manDr.isDriverClassLoaded()) {
                        this.loadDriverByLibManageSystem(dbConn);
                    }
                    if (manDr != null) {
                        alias.setDriver(manDr);
                    }
                }
                if (!aliasManager.contains(alias) && alias.getName() != null) {
                    aliasManager.addAlias(alias);
                }
                // MOD Qiongli TDQ-6166 just put once for every Alias
                if (sqlPlugin.getPropertyFile().get(alias) == null) {
                    sqlPlugin.getPropertyFile().put(alias, getPropertyFile(dataProvider));
                }
                aliasManager.modelChanged();
            }
        } catch (Throwable e) {
            // MOD scorreia 2010-07-24 catch all exceptions
            log.error(e, e);
            continue;
        }
    }
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) AliasAndManaDriverHelper(net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper) 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) AliasManager(net.sourceforge.sqlexplorer.dbproduct.AliasManager) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) SQLExplorerPlugin(net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)

Aggregations

DriverManager (net.sourceforge.sqlexplorer.dbproduct.DriverManager)8 ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)7 AliasManager (net.sourceforge.sqlexplorer.dbproduct.AliasManager)2 SQLExplorerPlugin (net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)2 AliasAndManaDriverHelper (net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper)2 PartInitException (org.eclipse.ui.PartInitException)2 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)2 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 MissingResourceException (java.util.MissingResourceException)1 TreeSet (java.util.TreeSet)1 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)1 User (net.sourceforge.sqlexplorer.dbproduct.User)1 SQLHistory (net.sourceforge.sqlexplorer.history.SQLHistory)1 MyURLClassLoader (net.sourceforge.sqlexplorer.util.MyURLClassLoader)1 IFile (org.eclipse.core.resources.IFile)1