Example #1
0
        protected internal virtual void flushCachedEntity(CachedDbEntity cachedDbEntity)
        {
            if (cachedDbEntity.EntityState == TRANSIENT)
            {
                // latest state of references in cache is relevant when determining insertion order
                cachedDbEntity.determineEntityReferences();
                // perform INSERT
                performEntityOperation(cachedDbEntity, INSERT);
                // mark PERSISTENT
                cachedDbEntity.EntityState = PERSISTENT;
            }
            else if (cachedDbEntity.EntityState == PERSISTENT && cachedDbEntity.Dirty)
            {
                // object is dirty -> perform UPDATE
                performEntityOperation(cachedDbEntity, UPDATE);
            }
            else if (cachedDbEntity.EntityState == MERGED)
            {
                // perform UPDATE
                performEntityOperation(cachedDbEntity, UPDATE);
                // mark PERSISTENT
                cachedDbEntity.EntityState = PERSISTENT;
            }
            else if (cachedDbEntity.EntityState == DELETED_TRANSIENT)
            {
                // remove from cache
                dbEntityCache.remove(cachedDbEntity);
            }
            else if (cachedDbEntity.EntityState == DELETED_PERSISTENT || cachedDbEntity.EntityState == DELETED_MERGED)
            {
                // perform DELETE
                performEntityOperation(cachedDbEntity, DELETE);
                // remove from cache
                dbEntityCache.remove(cachedDbEntity);
            }

            // if object is PERSISTENT after flush
            if (cachedDbEntity.EntityState == PERSISTENT)
            {
                // make a new copy
                cachedDbEntity.makeCopy();
                // update cached references
                cachedDbEntity.determineEntityReferences();
            }
        }