use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.
the class SessionTreeNodeManager method getSessionTreeNode.
/**
* Converts the DatabaseConnection to SessionTreeNode, and stores the SessionTreeNode.
*
* @param repositoryNode RepositoryNode
* @param selectedContext
* @return SessionTreeNode
*/
public SessionTreeNode getSessionTreeNode(RepositoryNode repositoryNode, String selectedContext) throws Exception {
// Gets the root RepositoryNode
RepositoryNode root = getRoot(repositoryNode);
// Gets the DatabaseConnection
DatabaseConnection connection = (DatabaseConnection) ((ConnectionItem) root.getObject().getProperty().getItem()).getConnection();
if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connection.getDatabaseType())) {
if (connection.getURL().lastIndexOf("=") != connection.getURL().length() - 1) {
//$NON-NLS-1$
connection.setDatasourceName(connection.getURL().substring(connection.getURL().lastIndexOf(File.separator) + 1, connection.getURL().length()));
connection.setSID(connection.getURL().substring(connection.getURL().lastIndexOf(File.separator) + 1, connection.getURL().length()));
}
}
SessionTreeNode sessionTreeNode = map.get(connection);
// hyWang modified for bug 0007062
if (sessionTreeNode != null && !sessionTreeNode.isConnectionClosed()) {
return sessionTreeNode;
}
// If the node is not existent,creates one and cache it.
sessionTreeNode = SessionTreeNodeUtils.getSessionTreeNode(connection, root, selectedContext);
map.put(connection, sessionTreeNode);
return sessionTreeNode;
}
use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.
the class ImportedKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node.getSession() == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ITableInfo ti = tableNode.getTableInfo();
if (tableNode.getTableInfo() == null) {
return null;
}
ResultSet resultSet = null;
SessionTreeNode treeNode = node.getSession();
// For synonym table, should get the corresponding table.
if (ti.getType().equals("SYNONYM")) {
//$NON-NLS-1$
String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
resultSet = treeNode.getMetaData().getJDBCMetaData().getImportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
} else {
resultSet = node.getSession().getMetaData().getImportedKeys((tableNode.getTableInfo()));
}
DataSet dataSet = new DataSet(null, resultSet, new int[] { 3, 4, 8, 9, 10, 11, 12, 13, 14 });
resultSet.close();
return dataSet;
}
return null;
}
use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.
the class PrimaryKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node.getSession() == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ITableInfo ti = tableNode.getTableInfo();
if (tableNode.getTableInfo() == null) {
return null;
}
ResultSet resultSet = null;
SessionTreeNode treeNode = node.getSession();
// For synonym table, should get the corresponding table name .
if (ti.getType().equals("SYNONYM")) {
//$NON-NLS-1$
String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
resultSet = treeNode.getMetaData().getJDBCMetaData().getPrimaryKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
} else {
resultSet = node.getSession().getMetaData().getPrimaryKeys((tableNode.getTableInfo()));
}
DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6 });
resultSet.close();
return dataSet;
}
return null;
}
use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.
the class ExportedKeysTab method getDataSet.
public DataSet getDataSet() throws Exception {
INode node = getNode();
if (node == null) {
return null;
}
if (node.getSession() == null) {
return null;
}
if (node instanceof TableNode) {
TableNode tableNode = (TableNode) node;
ITableInfo ti = tableNode.getTableInfo();
if (tableNode.getTableInfo() == null) {
return null;
}
ResultSet resultSet = null;
SessionTreeNode treeNode = node.getSession();
// For synonym table, should get the corresponding table.
if (ti.getType().equals("SYNONYM")) {
//$NON-NLS-1$
String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
resultSet = treeNode.getMetaData().getJDBCMetaData().getExportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
} else {
resultSet = node.getSession().getMetaData().getExportedKeys((tableNode.getTableInfo()));
}
DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 7, 8, 9, 10, 11, 12, 13, 14 });
resultSet.close();
return dataSet;
}
return null;
}
use of org.talend.sqlbuilder.sessiontree.model.SessionTreeNode in project tdi-studio-se by Talend.
the class OracleExplainPlanAction method run.
/*
* (non-Javadoc)
*
* @see org.talend.sqlbuilder.actions.AbstractEditorAction#run()
*/
//$NON-NLS-1$
@SuppressWarnings("unchecked")
@Override
public void run() {
RepositoryNode node = editor.getRepositoryNode();
SessionTreeNodeManager nodeManager = new SessionTreeNodeManager();
SessionTreeNode runNode = null;
try {
runNode = nodeManager.getSessionTreeNode(node, editor.getDialog().getSelectedContext());
} catch (Exception e) {
//$NON-NLS-1$
MessageDialog.openError(null, Messages.getString("AbstractSQLExecution.Executing.Error"), e.getMessage());
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage1"), e);
return;
}
Preferences prefs = SqlBuilderPlugin.getDefault().getPluginPreferences();
String queryDelimiter = prefs.getString(IConstants.QUERY_DELIMITER);
String alternateDelimiter = prefs.getString(IConstants.ALTERNATE_DELIMITER);
String commentDelimiter = prefs.getString(IConstants.COMMENT_DELIMITER);
QueryTokenizer qt = new QueryTokenizer(getSQLToBeExecuted(), queryDelimiter, alternateDelimiter, commentDelimiter);
List queryStrings = new ArrayList();
while (qt.hasQuery()) {
final String querySql = qt.nextQuery();
// ignore commented lines.
if (!querySql.startsWith("--")) {
//$NON-NLS-1$
queryStrings.add(querySql);
}
}
// check if we can run explain plans
try {
Statement st = runNode.getInteractiveConnection().createStatement();
boolean createPlanTable = false;
boolean notFoundTable = true;
try {
//$NON-NLS-1$
ResultSet rs = st.executeQuery("select statement_id from plan_table");
notFoundTable = false;
rs.close();
} catch (Throwable e) {
createPlanTable = MessageDialog.openQuestion(null, //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.notFound.Title"), //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.notFound"));
} finally {
try {
st.close();
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage2"), e);
}
}
if (notFoundTable && !createPlanTable) {
return;
}
if (notFoundTable && createPlanTable) {
SQLConnection conn = runNode.getInteractiveConnection();
st = conn.createStatement();
try {
st.execute(createPlanTableScript);
if (!conn.getAutoCommit()) {
conn.commit();
}
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage2"), e);
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
null, //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.createError.Title"), //$NON-NLS-1$
Messages.getString("oracle.editor.actions.explain.createError"));
try {
st.close();
} catch (Throwable e1) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage3"), e1);
}
return;
}
try {
st.close();
} catch (Throwable e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage3"), e);
}
}
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage4"), e);
}
try {
while (!queryStrings.isEmpty()) {
String querySql = (String) queryStrings.remove(0);
if (querySql != null) {
resultDisplayer.addSQLExecution(new OracleExplainPlanExecution(querySql, runNode));
}
}
} catch (Exception e) {
//$NON-NLS-1$
SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage5"), e);
}
}
Aggregations