public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append( name + " id: " + nodeID ); if ( route != null ) { buffer.append( " route name: " ).append( route.getName() ).append( " tour name: " ).append( tour.getName() ); } if ( pickupTransports != null ) { for (Iterator it = pickupTransports.iterator(); it.hasNext();) { buffer.append("Pickup transports: " + it.next()); } } if ( deliveryTransports != null ) { for (Iterator it = deliveryTransports.iterator(); it.hasNext();) { buffer.append("Delviery transports: " + it.next()); } } return buffer.toString(); }
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) { StringBuffer buf = new StringBuffer( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() ) .append( ' ' ) .append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) ) .append( " (" ); boolean identityColumn = idValue != null && idValue.isIdentityColumn( dialect ); // Try to find out the name of the primary key to create it as identity if the IdentityGenerator is used String pkname = null; if ( hasPrimaryKey() && identityColumn ) { pkname = ( (Column) getPrimaryKey().getColumnIterator().next() ).getQuotedName( dialect ); } Iterator iter = getColumnIterator(); while ( iter.hasNext() ) { Column col = (Column) iter.next(); buf.append( col.getQuotedName( dialect ) ) .append( ' ' ); if ( identityColumn && col.getQuotedName( dialect ).equals( pkname ) ) { // to support dialects that have their own identity data type if ( dialect.hasDataTypeInIdentityColumn() ) { buf.append( col.getSqlType( dialect, p ) ); } buf.append( ' ' ) .append( dialect.getIdentityColumnString( col.getSqlTypeCode( p ) ) ); } else { buf.append( col.getSqlType( dialect, p ) ); String defaultValue = col.getDefaultValue(); if ( defaultValue != null ) { buf.append( " default " ).append( defaultValue ); } if ( col.isNullable() ) { buf.append( dialect.getNullColumnString() ); } else { buf.append( " not null" ); } } boolean useUniqueConstraint = col.isUnique() && ( !col.isNullable() || dialect.supportsNotNullUnique() ); if ( useUniqueConstraint ) { if ( dialect.supportsUnique() ) { buf.append( " unique" ); } else { UniqueKey uk = getOrCreateUniqueKey( col.getQuotedName( dialect ) + '_' ); uk.addColumn( col ); } } if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) { buf.append( " check (" ) .append( col.getCheckConstraint() ) .append( ")" ); } String columnComment = col.getComment(); if ( columnComment != null ) { buf.append( dialect.getColumnComment( columnComment ) ); } if ( iter.hasNext() ) { buf.append( ", " ); } } if ( hasPrimaryKey() ) { buf.append( ", " ) .append( getPrimaryKey().sqlConstraintString( dialect ) ); } if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) { Iterator ukiter = getUniqueKeyIterator(); while ( ukiter.hasNext() ) { UniqueKey uk = (UniqueKey) ukiter.next(); String constraint = uk.sqlConstraintString( dialect ); if ( constraint != null ) { buf.append( ", " ).append( constraint ); } } } /*Iterator idxiter = getIndexIterator(); while ( idxiter.hasNext() ) { Index idx = (Index) idxiter.next(); buf.append(',').append( idx.sqlConstraintString(dialect) ); }*/ if ( dialect.supportsTableCheck() ) { Iterator chiter = checkConstraints.iterator(); while ( chiter.hasNext() ) { buf.append( ", check (" ) .append( chiter.next() ) .append( ')' ); } } buf.append( ')' ); if ( comment != null ) { buf.append( dialect.getTableComment( comment ) ); } return buf.append( dialect.getTableTypeString() ).toString(); }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/cascade/circle/Node.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/mapping/Table.java
Method name: String toString() Method name: String sqlCreateString(Dialect, Mapping, String, String)
Number of AST nodes: 2 Number of AST nodes: 2
1
public String toString()
1
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
2
	{
2
		StringBuffer buf = new StringBuffer( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() )
3
		StringBuffer buffer = new StringBuffer();
3
				.append( ' ' )
4
		
4
				.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
5
		buffer.append( name + " id: " + nodeID );
5
				.append( " (" );
6
		if ( route != null ) {
6
7
			buffer.append( " route name: " ).append( route.getName() ).append( " tour name: " ).append( tour.getName() );
7
		boolean identityColumn = idValue != null && idValue.isIdentityColumn( dialect );
8
		}
8
9
		if ( pickupTransports != null ) {
9
		// Try to find out the name of the primary key to create it as identity if the IdentityGenerator is used
10
			for (Iterator it = pickupTransports.iterator(); it.hasNext();) {
10
		String pkname = null;
11
				buffer.append("Pickup transports: " + it.next());
11
		if ( hasPrimaryKey() && identityColumn ) {
12
			}
12
			pkname = ( (Column) getPrimaryKey().getColumnIterator().next() ).getQuotedName( dialect );
13
		}
13
		}
14
		
14
15
		if ( deliveryTransports != null ) {
15
		Iterator iter = getColumnIterator();
16
			for (Iterator it = deliveryTransports.iterator(); it.hasNext();) {
16
		while ( iter.hasNext() ) {
17
				buffer.append("Delviery transports: " + it.next());
17
			Column col = (Column) iter.next();
18
			}
18
19
		}
19
			buf.append( col.getQuotedName( dialect ) )
20
		
20
					.append( ' ' );
21
		return buffer.toString();
21
22
	}
22
			if ( identityColumn && col.getQuotedName( dialect ).equals( pkname ) ) {
23
				// to support dialects that have their own identity data type
24
				if ( dialect.hasDataTypeInIdentityColumn() ) {
25
					buf.append( col.getSqlType( dialect, p ) );
26
				}
27
				buf.append( ' ' )
28
						.append( dialect.getIdentityColumnString( col.getSqlTypeCode( p ) ) );
29
			}
30
			else {
31
32
				buf.append( col.getSqlType( dialect, p ) );
33
34
				String defaultValue = col.getDefaultValue();
35
				if ( defaultValue != null ) {
36
					buf.append( " default " ).append( defaultValue );
37
				}
38
39
				if ( col.isNullable() ) {
40
					buf.append( dialect.getNullColumnString() );
41
				}
42
				else {
43
					buf.append( " not null" );
44
				}
45
46
			}
47
48
			boolean useUniqueConstraint = col.isUnique() &&
49
					( !col.isNullable() || dialect.supportsNotNullUnique() );
50
			if ( useUniqueConstraint ) {
51
				if ( dialect.supportsUnique() ) {
52
					buf.append( " unique" );
53
				}
54
				else {
55
					UniqueKey uk = getOrCreateUniqueKey( col.getQuotedName( dialect ) + '_' );
56
					uk.addColumn( col );
57
				}
58
			}
59
60
			if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
61
				buf.append( " check (" )
62
						.append( col.getCheckConstraint() )
63
						.append( ")" );
64
			}
