1 16 17 package org.springframework.orm.jpa.vendor; 18 19 import java.sql.Connection ; 20 import java.sql.SQLException ; 21 22 import javax.persistence.EntityManager; 23 import javax.persistence.PersistenceException; 24 25 import org.apache.openjpa.persistence.OpenJPAEntityManager; 26 27 import org.springframework.jdbc.datasource.ConnectionHandle; 28 import org.springframework.jdbc.datasource.SimpleConnectionHandle; 29 import org.springframework.orm.jpa.DefaultJpaDialect; 30 import org.springframework.transaction.TransactionDefinition; 31 import org.springframework.transaction.TransactionException; 32 33 40 public class OpenJpaDialect extends DefaultJpaDialect { 41 42 @Override 43 public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) 44 throws PersistenceException, SQLException { 45 46 Connection connection = (Connection ) getOpenJPAEntityManager(entityManager).getConnection(); 47 return new SimpleConnectionHandle(connection); 48 } 49 50 @Override 51 public void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager em) 52 throws PersistenceException, SQLException { 53 54 if (conHandle != null && conHandle.getConnection() != null) { 55 conHandle.getConnection().close(); 56 } 57 } 58 59 @Override 60 public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) 61 throws PersistenceException, SQLException , TransactionException { 62 63 super.beginTransaction(entityManager, definition); 64 if (!definition.isReadOnly()) { 65 getOpenJPAEntityManager(entityManager).beginStore(); 68 } 69 return null; 70 } 71 72 77 protected OpenJPAEntityManager getOpenJPAEntityManager(EntityManager em) { 78 return (OpenJPAEntityManager) em; 79 } 80 81 } 82 | Popular Tags |