1 16 17 package org.springframework.jca.cci.core.support; 18 19 import javax.resource.cci.Connection ; 20 import javax.resource.cci.ConnectionFactory ; 21 import javax.resource.cci.ConnectionSpec ; 22 23 import org.springframework.dao.support.DaoSupport; 24 import org.springframework.jca.cci.CannotGetCciConnectionException; 25 import org.springframework.jca.cci.connection.ConnectionFactoryUtils; 26 import org.springframework.jca.cci.core.CciTemplate; 27 28 46 public abstract class CciDaoSupport extends DaoSupport { 47 48 private CciTemplate cciTemplate; 49 50 51 54 public final void setConnectionFactory(ConnectionFactory connectionFactory) { 55 this.cciTemplate = createCciTemplate(connectionFactory); 56 } 57 58 67 protected CciTemplate createCciTemplate(ConnectionFactory connectionFactory) { 68 return new CciTemplate(connectionFactory); 69 } 70 71 74 public final ConnectionFactory getConnectionFactory() { 75 return this.cciTemplate.getConnectionFactory(); 76 } 77 78 82 public final void setCciTemplate(CciTemplate cciTemplate) { 83 this.cciTemplate = cciTemplate; 84 } 85 86 90 public final CciTemplate getCciTemplate() { 91 return this.cciTemplate; 92 } 93 94 protected final void checkDaoConfig() { 95 if (this.cciTemplate == null) { 96 throw new IllegalArgumentException ("'connectionFactory' or 'cciTemplate' is required"); 97 } 98 } 99 100 101 110 protected final CciTemplate getCciTemplate(ConnectionSpec connectionSpec) { 111 return getCciTemplate().getDerivedTemplate(connectionSpec); 112 } 113 114 121 protected final Connection getConnection() throws CannotGetCciConnectionException { 122 return ConnectionFactoryUtils.getConnection(getConnectionFactory()); 123 } 124 125 131 protected final void releaseConnection(Connection con) { 132 ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory()); 133 } 134 135 } 136 | Popular Tags |