65
66
			String columnComment = col.getComment();
67
			if ( columnComment != null ) {
68
				buf.append( dialect.getColumnComment( columnComment ) );
69
			}
70
71
			if ( iter.hasNext() ) {
72
				buf.append( ", " );
73
			}
74
75
		}
76
		if ( hasPrimaryKey() ) {
77
			buf.append( ", " )
78
					.append( getPrimaryKey().sqlConstraintString( dialect ) );
79
		}
80
81
		if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
82
			Iterator ukiter = getUniqueKeyIterator();
83
			while ( ukiter.hasNext() ) {
84
				UniqueKey uk = (UniqueKey) ukiter.next();
85
				String constraint = uk.sqlConstraintString( dialect );
86
				if ( constraint != null ) {
87
					buf.append( ", " ).append( constraint );
88
				}
89
			}
90
		}
91
		/*Iterator idxiter = getIndexIterator();
92
		while ( idxiter.hasNext() ) {
93
			Index idx = (Index) idxiter.next();
94
			buf.append(',').append( idx.sqlConstraintString(dialect) );
95
		}*/
96
97
		if ( dialect.supportsTableCheck() ) {
98
			Iterator chiter = checkConstraints.iterator();
99
			while ( chiter.hasNext() ) {
100
				buf.append( ", check (" )
101
						.append( chiter.next() )
102
						.append( ')' );
103
			}
104
		}
105
106
		buf.append( ')' );
107
108
		if ( comment != null ) {
109
			buf.append( dialect.getTableComment( comment ) );
110
		}
111
112
		return buf.append( dialect.getTableTypeString() ).toString();
113
	}
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.500
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    9
    for (Iterator it = deliveryTransports.iterator(); it.hasNext(); )
    9
    for (Iterator it = deliveryTransports.iterator(); it.hasNext(); )
    45
    while (chiter.hasNext())
    Differences
    Expression1Expression2Difference
    itchiterVARIABLE_NAME_MISMATCH
    java.util.Setjava.util.ListVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.Set of variable deliveryTransports does not match with type java.util.List of variable checkConstraints
    • Make classes java.util.Set and java.util.List extend a common superclass
    45
    while (chiter.hasNext())
    10
    buffer.append("Delviery transports: " + it.next());
    10
    buffer.append("Delviery transports: " + it.next());
    Preondition Violations
    Unmatched statement buffer.append("Delviery transports: " + it.next()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                  
                                                                                                                                
    46
    buf.append(", check (").append(chiter.next()).append(')');
    Precondition Violations (3)
    Row Violation
    1Type java.util.Set of variable deliveryTransports does not match with type java.util.List of variable checkConstraints
    2Unmatched statement buffer.append("Delviery transports: " + it.next()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Clone fragment #1 returns variables it , while Clone fragment #2 returns variables