public SQLQueryCollectionReturn(string alias, string ownerClass, string ownerProperty, IDictionary propertyResults,
		                                LockMode lockMode)
			: base(alias, propertyResults, lockMode)
		{
			this.ownerEntityName = ownerClass;
			this.ownerProperty = ownerProperty;
		}
		protected void InitAll(
			SqlString whereString,
			string orderByString,
			LockMode lockMode)
		{
			WalkEntityTree(persister, Alias);
			IList allAssociations = new ArrayList();
			foreach (object obj in associations)
			{
				allAssociations.Add(obj);
			}
			allAssociations.Add(
				new OuterJoinableAssociation(
					persister.EntityType,
					null,
					null,
					alias,
					JoinType.LeftOuterJoin,
					Factory,
					CollectionHelper.EmptyMap
					));

			InitPersisters(allAssociations, lockMode);
			InitStatementString(whereString, orderByString, lockMode);
		}
        private void wait(LockMode mode)
        {
            WaitContext ctx;
            lock (typeof(PersistentResource)) 
            {
                ctx = freeContexts;
                if (ctx == null) 
                {
                    ctx = new WaitContext();
                } 
                else 
                {
                    freeContexts = ctx.next;
                }
                ctx.next = null;
            }
            if (queueStart != null) 
            { 
                queueEnd = queueEnd.next = ctx;
            } 
            else 
            { 
                queueStart = queueEnd = ctx;
            }                            
            ctx.mode = mode;
 
            Monitor.Exit(this);
            ctx.evt.WaitOne();

            lock (typeof(PersistentResource)) 
            {
                ctx.next = freeContexts;
                freeContexts = ctx;
            }
        }
		public EntityLoader(
			IOuterJoinLoadable persister,
			string[] uniqueKey,
			IType uniqueKeyType,
			int batchSize,
			LockMode lockMode,
			ISessionFactoryImplementor factory,
			IDictionary enabledFilters)
			: base(persister, uniqueKeyType, factory, enabledFilters)
		{
			JoinWalker walker = new EntityJoinWalker(
				persister,
				uniqueKey,
				uniqueKeyType,
				batchSize,
				lockMode,
				factory,
				enabledFilters
				);
			InitFromWalker(walker);

			PostInstantiate();

			batchLoader = batchSize > 1;

			log.Debug("Static select for entity " + entityName + ": " + SqlString);
		}
		protected void InitProjection(SqlString projectionString, SqlString whereString,
			string orderByString, string groupByString, LockMode lockMode)
		{
			WalkEntityTree(persister, Alias);
			Persisters = new ILoadable[0];
			InitStatementString(projectionString, whereString, orderByString, groupByString, lockMode);
		}
		private void InitStatementString(SqlString projection,SqlString condition,
			string orderBy,string groupBy,LockMode lockMode)
		{
			int joins = CountEntityPersisters(associations);
			Suffixes = BasicLoader.GenerateSuffixes(joins + 1);
			JoinFragment ojf = MergeOuterJoins(associations);

			SqlString selectClause = projection
			                         ??
			                         new SqlString(persister.SelectFragment(alias, Suffixes[joins]) + SelectString(associations));
			
			SqlSelectBuilder select = new SqlSelectBuilder(Factory)
				.SetLockMode(lockMode)
				.SetSelectClause(selectClause)
				.SetFromClause(Dialect.AppendLockHint(lockMode, persister.FromTableFragment(alias)) +persister.FromJoinFragment(alias, true, true))
				.SetWhereClause(condition)
				.SetOuterJoins(ojf.ToFromFragmentString,ojf.ToWhereFragmentString + WhereFragment)
				.SetOrderByClause(OrderBy(associations, orderBy))
				.SetGroupByClause(groupBy);

			if (Factory.Settings.IsCommentsEnabled)
				select.SetComment(Comment);

			SqlString = select.ToSqlString();
		}
		public CollectionFetchReturn(string alias, NonScalarReturn owner, string ownerProperty,
		                             ICollectionAliases collectionAliases, IEntityAliases elementEntityAliases,
		                             LockMode lockMode) : base(owner, ownerProperty, alias, lockMode)
		{
			this.collectionAliases = collectionAliases;
			this.elementEntityAliases = elementEntityAliases;
		}
		public SQLQueryJoinReturn(string alias, string ownerAlias, string ownerProperty, IDictionary propertyResults,
		                          LockMode lockMode)
			: base(alias, propertyResults, lockMode)
		{
			this.ownerAlias = ownerAlias;
			this.ownerProperty = ownerProperty;
		}
