Just curious, are you going to call setContainer(null); -dain
Scott M Stark wrote: > User: starksm > Date: 02/04/12 12:30:44 > > Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc > JDBCRelationInterceptor.java JDBCStoreManager.java > Log: > Start cleaning up the web of container references in destroy so that > the container may be garbage collected. > > Revision Changes Path > 1.11 +20 -14 >jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCRelationInterceptor.java > > Index: JDBCRelationInterceptor.java > =================================================================== > RCS file: >/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCRelationInterceptor.java,v > retrieving revision 1.10 > retrieving revision 1.11 > diff -u -r1.10 -r1.11 > --- JDBCRelationInterceptor.java 27 Dec 2001 17:32:25 -0000 1.10 > +++ JDBCRelationInterceptor.java 12 Apr 2002 19:30:44 -0000 1.11 > @@ -26,7 +26,7 @@ > * relationship. This interceptor also manages the relation table data. > * > * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> > - * @version $Revision: 1.10 $ > + * @version $Revision: 1.11 $ > */ > public class JDBCRelationInterceptor extends AbstractInterceptor > { > @@ -89,20 +89,26 @@ > this.container = (EntityContainer)container; > > JDBCStoreManager manager = null; > - try { > - EntityContainer entityContainer = (EntityContainer)container; > - CMPPersistenceManager cmpManager = > - (CMPPersistenceManager)entityContainer.getPersistenceManager(); > - manager = (JDBCStoreManager) cmpManager.getPersistenceStore(); > - } catch(ClassCastException e) { > - throw new EJBException("JDBCRealtionInteceptor can only be used " + > - "JDBCStoreManager", e); > + if( container != null ) > + { > + try > + { > + EntityContainer entityContainer = (EntityContainer)container; > + CMPPersistenceManager cmpManager = > + (CMPPersistenceManager)entityContainer.getPersistenceManager(); > + manager = (JDBCStoreManager) cmpManager.getPersistenceStore(); > + } > + catch(ClassCastException e) > + { > + throw new EJBException("JDBCRealtionInteceptor can only be used " + > + "JDBCStoreManager", e); > + } > + > + log = Logger.getLogger( > + this.getClass().getName() + > + "." + > + manager.getMetaData().getName()); > } > - > - log = Logger.getLogger( > - this.getClass().getName() + > - "." + > - manager.getMetaData().getName()); > } > > public Container getContainer() > > > > 1.31 +266 -195 >jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreManager.java > > Index: JDBCStoreManager.java > =================================================================== > RCS file: >/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreManager.java,v > retrieving revision 1.30 > retrieving revision 1.31 > diff -u -r1.30 -r1.31 > --- JDBCStoreManager.java 9 Apr 2002 21:39:51 -0000 1.30 > +++ JDBCStoreManager.java 12 Apr 2002 19:30:44 -0000 1.31 > @@ -60,37 +60,38 @@ > * > * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a> > * @see org.jboss.ejb.EntityPersistenceStore > - * @version $Revision: 1.30 $ > + * @version $Revision: 1.31 $ > */ > -public class JDBCStoreManager implements EntityPersistenceStore { > - > +public class JDBCStoreManager implements EntityPersistenceStore > +{ > + > /** > * The key used to store the tx data map. > */ > private static final Object TX_DATA_KEY = "TX_DATA_KEY"; > - > - private static final Map applicationData = > - Collections.synchronizedMap(new HashMap()); > - > + > + private static final Map applicationData = > + Collections.synchronizedMap(new HashMap()); > + > private EntityContainer container; > private Logger log; > - > + > private JDBCEntityMetaData metaData; > private JDBCEntityBridge entityBridge; > - > + > private JDBCTypeFactory typeFactory; > private JDBCQueryManager queryManager; > - > + > private JDBCCommandFactory commandFactory; > - > + > private ReadAheadCache readAheadCache; > - > + > // Manager life cycle commands > private JDBCInitCommand initCommand; > private JDBCStartCommand startCommand; > private JDBCStopCommand stopCommand; > private JDBCDestroyCommand destroyCommand; > - > + > // Entity life cycle commands > private JDBCCreateBeanClassInstanceCommand createBeanClassInstanceCommand; > private JDBCInitEntityCommand initEntityCommand; > @@ -103,217 +104,253 @@ > private JDBCStoreEntityCommand storeEntityCommand; > private JDBCActivateEntityCommand activateEntityCommand; > private JDBCPassivateEntityCommand passivateEntityCommand; > - > + > // commands > private JDBCLoadRelationCommand loadRelationCommand; > private JDBCDeleteRelationsCommand deleteRelationsCommand; > private JDBCInsertRelationsCommand insertRelationsCommand; > - > + > /** > * A Transaction manager so that we can link preloaded data to a transaction > */ > private TransactionManager tm; > - > + > /** > * Gets the container for this entity. > * @return the container for this entity; null if container has not been set > */ > - public EntityContainer getContainer() { > + public EntityContainer getContainer() > + { > return container; > } > - > + > /** > * Sets the container for this entity. > * @param container the container for this entity > - * @throws ClassCastException if the container is not an instance of > + * @throws ClassCastException if the container is not an instance of > * EntityContainer > */ > - public void setContainer(Container container) { > - this.container = (EntityContainer)container; > - this.log = Logger.getLogger( > - this.getClass().getName() + > - "." + > - container.getBeanMetaData().getEjbName()); > + public void setContainer(Container container) > + { > + this.container = (EntityContainer) container; > + if( container != null ) > + { > + String categoryName = this.getClass().getName() + > + "." + container.getBeanMetaData().getEjbName(); > + this.log = Logger.getLogger(categoryName); > + } > } > - > - public JDBCEntityBridge getEntityBridge() { > + > + public JDBCEntityBridge getEntityBridge() > + { > return entityBridge; > } > - > - public JDBCTypeFactory getJDBCTypeFactory() { > + > + public JDBCTypeFactory getJDBCTypeFactory() > + { > return typeFactory; > } > - > - public JDBCEntityMetaData getMetaData() { > + > + public JDBCEntityMetaData getMetaData() > + { > return metaData; > } > - > - public JDBCQueryManager getQueryManager() { > + > + public JDBCQueryManager getQueryManager() > + { > return queryManager; > } > - > - public JDBCCommandFactory getCommandFactory() { > + > + public JDBCCommandFactory getCommandFactory() > + { > return commandFactory; > } > > - public ReadAheadCache getReadAheadCache() { > + public ReadAheadCache getReadAheadCache() > + { > return readAheadCache; > } > > // > // Genertic data containers > // > - public Map getApplicationDataMap() { > + public Map getApplicationDataMap() > + { > return applicationData; > } > - > - public Object getApplicationData(Object key) { > + > + public Object getApplicationData(Object key) > + { > return applicationData.get(key); > } > - > - public void putApplicationData(Object key, Object value) { > + > + public void putApplicationData(Object key, Object value) > + { > applicationData.put(key, value); > } > - > - public void removeApplicationData(Object key) { > + > + public void removeApplicationData(Object key) > + { > applicationData.remove(key); > } > - > - public Map getApplicationTxDataMap() { > - try { > + > + public Map getApplicationTxDataMap() > + { > + try > + { > Transaction tx = tm.getTransaction(); > - > + > // get the map between the tx and the txDataMap > Map txMap = (Map)getApplicationData(TX_DATA_KEY); > - synchronized(txMap) { > + synchronized(txMap) > + { > // get the txDataMap from the txMap > Map txDataMap = (Map)txMap.get(tx); > - > + > // do we have an existing map > int status = tx.getStatus(); > - if(txDataMap == null && > - (status == Status.STATUS_ACTIVE || > - status == Status.STATUS_PREPARING)) { > - > + if(txDataMap == null && > + (status == Status.STATUS_ACTIVE || > + status == Status.STATUS_PREPARING)) > + { > + > // We want to be notified when the transaction commits > - ApplicationTxDataSynchronization synch = > - new ApplicationTxDataSynchronization(tx); > + ApplicationTxDataSynchronization synch = > + new ApplicationTxDataSynchronization(tx); > tx.registerSynchronization(synch); > - > + > // create and add the new map > txDataMap = new HashMap(); > txMap.put(tx, txDataMap); > } > return txDataMap; > } > - } catch(EJBException e) { > + } catch(EJBException e) > + { > throw e; > - } catch(Exception e) { > + } catch(Exception e) > + { > throw new EJBException("Error getting application tx data map.", e); > } > } > - > - public Object getApplicationTxData(Object key) { > + > + public Object getApplicationTxData(Object key) > + { > Map map = getApplicationTxDataMap(); > - if(map != null) { > + if(map != null) > + { > return map.get(key); > } > return null; > } > - > - public void putApplicationTxData(Object key, Object value) { > + > + public void putApplicationTxData(Object key, Object value) > + { > Map map = getApplicationTxDataMap(); > - if(map != null) { > + if(map != null) > + { > map.put(key, value); > } > } > - > - public void removeApplicationTxData(Object key) { > + > + public void removeApplicationTxData(Object key) > + { > Map map = getApplicationTxDataMap(); > - if(map != null) { > + if(map != null) > + { > map.remove(key); > } > } > - > - public Map getEntityTxDataMap() { > + > + public Map getEntityTxDataMap() > + { > Map entityTxDataMap = (Map)getApplicationTxData(this); > - if(entityTxDataMap == null) { > + if(entityTxDataMap == null) > + { > entityTxDataMap = new HashMap(); > putApplicationTxData(this, entityTxDataMap); > } > return entityTxDataMap; > } > - > - public Object getEntityTxData(Object key) { > + > + public Object getEntityTxData(Object key) > + { > return getEntityTxDataMap().get(key); > } > - > - public void putEntityTxData(Object key, Object value) { > + > + public void putEntityTxData(Object key, Object value) > + { > getEntityTxDataMap().put(key, value); > } > - > - public void removeEntityTxData(Object key) { > + > + public void removeEntityTxData(Object key) > + { > getEntityTxDataMap().remove(key); > } > - > - private void initApplicationDataMap() { > - synchronized(applicationData) { > + > + private void initApplicationDataMap() > + { > + synchronized(applicationData) > + { > Map txDataMap = (Map)getApplicationData(TX_DATA_KEY); > - if(txDataMap == null) { > + if(txDataMap == null) > + { > txDataMap = new HashMap(); > putApplicationData(TX_DATA_KEY, txDataMap); > } > } > } > - > + > // > // Store Manager Life Cycle Commands > // > - public void create() throws Exception { > + public void create() throws Exception > + { > log.debug("Initializing CMP plugin for " + > - container.getBeanMetaData().getEjbName()); > - > + container.getBeanMetaData().getEjbName()); > + > // initializes the generic data containers > initApplicationDataMap(); > - > + > // load the metadata for this entity > metaData = loadJDBCEntityMetaData(); > - > + > // get the transaction manager > tm = container.getTransactionManager(); > - > + > // setup the type factory, which is used to map java types to sql types. > typeFactory = new JDBCTypeFactory( > - metaData.getTypeMapping(), > - metaData.getJDBCApplication().getValueClasses()); > - > + metaData.getTypeMapping(), > + metaData.getJDBCApplication().getValueClasses()); > + > // create the bridge between java land and this engine (sql land) > entityBridge = new JDBCEntityBridge(metaData, this); > - > + > // add the entity bridge to the catalog > Catalog catalog = (Catalog)getApplicationData("CATALOG"); > - if(catalog == null) { > + if(catalog == null) > + { > catalog = new Catalog(); > putApplicationData("CATALOG", catalog); > } > catalog.addEntity(entityBridge); > - > + > // create the read ahead cache > readAheadCache = new ReadAheadCache(this); > readAheadCache.create(); > - > + > // Set up Commands > commandFactory = new JDBCCommandFactory(this); > - > + > // Create store manager life cycle commands > initCommand = commandFactory.createInitCommand(); > startCommand = commandFactory.createStartCommand(); > stopCommand = commandFactory.createStopCommand(); > destroyCommand = commandFactory.createDestroyCommand(); > - > + > /// Create ejb life cycle commands > - createBeanClassInstanceCommand = > - commandFactory.createCreateBeanClassInstanceCommand(); > + createBeanClassInstanceCommand = > + commandFactory.createCreateBeanClassInstanceCommand(); > initEntityCommand = commandFactory.createInitEntityCommand(); > findEntityCommand = commandFactory.createFindEntityCommand(); > findEntitiesCommand = commandFactory.createFindEntitiesCommand(); > @@ -324,19 +361,20 @@ > storeEntityCommand = commandFactory.createStoreEntityCommand(); > activateEntityCommand = commandFactory.createActivateEntityCommand(); > passivateEntityCommand = commandFactory.createPassivateEntityCommand(); > - > + > loadRelationCommand = commandFactory.createLoadRelationCommand(); > deleteRelationsCommand = commandFactory.createDeleteRelationsCommand(); > insertRelationsCommand = commandFactory.createInsertRelationsCommand(); > - > + > // Create the query manager > queryManager = new JDBCQueryManager(this); > - > + > // Execute the init Command > initCommand.execute(); > } > - > - public void start() throws Exception { > + > + public void start() throws Exception > + { > startCommand.execute(); > > // Start the query manager. At this point is creates all of the > @@ -347,26 +385,30 @@ > > readAheadCache.start(); > } > - > - public void stop() { > + > + public void stop() > + { > // On deploy errors, sometimes CMPStoreManager was never initialized! > - if(stopCommand != null) { > + if(stopCommand != null) > + { > stopCommand.execute(); > } > - > + > readAheadCache.stop(); > } > - > - public void destroy() { > + > + public void destroy() > + { > // On deploy errors, sometimes CMPStoreManager was never initialized! > - if(destroyCommand != null) { > + if(destroyCommand != null) > + { > destroyCommand.execute(); > } > - > + > readAheadCache.destroy(); > readAheadCache = null; > } > - > + > // > // EJB Life Cycle Commands > // > @@ -375,163 +417,189 @@ > * > * @return the new instance > */ > - public Object createBeanClassInstance() throws Exception { > + public Object createBeanClassInstance() throws Exception > + { > return createBeanClassInstanceCommand.execute(); > } > - > - public void initEntity(EntityEnterpriseContext ctx) { > + > + public void initEntity(EntityEnterpriseContext ctx) > + { > initEntityCommand.execute(ctx); > } > - > + > public Object createEntity( > - Method createMethod, > - Object[] args, > - EntityEnterpriseContext ctx) throws CreateException { > - > + Method createMethod, > + Object[] args, > + EntityEnterpriseContext ctx) throws CreateException > + { > + > Object pk = createEntityCommand.execute(createMethod, args, ctx); > - > + > // mark the entity as created > entityBridge.setCreated(ctx); > - > + > return pk; > } > - > + > public Object findEntity( > - Method finderMethod, > - Object[] args, > - EntityEnterpriseContext ctx) throws FinderException { > - > + Method finderMethod, > + Object[] args, > + EntityEnterpriseContext ctx) throws FinderException > + { > + > return findEntityCommand.execute(finderMethod, args, ctx); > } > - > + > public FinderResults findEntities( > - Method finderMethod, > - Object[] args, > - EntityEnterpriseContext ctx) throws FinderException { > + Method finderMethod, > + Object[] args, > + EntityEnterpriseContext ctx) throws FinderException > + { > return findEntitiesCommand.execute(finderMethod, args, ctx); > } > - > - public void activateEntity(EntityEnterpriseContext ctx) { > + > + public void activateEntity(EntityEnterpriseContext ctx) > + { > activateEntityCommand.execute(ctx); > } > - > - public void loadEntity(EntityEnterpriseContext ctx) { > + > + public void loadEntity(EntityEnterpriseContext ctx) > + { > // is any on the data already in the entity valid > - if(!ctx.isValid()) { > - if(log.isTraceEnabled()) { > + if(!ctx.isValid()) > + { > + if(log.isTraceEnabled()) > + { > log.trace("RESET PERSISTENCE CONTEXT: id="+ctx.getId()); > } > entityBridge.resetPersistenceContext(ctx); > } > - > - // mark the entity as created; if it was loading it was created > + > + // mark the entity as created; if it was loading it was created > entityBridge.setCreated(ctx); > - > + > loadEntityCommand.execute(ctx); > } > - > + > public void loadField( > - JDBCCMPFieldBridge field, EntityEnterpriseContext ctx) { > - > + JDBCCMPFieldBridge field, EntityEnterpriseContext ctx) > + { > + > loadEntityCommand.execute(field, ctx); > } > - > - public boolean isModified(EntityEnterpriseContext ctx) { > + > + public boolean isModified(EntityEnterpriseContext ctx) > + { > return isModifiedCommand.execute(ctx); > } > - > - public void storeEntity(EntityEnterpriseContext ctx) { > + > + public void storeEntity(EntityEnterpriseContext ctx) > + { > storeEntityCommand.execute(ctx); > synchronizeRelationData(); > } > - > - private void synchronizeRelationData() { > + > + private void synchronizeRelationData() > + { > Map txData = getApplicationTxDataMap(); > - if(txData == null) { > + if(txData == null) > + { > return; > } > - > + > Iterator iterator = txData.values().iterator(); > - while(iterator.hasNext()) { > + while(iterator.hasNext()) > + { > Object obj = iterator.next(); > - if(obj instanceof RelationData) { > + if(obj instanceof RelationData) > + { > RelationData relationData = (RelationData) obj; > - > + > // only need to bother if neither side has a foreign key > if(!relationData.getLeftCMRField().hasForeignKey() && > - !relationData.getRightCMRField().hasForeignKey()) { > - > + !relationData.getRightCMRField().hasForeignKey()) > + { > + > // delete all removed pairs from relation table > deleteRelations(relationData); > - > + > // insert all added pairs into the relation table > insertRelations(relationData); > - > + > relationData.addedRelations.clear(); > relationData.removedRelations.clear(); > relationData.notRelatedPairs.clear(); > } > } > } > - } > - > - public void passivateEntity(EntityEnterpriseContext ctx) { > + } > + > + public void passivateEntity(EntityEnterpriseContext ctx) > + { > passivateEntityCommand.execute(ctx); > } > - > + > public void removeEntity(EntityEnterpriseContext ctx) > - throws RemoveException { > + throws RemoveException > + { > removeEntityCommand.execute(ctx); > } > - > + > // > // Relationship Commands > // > - public Collection loadRelation(JDBCCMRFieldBridge cmrField, Object pk) { > + public Collection loadRelation(JDBCCMRFieldBridge cmrField, Object pk) > + { > return loadRelationCommand.execute(cmrField, pk); > } > - > - public void deleteRelations(RelationData relationData) { > + > + public void deleteRelations(RelationData relationData) > + { > deleteRelationsCommand.execute(relationData); > } > - > - public void insertRelations(RelationData relationData) { > + > + public void insertRelations(RelationData relationData) > + { > insertRelationsCommand.execute(relationData); > } > - > - private JDBCEntityMetaData loadJDBCEntityMetaData() > - throws DeploymentException { > - > - ApplicationMetaData amd = > - container.getBeanMetaData().getApplicationMetaData(); > - > + > + private JDBCEntityMetaData loadJDBCEntityMetaData() > + throws DeploymentException > + { > + > + ApplicationMetaData amd = > + container.getBeanMetaData().getApplicationMetaData(); > + > // Get JDBC MetaData > - JDBCApplicationMetaData jamd = > - (JDBCApplicationMetaData)amd.getPluginData("CMP-JDBC"); > - > - if (jamd == null) { > - // we are the first cmp entity to need jbosscmp-jdbc. > + JDBCApplicationMetaData jamd = > + (JDBCApplicationMetaData)amd.getPluginData("CMP-JDBC"); > + > + if (jamd == null) > + { > + // we are the first cmp entity to need jbosscmp-jdbc. > // Load jbosscmp-jdbc.xml for the whole application > JDBCXmlFileLoader jfl = new JDBCXmlFileLoader( > - amd, > - container.getClassLoader(), > - container.getLocalClassLoader(), > - log); > - > + amd, > + container.getClassLoader(), > + container.getLocalClassLoader(), > + log); > + > jamd = jfl.load(); > amd.addPluginData("CMP-JDBC", jamd); > } > - > + > // Get JDBC Bean MetaData > String ejbName = container.getBeanMetaData().getEjbName(); > JDBCEntityMetaData metadata = jamd.getBeanByEjbName(ejbName); > - if(metadata == null) { > + if(metadata == null) > + { > throw new DeploymentException("No metadata found for bean " + ejbName); > } > return metadata; > } > - > - private class ApplicationTxDataSynchronization implements Synchronization { > + > + private class ApplicationTxDataSynchronization implements Synchronization > + { > /** > * The transaction we follow. > */ > @@ -544,20 +612,23 @@ > { > this.tx = tx; > } > - > + > /** > * Unused > */ > - public void beforeCompletion() { > + public void beforeCompletion() > + { > //no-op > } > - > + > /** > * Free-up any data associated with this transaction. > */ > - public void afterCompletion(int status) { > + public void afterCompletion(int status) > + { > Map txMap = (Map)getApplicationData(TX_DATA_KEY); > - synchronized(txMap) { > + synchronized(txMap) > + { > txMap.remove(tx); > } > } > > > > > _______________________________________________ > Jboss-development mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-development > _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
