Beispiel #1
0
        /// <summary>
        /// Put a new, <seealso cref="DbEntityState.TRANSIENT"/> object into the cache.
        /// </summary>
        /// <param name="e"> the object to put into the cache </param>
        public virtual void putTransient(DbEntity e)
        {
            CachedDbEntity cachedDbEntity = new CachedDbEntity();

            cachedDbEntity.Entity      = e;
            cachedDbEntity.EntityState = TRANSIENT;
            putInternal(cachedDbEntity);
        }
Beispiel #2
0
        /// <summary>
        /// Put a <seealso cref="DbEntityState.MERGED"/> object into the cache.
        /// </summary>
        /// <param name="e"> the object to put into the cache </param>
        public virtual void putMerged(DbEntity e)
        {
            CachedDbEntity cachedDbEntity = new CachedDbEntity();

            cachedDbEntity.Entity      = e;
            cachedDbEntity.EntityState = MERGED;
            cachedDbEntity.determineEntityReferences();
            // no copy required

            putInternal(cachedDbEntity);
        }
Beispiel #3
0
        /// <summary>
        /// Put a <seealso cref="DbEntityState.PERSISTENT"/> object into the cache.
        /// </summary>
        /// <param name="e"> the object to put into the cache </param>
        public virtual void putPersistent(DbEntity e)
        {
            CachedDbEntity cachedDbEntity = new CachedDbEntity();

            cachedDbEntity.Entity      = e;
            cachedDbEntity.EntityState = PERSISTENT;
            cachedDbEntity.determineEntityReferences();
            cachedDbEntity.makeCopy();

            putInternal(cachedDbEntity);
        }
