コード例 #1
0
        // 6.0 TODO: merge in IUniqueKeyLoadable
        public static async Task CacheByUniqueKeysAsync(
            this IUniqueKeyLoadable ukLoadable,
            object entity,
            ISessionImplementor session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (ukLoadable is AbstractEntityPersister persister)
            {
                await(persister.CacheByUniqueKeysAsync(entity, session, cancellationToken)).ConfigureAwait(false);
                return;
            }

            // Use reflection for supporting custom persisters.
            var ukLoadableType          = ukLoadable.GetType();
            var cacheByUniqueKeysMethod = ukLoadableType.GetMethod(
                nameof(AbstractEntityPersister.CacheByUniqueKeysAsync),
                new[] { typeof(object), typeof(ISessionImplementor) });

            if (cacheByUniqueKeysMethod != null)
            {
                cacheByUniqueKeysMethod.Invoke(ukLoadable, new[] { entity, session });
                return;
            }

            Logger.Warn(
                "{0} does not implement 'void CacheByUniqueKeys(object, ISessionImplementor)', " +
                "some caching may be lacking",
                ukLoadableType);
        }
コード例 #2
0
        // 6.0 TODO: merge in IUniqueKeyLoadable
        public static void CacheByUniqueKeys(
            this IUniqueKeyLoadable ukLoadable,
            object entity,
            ISessionImplementor session)
        {
            if (ukLoadable is AbstractEntityPersister persister)
            {
                persister.CacheByUniqueKeys(entity, session);
                return;
            }

            // Use reflection for supporting custom persisters.
            var ukLoadableType          = ukLoadable.GetType();
            var cacheByUniqueKeysMethod = ukLoadableType.GetMethod(
                nameof(AbstractEntityPersister.CacheByUniqueKeys),
                new[] { typeof(object), typeof(ISessionImplementor) });

            if (cacheByUniqueKeysMethod != null)
            {
                cacheByUniqueKeysMethod.Invoke(ukLoadable, new[] { entity, session });
                return;
            }

            Logger.Warn(
                "{0} does not implement 'void CacheByUniqueKeys(object, ISessionImplementor)', " +
                "some caching may be lacking",
                ukLoadableType);
        }