Search in sources :

Example 1 with ExplorerException

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

the class AliasManager method loadAliases.

/**
 * Loads Aliases from the users preferences
 */
public void loadAliases() throws ExplorerException {
    aliases.clear();
    try {
        SAXReader reader = new SAXReader();
        File file = new File(ApplicationFiles.USER_ALIAS_FILE_NAME);
        if (file.exists()) {
            Element root = reader.read(file).getRootElement();
            if (root.getName().equals("Beans")) {
                root = convertToV350(root);
            }
            List<Element> list = root.elements(Alias.ALIAS);
            // MOD mzhao bug:19539 Judge if the alias need to save again because it was not encripted in previouse
            // workspace. (before
            // 4.2)
            Boolean needToSave = false;
            if (list != null) {
                for (Element elem : list) {
                    Alias alias = new Alias(elem);
                    Boolean needToSaveUnit = getDecryptUser(alias.getDefaultUser());
                    if (!needToSave) {
                        needToSave = needToSaveUnit;
                    }
                    addAlias(alias);
                }
            }
            if (needToSave) {
                saveAliases();
            }
        // ~ 19539
        }
    } catch (DocumentException e) {
        throw new ExplorerException(e);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) SAXReader(org.dom4j.io.SAXReader) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) DocumentException(org.dom4j.DocumentException) File(java.io.File)

Example 2 with ExplorerException

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

the class DriverManager method loadDrivers.

/**
 * Loads drivers from the users preferences
 * @throws ExplorerException
 */
public void loadDrivers() throws ExplorerException {
    try {
        File file = new File(ApplicationFiles.USER_DRIVER_FILE_NAME);
        if (!file.exists()) {
            restoreDrivers();
            saveDrivers();
            return;
        }
        loadDrivers(new FileInputStream(file));
    } catch (IOException e) {
        throw new ExplorerException("Cannot load user drivers: " + e.getMessage(), e);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with ExplorerException

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

the class DriverManager method loadDrivers.

/**
 * Loads driver definition from a given location
 * @param input
 * @throws ExplorerException
 */
protected void loadDrivers(InputStream input) throws ExplorerException {
    try {
        SAXReader reader = new SAXReader();
        Document doc = reader.read(input);
        Element root = doc.getRootElement();
        if (root.getName().equals("Beans"))
            root = convertFromV3(root);
        for (Element driverElem : root.elements(DRIVER)) {
            ManagedDriver driver = new ManagedDriver(driverElem);
            addDriver(driver);
        }
    } catch (Exception e) {
        throw new ExplorerException(e);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) SAXReader(org.dom4j.io.SAXReader) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Document(org.dom4j.Document) IOException(java.io.IOException) ExplorerException(net.sourceforge.sqlexplorer.ExplorerException)

Example 4 with ExplorerException

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

the class XmlPreviewer method getXml.

private Element getXml(Object data) throws ExplorerException {
    try {
        if (data == null)
            return null;
        if (data instanceof XmlDataType)
            return ((XmlDataType) data).getRootElement();
        String text = data.toString();
        if (text == null)
            return null;
        SAXReader reader = new SAXReader();
        return reader.read(new StringReader(text)).getRootElement();
    } catch (DocumentException e) {
        throw new ExplorerException(e);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) XmlDataType(net.sourceforge.sqlexplorer.dataset.XmlDataType) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader)

Example 5 with ExplorerException

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

the class ManagedDriver method getConnection.

/**
 * Establishes a JDBC connection
 *
 * @param user
 * @return
 * @throws ExplorerException
 * @throws SQLException
 */
public SQLConnection getConnection(User user) throws SQLException {
    Properties props = new Properties();
    // jars(e.g:ojdbc14.jar) don't support international and cause to get connection error
    if (user.getUserName() != null) {
        // $NON-NLS-1$
        props.put("user", user.getUserName());
    }
    if (user.getPassword() != null) {
        // $NON-NLS-1$
        props.put("password", user.getPassword());
    }
    if (!isDriverClassLoaded()) {
        try {
            DatabaseConnection dbConn = user.getDatabaseConnection();
            if (dbConn != null) {
                registerSQLDriver(dbConn);
            }
        } catch (Exception e) {
            throw new SQLException(// $NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("ManagedDriver.CannotLoadDriver1", driverClassName) + " " + // $NON-NLS-1$
            Messages.getString("ManagedDriver.CannotLoadDriver2"));
        }
    }
    if (!isDriverClassLoaded()) {
        // $NON-NLS-1$
        throw new SQLException(Messages.getString("ManagedDriver.CannotLoadDriver1", driverClassName));
    }
    Connection jdbcConn = null;
    try {
        String dbUrl = user.getAlias().getUrl();
        if (ConnectionUtils.isHsql(dbUrl)) {
            dbUrl = ConnectionUtils.addShutDownForHSQLUrl(dbUrl, user.getDatabaseConnection().getAdditionalParams());
        }
        jdbcConn = jdbcDriver.connect(dbUrl, props);
    } catch (SQLException e) {
        throw new SQLCannotConnectException(user, e);
    }
    if (jdbcConn == null) {
        throw new SQLCannotConnectException(user);
    }
    return new SQLConnection(user, jdbcConn, this, getDatabaseProduct().describeConnection(jdbcConn));
}
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) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Properties(java.util.Properties) SQLException(java.sql.SQLException) ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) ValidationException(net.sourceforge.squirrel_sql.fw.persist.ValidationException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Aggregations

ExplorerException (net.sourceforge.sqlexplorer.ExplorerException)12 IOException (java.io.IOException)5 File (java.io.File)4 DefaultElement (org.dom4j.tree.DefaultElement)4 Element (org.dom4j.Element)3 SAXReader (org.dom4j.io.SAXReader)3 FileWriter (java.io.FileWriter)2 SQLException (java.sql.SQLException)2 ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)2 DocumentException (org.dom4j.DocumentException)2 OutputFormat (org.dom4j.io.OutputFormat)2 XMLWriter (org.dom4j.io.XMLWriter)2 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 DataSet (net.sourceforge.sqlexplorer.dataset.DataSet)1 XmlDataType (net.sourceforge.sqlexplorer.dataset.XmlDataType)1