class ManagedProviderConnectionHelper implements ConnectionHelper { private Properties cfgProperties; private ConnectionProvider connectionProvider; private Connection connection; public ManagedProviderConnectionHelper(Properties cfgProperties) { this.cfgProperties = cfgProperties; } public void prepare(boolean needsAutoCommit) throws SQLException { connectionProvider = ConnectionProviderFactory.newConnectionProvider( cfgProperties ); connection = connectionProvider.getConnection(); if ( needsAutoCommit && !connection.getAutoCommit() ) { connection.commit(); connection.setAutoCommit( true ); } } public Connection getConnection() throws SQLException { return connection; } public void release() throws SQLException { if ( connection != null ) { try { JDBCExceptionReporter.logAndClearWarnings( connection ); connectionProvider.closeConnection( connection ); } finally { connectionProvider.close(); } } connection = null;
class SuppliedConnectionProviderConnectionHelper implements ConnectionHelper { private ConnectionProvider provider; private Connection connection; private boolean toggleAutoCommit; public SuppliedConnectionProviderConnectionHelper(ConnectionProvider provider) { this.provider = provider; } public void prepare(boolean needsAutoCommit) throws SQLException { connection = provider.getConnection(); toggleAutoCommit = needsAutoCommit && !connection.getAutoCommit(); if ( toggleAutoCommit ) { try { connection.commit(); } catch( Throwable ignore ) { // might happen with a managed connection } connection.setAutoCommit( true ); } } public Connection getConnection() throws SQLException { return connection; } public void release() throws SQLException { // we only release the connection if ( connection != null ) { JDBCExceptionReporter.logAndClearWarnings( connection ); if ( toggleAutoCommit ) { connection.setAutoCommit( false ); } provider.closeConnection( connection ); connection = null;
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/tool/hbm2ddl/ManagedProviderConnectionHelper.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/tool/hbm2ddl/SuppliedConnectionProviderConnectionHelper.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
class ManagedProviderConnectionHelper implements ConnectionHelper {
1
class SuppliedConnectionProviderConnectionHelper implements ConnectionHelper {
2
	private Properties cfgProperties;
2
	private ConnectionProvider provider;
3
	private ConnectionProvider connectionProvider;
3
	private Connection connection;
4
	private Connection connection;
4
	private 
5
	public ManagedProviderConnectionHelper(Properties cfgProperties) {
6
		this.cfgProperties = cfgProperties
5
boolean toggleAutoCommit;
6
	public SuppliedConnectionProviderConnectionHelper(ConnectionProvider provider) {
7
;
7
		this.provider = provider;
8
	}
8
	}
9
	public void prepare(boolean needsAutoCommit) throws SQLException {
9
	public void prepare(boolean needsAutoCommit) throws SQLException {
10
		connectionProvider = ConnectionProviderFactory.newConnectionProvider( cfgProperties );
10
		connection
11
		connection = connectionProvider.getConnection
11
 = provider.getConnection();
12
();
12
		toggleAutoCommit = needsAutoCommit && !connection.getAutoCommit();
13
		if ( needsAutoCommit && !connection.getAutoCommit() ) {
13
		if ( toggleAutoCommit 
14
			connection.commit();
14
) {
15
			try {
16
				connection.commit();
17
			}
18
			catch( Throwable ignore ) {
19
				// might happen with a managed connection
20
			}
15
			connection.setAutoCommit( true );
21
			connection.setAutoCommit( true );
16
		}
22
		}
17
	}
23
	}
18
	public Connection getConnection() throws SQLException {
24
	public Connection getConnection() throws SQLException {
19
		return connection;
25
		return connection;
20
	}
26
	}
21
	public void release() throws SQLException {
27
	public void release() throws SQLException {
22
		
28
		// we only release the connection
23
if ( connection != null ) {
29
		if ( connection != null ) {
24
			try {
30
			
25
				JDBCExceptionReporter.logAndClearWarnings( connection );
31
JDBCExceptionReporter.logAndClearWarnings( connection );
26
				connectionProvider.closeConnection( connection );
32
			
27
			}
28
			finally {
29
				connectionProvider.close();
30
			}
31
		}
33
if ( toggleAutoCommit ) {
34
				connection.setAutoCommit( false );
35
			}
36
			provider.closeConnection( connection );
32
		connection = null;
37
			connection = null;
33
	
38
		
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