PreparedStatement ps = null; 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 ); } } }
CallableStatement cs = null; 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: 9 Number of AST nodes: 9
1
PreparedStatement ps = null;
1
CallableStatement cs = null;
2
		try {
2
		try {
3
			ps = session.getBatcher().prepareStatement( timestampSelectString );
3
			cs = session.getBatcher().prepareCallableStatement( 
4
			ResultSet rs = session.getBatcher().getResultSet( ps
4
callString );
5
 );
5
			cs.registerOutParameter( 1, java.sql.Types.TIMESTAMP );
6
			rs.next();
6
			cs.execute();
7
			Timestamp ts = rs.getTimestamp( 1 );
7
			Timestamp ts = cs.getTimestamp( 1 );
8
			if ( log.isTraceEnabled() ) {
8
			if ( log.isTraceEnabled() ) {
9
				log.trace(
9
				log.trace(
10
				        "current timestamp retreived from db : " + ts +
10
				        "current timestamp retreived from db : " + ts +
11
				        " (nanos=" + ts.getNanos() +
11
				        " (nanos=" + ts.getNanos() +
12
				        ", time=" + ts.getTime() + ")"
12
				        ", time=" + ts.getTime() + ")"
13
					);
13
					);
14
			}
14
			}
15
			return ts;
15
			return ts;
16
		}
16
		}
17
		catch( SQLException sqle ) {
17
		catch( SQLException sqle ) {
18
			throw JDBCExceptionHelper.convert(
18
			throw JDBCExceptionHelper.convert(
19
			        session.getFactory().getSQLExceptionConverter(),
19
			        session.getFactory().getSQLExceptionConverter(),
20
			        sqle,
20
			        sqle,
21
			        "could not select current db timestamp",
21
			        "could not call current db timestamp function",
22
			        timestampSelectString
22
			        callString
23
				);
23
				);
24
		}
24
		}
25
		finally {
25
		finally {
26
			if ( ps != null ) {
26
			if ( cs != null ) {
27
				try {
27
				try {
28
					session.getBatcher().closeStatement( ps );
28
					session.getBatcher().closeStatement( cs );
29
				}
29
				}
30
				catch( SQLException sqle ) {
30
				catch( SQLException sqle ) {
31
					log.warn( "unable to clean up prepared statement", sqle );
31
					log.warn( "unable to clean up callable statement", sqle );
32
				}
32
				}
33
			}
33
			}
34
		}
34
		}
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.6
Clones locationClones are declared in the same class
Number of node comparisons41
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements7
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)20.8
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    PreparedStatement ps = null;
    1
    PreparedStatement ps = null;
    1
    CallableStatement cs = null;
    Differences
    Expression1Expression2Difference
    java.sql.PreparedStatementjava.sql.CallableStatementSUBCLASS_TYPE_MISMATCH
    pscsVARIABLE_NAME_MISMATCH
    java.sql.PreparedStatementjava.sql.CallableStatementSUBCLASS_TYPE_MISMATCH
    1
    CallableStatement cs = null;
    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 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 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 (19)
    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 ps cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression session.getBatcher().prepareStatement(timestampSelectString) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression session.getBatcher().prepareCallableStatement(callString) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Unmatched 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
    10Unmatched 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
    11Unmatched 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
    12Unmatched 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
    13Unmatched statement cs.execute(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Unmatched 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
    15Unmatched 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
    16Expression rs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression cs cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Type java.sql.ResultSet of variable rs does not match with type java.sql.CallableStatement of variable cs
    19Clone fragment #1 returns variable ps with type java.sql.PreparedStatement , while Clone fragment #2 returns variable cs with type java.sql.CallableStatement