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);
}
}
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);
}
}
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);
}
}
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);
}
}
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));
}
Aggregations