示例#1
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 ITask: 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 : IDbEntity
        {
            var cacheKey       = CacheKeyMapping.GetEntityCacheKey(type);
            var cachedDbEntity = GetCachedEntity(cacheKey, id);

            if (cachedDbEntity != null)
            {
                var dbEntity = cachedDbEntity.Entity;
                try
                {
                    return((T)dbEntity);
                }
                catch (InvalidCastException e)
                {
                    //throw e;
                    throw Log.EntityCacheLookupException <T>(type, id, dbEntity.GetType(), e);
                }
            }
            return(default(T));
        }