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();
12
		if ( needsAutoCommit && !connection.getAutoCommit() ) {
13
			connection.commit();
11
 = provider.getConnection();
12
		toggleAutoCommit = needsAutoCommit && !connection.getAutoCommit();
13
		if ( toggleAutoCommit ) {
14
			try {
15
				connection.commit();
16
			}
17
			catch( Throwable ignore ) {
18
				// might happen with a managed connection
19
			}
14
			connection.setAutoCommit( true );
20
			connection.setAutoCommit( true );
15
		}
21
		}
16
	}
22
	}
17
	public Connection getConnection() throws SQLException {
23
	public Connection getConnection() throws SQLException {
18
		return connection;
24
		return connection;
19
	}
25
	}
20
	public void release() throws SQLException {
26
	public void release() throws SQLException {
21
		
27
		// we only release the connection
22
if ( connection != null ) {
28
		if ( connection != null ) {
23
			try {
29
			
24
				JDBCExceptionReporter.logAndClearWarnings( connection );
30
JDBCExceptionReporter.logAndClearWarnings( connection );
25
				connectionProvider.closeConnection( connection );
31
			
26
			}
27
			finally {
28
				connectionProvider.close();
29
			}
30
		}
32
if ( toggleAutoCommit ) {
33
				connection.setAutoCommit( false );
34
			}
35
			provider.closeConnection( connection );
31
		connection = null
36
			connection = null
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