Package org.jboss.ejb

Examples of org.jboss.ejb.EntityEnterpriseContext


      // Do we own the lock?
      Transaction tx = mi.getTransaction();
      if (tx != null && tx.equals(getTransaction()))
      {
         // If there is no context or synchronization, release the lock
         EntityEnterpriseContext ctx = (EntityEnterpriseContext) mi.getEnterpriseContext();
         if (ctx == null || ctx.hasTxSynchronization() == false)
            endTransaction(tx);
      }
   }
View Full Code Here


   public Object invoke(Invocation mi)
           throws Exception
   {
      // We are going to work with the context a lot
      EntityEnterpriseContext ctx = (EntityEnterpriseContext) mi.getEnterpriseContext();
      boolean nonReentrant = !(reentrant || isReentrantMethod(mi));

      // Not a reentrant method like getPrimaryKey
      NonReentrantLock methodLock = ctx.getMethodLock();
      Transaction miTx = ctx.getTransaction();
      boolean locked = false;
      try
      {
         while (!locked)
         {
            if (methodLock.attempt(5000, miTx, nonReentrant))
            {
               locked = true;
            }
            else
            {
               if (isTxExpired(miTx))
               {
                  log.error("Saw rolled back tx=" + miTx);
                  throw new RuntimeException("Transaction marked for rollback, possibly a timeout");
               }
            }
         }
      }
      catch (NonReentrantLock.ReentranceException re)
      {
         if (mi.getType() == InvocationType.REMOTE)
         {
            throw new RemoteException("Reentrant method call detected: "
                    + container.getBeanMetaData().getEjbName() + " "
                    + ctx.getId().toString());
         }
         else
         {
            throw new EJBException("Reentrant method call detected: "
                    + container.getBeanMetaData().getEjbName() + " "
                    + ctx.getId().toString());
         }
      }
      try
      {
         ctx.lock();
         return getNext().invoke(mi);
      }
      finally
      {
         ctx.unlock();
         methodLock.release(nonReentrant);
      }
   }
View Full Code Here

