private static JdbcTransactionFactory createTransactionFactory() { return new JdbcTransactionFactory(); } }
@Override public Connection getConnection() throws SQLException { if (connection == null) { openConnection(); } return connection; }
@Override public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) { return new JdbcTransaction(ds, level, autoCommit); } }
protected void openConnection() throws SQLException { if (log.isDebugEnabled()) { log.debug("Opening JDBC Connection"); } connection = dataSource.getConnection(); if (level != null) { connection.setTransactionIsolation(level.getLevel()); } setDesiredAutoCommit(autoCommmit); }
@Override public void close() throws SQLException { if (connection != null) { resetAutoCommit(); if (log.isDebugEnabled()) { log.debug("Closing JDBC Connection [" + connection + "]"); } connection.close(); } }
public void initTransactionFactory() { if (transactionFactory == null) { if (transactionsExternallyManaged) { transactionFactory = new ManagedTransactionFactory(); } else { transactionFactory = new JdbcTransactionFactory(); } } }
@Override public Transaction newTransaction(DataSource ds, TransactionIsolationLevel level, boolean autoCommit) { return new JdbcTransaction(ds, level, autoCommit); } }
protected void openConnection() throws SQLException { if (log.isDebugEnabled()) { log.debug("Opening JDBC Connection"); } connection = dataSource.getConnection(); if (level != null) { connection.setTransactionIsolation(level.getLevel()); } setDesiredAutoCommit(autoCommit); }
@Override public void close() throws SQLException { if (connection != null) { resetAutoCommit(); if (log.isDebugEnabled()) { log.debug("Closing JDBC Connection [" + connection + "]"); } connection.close(); } }
@Override public Connection getConnection() throws SQLException { if (connection == null) { openConnection(); } return connection; }
protected void initTransactionFactory() { if (transactionFactory == null) { if (transactionsExternallyManaged) { transactionFactory = new ManagedTransactionFactory(); } else { transactionFactory = new JdbcTransactionFactory(); } } }
@Override public Transaction newTransaction(Connection conn) { return new JdbcTransaction(conn); }
public JdbcTransaction(Connection connection, boolean desiredAutoCommit) { this.connection = connection; setDesiredAutoCommit(desiredAutoCommit); }
protected void initTransactionFactory() { if (transactionFactory == null) { if (transactionsExternallyManaged) { transactionFactory = new ManagedTransactionFactory(); } else { transactionFactory = new JdbcTransactionFactory(); } } }
@Override public Transaction newTransaction(Connection conn) { return new JdbcTransaction(conn); }
private static JdbcTransactionFactory createTransactionFactory() { return new JdbcTransactionFactory(); } }
public Transaction newTransaction(Connection conn, boolean autoCommit) { return new JdbcTransaction(conn, autoCommit); }
protected void initTransactionFactory() { if (transactionFactory == null) { if (transactionsExternallyManaged) { transactionFactory = new ManagedTransactionFactory(); } else { transactionFactory = new JdbcTransactionFactory(); } } }
public void initTransactionFactory() { if (transactionFactory == null) { if (transactionsExternallyManaged) { transactionFactory = new ManagedTransactionFactory(); } else { transactionFactory = new JdbcTransactionFactory(); } } }
public static void main(String[] args) throws IOException { UnpooledDataSource dataSource = new UnpooledDataSource( "com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/mybatis", "root", ""); TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("Java", transactionFactory, dataSource); Configuration configuration = new Configuration(environment); configuration.getTypeAliasRegistry().registerAliases("tk.mybatis.simple.model"); configuration.setLogImpl(Log4jImpl.class); InputStream inputStream = Resources.getResourceAsStream("tk/mybatis/simple/mapper/CountryMapper.xml"); XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, "tk/mybatis/simple/mapper/CountryMapper.xml", configuration.getSqlFragments()); mapperParser.parse(); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); SqlSession sqlSession = sqlSessionFactory.openSession(); try { List<Country> countryList = sqlSession.selectList("selectAll"); printCountryList(countryList); } finally { sqlSession.close(); } }