use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.
the class FileListEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
// Configure the editor
setSite(site);
setInput(input);
// Create the text editor
editor = new TextEditor();
editor.init(site, input);
// Make sure we get notification that our editor is closing because
// we may need to stop running queries
getSite().getPage().addPartListener(new PartAdapter2() {
/* (non-JavaDoc)
* @see net.sourceforge.sqlexplorer.util.PartAdapter2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
*/
public void partClosed(IWorkbenchPartReference partRef) {
if (partRef.getPart(false) == FileListEditor.this) {
onCloseEditor();
}
}
});
// If we havn't got a view, then try for the current session in the ConnectionsView
if (getSession() == null) {
ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
if (view != null) {
User user = view.getDefaultUser();
if (user != null)
user.queueForNewSession(new SessionEstablishedAdapter() {
@Override
public void sessionEstablished(Session session) {
setSession(session);
}
});
}
}
}
use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.
the class Session method setAutoCommit.
public synchronized void setAutoCommit(boolean autoCommit) throws SQLException {
boolean enabling = !this.autoCommit && autoCommit;
this.autoCommit = autoCommit;
// If we're turning it on, get rid of any existing connection back to the pool
if (enabling) {
// If there's a connection but its not in use, then release it
if (connection != null && !connectionInUse) {
try {
user.releaseConnection(connection);
internalSetConnection(null);
ConnectionsView connectionsView = SQLExplorerPlugin.getDefault().getConnectionsView();
if (connectionsView != null) {
connectionsView.refresh();
}
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot release connection", e);
}
}
}
}
use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.
the class Session method releaseConnection.
/**
* Releases the connection; if the connection does NOT have auto-commit, this session will hang on to it for next
* time, otherwise it is returned to the pool
*
* @param toRelease
*/
public synchronized void releaseConnection(SQLConnection toRelease) {
if (!connectionInUse) {
throw new IllegalStateException("Cannot release connection - not inuse");
}
if (connection != toRelease) {
// User will be null if we've closed
if (user == null) {
return;
}
throw new IllegalArgumentException("Attempt to release the wrong connection");
}
// Run any queued tasks
try {
while (!queuedTasks.isEmpty()) {
QueuedTask task = queuedTasks.removeFirst();
task.run();
}
} catch (SQLException e) {
SQLExplorerPlugin.error("Failed running queued task", e);
}
connectionInUse = false;
try {
// Update the connection to the auto-commit and commit-on-close status
connection.setAutoCommit(autoCommit);
connection.setCommitOnClose(commitOnClose);
// If it's not auto-commit, then we have to keep the connection
if (!autoCommit || keepConnection) {
return;
}
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot commit", e);
}
// Give it back into the pool
try {
user.releaseConnection(connection);
internalSetConnection(null);
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot release connection", e);
}
ConnectionsView connectionsView = SQLExplorerPlugin.getDefault().getConnectionsView();
if (connectionsView != null) {
connectionsView.refresh();
}
}
use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.
the class SQLEditor method init.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
*/
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
// Configure the editor
setSite(site);
// PTODO qzhang fixed bug 3904: syschronize the resource.
if (input instanceof FileEditorInput) {
try {
((FileEditorInput) input).getFile().getParent().refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e) {
e.printStackTrace();
}
}
setInput(input);
// Create the text editor
textEditor = new SQLTextEditor(this);
textEditor.init(site, input);
// setPartName(getSite().getPage().getLabel());
// Make sure we get notification that our editor is closing because
// we may need to stop running queries
getSite().getPage().addPartListener(new PartAdapter2() {
/*
* (non-JavaDoc)
*
* @see net.sourceforge.sqlexplorer.util.PartAdapter2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
*/
@Override
public void partClosed(IWorkbenchPartReference partRef) {
if (partRef.getPart(false) == SQLEditor.this) {
onCloseEditor();
}
}
});
// If we havn't got a view, then try for the current session in the ConnectionsView
if (getSession() == null) {
ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
if (view != null) {
User user = view.getDefaultUser();
if (user != null) {
user.queueForNewSession(new SessionEstablishedAdapter() {
@Override
public void sessionEstablished(Session session) {
setSession(session);
}
});
}
}
}
}
use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.
the class OpenInEditorAction method run.
public void run() {
try {
TableItem[] ti = _table.getSelection();
if (ti == null || ti.length == 0) {
return;
}
String queryDelimiter = SQLExplorerPlugin.getDefault().getPluginPreferences().getString(IConstants.SQL_QRY_DELIMITER);
StringBuffer copiedText = new StringBuffer();
for (int i = 0; i < ti.length; i++) {
SQLHistoryElement el = (SQLHistoryElement) ti[i].getData();
copiedText.append(el.getRawSQLString());
if (ti.length > 0) {
copiedText.append(queryDelimiter);
copiedText.append("\n");
}
}
SQLHistoryElement sqlHistoryElement = (SQLHistoryElement) ti[0].getData();
User user = sqlHistoryElement.getUser();
Alias alias;
if (user != null)
alias = user.getAlias();
else {
alias = sqlHistoryElement.getAlias();
if (alias != null)
user = alias.getDefaultUser();
if (user == null) {
ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
if (view != null)
user = view.getDefaultUser();
}
}
if (user != null && !user.hasAuthenticated()) {
boolean okToOpen = MessageDialog.openConfirm(_table.getShell(), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Title"), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Prefix") + " " + user.getDescription() + Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Postfix"));
if (okToOpen) {
OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, user, false);
openDlgAction.run();
}
}
SQLEditorInput input = new SQLEditorInput("SQL Editor (" + SQLExplorerPlugin.getDefault().getEditorSerialNo() + ").sql");
input.setUser(user);
IWorkbenchPage page = SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (page == null)
return;
SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
editorPart.setText(copiedText.toString());
} catch (Throwable e) {
SQLExplorerPlugin.error("Error creating sql editor", e);
}
}
Aggregations