try { Statement stat = _session.getSQLConnection().createStatement(); SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame(); IDatabaseObjectInfo[] dbObjs = sessMainFrm.getObjectTreeAPI().getSelectedDatabaseObjects(); StringBuffer script = new StringBuffer(); for (int i = 0; i < dbObjs.length; i++) { ITableInfo ti = (ITableInfo) dbObjs[i]; /////////////////////////////////////////////////////////// // IBM DB 2 specific code to read view definitions. String sql = "SELECT TEXT " + "FROM SYSIBM.SYSVIEWS " + "WHERE NAME = '" + ti.getSimpleName() + "'"; ResultSet res = stat.executeQuery(sql); res.next(); script.append(res.getString("TEXT")); script.append(getStatementSeparator()); res.close(); // /////////////////////////////////////////////////////////// } stat.close(); sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString()); sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB); } catch (Exception e) { throw new RuntimeException(e); }
try { IDatabaseObjectInfo[] dbObjs = _session.getSessionInternalFrame().getObjectTreeAPI().getSelectedDatabaseObjects(); Statement stat = _session.getSQLConnection().createStatement(); StringBuffer script = new StringBuffer(); for (int i = 0; i < dbObjs.length; i++) { IProcedureInfo pi = (IProcedureInfo) dbObjs[i]; /////////////////////////////////////////////////////////// // SybaseASE specific code to read procedure definitions. String sql = "Select text " + "from sysobjects inner join syscomments on syscomments.id = sysobjects.id " + "where name = '" + pi.getSimpleName().replace(";1", "") + "'"; ResultSet res = stat.executeQuery(sql); while(res.next()) { script.append(res.getString("text")); } script.append(getStatementSeparator()); res.close(); // /////////////////////////////////////////////////////////// } stat.close(); SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame(); sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString()); sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB); } catch (Exception e) { throw new RuntimeException(e); }
Clone fragments detected by clone detection tool
File path: /sql12/plugins/example/src/net/sourceforge/squirrel_sql/plugins/example/ScriptDB2ViewAction.java File path: /sql12/plugins/sybase/src/net/sourceforge/squirrel_sql/plugins/SybaseASE/ScriptSybaseASEProcedureAction.java
Method name: void actionPerformed(ActionEvent) Method name: void actionPerformed(ActionEvent)
Number of AST nodes: 16 Number of AST nodes: 16
1
try
1
try
2
      {
2
      {
3
         Statement stat = _session.getSQLConnection().createStatement();
3
         
4
         SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame();
4
IDatabaseObjectInfo[] dbObjs = _session.getSessionInternalFrame().getObjectTreeAPI().getSelectedDatabaseObjects();
5
         IDatabaseObjectInfo[] dbObjs = sessMainFrm.getObjectTreeAPI().getSelectedDatabaseObjects();
5
         Statement stat = _session.getSQLConnection().createStatement();
6
         StringBuffer script = new StringBuffer();
6
         StringBuffer script = new StringBuffer();
7
         for (int i = 0; i < dbObjs.length; i++)
7
         for (int i = 0; i < dbObjs.length; i++)
8
         {
8
         {
9
            ITableInfo ti = (ITableInfo) dbObjs[i];
9
            IProcedureInfo pi = (IProcedureInfo) dbObjs[i];
10
            ///////////////////////////////////////////////////////////
10
            ///////////////////////////////////////////////////////////
11
            // IBM DB 2 specific code to read view definitions.
11
            // SybaseASE specific code to read procedure definitions.
12
            String sql =
12
            String sql =
13
               "SELECT TEXT " +
13
                "Select text " +
14
               "FROM SYSIBM.SYSVIEWS " +
14
                "from sysobjects inner join syscomments on syscomments.id = sysobjects.id " +
15
               "WHERE NAME = '" + ti.getSimpleName() + "'";
15
                "where name = '" + pi.getSimpleName().replace(";1", "") + "'";
16
            ResultSet res = stat.executeQuery(sql);
16
             ResultSet res = stat.executeQuery(sql);
17
            res.next();
17
             while(res.next()
18
)
19
             {
18
            script.append(res.getString("TEXT"));
20
                 script.append(res.getString("
21
text"));            
22
             }
19
            script.append(getStatementSeparator());
23
             script.append(getStatementSeparator());
20
            res.close();
24
             res.close();
21
            //
25
             //
22
            ///////////////////////////////////////////////////////////
26
             ///////////////////////////////////////////////////////////
23
         }
27
         }
24
         stat.close();
28
         stat.close();
29
         SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame();
25
         sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());
30
         sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());
26
         sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
31
         sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
27
      }
32
      }
28
      catch (Exception e)
33
      catch (Exception e)
29
      {
34
      {
30
         throw new RuntimeException(e);
35
         throw new RuntimeException(e);
31
      }
36
      }
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)7.4
Clones locationClones are in different classes having the same super class
Number of node comparisons2