ORBADA - Dokumentacja
Author: Andrzej Kałuża, ORBADA
Description: Organizer Bazy Danych, Db Pages

2016-12-06 08:15
ORBADA » Documentation in English » Plug-in documentation » BeanShell » Examples » BeanShell action

### 4.A.1.7.4.1. Oracle schema and table name

The following code can be placed in a configuration script action to hook it to the list of tables plugin support an Oracle database.
Example, in addition to how to use the BeanShell shows you how to get to the data contained in the results list.

Action title: What is a table (example BeanShell)
Action key: oracle-tables-actions

    import pl.mpak.orbada.gui.comps.table.ViewTable;
    import pl.mpak.sky.gui.mr.ModalResult;
    import pl.mpak.sky.gui.swing.MessageBox;
    import pl.mpak.usedb.util.SQLUtil;

    if (component instanceof ViewTable) {
      ViewTable vt = (ViewTable)component;
      if (vt.getSelectedRow() >= 0) {
        try {
          vt.getQuery().getRecord(vt.getSelectedRow());
          String schemaName = vt.getQuery().fieldByName("schema_name").getString();
          String tableName = vt.getQuery().fieldByName("table_name").getString();
          MessageBox.show(SQLUtil.createSqlName(schemaName, tableName));
        } catch (Exception ex) {
          MessageBox.show("Error", ex.getMessage(), ModalResult.OK);
        }
      }
    }

### 4.A.1.7.4.2. Oracle quick copy a table DDL to clipboard

The following code can be placed in a configuration script action to hook it to the list of tables plugin support an Oracle database.
The example shows how you can use the Oracle plugin object `SourceCreator` and copy the result to the clipboard of the operating system.

Action title: Quick copy DLL (example BeanShell)
Action key: oracle-tables-actions

    import pl.mpak.orbada.gui.comps.table.ViewTable;
    import pl.mpak.sky.gui.mr.ModalResult;
    import pl.mpak.sky.gui.swing.MessageBox;
    import pl.mpak.orbada.oracle.util.SourceCreator;
    import pl.mpak.util.TextTransfer;

    if (component instanceof ViewTable) {
      ViewTable vt = (ViewTable)component;
      if (vt.getSelectedRow() >= 0) {
        try {
          vt.getQuery().getRecord(vt.getSelectedRow());
          new TextTransfer().setClipboardContents(
            new SourceCreator(database, null).getSource(
              vt.getQuery().fieldByName("schema_name").getString(),
              "TABLE",
              vt.getQuery().fieldByName("table_name").getString()));
        } catch (Exception ex) {
          MessageBox.show("Problem", ex.getMessage(), ModalResult.OK);
        }
      }
    }

### 4.A.1.7.4.3. Kill Oracle session without DBA role

The following code can be placed in a configuration script action to hook it to the list of Oracle sessions.

This example shows how to call PL/SQL procedure to allow user without DBA privileges kill Oracle database session.

Action title: Kill RAC session
Action key: oracle-sessions-actions

    import pl.mpak.orbada.gui.comps.table.ViewTable;
    import pl.mpak.sky.gui.mr.ModalResult;
    import pl.mpak.sky.gui.swing.MessageBox;
    import pl.mpak.usedb.util.SQLUtil;

    if (component instanceof ViewTable) {
      ViewTable vt = (ViewTable)component;
      if (vt.getSelectedRow() >= 0) {
        try {
          vt.getQuery().getRecord(vt.getSelectedRow());
          String sid = vt.getQuery().fieldByName("sid").getString();
          String serial = vt.getQuery().fieldByName("serial#").getString();
          String inst = vt.getQuery().fieldByName("inst_id").getString();
          database.createCommand("begin kskill.kill_session("+sid+","+serial +","+inst+"); end;", true);
        } catch (Exception ex) {
          MessageBox.show("Błąd", ex.getMessage(), ModalResult.OK);
        }
      }
    }

ORBADA » Documentation in English » Plug-in documentation » BeanShell » Examples » BeanShell action
• © 2007–2016 • Andrzej Kałuża • Powered By DBPAGES • Hostet at •