use of net.sourceforge.sqlexplorer.dbproduct.SQLConnection in project tdq-studio-se by Talend.
the class ConnectionsView method getSelectedUsers.
/**
* Returns a list of selected Users; if recurse is true, indirectly selected users are included also (eg a session's
* user)
*
* @param recurse
* @return Set of Users, never returns null
*/
public Set<User> getSelectedUsers(boolean recurse) {
IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
if (selection == null) {
return EMPTY_USERS;
}
LinkedHashSet<User> result = new LinkedHashSet<User>();
Iterator iter = selection.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof User) {
result.add((User) obj);
} else if (recurse) {
if (obj instanceof Alias) {
Alias alias = (Alias) obj;
result.addAll(alias.getUsers());
} else if (obj instanceof SQLConnection) {
SQLConnection connection = (SQLConnection) obj;
result.add(connection.getUser());
}
}
}
return result;
}
use of net.sourceforge.sqlexplorer.dbproduct.SQLConnection in project tdq-studio-se by Talend.
the class CloseAllConnectionsAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
boolean confirm = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.CONFIRM_BOOL_CLOSE_ALL_CONNECTIONS);
if (confirm) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getView().getSite().getShell(), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Title"), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Message"), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Toggle"), false, null, null);
if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.YES_ID)
SQLExplorerPlugin.getDefault().getPluginPreferences().setValue(IConstants.CONFIRM_BOOL_CLOSE_ALL_CONNECTIONS, false);
if (dialog.getReturnCode() != IDialogConstants.YES_ID)
return;
}
Set<SQLConnection> connections = getView().getSelectedConnections(true);
for (SQLConnection connection : connections) {
synchronized (connection) {
Session session = connection.getSession();
if (session != null) {
synchronized (session) {
if (!session.isConnectionInUse())
session.disposeConnection();
}
} else
connection.getUser().releaseFromPool(connection);
}
}
setEnabled(false);
getView().refresh();
}
use of net.sourceforge.sqlexplorer.dbproduct.SQLConnection in project tdq-studio-se by Talend.
the class AbstractSQLFolderNode method loadChildren.
public final void loadChildren() {
SQLConnection connection = null;
ResultSet rs = null;
Statement stmt = null;
PreparedStatement pStmt = null;
int timeOut = SQLExplorerPlugin.getDefault().getPluginPreferences().getInt(IConstants.INTERACTIVE_QUERY_TIMEOUT);
try {
connection = getSession().grabConnection();
Object[] params = getSQLParameters();
if (params == null || params.length == 0) {
// use normal statement
stmt = connection.createStatement();
stmt.setQueryTimeout(timeOut);
rs = stmt.executeQuery(getSQL());
} else {
// use prepared statement
pStmt = connection.prepareStatement(getSQL());
pStmt.setQueryTimeout(timeOut);
for (int i = 0; i < params.length; i++) {
if (params[i] instanceof String) {
pStmt.setString(i + 1, (String) params[i]);
} else if (params[i] instanceof Integer) {
pStmt.setInt(i + 1, ((Integer) params[i]).intValue());
} else if (params[i] instanceof String) {
pStmt.setLong(i + 1, ((Long) params[i]).longValue());
}
}
rs = pStmt.executeQuery();
}
while (rs.next()) {
String name = rs.getString(1);
if (!isExcludedByFilter(name)) {
ObjectNode node = new ObjectNode(name, getChildType(), this, getImage());
addChildNode(node);
}
}
rs.close();
} catch (Exception e) {
SQLExplorerPlugin.error("Couldn't load children for: " + getName(), e);
} finally {
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Error closing result set", e);
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Error closing statement", e);
}
if (pStmt != null)
try {
pStmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Error closing statement", e);
}
if (connection != null)
getSession().releaseConnection(connection);
}
}
use of net.sourceforge.sqlexplorer.dbproduct.SQLConnection in project tdq-studio-se by Talend.
the class PreviewTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
int maxResults = SQLExplorerPlugin.getDefault().getPluginPreferences().getInt(IConstants.PRE_ROW_COUNT);
if (maxResults == 0) {
maxResults = 50;
}
SQLConnection connection = null;
Statement statement = null;
ResultSet resultSet = null;
DataSet dataSet = null;
try {
connection = tableNode.getSession().grabConnection();
statement = connection.createStatement();
statement.setMaxRows(maxResults);
// $NON-NLS-1$
statement.execute("select * from " + tableNode.getQualifiedName());
resultSet = statement.getResultSet();
dataSet = new DataSet(resultSet, null);
} finally {
if (resultSet != null)
try {
resultSet.close();
} catch (SQLException e) {
SQLExplorerPlugin.error(Messages.getString("DataSet.errorCloseRs"), e);
}
if (statement != null)
try {
statement.close();
} catch (SQLException e) {
SQLExplorerPlugin.error(Messages.getString("DataSet.errorCloseStmt"), e);
}
if (connection != null)
getNode().getSession().releaseConnection(connection);
}
return dataSet;
}
return null;
}
use of net.sourceforge.sqlexplorer.dbproduct.SQLConnection in project tdq-studio-se by Talend.
the class SQLEditor method onCloseEditor.
/**
* Called internally when the user tries to close the editor
*/
private void onCloseEditor() {
textEditor.getDocumentProvider().disconnect(getEditorInput());
textEditor.setInput(null);
clearResults();
// when close the SQLEditor, close the connection
if (session != null) {
List<SQLConnection> connections = session.getUser().getUnusedConnections();
for (SQLConnection sqlConn : connections) {
session.getUser().releaseFromPool(sqlConn);
}
}
// TDQ-5952~
}
Aggregations