Example #9
0
		public RefreshEvent(object entity, LockMode lockMode, IEventSource source)
			: this(entity, source)
		{
			if (lockMode == null)
				throw new ArgumentNullException("lockMode", "Attempt to generate refresh event with null lock mode");

			this.lockMode = lockMode;
		}
		public SimpleEntityLoader( ILoadable persister, SqlString sql, LockMode lockMode )
		{
			this.persister = new ILoadable[ ] {persister};
			this.idType = persister.IdentifierType;
			this.sql = sql;
			this.lockMode = new LockMode[ ] {lockMode};
			PostInstantiate();
		}
		public EntityLoader(
			IOuterJoinLoadable persister,
			LockMode lockMode,
			ISessionFactoryImplementor factory,
			IDictionary enabledFilters)
			: this(persister, 1, lockMode, factory, enabledFilters)
		{
		}
		private void InitStatementString(
			SqlString condition,
			string orderBy,
			LockMode lockMode)

		{
			InitStatementString(null, condition, orderBy, "", lockMode);
		}
		public CollectionReturn(string alias, string ownerEntityName, string ownerProperty,
		                        ICollectionAliases collectionAliases, IEntityAliases elementEntityAliases, LockMode lockMode)
			: base(alias, lockMode)
		{
			this.ownerEntityName = ownerEntityName;
			this.ownerProperty = ownerProperty;
			this.collectionAliases = collectionAliases;
			this.elementEntityAliases = elementEntityAliases;
		}
		public static LockMode[] FillArray(LockMode lockMode, int length)
		{
			LockMode[] result = new LockMode[length];
			for (int i = 0; i < length; i++)
			{
				result[i] = lockMode;
			}
			return result;
		}
		public NonScalarReturn(string alias, LockMode lockMode)
		{
			this.alias = alias;
			if (alias == null)
			{
				throw new HibernateException("alias must be specified");
			}
			this.lockMode = lockMode;
		}
Example #16
0
        /**
         * Construct a SetLockModeEvent
         *
         * @param methodSig tells us which overload of setLockMode to use
         * @param lockMode the lock mode we'll set when the event fires
         * @param alias the alias for which we'll set the lcok mode when the event
         * fires.  Can be null.
         */
        private SetLockModeEvent(
			MethodSig methodSig,
			LockMode lockMode,
			/*@Nullable*/ string alias)
        {
            this.methodSig = methodSig;
            this.lockMode = lockMode;
            this.alias = alias;
        }
 /// <summary>
 /// .ctor
 /// </summary>
 /// <param name="alock">Lock to handle</param>
 /// <param name="timeout">timeout to acquire lock</param>
 /// <param name="mode">Lock mode</param>
 public DisposableReaderWriterLock(ReaderWriterLock alock, TimeSpan timeout, LockMode mode = LockMode.Read)
 {
     ParametersValidator.IsNotNull(alock, ()=>alock);
     _lock = alock;
     _timeout = timeout;
     _mode = mode;
     AcquireLock();
     Logger.TraceFormat("lock created timeout={0}, mode ={1}", timeout, mode);
 }
		/// <summary> 
		/// Performs a pessimistic lock upgrade on a given entity, if needed. 
		/// </summary>
		/// <param name="entity">The entity for which to upgrade the lock.</param>
		/// <param name="entry">The entity's EntityEntry instance.</param>
		/// <param name="requestedLockMode">The lock mode being requested for locking. </param>
		/// <param name="source">The session which is the source of the event being processed.</param>
		protected virtual void UpgradeLock(object entity, EntityEntry entry, LockMode requestedLockMode, ISessionImplementor source)
		{
			if (requestedLockMode.GreaterThan(entry.LockMode))
			{
				// The user requested a "greater" (i.e. more restrictive) form of
				// pessimistic lock
				if (entry.Status != Status.Loaded)
				{
					throw new ObjectDeletedException("attempted to lock a deleted instance", entry.Id, entry.EntityName);
				}

				IEntityPersister persister = entry.Persister;

				if (log.IsDebugEnabled)
				{
					log.Debug(string.Format("locking {0} in mode: {1}", MessageHelper.InfoString(persister, entry.Id, source.Factory), requestedLockMode));
				}

				ISoftLock slock;
				CacheKey ck;
				if (persister.HasCache)
				{
					ck = new CacheKey(entry.Id, persister.IdentifierType, persister.RootEntityName, source.EntityMode, source.Factory);
					slock = persister.Cache.Lock(ck, entry.Version);
				}
				else
				{
					ck = null;
					slock = null;
				}

				try
				{
					if (persister.IsVersioned && requestedLockMode == LockMode.Force)
					{
						// todo : should we check the current isolation mode explicitly?
						object nextVersion = persister.ForceVersionIncrement(entry.Id, entry.Version, source);
						entry.ForceLocked(entity, nextVersion);
					}
					else
					{
						persister.Lock(entry.Id, entry.Version, entity, requestedLockMode, source);
					}
					entry.LockMode = requestedLockMode;
				}
				finally
				{
					// the database now holds a lock + the object is flushed from the cache,
					// so release the soft lock
					if (persister.HasCache)
					{
						persister.Cache.Release(ck, slock);
					}
				}
			}
		}
