public class SequenceParentExpander implements INodeExpander { /** SQL used to load sequence names */ private static final String SQL = "select SEQNAME " + "from SYSCAT.SEQUENCES " + "WHERE SEQSCHEMA = ? " + "AND SEQNAME like ? "; /** SQL used to load sequence names on OS/400 */ private static final String OS_400_SQL = "select sequence_name " + "from qsys2.syssequences " + "where sequence_schema = ? " + "and sequence_name like ? "; /** whether or not we are connected to OS/400 */ private boolean isOS400 = false; /** * Default ctor. */ public SequenceParentExpander(boolean isOS400) { super(); this.isOS400 = isOS400; } /** * Create the child nodes for the passed parent node and return them. Note * that this method should <B>not</B> actually add the child nodes to the * parent node as this is taken care of in the caller. * * @param session Current session. * @param node Node to be expanded. * * @return A list of <TT>ObjectTreeNode</TT> objects representing the child * nodes for the passed node. */ public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode) throws SQLException { final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>(); final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo(); final ISQLConnection conn = session.getSQLConnection(); final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData(); final String catalogName = parentDbinfo.getCatalogName(); final String schemaName = parentDbinfo.getSchemaName(); final ObjFilterMatcher filterMatcher = new ObjFilterMatcher(session.getProperties()); String sql = SQL; if (isOS400) { sql = OS_400_SQL; } final PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = null; try { pstmt.setString(1, schemaName); pstmt.setString(2, filterMatcher.getSqlLikeMatchString()); rs = pstmt.executeQuery(); while (rs.next()) { IDatabaseObjectInfo si = new DatabaseObjectInfo(catalogName, schemaName, rs.getString(1), DatabaseObjectType.SEQUENCE, md); if(filterMatcher.matches(si.getSimpleName())) { childNodes.add(new ObjectTreeNode(session, si)); } } } finally { SQLUtilities.closeResultSet(rs); SQLUtilities.closeStatement(pstmt); } return childNodes
public class UDFParentExpander implements INodeExpander { /** SQL used to load UDF names */ private static final String SQL = "SELECT name " + "FROM SYSIBM.SYSFUNCTIONS " + "WHERE schema = ? " + "AND name like ? " + "AND implementation is null"; /** SQL used to load UDF names on OS/400 systems */ private static final String OS_400_SQL = "select routine_name " + "from QSYS2.SYSFUNCS " + "where routine_schema = ? " + "and routine_name like ? "; /** whether or not we are connected to OS/400 */ private boolean isOS400 = false; /** * Default ctor. */ public UDFParentExpander(boolean isOS400) { super(); this.isOS400 = isOS400; } /** * Create the child nodes for the passed parent node and return them. Note * that this method should <B>not</B> actually add the child nodes to the * parent node as this is taken care of in the caller. * * @param session Current session. * @param node Node to be expanded. * * @return A list of <TT>ObjectTreeNode</TT> objects representing the child * nodes for the passed node. */ public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode) throws SQLException { final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>(); final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo(); final ISQLConnection conn = session.getSQLConnection(); final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData(); final String catalogName = parentDbinfo.getCatalogName(); final String schemaName = parentDbinfo.getSchemaName(); final ObjFilterMatcher filterMatcher = new ObjFilterMatcher(session.getProperties()); String sql = SQL; if (isOS400) { sql = OS_400_SQL; } final PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = null; try { pstmt.setString(1, schemaName); pstmt.setString(2, filterMatcher.getSqlLikeMatchString()); rs = pstmt.executeQuery(); while (rs.next()) { IDatabaseObjectInfo si = new DatabaseObjectInfo(catalogName, schemaName, rs.getString(1), DatabaseObjectType.UDF, md); if(filterMatcher.matches(si.getSimpleName())) { childNodes.add(new ObjectTreeNode(session, si)); } } } finally { SQLUtilities.closeResultSet(rs); SQLUtilities.closeStatement(pstmt); } return childNodes
Clone fragments detected by clone detection tool
File path: /sql12/plugins/db2/src/net/sourceforge/squirrel_sql/plugins/db2/exp/SequenceParentExpander.java File path: /sql12/plugins/db2/src/net/sourceforge/squirrel_sql/plugins/db2/exp/UDFParentExpander.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class SequenceParentExpander implements INodeExpander
1
public class UDFParentExpander implements INodeExpander
2
{
2
{
3
	/** SQL used to load sequence names  */
3
	/** SQL used to load UDF names  */
4
	private static final String SQL =
4
	private static final String SQL =
5
        "select SEQNAME " +
5
	    "SELECT name " +
6
        "from SYSCAT.SEQUENCES " +
6
	    "FROM SYSIBM.SYSFUNCTIONS " +
7
        "WHERE SEQSCHEMA = ? " +
7
	    "WHERE schema = ? " +
8
        "AND SEQNAME like ? ";
8
	    "AND name like ? "
9
    
9
 +
10
	    "AND implementation is null";
11
	
10
	/** SQL used to load sequence names on OS/400 */
12
	/** SQL used to load UDF names on OS/400 systems */
11
	private static final String OS_400_SQL = 
13
	private static final String OS_400_SQL = 
12
	    "select sequence_name " +
14
	    "select routine_name " +
13
	    "from qsys2.syssequences " +
15
	    "from QSYS2.SYSFUNCS " +
14
	    "where sequence_schema = ? " +
16
	    "where routine_schema = ? " +
15
	    "and sequence_name like ? ";
17
	    "and routine_name like ? ";
16
	
17
    
18
	    
19
	
18
/** whether or not we are connected to OS/400 */
20
	/** whether or not we are connected to OS/400 */
19
    private boolean isOS400 = false;	
21
	private boolean isOS400 = false;
20
	
22
	
21
	/**
23
	/**
22
	 * Default ctor.
24
	 * Default ctor.
23
	 */
25
	 */
24
	public SequenceParentExpander(boolean isOS400)
26
	public UDFParentExpander(boolean isOS400)
25
	{
27
	{
26
		super();
28
		super();
27
		this.isOS400 = isOS400;
29
		this.isOS400 = isOS400;
28
	}
30
	}
29
	/**
31
	/**
30
	 * Create the child nodes for the passed parent node and return them. Note
32
	 * Create the child nodes for the passed parent node and return them. Note
31
	 * that this method should <B>not</B> actually add the child nodes to the
33
	 * that this method should <B>not</B> actually add the child nodes to the
32
	 * parent node as this is taken care of in the caller.
34
	 * parent node as this is taken care of in the caller.
33
	 *
35
	 *
34
	 * @param	session	Current session.
36
	 * @param	session	Current session.
35
	 * @param	node	Node to be expanded.
37
	 * @param	node	Node to be expanded.
36
	 *
38
	 *
37
	 * @return	A list of <TT>ObjectTreeNode</TT> objects representing the child
39
	 * @return	A list of <TT>ObjectTreeNode</TT> objects representing the child
38
	 *			nodes for the passed node.
40
	 *			nodes for the passed node.
39
	 */
41
	 */
40
	public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode)
42
	public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode)
41
		throws SQLException
43
		throws SQLException
42
	{
44
	{
43
		final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
45
		final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
44
		final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
46
		final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
45
		final ISQLConnection conn = session.getSQLConnection();
47
		final ISQLConnection conn = session.getSQLConnection();
46
		final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
48
		final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
47
		final String catalogName = parentDbinfo.getCatalogName();
49
		final String catalogName = parentDbinfo.getCatalogName();
48
		final String schemaName = parentDbinfo.getSchemaName();
50
		final String schemaName = parentDbinfo.getSchemaName();
49
      final ObjFilterMatcher filterMatcher = new ObjFilterMatcher(session.getProperties());
51
      final ObjFilterMatcher filterMatcher = new ObjFilterMatcher(session.getProperties());
50
  
51
      String sql = SQL;
52
      String sql = SQL;
52
        if (isOS400) {
53
		if (isOS400) {
53
            sql = OS_400_SQL;
54
		    sql = OS_400_SQL;
54
        }
55
		}
55
		final PreparedStatement pstmt = conn.prepareStatement(sql);
56
		final PreparedStatement pstmt = conn.prepareStatement(sql);
56
        ResultSet rs = null;
57
        ResultSet rs = null;
57
		try
58
		try
58
		{
59
		{
59
			pstmt.setString(1, schemaName);
60
			pstmt.setString(1, schemaName);
60
			pstmt.setString(2, filterMatcher.getSqlLikeMatchString());
61
			pstmt.setString(2, filterMatcher.getSqlLikeMatchString());
61
			rs = pstmt.executeQuery();
62
			rs = pstmt.executeQuery();
62
            while (rs.next())
63
				while (rs.next())
63
            {
64
               
64
				{
65
IDatabaseObjectInfo si = new DatabaseObjectInfo(catalogName,
65
					IDatabaseObjectInfo si = new DatabaseObjectInfo(catalogName,
66
                                    schemaName, rs.getString(1),
67
                                    
66
												schemaName, rs.getString(1),
68
DatabaseObjectType.SEQUENCE, md);
67
												DatabaseObjectType.UDF, md);
69
               if(filterMatcher.matches(si.getSimpleName()))
68
               if(filterMatcher.matches(si.getSimpleName()))
70
               {
69
               {
71
                  childNodes.add(new ObjectTreeNode(session, si));
70
                  childNodes.add(new ObjectTreeNode(session, si));
72
               }
71
               }
73
            }
72
            }
74
		}
73
		}
75
		finally
74
		finally
76
		{
75
		{
77
		    SQLUtilities.closeResultSet(rs);
76
		    SQLUtilities.closeResultSet(rs);
78
            SQLUtilities.closeStatement(pstmt);
77
            SQLUtilities.closeStatement(pstmt);
79
		}
78
		}
80
		return childNodes
79
		return childNodes
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)0.0
Clones location
Number of node comparisons0