try { ps = session.getBatcher().prepareStatement( timestampSelectString ); ResultSet rs = session.getBatcher().getResultSet( ps ); rs.next(); Timestamp ts = rs.getTimestamp( 1 ); if ( log.isTraceEnabled() ) { log.trace( "current timestamp retreived from db : " + ts + " (nanos=" + ts.getNanos() + ", time=" + ts.getTime() + ")" ); } return ts; } catch( SQLException sqle ) { throw JDBCExceptionHelper.convert( session.getFactory().getSQLExceptionConverter(), sqle, "could not select current db timestamp", timestampSelectString ); } finally { if ( ps != null ) { try { session.getBatcher().closeStatement( ps ); } catch( SQLException sqle ) { log.warn( "unable to clean up prepared statement", sqle ); } } }
try { cs = session.getBatcher().prepareCallableStatement( callString ); cs.registerOutParameter( 1, java.sql.Types.TIMESTAMP ); cs.execute(); Timestamp ts = cs.getTimestamp( 1 ); if ( log.isTraceEnabled() ) { log.trace( "current timestamp retreived from db : " + ts + " (nanos=" + ts.getNanos() + ", time=" + ts.getTime() + ")" ); } return ts; } catch( SQLException sqle ) { throw JDBCExceptionHelper.convert( session.getFactory().getSQLExceptionConverter(), sqle, "could not call current db timestamp function", callString ); } finally { if ( cs != null ) { try { session.getBatcher().closeStatement( cs ); } catch( SQLException sqle ) { log.warn( "unable to clean up callable statement", sqle ); } } }
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/type/DbTimestampType.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/type/DbTimestampType.java
Method name: Timestamp usePreparedStatement(String, SessionImplementor) Method name: Timestamp useCallableStatement(String, SessionImplementor)
Number of AST nodes: 8 Number of AST nodes: 8
1
try {
1
try {
2
			ps = session.getBatcher().prepareStatement( timestampSelectString );
2
			cs = session.getBatcher().prepareCallableStatement( 
3
			ResultSet rs = session.getBatcher().getResultSet( ps
3
callString );
4
 );
4
			cs.registerOutParameter( 1, java.sql.Types.TIMESTAMP );
5
			rs.next();
5
			cs.execute();
6
			Timestamp ts = rs.getTimestamp( 1 );
6
			Timestamp ts = cs.getTimestamp( 1 );
7
			if ( log.isTraceEnabled() ) {
7
			if ( log.isTraceEnabled() ) {
8
				log.trace(
8
				log.trace(
9
				        "current timestamp retreived from db : " + ts +
9
				        "current timestamp retreived from db : " + ts +
10
				        " (nanos=" + ts.getNanos() +
10
				        " (nanos=" + ts.getNanos() +
11
				        ", time=" + ts.getTime() + ")"
11
				        ", time=" + ts.getTime() + ")"
12
					);
12
					);
13
			}
13
			}
14
			return ts;
14
			return ts;
15
		}
15
		}
16
		catch( SQLException sqle ) {
16
		catch( SQLException sqle ) {
17
			throw JDBCExceptionHelper.convert(
17
			throw JDBCExceptionHelper.convert(
18
			        session.getFactory().getSQLExceptionConverter(),
18
			        session.getFactory().getSQLExceptionConverter(),
19
			        sqle,
19
			        sqle,
20
			        "could not select current db timestamp",
20
			        "could not call current db timestamp function",
21
			        timestampSelectString
21
			        callString
22
				);
22
				);
23
		}
23
		}
24
		finally {
24
		finally {
25
			if ( ps != null ) {
25
			if ( cs != null ) {
26
				try {
26
				try {
27
					session.getBatcher().closeStatement( ps );
27
					session.getBatcher().closeStatement( cs );
28
				}
28
				}
29
				catch( SQLException sqle ) {
29
				catch( SQLException sqle ) {
30
					log.warn( "unable to clean up prepared statement", sqle );
30
					log.warn( "unable to clean up callable statement", sqle );
31
				}
31
				}
32
			}
32
			}
33
		}
33
		}
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.7
Clones locationClones are declared in the same class
Number of node comparisons21
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)1.3
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    6
    Timestamp ts = rs.getTimestamp(1);
    6
    Timestamp ts = rs.getTimestamp(1);
    6
    Timestamp ts = cs.getTimestamp(1);
    Differences
    Expression1Expression2Difference
    rscsVARIABLE_NAME_MISMATCH
    java.sql.ResultSetjava.sql.CallableStatementVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.sql.ResultSet of variable rs does not match with type java.sql.CallableStatement of variable cs
    • Make classes java.sql.ResultSet and java.sql.CallableStatement extend a common superclass
    6
    Timestamp ts = cs.getTimestamp(1);
    7
    if (log.isTraceEnabled())
    7
    if (log.isTraceEnabled())
    8
    log.trace("current timestamp retreived from db : " + ts + " (nanos=" + ts.getNanos() + ", time=" + ts.getTime() + ")");
    8
    log.trace("current timestamp retreived from db : " + ts + " (nanos=" + ts.getNanos() + ", time=" + ts.getTime() + ")");
    Precondition Violations (1)
    Row Violation
    1Type java.sql.ResultSet of variable rs does not match with type java.sql.CallableStatement of variable cs