📄 browsercontroller.java
字号:
case BrowserConstants.SYSTEM_NUMERIC_FUNCTIONS_NODE: case BrowserConstants.SYSTEM_DATE_TIME_FUNCTIONS_NODE: BrowserProcedurePanel procsPanel = null; if (!viewPanel.containsPanel(BrowserProcedurePanel.NAME)) { procsPanel = new BrowserProcedurePanel(this); viewPanel.addToLayout(procsPanel); } else { procsPanel = (BrowserProcedurePanel) viewPanel.getFormObjectView(BrowserProcedurePanel.NAME); } // set the catalog and schema values to null if // its a system function type if (type == BrowserConstants.SYSTEM_STRING_FUNCTIONS_NODE || type == BrowserConstants.SYSTEM_NUMERIC_FUNCTIONS_NODE || type == BrowserConstants.SYSTEM_DATE_TIME_FUNCTIONS_NODE) { catalog = null; schema = null; } // maybe force a reload here if (reload) { procsPanel.removeObject(databaseObject); } if (!procsPanel.hasObject(databaseObject)) { procsPanel.setValues( databaseObject, getProcedureColumns(dc, catalog, schema, name)); } else { procsPanel.setValues(databaseObject); } return procsPanel; case BrowserConstants.TABLE_NODE: if (databaseObject.isDefaultCatalog()) { BrowserTableEditingPanel editingPanel = viewPanel.getEditingPanel(); editingPanel.selectionChanged(databaseObject, reload); return editingPanel; } break; case BrowserConstants.COLUMN_NODE: TableColumnPanel columnPanel = null; if (!viewPanel.containsPanel(TableColumnPanel.NAME)) { columnPanel = new TableColumnPanel(this); viewPanel.addToLayout(columnPanel); } else { columnPanel = (TableColumnPanel)viewPanel.getFormObjectView(TableColumnPanel.NAME); } Map columnMap = null; if (reload || !columnPanel.hasObject(databaseObject)) { String parentName = databaseObject.getParentName(); columnMap = getColumnProperties(dc, schema, parentName, name); } columnPanel.setValues(databaseObject, columnMap, reload); return columnPanel; } ObjectDefinitionPanel objectDefnPanel = null; if (reload || !viewPanel.containsPanel(ObjectDefinitionPanel.NAME)) { objectDefnPanel = new ObjectDefinitionPanel(this); viewPanel.addToLayout(objectDefnPanel); } else { objectDefnPanel = (ObjectDefinitionPanel) viewPanel.getFormObjectView(ObjectDefinitionPanel.NAME); } objectDefnPanel.changeTable(databaseObject, reload); return objectDefnPanel; } catch (Exception e) { handleException(e); return null; } } /** * Selects the node that matches the specified prefix forward * from the currently selected node. * * @param prefix - the prefix of the node to select */ protected void selectBrowserNode(String prefix) { treePanel.selectBrowserNode(prefix); } /** * Displays the root main view panel. */ protected void displayRootPanel() { checkBrowserPanel(); viewPanel.displayRootPanel(); } /** * Applies the table alteration changes. */ protected void applyTableChange(boolean valueChange) { BrowserTableEditingPanel editingPanel = viewPanel.getEditingPanel(); // check we actually have something to apply if (!editingPanel.hasSQLText()) { return; } // retrieve the browser node BrowserTreeNode node = null; if (valueChange) { // if we are selecting a new node, get the previous selection node = treePanel.getOldBrowserNodeSelection(); } else { // otherwise get the current selection node = treePanel.getSelectedBrowserNode(); } try { treePanel.removeTreeListener(); // if specified, ask the user again if (valueChange) { int yesNo = GUIUtilities.displayConfirmCancelDialog( "Do you wish to apply your changes?"); if (yesNo == JOptionPane.NO_OPTION) { node = treePanel.getSelectedBrowserNode(); editingPanel.selectionChanged(node.getDatabaseUserObject(), true); editingPanel.resetSQLText(); return; } else if (yesNo == JOptionPane.CANCEL_OPTION) { treePanel.setNodeSelected(node); return; } } // apply the changes to the database if (querySender == null) { querySender = new QuerySender(); } querySender.setDatabaseConnection(getDatabaseConnection()); SqlStatementResult result = null; StringTokenizer st = new StringTokenizer( editingPanel.getSQLText().trim(), ";\n"); try { while (st.hasMoreTokens()) { result = querySender.updateRecords(st.nextToken()); if (result.getUpdateCount() < 0) { editingPanel.setSQLText(); SQLException e = result.getSqlException(); if (e != null) { StringBuffer sb = new StringBuffer(); sb.append("An error occurred applying the specified changes."). append("\n\nThe system returned:\n"). append(MiscUtils.formatSQLError(e)); GUIUtilities.displayExceptionErrorDialog(sb.toString(), e); } else { GUIUtilities.displayErrorMessage(result.getErrorMessage()); } treePanel.setNodeSelected(node); return; } } } catch (SQLException e) { StringBuffer sb = new StringBuffer(); sb.append("An error occurred applying the specified changes."). append("\n\nThe system returned:\n"). append(MiscUtils.formatSQLError(e)); GUIUtilities.displayExceptionErrorDialog(sb.toString(), e); treePanel.setNodeSelected(node); return; } // reset the current panel editingPanel.selectionChanged(node.getDatabaseUserObject(), true); editingPanel.resetSQLText(); treePanel.setNodeSelected(node); } finally { treePanel.addTreeListener(); } } /** * Returns whether a table alteration has occurred and * is actionable. * * @return true | false */ protected boolean hasAlterTable() { if (viewPanel == null) { return false; } return viewPanel.getEditingPanel().hasSQLText(); } /** * Checks the procedure term against a function or procedure node * when the returned results from getTables(...) is null or empty. * * @param dc - the database connection objeect * @param object - the meta object */ protected String[] checkProcedureTerm(DatabaseConnection dc, DatabaseObject object) { int type = object.getType(); if (type == BrowserConstants.FUNCTIONS_NODE || type == BrowserConstants.PROCEDURE_NODE) { // check the procedure term String procedureTerm = getProcedureTerm(dc); if (procedureTerm != null) { String catalog = object.getCatalogName(); String schema = object.getSchemaName(); String metaKey = object.getMetaDataKey(); if (procedureTerm.toUpperCase().equals(metaKey)) { return getProcedureNames(dc, catalog, schema, null); } } } return new String[0]; } // -------------------------------------------- // Meta data propagation methods // -------------------------------------------- /** * Generic exception handler. */ private void handleException(Throwable e) { if (Log.isDebugEnabled()) { Log.debug("Error retrieving data.", e); } boolean isDataSourceException = (e instanceof DataSourceException); GUIUtilities.displayExceptionErrorDialog( "Error retrieving the selected database " + "object.\n\nThe system returned:\n" + (isDataSourceException ? ((DataSourceException)e).getExtendedMessage() : e.getMessage()), e); if (isDataSourceException) { if (((DataSourceException)e).wasConnectionClosed()) { connect(treePanel.getSelectedDatabaseConnection(), false); } } } /** * Propagates the call to the meta data object. */ protected String[] getSystemFunctions(DatabaseConnection dc, int type) { try { checkMetaDataObject(); metaData.setDatabaseConnection(dc); return metaData.getSystemFunctions(type); } catch (DataSourceException e) { handleException(e); return null; } } /** * Propagates the call to the meta data object. */ protected String[] getProcedureNames(DatabaseConnection dc, String catalog, String schema, String name) { try { checkMetaDataObject(); metaData.setDatabaseConnection(dc); return metaData.getProcedureNames(catalog, schema, name); } catch (DataSourceException e) { handleException(e); return null; } } /** * Propagates the call to the meta data object. */ protected String getProcedureTerm(DatabaseConnection dc) { try { checkMetaDataObject(); metaData.setDatabaseConnection(dc); return metaData.getProcedureTerm(); } catch (DataSourceException e) { handleException(e); return null; } } /** * Propagates the call to the meta data object. */ protected String[] getTableTypes(DatabaseConnection dc) { try { checkMetaDataObject(); metaData.setDatabaseConnection(dc); return metaData.getTableTypes(); } catch (DataSourceException e) { handleException(e); return new String[0]; } } /** * Propagates the call to the meta data object. */ protected String[] getTables(DatabaseConnection dc, String catalog, String schema, String metaName) { try { checkMetaDataObject(); metaData.setDatabaseConnection(dc); return metaData.getTables(catalog, schema, metaName); } catch (DataSourceException e) { handleException(e); return new String[0]; } } /** * Propagates the call to the meta data object. */ protected DatabaseObject[] getTables(DatabaseConnection dc, String catalog, String schema, String[] types) { checkMetaDataObject(); metaData.setDatabaseConnection(dc); try { return metaData.getTables(catalog, schema, types); } catch (DataSourceException e) { handleException(e); return new DatabaseObject[0]; } } protected ResultSet getDataTypesResultSet() { try { checkMetaDataObject(); metaData.setDatabaseConnection(getDatabaseConnection()); return metaData.getDataTypesResultSet(); } catch (DataSourceException e) { handleException(e); return null; } } protected String[] getDatabaseKeywords() { try { checkMetaDataObject(); metaData.setDatabaseConnection(getDatabaseConnection()); return metaData.getDatabaseKeywords(); } catch (DataSourceException e) { handleException(e); return new String[0]; } } protected Hashtable getDatabaseProperties() { try { checkMetaDataObject(); DatabaseConnection dc = getDatabaseConnection(); if (dc != null) { metaData.setDatabaseConnection(getDatabaseConnection()); return metaData.getDatabaseProperties(); } } catch (DataSourceException e) { handleException(e); } return new Hashtable(0); } /** * Propagates the call to the meta data object. */ protected String[] getColumnNames(DatabaseConnection dc, String table, String schema) { try { checkMetaDataObject(); metaData.setDatabaseConnection(dc); return metaData.getColumnNames(table, schema); } catch (DataSourceException e) { handleException(e); return new String[0]; } } /** * Propagates the call to the meta data object. */ protected String getSchemaName(DatabaseConnection dc) { checkMetaDataObject(); metaData.setDatabaseConnection(dc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -