private List<DbObject> retrieveTriggers() throws SQLException { if (this.monitor != null) { monitor.setMonitorType(RowActionMonitor.MONITOR_PLAIN); monitor.setCurrentObject(ResourceMgr.getString("MsgRetrievingTriggers"), -1, -1); } TriggerReader trgReader = TriggerReaderFactory.createReader(connection); List<DbObject> result = CollectionUtil.sizedArrayList(50); for (String schema : schemas) { if (cancelSearch) return null; List<TriggerDefinition> triggers = trgReader.getTriggerList(null, schema, null); result.addAll(triggers); } return result; }
public void retrieve() { initGui(); if (this.dbConnection == null) return; if (this.reader == null) return; if (this.isRetrieving) return; if (!WbSwingUtilities.isConnectionIdle(this, this.dbConnection)) return; try { this.reset(); this.dbConnection.setBusy(true); this.isRetrieving = true; this.infoLabel.setText(ResourceMgr.getString("MsgRetrieving")); WbSwingUtilities.showWaitCursorOnWindow(this); DataStore ds = reader.getTriggers(currentCatalog, currentSchema); final DataStoreTableModel model = new DataStoreTableModel(ds); WbSwingUtilities.invoke( () -> { infoLabel.showObjectListInfo(model); triggerList.setModel(model, true); }); shouldRetrieve = false; } catch (OutOfMemoryError mem) { WbManager.getInstance().showOutOfMemoryError(); } catch (Throwable e) { LogMgr.logError("ProcedureListPanel.retrieve() thread", "Could not retrieve trigger list", e); } finally { this.isRetrieving = false; this.dbConnection.setBusy(false); WbSwingUtilities.showDefaultCursorOnWindow(this); } }
protected void retrieveCurrentTrigger() { if (this.dbConnection == null || this.reader == null) return; int row = this.triggerList.getSelectedRow(); if (!WbSwingUtilities.isConnectionIdle(this, this.dbConnection)) return; if (row < 0) return; final String triggerName = this.triggerList.getValueAsString(row, TriggerReader.COLUMN_IDX_TABLE_TRIGGERLIST_TRG_NAME); final String tableName = this.triggerList.getValueAsString( row, TriggerReader.COLUMN_IDX_TABLE_TRIGGERLIST_TRG_TABLE); final String comment = this.triggerList.getValueAsString( row, TriggerReader.COLUMN_IDX_TABLE_TRIGGERLIST_TRG_COMMENT); Container parent = this.getParent(); WbSwingUtilities.showWaitCursor(parent); try { if (dbConnection.getProfile().getUseSeparateConnectionPerTab()) { levelChanger.changeIsolationLevel(dbConnection); } dbConnection.setBusy(true); try { TableIdentifier tbl = null; if (tableName != null) { tbl = new TableIdentifier(tableName, dbConnection); if (tbl.getCatalog() == null) tbl.setCatalog(currentCatalog); if (tbl.getSchema() == null) tbl.setSchema(currentSchema); } DropType dropType = DbExplorerSettings.getDropTypeToGenerate(TriggerDefinition.TRIGGER_TYPE_NAME); String sql = reader.getTriggerSource(currentCatalog, currentSchema, triggerName, tbl, comment, true); Object obj = triggerList.getUserObject(row); boolean isReplace = SqlUtil.isReplaceDDL(sql, dbConnection, dropType); if (dropType != DropType.none && obj instanceof TriggerDefinition && sql != null && !isReplace) { TriggerDefinition trg = (TriggerDefinition) obj; String drop = trg.getDropStatement(dbConnection, dropType == DropType.cascaded); if (StringUtil.isNonBlank(drop)) { sql = drop + getDelimiterForDrop() + "\n\n" + sql; } } final String sourceSql = sql == null ? "" : sql; WbSwingUtilities.invoke( () -> { source.setText(sourceSql, triggerName, TRG_TYPE_NAME); }); } catch (Throwable ex) { LogMgr.logError( "TriggerListPanel.retrieveTriggerSource() thread", "Could not read trigger source", ex); source.setPlainText(ExceptionUtil.getDisplay(ex)); } } finally { WbSwingUtilities.showDefaultCursor(parent); levelChanger.restoreIsolationLevel(dbConnection); dbConnection.setBusy(false); } if (this.triggerList.getSelectedRowCount() == 1) { EventQueue.invokeLater( () -> { source.setCaretPosition(0, false); if (DbExplorerSettings.getSelectSourcePanelAfterRetrieve()) { source.requestFocusInWindow(); } }); } }