1 16 17 package org.springframework.orm.toplink; 18 19 import java.sql.SQLException ; 20 21 import oracle.toplink.exceptions.DatabaseException; 22 import oracle.toplink.exceptions.TopLinkException; 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import org.springframework.beans.factory.InitializingBean; 27 import org.springframework.dao.DataAccessException; 28 import org.springframework.jdbc.support.SQLExceptionTranslator; 29 30 43 public abstract class TopLinkAccessor implements InitializingBean { 44 45 46 protected final Log logger = LogFactory.getLog(getClass()); 47 48 private SessionFactory sessionFactory; 49 50 private SQLExceptionTranslator jdbcExceptionTranslator; 51 52 53 66 public void setSessionFactory(SessionFactory sessionFactory) { 67 this.sessionFactory = sessionFactory; 68 } 69 70 74 public SessionFactory getSessionFactory() { 75 return sessionFactory; 76 } 77 78 87 public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator) { 88 this.jdbcExceptionTranslator = jdbcExceptionTranslator; 89 } 90 91 94 public SQLExceptionTranslator getJdbcExceptionTranslator() { 95 return this.jdbcExceptionTranslator; 96 } 97 98 99 102 public void afterPropertiesSet() { 103 if (this.sessionFactory == null) { 104 throw new IllegalArgumentException ("sessionFactory is required"); 105 } 106 } 107 108 109 119 public DataAccessException convertTopLinkAccessException(TopLinkException ex) { 120 if (getJdbcExceptionTranslator() != null && ex instanceof DatabaseException) { 121 Throwable internalEx = ex.getInternalException(); 122 if (internalEx instanceof SQLException ) { 124 return getJdbcExceptionTranslator().translate( 125 "TopLink operation: " + ex.getMessage(), null, (SQLException ) internalEx); 126 } 127 } 128 return SessionFactoryUtils.convertTopLinkAccessException(ex); 129 } 130 131 } 132 | Popular Tags |