Changes between Version 3 and Version 4 of v6/pgsummary


Ignore:
Timestamp:
04/17/2012 11:38:51 AM (14 years ago)
Author:
huangzhong
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • v6/pgsummary

    v3 v4  
    7575 
    7676== 驱动 == 
    77 * pg 里没有rollback 语句,不会自动rollback ,需要应用里触发异常。  
     77* pg 里没有rollback 语句,不会自动rollback ,需要应用里触发异常。 
     78{{{ 
     791.使用JPA,方法声明为@Transactional自动回滚 
     802.使用JPA,手动方式进行回滚 
     81EntityManagerFactory emf = ((EntityManagerFactory)EnvUtils.getEnv().getApplicationContext().getBean("entityManagerFactory")); 
     82EntityManager em = emf.createEntityManager(); 
     83EntityTransaction et = em.getTransaction(); 
     84try { 
     85  et.begin();//事务开始 
     86  em.createNativeQuery(sql).executeUpdate(); 
     87  em.createNativeQuery(sql).executeUpdate(); 
     88  et.commit(); 
     89} catch (Exception e) { 
     90  et.rollback(); 
     91} 
     923.使用JDBC 
     93DataSourceTransactionManager tm = new DataSourceTransactionManager(((DataSource) EnvUtils.getEnv().getApplicationContext().getBean("dataSource"))); 
     94TransactionTemplate tt = new TransactionTemplate(tm); 
     95final JdbcTemplate jt = new JdbcTemplate(((DataSource) EnvUtils.getEnv().getApplicationContext().getBean("dataSource"))); 
     96tt.execute(new TransactionCallback() { 
     97    public Object doInTransaction(TransactionStatus ts) { 
     98        String sql = "update ent_faq set title = '压力山大' where id = 1"; 
     99        jt.execute(sql); 
     100        sql = "update ent_faq set title = title || '困死我了' where id = 3"; 
     101        jt.execute(sql); 
     102        return null; 
     103    } 
     104}); 
     105}}} 
    78106* 缺省返回的整型是Long 
    79107{{{