use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.
the class SQLHistory method loadFromFileV300.
/**
* Load the sql history from previous sessions.
*/
private void loadFromFileV300() {
try {
File file = new File(ApplicationFiles.SQLHISTORY_FILE_NAME_V300);
if (!file.exists()) {
return;
}
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String currentLine = reader.readLine();
while (currentLine != null) {
if (currentLine.trim().length() != 0) {
String sessionHint = null;
String query = null;
String time = null;
String executions = null;
int pos = currentLine.indexOf(SESSION_HINT_MARKER);
if (pos != -1) {
// split line in session and query
sessionHint = currentLine.substring(0, pos);
currentLine = currentLine.substring(pos + SESSION_HINT_MARKER.length());
int posT = currentLine.indexOf(TIME_HINT_MARKER);
if (posT != -1) {
// split line in session and query
query = currentLine.substring(0, posT);
currentLine = currentLine.substring(posT + TIME_HINT_MARKER.length());
int posE = currentLine.indexOf(EXECUTION_HINT_MARKER);
time = currentLine.substring(0, posE);
executions = currentLine.substring(posE + EXECUTION_HINT_MARKER.length());
} else {
query = currentLine;
}
// clean up query
query = query.replaceAll(NEWLINE_REPLACEMENT, NEWLINE_SEPARATOR);
query = query.replaceAll(TAB_REPLACEMENT, " ");
}
if (query != null && query.trim().length() != 0) {
Alias alias = SQLExplorerPlugin.getDefault().getAliasManager().getAlias(sessionHint);
_history.add(new SQLHistoryElement(query, alias.getDefaultUser(), time, executions));
}
}
currentLine = reader.readLine();
}
reader.close();
} catch (Exception e) {
SQLExplorerPlugin.error("Couldn't load sql history.", e);
}
}
use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.
the class ConnectionTreeActionGroup method fillContextMenu.
/**
* Fill the node context menu with all the correct actions.
*
* @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
*/
public void fillContextMenu(IMenuManager menu) {
ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
Object[] selection = (view == null) ? null : view.getSelected();
// If nothing is selected, then show the default ones
if (selection == null || selection.length != 1) {
// addAction(menu, new CloseAllConnectionsAction());
return;
}
if (selection[0] instanceof Alias) {
Alias alias = (Alias) selection[0];
addAction(menu, new NewEditorAction());
addAction(menu, new NewDatabaseStructureViewAction());
addAction(menu, new ConnectAliasAction());
menu.add(new Separator());
for (User user : alias.getUsers()) if (!user.isAutoCommit()) {
addAction(menu, new CommitAction());
addAction(menu, new RollbackAction());
menu.add(new Separator());
break;
}
// addAction(menu, new NewUserAction());
// addAction(menu, new ChangeAliasAction());
// addAction(menu, new CopyAliasAction());
// addAction(menu, new DeleteAction());
} else if (selection[0] instanceof User) {
User user = (User) selection[0];
addAction(menu, new NewEditorAction());
addAction(menu, new NewDatabaseStructureViewAction());
addAction(menu, new ConnectAliasAction());
menu.add(new Separator());
if (!user.isAutoCommit()) {
addAction(menu, new CommitAction());
addAction(menu, new RollbackAction());
menu.add(new Separator());
}
// addAction(menu, new NewUserAction());
// addAction(menu, new EditUserAction());
// addAction(menu, new CopyUserAction());
// addAction(menu, new DeleteAction());
} else if (selection[0] instanceof SQLConnection) {
SQLConnection connection = (SQLConnection) selection[0];
addAction(menu, new NewEditorAction());
addAction(menu, new NewDatabaseStructureViewAction());
menu.add(new Separator());
if (!connection.getUser().isAutoCommit()) {
addAction(menu, new CommitAction());
addAction(menu, new RollbackAction());
menu.add(new Separator());
}
// addAction(menu, new CloseConnectionAction());
}
}
use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.
the class ConnectionsView method getDefaultAlias.
private Alias getDefaultAlias() {
IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
if (selection == null) {
return null;
}
Object element = selection.getFirstElement();
if (element instanceof Alias) {
return (Alias) element;
} else if (element instanceof Session) {
ITreeContentProvider provider = (ITreeContentProvider) _treeViewer.getContentProvider();
return (Alias) provider.getParent(element);
}
return null;
}
use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.
the class ConnectionsView method getSelectedAliases.
/**
* Returns a list of the selected Aliases. If recurse is true then the result will include any aliases associated
* with other objects; eg, if a connection is selected and recurse is true, then the connection's alias will also be
* returned
*
* @param recurse
* @return Set of Aliases, never returns null
*/
public Set<Alias> getSelectedAliases(boolean recurse) {
IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
if (selection == null) {
return EMPTY_ALIASES;
}
LinkedHashSet<Alias> result = new LinkedHashSet<Alias>();
Iterator iter = selection.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Alias) {
result.add((Alias) obj);
} else if (recurse) {
if (obj instanceof User) {
User user = (User) obj;
result.add(user.getAlias());
} else if (obj instanceof SQLConnection) {
SQLConnection connection = (SQLConnection) obj;
result.add(connection.getUser().getAlias());
}
}
}
return result;
}
use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.
the class ConnectionsView method getSelectedConnections.
/**
* Returns a list of selected sessions; if recurse is true, then it includes indirectly selected sessions (eg a
* selected user's sessions)
*
* @param recurse
* @return Set of Sessions, never returns null
*/
public Set<SQLConnection> getSelectedConnections(boolean recurse) {
IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
if (selection == null) {
return EMPTY_CONNECTIONS;
}
LinkedHashSet<SQLConnection> result = new LinkedHashSet<SQLConnection>();
Iterator iter = selection.iterator();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof SQLConnection) {
result.add((SQLConnection) obj);
} else if (recurse) {
if (obj instanceof Alias) {
Alias alias = (Alias) obj;
for (User user : alias.getUsers()) {
result.addAll(user.getConnections());
}
} else if (obj instanceof User) {
User user = (User) obj;
result.addAll(user.getConnections());
}
}
}
return result;
}
Aggregations