/*  90 */     if (relationshipMessage == null)
/*     */     {
/*  93 */       return getNext().invoke(mi);
/*     */     }
/*     */
/*  97 */     EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext();
/*  98 */     JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge)mi.getArguments()[0];
/*     */
/* 100 */     if (CMRMessage.GET_RELATED_ID == relationshipMessage)
/*     */     {
/* 103 */       if (this.log.isTraceEnabled())
/*     */       {
/* 105 */         this.log.trace("Getting related id: field=" + cmrField.getFieldName() + " id=" + ctx.getId());
/*     */       }
/* 107 */       return cmrField.getRelatedId(ctx);
/*     */     }
/*     */
/* 110 */     if (CMRMessage.ADD_RELATION == relationshipMessage)
/*     */     {
/* 113 */       Object relatedId = mi.getArguments()[1];
/* 114 */       if (this.log.isTraceEnabled())
/*     */       {
/* 116 */         this.log.trace("Add relation: field=" + cmrField.getFieldName() + " id=" + ctx.getId() + " relatedId=" + relatedId);
/*     */       }
/*     */
/* 121 */       cmrField.addRelation(ctx, relatedId);
/*     */
/* 123 */       return null;
/*     */     }
/*     */
/* 126 */     if (CMRMessage.REMOVE_RELATION == relationshipMessage)
/*     */     {
/* 129 */       Object relatedId = mi.getArguments()[1];
/* 130 */       if (this.log.isTraceEnabled())
/*     */       {
/* 132 */         this.log.trace("Remove relation: field=" + cmrField.getFieldName() + " id=" + ctx.getId() + " relatedId=" + relatedId);
/*     */       }
/*     */
/* 137 */       cmrField.removeRelation(ctx, relatedId);
/*     */
/* 139 */       return null;
View Full Code Here

/*     */
/*     */   public Object invoke(Invocation mi) throws Exception
/*     */   {
/*  98 */     if (this.doCacheInvalidations)
/*     */     {
/* 101 */       EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext();
/* 102 */       Object id = ctx.getId();
/*     */
/* 105 */       Transaction tx = mi.getTransaction();
/*     */
/* 108 */       if ((tx != null) && (tx.getStatus() != 6))
/*     */       {
View Full Code Here

/*  67 */       return getNext().invoke(mi);
/*     */     }
/*     */
/*  70 */     CMRMessage msg = ((CMRInvocation)mi).getCmrMessage();
/*     */
/*  73 */     EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext();
/*  74 */     JDBCCMRFieldBridge2 cmrField = (JDBCCMRFieldBridge2)mi.getArguments()[0];
/*     */
/*  76 */     if (CMRMessage.ADD_RELATION == msg)
/*     */     {
/*  78 */       Object relatedId = mi.getArguments()[1];
/*  79 */       if (this.log.isTraceEnabled())
/*     */       {
/*  81 */         this.log.trace("Add relation: field=" + cmrField.getFieldName() + " id=" + ctx.getId() + " relatedId=" + relatedId);
/*     */       }
/*     */
/*  86 */       cmrField.addRelatedId(ctx, relatedId);
/*     */     }
/*  88 */     else if (CMRMessage.REMOVE_RELATION == msg)
/*     */     {
/*  91 */       Object relatedId = mi.getArguments()[1];
/*  92 */       if (this.log.isTraceEnabled())
/*     */       {
/*  94 */         this.log.trace("Remove relation: field=" + cmrField.getFieldName() + " id=" + ctx.getId() + " relatedId=" + relatedId);
/*     */       }
/*     */
/*  99 */       cmrField.removeRelatedId(ctx, relatedId);
/*     */     }
/*     */     else
View Full Code Here

/*     */   public void endInvocation(Invocation mi)
/*     */   {
/* 430 */     Transaction tx = mi.getTransaction();
/* 431 */     if ((tx != null) && (tx.equals(getTransaction())))
/*     */     {
/* 434 */       EntityEnterpriseContext ctx = (EntityEnterpriseContext)mi.getEnterpriseContext();
/* 435 */       if ((ctx == null) || (!ctx.hasTxSynchronization()))
/* 436 */         endTransaction(tx);
/*     */     }
/*     */   }
View Full Code Here

/*     */
/*     */   public Object invokeHome(Invocation mi)
/*     */     throws Exception
/*     */   {
/*  89 */     EntityContainer ec = (EntityContainer)getContainer();
/*  90 */     EntityEnterpriseContext ctx = (EntityEnterpriseContext)ec.getInstancePool().get();
/*     */
/*  93 */     mi.setEnterpriseContext(ctx);
/*     */
/*  96 */     ctx.setTransaction(mi.getTransaction());
/*     */
/*  99 */     ctx.setPrincipal(mi.getPrincipal());
/*     */
/* 101 */     AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_HOME);
/*     */     Object result;
/*     */     try
/*     */     {
/* 107 */       result = getNext().invokeHome(mi);
/*     */     }
/*     */     finally
/*     */     {
/* 111 */       AllowedOperationsAssociation.popInMethodFlag();
/*     */     }
/*     */
/* 115 */     if (ctx.getId() == null)
/*     */     {
/* 117 */       ctx.setTransaction(null);
/* 118 */       ec.getInstancePool().free(ctx);
/*     */     }
/*     */
/* 122 */     return result;
/*     */   }
View Full Code Here

/*     */   public Object invoke(Invocation mi)
/*     */     throws Exception
/*     */   {
/* 130 */     Object key = mi.getId();
/*     */
/* 132 */     EntityEnterpriseContext ctx = null;
/* 133 */     EntityContainer ec = (EntityContainer)this.container;
/*     */     InvocationType type;
/* 134 */     if ((mi.getTransaction() == null) ||
/* 138 */       (ctx == null))
/*     */     {
/* 140 */       InstancePool pool = ec.getInstancePool();
/*     */       try
/*     */       {
/* 143 */         ctx = (EntityEnterpriseContext)pool.get();
/*     */       }
/*     */       catch (EJBException e)
/*     */       {
/* 147 */         throw e;
/*     */       }
/*     */       catch (RemoteException e)
/*     */       {
/* 151 */         throw e;
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 155 */         type = mi.getType();
/* 156 */         boolean isLocal = (type == InvocationType.LOCAL) || (type == InvocationType.LOCALHOME);
/* 157 */         if (isLocal) {
/* 158 */           throw new EJBException("Unable to get an instance from the pool", e);
/*     */         }
/* 160 */         throw new RemoteException("Unable to get an intance from the pool", e);
/*     */       }
/* 162 */       ctx.setCacheKey(key);
/* 163 */       ctx.setId(key);
/* 164 */       EntityPersistenceManager pm = ec.getPersistenceManager();
/* 165 */       pm.activateEntity(ctx);
/*     */     }
/*     */
/* 168 */     boolean trace = this.log.isTraceEnabled();
/* 169 */     if (trace) this.log.trace("Begin invoke, key=" + key);
/*     */
/* 173 */     ctx.setTransaction(mi.getTransaction());
/*     */
/* 176 */     ctx.setPrincipal(mi.getPrincipal());
/*     */
/* 178 */     EnterpriseBeanPolicyContextHandler.setEnterpriseBean(ctx.getInstance());
/*     */
/* 181 */     mi.setEnterpriseContext(ctx);
/*     */
/* 183 */     if (ejbTimeout.equals(mi.getMethod()))
/* 184 */       AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_TIMEOUT);
View Full Code Here

/*     */   public EnterpriseContext get(Object id) throws RemoteException, NoSuchObjectException
/*     */   {
/*  71 */     if (id == null) throw new IllegalArgumentException("Can't get an object with a null key");
/*     */
/*  73 */     Map cache = getLocalCache();
/*  74 */     EntityEnterpriseContext instance = (EntityEnterpriseContext)cache.get(id);
/*  75 */     if (instance == null)
/*     */     {
/*     */       try
/*     */       {
/*  80 */         instance = (EntityEnterpriseContext)this.container.getInstancePool().get();
/*     */
/*  82 */         instance.setId(id);
/*  83 */         instance.setCacheKey(id);
/*     */
/*  85 */         this.container.getPersistenceManager().activateEntity(instance);
/*     */
/*  87 */         cache.put(id, instance);
/*     */       }
View Full Code Here

/*     */
/*     */   public void insert(EnterpriseContext instance)
/*     */   {
/*  99 */     if (instance == null) throw new IllegalArgumentException("Can't insert a null object in the cache");
/*     */
/* 101 */     EntityEnterpriseContext entity = (EntityEnterpriseContext)instance;
/* 102 */     getLocalCache().put(entity.getCacheKey(), instance);
/*     */   }
View Full Code Here

TOP

Related Classes of org.jboss.ejb.EntityEnterpriseContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.