Beispiel #4
0
        public virtual void undoDelete(DbEntity dbEntity)
        {
            CachedDbEntity cachedEntity = getCachedEntity(dbEntity);

            if (cachedEntity.EntityState == DbEntityState.DELETED_TRANSIENT)
            {
                cachedEntity.EntityState = DbEntityState.TRANSIENT;
            }
            else
            {
                cachedEntity.EntityState = DbEntityState.MERGED;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Allows checking whether the provided entity is present in the cache
        /// and is <seealso cref="DbEntityState.TRANSIENT"/>.
        /// </summary>
        /// <param name="dbEntity"> the entity to check </param>
        /// <returns> true if the provided entity is present in the cache and is
        /// <seealso cref="DbEntityState.TRANSIENT"/>. </returns>
        public virtual bool isTransient(DbEntity dbEntity)
        {
            CachedDbEntity cachedDbEntity = getCachedEntity(dbEntity);

            if (cachedDbEntity == null)
            {
                return(false);
            }
            else
            {
                return(cachedDbEntity.EntityState == TRANSIENT);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Allows checking whether the provided entity is present in the cache
        /// and is marked to be deleted.
        /// </summary>
        /// <param name="dbEntity"> the entity to check </param>
        /// <returns> true if the provided entity is present in the cache and is
        /// marked to be deleted </returns>
        public virtual bool isDeleted(DbEntity dbEntity)
        {
            CachedDbEntity cachedDbEntity = getCachedEntity(dbEntity);

            if (cachedDbEntity == null)
            {
                return(false);
            }
            else
            {
                return(cachedDbEntity.EntityState == DELETED_MERGED || cachedDbEntity.EntityState == DELETED_PERSISTENT || cachedDbEntity.EntityState == DELETED_TRANSIENT);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Allows checking whether the provided entity is present in the cache
        /// and is <seealso cref="DbEntityState.PERSISTENT"/>.
        /// </summary>
        /// <param name="dbEntity"> the entity to check </param>
        /// <returns> true if the provided entity is present in the cache and is
        /// <seealso cref="DbEntityState.PERSISTENT"/>. </returns>
        public virtual bool isPersistent(DbEntity dbEntity)
        {
            CachedDbEntity cachedDbEntity = getCachedEntity(dbEntity);

            if (cachedDbEntity == null)
            {
                return(false);
            }
            else
            {
                return(cachedDbEntity.EntityState == PERSISTENT);
            }
        }
Beispiel #8
0
        /// <summary>
        /// get an object from the cache
        /// </summary>
        /// <param name="type"> the type of the object </param>
        /// <param name="id"> the id of the object </param>
        /// <returns> the object or 'null' if the object is not in the cache </returns>
        /// <exception cref="ProcessEngineException"> if an object for the given id can be found but is of the wrong type. </exception>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public <T extends org.camunda.bpm.engine.impl.db.DbEntity> T get(Class<T> type, String id)
        public virtual T get <T>(Type type, string id) where T : org.camunda.bpm.engine.impl.db.DbEntity
        {
            type = typeof(T);
            Type           cacheKey       = cacheKeyMapping.getEntityCacheKey(type);
            CachedDbEntity cachedDbEntity = getCachedEntity(cacheKey, id);

            if (cachedDbEntity != null)
            {
                DbEntity dbEntity = cachedDbEntity.Entity;
                try
                {
                    return((T)dbEntity);
                }
                catch (System.InvalidCastException e)
                {
                    throw LOG.entityCacheLookupException(type, id, dbEntity.GetType(), e);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #9
0
 /// <param name="cachedDbEntity"> </param>
 public virtual void remove(CachedDbEntity cachedDbEntity)
 {
     remove(cachedDbEntity.Entity);
 }
Beispiel #10
0
        protected internal virtual void putInternal(CachedDbEntity entityToAdd)
        {
            Type type     = entityToAdd.Entity.GetType();
            Type cacheKey = cacheKeyMapping.getEntityCacheKey(type);

            IDictionary <string, CachedDbEntity> map = cachedEntites[cacheKey];

            if (map == null)
            {
                map = new Dictionary <string, CachedDbEntity>();
                cachedEntites[cacheKey] = map;
            }

            // check whether this object is already present in the cache
            CachedDbEntity existingCachedEntity = map[entityToAdd.Entity.Id];

            if (existingCachedEntity == null)
            {
                // no such entity exists -> put it into the cache
                map[entityToAdd.Entity.Id] = entityToAdd;
            }
            else
            {
                // the same entity is already cached
                switch (entityToAdd.EntityState)
                {
                case TRANSIENT:
                    // cannot put TRANSIENT entity if entity with same id already exists in cache.
                    if (existingCachedEntity.EntityState == TRANSIENT)
                    {
                        throw LOG.entityCacheDuplicateEntryException("TRANSIENT", entityToAdd.Entity.Id, entityToAdd.Entity.GetType(), existingCachedEntity.EntityState);
                    }
                    else
                    {
                        throw LOG.alreadyMarkedEntityInEntityCacheException(entityToAdd.Entity.Id, entityToAdd.Entity.GetType(), existingCachedEntity.EntityState);
                    }

                case PERSISTENT:
                    if (existingCachedEntity.EntityState == PERSISTENT)
                    {
                        // use new entity state, replacing the existing one.
                        map[entityToAdd.Entity.Id] = entityToAdd;
                        break;
                    }
                    if (existingCachedEntity.EntityState == DELETED_PERSISTENT || existingCachedEntity.EntityState == DELETED_MERGED)
                    {
                        // ignore put -> this is already marked to be deleted
                        break;
                    }

                    // otherwise fail:
                    throw LOG.entityCacheDuplicateEntryException("PERSISTENT", entityToAdd.Entity.Id, entityToAdd.Entity.GetType(), existingCachedEntity.EntityState);

                case MERGED:
                    if (existingCachedEntity.EntityState == PERSISTENT || existingCachedEntity.EntityState == MERGED)
                    {
                        // use new entity state, replacing the existing one.
                        map[entityToAdd.Entity.Id] = entityToAdd;
                        break;
                    }
                    if (existingCachedEntity.EntityState == DELETED_PERSISTENT || existingCachedEntity.EntityState == DELETED_MERGED)
                    {
                        // ignore put -> this is already marked to be deleted
                        break;
                    }

                    // otherwise fail:
                    throw LOG.entityCacheDuplicateEntryException("MERGED", entityToAdd.Entity.Id, entityToAdd.Entity.GetType(), existingCachedEntity.EntityState);

                default:
                    // deletes are always added
                    map[entityToAdd.Entity.Id] = entityToAdd;
                    break;
                }
            }
        }