1 16 17 package org.springframework.orm.toplink.support; 18 19 import oracle.toplink.exceptions.TopLinkException; 20 import oracle.toplink.sessions.Session; 21 22 import org.springframework.dao.DataAccessException; 23 import org.springframework.dao.DataAccessResourceFailureException; 24 import org.springframework.dao.support.DaoSupport; 25 import org.springframework.orm.toplink.SessionFactory; 26 import org.springframework.orm.toplink.SessionFactoryUtils; 27 import org.springframework.orm.toplink.TopLinkTemplate; 28 29 52 public abstract class TopLinkDaoSupport extends DaoSupport { 53 54 private TopLinkTemplate topLinkTemplate; 55 56 57 63 public final void setSessionFactory(SessionFactory sessionFactory) { 64 this.topLinkTemplate = createTopLinkTemplate(sessionFactory); 65 } 66 67 76 protected TopLinkTemplate createTopLinkTemplate(SessionFactory sessionFactory) { 77 return new TopLinkTemplate(sessionFactory); 78 } 79 80 83 public final SessionFactory getSessionFactory() { 84 return (this.topLinkTemplate != null ? this.topLinkTemplate.getSessionFactory() : null); 85 } 86 87 92 public final void setTopLinkTemplate(TopLinkTemplate topLinkTemplate) { 93 this.topLinkTemplate = topLinkTemplate; 94 } 95 96 100 public final TopLinkTemplate getTopLinkTemplate() { 101 return topLinkTemplate; 102 } 103 104 protected final void checkDaoConfig() { 105 if (this.topLinkTemplate == null) { 106 throw new IllegalArgumentException ("sessionFactory or topLinkTemplate is required"); 107 } 108 } 109 110 111 132 protected final Session getSession() 133 throws DataAccessResourceFailureException, IllegalStateException { 134 135 return getSession(this.topLinkTemplate.isAllowCreate()); 136 } 137 138 158 protected final Session getSession(boolean allowCreate) 159 throws DataAccessResourceFailureException, IllegalStateException { 160 161 return SessionFactoryUtils.getSession(this.getSessionFactory(), allowCreate); 162 } 163 164 175 protected final DataAccessException convertTopLinkAccessException(TopLinkException ex) { 176 return this.topLinkTemplate.convertTopLinkAccessException(ex); 177 } 178 179 185 protected final void releaseSession(Session session) { 186 SessionFactoryUtils.releaseSession(session, getSessionFactory()); 187 } 188 189 } 190 | Popular Tags |