Example #19
0
 public FetchReturn(
     NonScalarReturn owner,
     string ownerProperty,
     string alias,
     LockMode lockMode)
     : base(alias, lockMode)
 {
     this.owner = owner;
     this.ownerProperty = ownerProperty;
 }
Example #20
0
 public EntityFetchReturn(
     String alias,
     IEntityAliases entityAliases,
     NonScalarReturn owner,
     String ownerProperty,
     LockMode lockMode)
     : base(owner, ownerProperty, alias, lockMode)
 {
     this.entityAliases = entityAliases;
 }
Example #21
0
 public RootReturn(
     String alias,
     String entityName,
     IEntityAliases entityAliases,
     LockMode lockMode)
     : base(alias, lockMode)
 {
     this.entityName = entityName;
     this.entityAliases = entityAliases;
 }
		protected void InitAll(SqlString whereString,string orderByString,LockMode lockMode)
		{
			WalkEntityTree(persister, Alias);
			IList<OuterJoinableAssociation> allAssociations = new List<OuterJoinableAssociation>(associations);
			allAssociations.Add(
				new OuterJoinableAssociation(persister.EntityType, null, null, alias, JoinType.LeftOuterJoin, Factory,
				                             new CollectionHelper.EmptyMapClass<string, IFilter>()));

			InitPersisters(allAssociations, lockMode);
			InitStatementString(whereString, orderByString, lockMode);
		}
Example #23
0
		/// <summary>
		/// Register the "hydrated" state of an entity instance, after the first step of 2-phase loading.
		///
		/// Add the "hydrated state" (an array) of an uninitialized entity to the session. We don't try
		/// to resolve any associations yet, because there might be other entities waiting to be
		/// read from the JDBC result set we are currently processing
		/// </summary>
		public static void PostHydrate(IEntityPersister persister, object id, object[] values, object rowId, object obj, LockMode lockMode, bool lazyPropertiesAreUnfetched, ISessionImplementor session)
		{
			object version = Versioning.GetVersion(values, persister);
			session.PersistenceContext.AddEntry(obj, Status.Loading, values, rowId, id, version, lockMode, true, persister, false, lazyPropertiesAreUnfetched);

			if (log.IsDebugEnabled && version != null)
			{
				System.String versionStr = persister.IsVersioned ? persister.VersionType.ToLoggableString(version, session.Factory) : "null";
				log.Debug("Version: " + versionStr);
			}
		}
