use of net.sourceforge.sqlexplorer.dbproduct.Session in project tdq-studio-se by Talend.
the class FilterStructureAction method run.
public void run() {
try {
DatabaseStructureView view = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
FilterStructureDialog dialog = new FilterStructureDialog();
Session session = view.getSession();
if (session == null)
return;
Alias alias = session.getUser().getAlias();
if (alias.getSchemaFilterExpression() != null && alias.getSchemaFilterExpression().length() != 0) {
dialog.setSchemaFilter(alias.getSchemaFilterExpression().split(","));
}
if (alias.getFolderFilterExpression() != null && alias.getFolderFilterExpression().length() != 0) {
dialog.setFolderFilter(alias.getFolderFilterExpression().split(","));
}
if (alias.getNameFilterExpression() != null && alias.getNameFilterExpression().length() != 0) {
dialog.setNameFilter(alias.getNameFilterExpression());
}
if (dialog.open() != Window.OK) {
return;
}
String[] schemaFilter = dialog.getSchemaFilter();
StringBuffer schemaFilterString = new StringBuffer("");
String sep = "";
if (schemaFilter != null) {
for (int i = 0; i < schemaFilter.length; i++) {
schemaFilterString.append(sep);
schemaFilterString.append(schemaFilter[i]);
sep = ",";
}
}
alias.setSchemaFilterExpression(schemaFilterString.toString());
String[] folderFilter = dialog.getFolderFilter();
StringBuffer folderFilterString = new StringBuffer("");
sep = "";
if (folderFilter != null) {
for (int i = 0; i < folderFilter.length; i++) {
folderFilterString.append(sep);
folderFilterString.append(folderFilter[i]);
sep = ",";
}
}
alias.setFolderFilterExpression(folderFilterString.toString());
alias.setNameFilterExpression(dialog.getNameFilter());
view.refreshSessionTrees(view.getSession());
} catch (Exception e) {
SQLExplorerPlugin.error("Error creating dialog", e);
}
}
use of net.sourceforge.sqlexplorer.dbproduct.Session in project tdq-studio-se by Talend.
the class ExecSQLAction method run.
protected void run(int maxRows) {
Session session = getSession();
if (session == null)
return;
QueryParser qt = session.getDatabaseProduct().getQueryParser(_editor.getSQLToBeExecuted(), _editor.getSQLLineNumber());
try {
qt.parse();
} catch (final ParserException e) {
_editor.getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(_editor.getSite().getShell(), Messages.getString("SQLResultsView.Error.Title"), e.getMessage());
}
});
}
if (qt.iterator().hasNext()) {
boolean clearResults = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.CLEAR_RESULTS_ON_EXECUTE);
if (clearResults)
_editor.clearResults();
AbstractSQLExecution job = new SQLExecution(_editor, qt, maxRows);
job.schedule();
}
}
use of net.sourceforge.sqlexplorer.dbproduct.Session in project tdq-studio-se by Talend.
the class SQLEditor method setInput.
/*
* (non-JavaDoc)
*
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
*/
@Override
protected void setInput(IEditorInput input) {
super.setInput(input);
if (textEditor != null) {
textEditor.setInput(input);
}
// Handle our own form of input
if (input instanceof SQLEditorInput) {
SQLEditorInput sqlInput = (SQLEditorInput) input;
if (input != null) {
User user = sqlInput.getUser();
if (user != null) {
user.queueForNewSession(new SessionEstablishedAdapter() {
@Override
public void sessionEstablished(Session session) {
setSession(session);
}
});
}
isDirty = true;
isUntitled = true;
}
}
// set part name as displayName + " " + version
String partName = input.getName();
if (input instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) input;
// $NON-NLS-1$
IPath fileName = fileEditorInput.getPath().removeFileExtension().addFileExtension("properties");
Property property = null;
URI propURI = URI.createFileURI(fileName.toOSString());
Resource resource = new ResourceSetImpl().getResource(propURI, true);
if (resource.getContents() != null) {
Object object = EcoreUtil.getObjectByType(resource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
if (object != null) {
property = (Property) object;
}
}
if (property != null) {
// $NON-NLS-1$
partName = property.getDisplayName() + " " + property.getVersion();
}
}
setPartName(partName);
}
use of net.sourceforge.sqlexplorer.dbproduct.Session 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.dbproduct.Session in project tdq-studio-se by Talend.
the class ExplainAction2 method run.
public void run() {
try {
Session session;
SQLConnection connection;
Statement stmt;
ResultSet rs;
session = getSession();
if (session == null)
return;
connection = null;
stmt = null;
rs = null;
boolean createPlanTable;
boolean notFoundTable;
connection = session.grabConnection();
Statement st = connection.createStatement();
createPlanTable = false;
notFoundTable = true;
try {
rs = st.executeQuery("select statement_id from plan_table");
notFoundTable = false;
rs.close();
rs = null;
} catch (SQLException _ex) {
createPlanTable = MessageDialog.openQuestion(null, Messages.getString("oracle.editor.actions.explain.notFound.Title"), Messages.getString("oracle.editor.actions.explain.notFound"));
}
st.close();
st = null;
if (notFoundTable && !createPlanTable) {
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close result set", e);
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close statement", e);
}
if (connection != null)
session.releaseConnection(connection);
return;
}
try {
if (notFoundTable && createPlanTable) {
st = connection.createStatement();
st.execute("CREATE TABLE PLAN_TABLE ( STATEMENT_ID VARCHAR2(30), TIMESTAMP DATE, REMARKS VARCHAR2(80), OPERATION VARCHAR2(30), OPTIONS VARCHAR2(30), OBJECT_NODE VARCHAR2(128), OBJECT_OWNER VARCHAR2(30), OBJECT_NAME VARCHAR2(30), OBJECT_INSTANCE NUMBER(38), OBJECT_TYPE VARCHAR2(30), OPTIMIZER VARCHAR2(255), SEARCH_COLUMNS NUMBER, ID NUMBER(38), PARENT_ID NUMBER(38), POSITION NUMBER(38), COST NUMBER(38), CARDINALITY NUMBER(38), BYTES NUMBER(38), OTHER_TAG VARCHAR2(255), PARTITION_START VARCHAR2(255), PARTITION_STOP VARCHAR2(255), PARTITION_ID NUMBER(38), OTHER LONG, DISTRIBUTION VARCHAR2(30))");
st.close();
st = null;
}
QueryParser qt = session.getDatabaseProduct().getQueryParser(_editor.getSQLToBeExecuted(), _editor.getSQLLineNumber());
qt.parse();
(new ExplainExecution(_editor, qt)).schedule();
} catch (SQLException e) {
SQLExplorerPlugin.error("Error creating explain plan", e);
} catch (ParserException e) {
SQLExplorerPlugin.error("Cannot parse query", e);
}
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close result set", e);
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close statement", e);
}
if (connection != null)
session.releaseConnection(connection);
if (rs != null)
try {
rs.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close result set", e);
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException e) {
SQLExplorerPlugin.error("Cannot close statement", e);
}
if (connection != null)
session.releaseConnection(connection);
} catch (Exception e) {
}
}
Aggregations