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 comparisons40
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)21.4
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    2
    try
    2
    try
    2
    try
    Differences
    Expression1Expression2Difference
    "could not select current db timestamp""could not call current db timestamp function"LITERAL_VALUE_MISMATCH
    timestampSelectStringcallStringVARIABLE_NAME_MISMATCH
    pscsVARIABLE_NAME_MISMATCH
    java.sql.PreparedStatementjava.sql.CallableStatementSUBCLASS_TYPE_MISMATCH
    pscsVARIABLE_NAME_MISMATCH
    java.sql.PreparedStatementjava.sql.CallableStatementSUBCLASS_TYPE_MISMATCH
    "unable to clean up prepared statement""unable to clean up callable statement"LITERAL_VALUE_MISMATCH
    Preondition Violations
    Expression ps cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression ps cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2
    try
    3
    ps = session.getBatcher().prepareStatement(timestampSelectString);
    3
    ps = session.getBatcher().prepareStatement(timestampSelectString);
    3
    cs = session.getBatcher().prepareCallableStatement(callString);
    Differences
    Expression1Expression2Difference
    pscsVARIABLE_NAME_MISMATCH
    java.sql.PreparedStatementjava.sql.CallableStatementSUBCLASS_TYPE_MISMATCH
    timestampSelectStringcallStringVARIABLE_NAME_MISMATCH
    prepareStatementprepareCallableStatementMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression session.getBatcher().prepareStatement(timestampSelectString) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression session.getBatcher().prepareCallableStatement(callString) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3
    cs = session.getBatcher().prepareCallableStatement(callString);
                                                                                                                  
    4
    cs.registerOutParameter(1, java.sql.Types.TIMESTAMP);
    Preondition Violations
    Unmatched statement cs.registerOutParameter(1,java.sql.Types.TIMESTAMP); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement cs.registerOutParameter(1,java.sql.Types.TIMESTAMP); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    4
    cs.registerOutParameter(1, java.sql.Types.TIMESTAMP);
    4
    ResultSet rs = session.getBatcher().getResultSet(ps);
    4
    ResultSet rs = session.getBatcher().getResultSet(ps);
    Preondition Violations
    Unmatched statement ResultSet rs=session.getBatcher().getResultSet(ps); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement ResultSet rs=session.getBatcher().getResultSet(ps); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                                                                                
                                    
    5
    cs.execute();
    Preondition Violations
    Unmatched statement cs.execute(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched statement cs.execute(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    5
    cs.execute();
    5
    rs.next();
    5
    rs.next();
    Preondition Violations
    Unmatched statement rs.next(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                              
    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
    Expression rs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    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() + ")");
    9
    return ts;
    9
    return ts;
    Precondition Violations (17)
    Row Violation
    1Expression ps cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression ps cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression session.getBatcher().prepareStatement(timestampSelectString) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression session.getBatcher().prepareCallableStatement(callString) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Unmatched statement cs.registerOutParameter(1,java.sql.Types.TIMESTAMP); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Unmatched statement cs.registerOutParameter(1,java.sql.Types.TIMESTAMP); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    9Unmatched statement ResultSet rs=session.getBatcher().getResultSet(ps); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Unmatched statement ResultSet rs=session.getBatcher().getResultSet(ps); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    11Unmatched statement cs.execute(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement cs.execute(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    13Unmatched statement rs.next(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    14Expression rs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    15Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    16Type java.sql.ResultSet of variable rs does not match with type java.sql.CallableStatement of variable cs
    17Clone fragment #1 returns variable ps with type java.sql.PreparedStatement , while Clone fragment #2 returns variable cs with type java.sql.CallableStatement