Example #24
0
 private static int GetMatrixIndex(LockMode mode)
 {
     int idx = -1;
     switch (mode)
     {
         case LockMode.Locked: idx = 0; break;
         case LockMode.WriteLock: idx = 2; break;
         case LockMode.ReadLock: idx = 3; break;
         default: break;
     }
     return idx;
 }
		public EntityJoinWalker(IOuterJoinLoadable persister, string[] uniqueKey, int batchSize, LockMode lockMode,
		                        ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
			: base(persister, factory, enabledFilters)
		{
			this.lockMode = lockMode;

			SqlStringBuilder whereCondition = WhereString(Alias, uniqueKey, batchSize)
				//include the discriminator and class-level where, but not filters
				.Add(persister.FilterFragment(Alias, new CollectionHelper.EmptyMapClass<string, IFilter>()));

			InitAll(whereCondition.ToSqlString(), SqlString.Empty, lockMode);
		}
		protected SQLQueryNonScalarReturn(string alias, IDictionary propertyResults, LockMode lockMode)
		{
			this.alias = alias;
			if (alias == null)
			{
				throw new HibernateException("alias must be specified");
			}
			this.lockMode = lockMode;
			if (propertyResults != null)
			{
				this.propertyResults = propertyResults;
			}
		}
		/// <summary> Constructs some form of non-scalar return descriptor </summary>
		/// <param name="alias">The result alias </param>
		/// <param name="propertyResults">Any user-supplied column->property mappings </param>
		/// <param name="lockMode">The lock mode to apply to the return. </param>
		protected internal NativeSQLQueryNonScalarReturn(string alias, IDictionary<string, string[]> propertyResults, LockMode lockMode)
		{
			if (string.IsNullOrEmpty(alias))
				throw new ArgumentNullException("alias", "A valid scalar alias must be specified.");

			this.alias = alias;
			this.lockMode = lockMode;
			
			if (propertyResults != null)
			{
				ArrayHelper.AddAll(this.propertyResults, propertyResults);
			}
		}
Example #28
0
 /// <summary>
 /// Tries to lock the items passed in LockBatch.
 /// </summary>
 /// <param name="login">The login of the user is our transaction id</param>
 /// <param name="batch">The items to lock</param>
 /// <param name="mode">The lock mode</param>
 /// <returns>True on lock success, false on rollback</returns>
 public bool Lock(String login, LockBatch batch, LockMode mode)
 {
     lock(locks)
     {
         foreach (LockItem item in batch.ItemsToLock)
         {
             if (SetLocks(login, batch, mode, item) == false)
             {
                 return false;
             }
         }
         return true;
     }
 }
		/// <summary>
		/// Initializes a new instance of EntityEntry.
		/// </summary>
		/// <param name="status">The current <see cref="Status"/> of the Entity.</param>
		/// <param name="loadedState">The snapshot of the Entity's state when it was loaded.</param>
		/// <param name="id">The identifier of the Entity in the database.</param>
		/// <param name="version">The version of the Entity.</param>
		/// <param name="lockMode">The <see cref="LockMode"/> for the Entity.</param>
		/// <param name="existsInDatabase">A boolean indicating if the Entity exists in the database.</param>
		/// <param name="persister">The <see cref="IClassPersister"/> that is responsible for this Entity.</param>
		/// <param name="disableVersionIncrement"></param>
		public EntityEntry(Status status, object[] loadedState, object id, object version, LockMode lockMode, bool existsInDatabase, IClassPersister persister, bool disableVersionIncrement ) 
		{
			this.status = status;
			this.loadedState = loadedState;
			this.id = id;
			this.existsInDatabase = existsInDatabase;
			this.version = version;
			this.lockMode = lockMode;
			this.isBeingReplicated = disableVersionIncrement;
			this.persister = persister;
			if ( persister != null ) 
			{
				className = persister.ClassName;
			}
		}
Example #30
0
 /// <summary>
 /// Unlock the locks for given user and mode.
 /// </summary>
 /// <param name="login">The login name of the user the unlock should be processed for</param>
 /// <param name="batch">The items to unlock</param>
 /// <param name="mode">The lock mode to unlock</param>
 /// <returns>True on all items could be unlocked. False if unlocking of at least one item has failed.</returns>
 public bool Unlock(String login, LockBatch batch, LockMode mode)
 {
     lock(locks)
     {
         bool allLocksReleased = true;
         foreach (LockItem item in batch.ItemsToLock)
         {
             if (ReleaseLocks(login, mode, item) == false)
             {
                 allLocksReleased = false;
             }
         }
         return allLocksReleased;
     }
 }
Example #31
0
 public ICriteria SetLockMode(string alias, LockMode lockMode)
 {
     root.SetLockMode(alias, lockMode);
     return(this);
 }
Example #32
0
 public object Get(Type clazz, object id, LockMode lockMode)
 {
     return(_Session.Get(clazz, id, lockMode));
 }
Example #33
0
 public T Get <T>(object id, LockMode lockMode)
 {
     return(_Session.Get <T>(id, lockMode));
 }
 public object Load(string entityName, object id, LockMode lockMode)
 {
     throw new NotImplementedException();
 }
Example #35
0
 public object Load(string entityName, object id, LockMode lockMode)
 {
     return(_backingSession.Load(entityName, id, lockMode));
 }
Example #36
0
 public void Lock(object id, object version, object obj, LockMode lockMode, ISessionImplementor session)
 {
     throw new NotSupportedException();
 }
Example #37
0
 public ICriteria SetLockMode(string alias, LockMode lockMode)
 {
     lockModes[alias] = lockMode;
     return(this);
 }
 protected bool NeedsLockHint(LockMode lockMode)
 {
     return(lockMode.GreaterThan(LockMode.Read));
 }
 public Task <ConditionalValue <T> > TryPeekAsync(ITransaction tx, LockMode lockMode)
 {
     return(TryPeekAsync(tx));
 }
 public object Get(Type clazz, object id, LockMode lockMode)
 {
     throw new NotImplementedException();
 }
Example #41
0
 public void Lock(object obj, LockMode lockMode)
 {
     _backingSession.Lock(obj, lockMode);
 }
Example #42
0
 public void Lock(string entityName, object obj, LockMode lockMode)
 {
     _backingSession.Lock(entityName, obj, lockMode);
 }
Example #43
0
 public T Load <T>(object id, LockMode lockMode)
 {
     return(_backingSession.Load <T>(id, lockMode));
 }
        /// <summary>
        /// Applies locks to the specified source queryable.
        /// </summary>
        /// <typeparam name="TSource">The type of the source element.</typeparam>
        /// <param name="source">The source sequence.</param>
        /// <param name="lockMode">The lock mode.</param>
        /// <param name="lockBehavior">The lock behavior.</param>
        /// <returns>The same sequence, but with "apply lock" hint.</returns>
        public static IQueryable <TSource> Lock <TSource>(this IQueryable <TSource> source, LockMode lockMode, LockBehavior lockBehavior)
        {
            ArgumentValidator.EnsureArgumentNotNull(source, "source");
            ArgumentValidator.EnsureArgumentNotNull(lockMode, "lockMode");
            ArgumentValidator.EnsureArgumentNotNull(lockBehavior, "lockBehavior");
            var errorMessage = Strings.ExLockDoesNotSupportQueryProviderOfTypeX;
            var providerType = source.Provider.GetType();

            if (providerType != WellKnownOrmTypes.QueryProvider)
            {
                throw new NotSupportedException(String.Format(errorMessage, providerType));
            }

            var genericMethod = WellKnownMembers.Queryable.ExtensionLock.MakeGenericMethod(new[] { typeof(TSource) });
            var expression    = Expression.Call(null, genericMethod, new[] { source.Expression, Expression.Constant(lockMode), Expression.Constant(lockBehavior) });

            return(source.Provider.CreateQuery <TSource>(expression));
        }
Example #45
0
 public ICriteria SetLockMode(LockMode lockMode)
 {
     this.lockMode = lockMode;
     return(this);
 }
Example #46
0
 public void Lock(object obj, LockMode lockMode)
 {
     _session.Lock(obj, lockMode);
 }
Example #47
0
 public ICriteria SetLockMode(LockMode lockMode)
 {
     return(SetLockMode(CriteriaSpecification.RootAlias, lockMode));
 }
Example #48
0
 public void Refresh(object obj, LockMode lockMode)
 {
     _backingSession.Refresh(obj, lockMode);
 }
Example #49
0
 public abstract IQuery SetLockMode(string alias, LockMode lockMode);
 public Task <ConditionalValue <T> > TryPeekAsync(ITransaction tx, LockMode lockMode, TimeSpan timeout, CancellationToken cancellationToken)
 {
     return(TryPeekAsync(tx));
 }
Example #51
0
 public void Refresh(object obj, LockMode lockMode)
 {
     _session.Refresh(obj, lockMode);
 }
Example #52
0
 public Task <bool> ContainsKeyAsync(ITransaction tx, TKey key, LockMode lockMode, TimeSpan timeout, CancellationToken cancellationToken)
 {
     return(Task.FromResult(this.dictionary.ContainsKey(key)));
 }
 public object Load(Type theType, object id, LockMode lockMode)
 {
     throw new NotImplementedException();
 }
Example #54
0
 public object Load(Type theType, object id, LockMode lockMode)
 {
     return(_backingSession.Load(theType, id, lockMode));
 }
Example #55
0
 public Task <bool> ContainsKeyAsync(ITransaction tx, TKey key, LockMode lockMode)
 {
     return(Task.FromResult(this.dictionary.ContainsKey(key)));
 }
 public void Refresh(object obj, LockMode lockMode)
 {
     throw new NotImplementedException();
 }
Example #57
0
        public Task <ConditionalValue <TValue> > TryGetValueAsync(ITransaction tx, TKey key, LockMode lockMode)
        {
            TValue value;
            bool   result = this.dictionary.TryGetValue(key, out value);

            return(Task.FromResult(new ConditionalValue <TValue>(result, value)));
        }
 public void Lock(string entityName, object obj, LockMode lockMode)
 {
     throw new NotImplementedException();
 }
Example #59
0
 private LockingHints(LockMode lockingHintAnalog)
 {
     LockingModeAnalog = lockingHintAnalog;
 }
 public T Get <T>(object id, LockMode lockMode)
 {
     throw new NotImplementedException();
 }