1 21 package net.mlw.vlh.adapter.jdbc.util; 22 23 import java.sql.Connection ; 24 import java.sql.PreparedStatement ; 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 28 import javax.sql.DataSource ; 29 30 36 public class StandardConnectionCreator implements ConnectionCreator 37 { 38 private DataSource dataSource; 39 40 private int transactionIsolation = 0; 41 42 public StandardConnectionCreator() 43 {} 44 45 public StandardConnectionCreator(DataSource dataSource) 46 { 47 this.dataSource = dataSource; 48 } 49 50 public Connection createConnection() throws SQLException 51 { 52 Connection connection = dataSource.getConnection(); 53 switch (transactionIsolation) 54 { 55 case Connection.TRANSACTION_READ_UNCOMMITTED: 56 case Connection.TRANSACTION_READ_COMMITTED: 57 case Connection.TRANSACTION_REPEATABLE_READ: 58 case Connection.TRANSACTION_SERIALIZABLE: 59 connection.setTransactionIsolation(transactionIsolation); 60 connection.setAutoCommit(false); 61 break; 62 } 63 return connection; 64 } 65 66 public void close(ResultSet result, PreparedStatement statement, Connection connection) 67 { 68 JdbcUtil.close(result, statement, connection); 69 } 70 71 public DataSource getDataSource() 72 { 73 return dataSource; 74 } 75 76 public void setDataSource(DataSource dataSource) 77 { 78 this.dataSource = dataSource; 79 } 80 public void setTransactionIsolation(int transactionIsolation) 81 { 82 this.transactionIsolation = transactionIsolation; 83 } 84 } | Popular Tags |