protected void BuildSelectQuery(Dialect dialect)
        {
            const string     alias         = "tbl";
            SqlStringBuilder selectBuilder = new SqlStringBuilder(100);

            selectBuilder.Add("select ").Add("max(" + StringHelper.Qualify(alias, ValueColumnName) + ")")
            .Add(" from " + TableName + " " + alias + " where ")
            .Add(StringHelper.Qualify(alias, ValueColumnName) + " > ")
            .AddParameter().Add("  ").Add(" and ")               // parameter = nodeSuffixInt64
            .Add(StringHelper.Qualify(alias, ValueColumnName) + " <= ")
            .AddParameter().Add("  ");

            Dictionary <string, LockMode> lockOptions = new Dictionary <string, LockMode>();

            lockOptions[alias] = LockMode.Upgrade;

            Dictionary <string, string[]> updateTargetColumnsMap = new Dictionary <string, string[]>();

            updateTargetColumnsMap[alias] = new[] { ValueColumnName };

            selectQuery = dialect.ApplyLocksToSql(selectBuilder.ToSqlString(), lockOptions, updateTargetColumnsMap);
        }
Exemplo n.º 2
0
		protected override SqlString ApplyLocks(SqlString sql, IDictionary<string, LockMode> lockModes,
		                                        Dialect.Dialect dialect)
		{
			if (lockModes == null || lockModes.Count == 0)
			{
				return sql;
			}

			// can't cache this stuff either (per-invocation)
			// we are given a map of user-alias -> lock mode
			// create a new map of sql-alias -> lock mode
			var aliasedLockModes = new Dictionary<string, LockMode>();
			Dictionary<string, string[]> keyColumnNames = dialect.ForUpdateOfColumns ? new Dictionary<string, string[]>() : null;

			foreach (var entry in lockModes)
			{
				string userAlias = entry.Key;
				string drivingSqlAlias = _sqlAliasByEntityAlias[userAlias];
				if (drivingSqlAlias == null)
				{
					throw new InvalidOperationException("could not locate alias to apply lock mode : " + userAlias);
				}

				// at this point we have (drivingSqlAlias) the SQL alias of the driving table
				// corresponding to the given user alias.  However, the driving table is not
				// (necessarily) the table against which we want to apply locks.  Mainly,
				// the exception case here is joined-subclass hierarchies where we instead
				// want to apply the lock against the root table (for all other strategies,
				// it just happens that driving and root are the same).
				var select = (QueryNode) _queryTranslator.SqlAST;
				var drivingPersister = (ILockable) select.FromClause.GetFromElement(userAlias).Queryable;
				string sqlAlias = drivingPersister.GetRootTableAlias(drivingSqlAlias);
				aliasedLockModes.Add(sqlAlias, entry.Value);

				if (keyColumnNames != null)
				{
					keyColumnNames.Add(sqlAlias, drivingPersister.RootTableIdentifierColumnNames);
				}
			}

			return dialect.ApplyLocksToSql(sql, aliasedLockModes, keyColumnNames);
		}
Exemplo n.º 3
0
		protected override SqlString ApplyLocks(SqlString sqlSelectString, IDictionary<string, LockMode> lockModes,
												Dialect.Dialect dialect)
		{
			if (lockModes == null || lockModes.Count == 0)
			{
				return sqlSelectString;
			}

			Dictionary<string, LockMode> aliasedLockModes = new Dictionary<string, LockMode>();
			Dictionary<string, string[]> keyColumnNames = dialect.ForUpdateOfColumns ? new Dictionary<string, string[]>() : null;
			string[] drivingSqlAliases = Aliases;

			//NH-3710: if we are issuing an aggregation function, Aliases will be null
			if (drivingSqlAliases != null)
			{
				for (int i = 0; i < drivingSqlAliases.Length; i++)
				{
					LockMode lockMode;
					if (lockModes.TryGetValue(drivingSqlAliases[i], out lockMode))
					{
						ILockable drivingPersister = (ILockable)EntityPersisters[i];
						string rootSqlAlias = drivingPersister.GetRootTableAlias(drivingSqlAliases[i]);
						aliasedLockModes[rootSqlAlias] = lockMode;
						if (keyColumnNames != null)
						{
							keyColumnNames[rootSqlAlias] = drivingPersister.RootTableIdentifierColumnNames;
						}
					}
				}
			}

			return dialect.ApplyLocksToSql(sqlSelectString, aliasedLockModes, keyColumnNames);
		}
Exemplo n.º 4
0
		protected override SqlString ApplyLocks(SqlString sql, IDictionary<string, LockMode> lockModes, Dialect.Dialect dialect)
		{
			SqlString result;
			if (lockModes == null || lockModes.Count == 0)
			{
				result = sql;
			}
			else
			{
				Dictionary<string, LockMode> aliasedLockModes = new Dictionary<string, LockMode>();
				foreach (KeyValuePair<string, LockMode> de in lockModes)
				{
					aliasedLockModes[GetAliasName(de.Key)] = de.Value;
				}

				Dictionary<string,string[]> keyColumnNames = null;
				if (dialect.ForUpdateOfColumns)
				{
					keyColumnNames = new Dictionary<string, string[]>();
					for (int i = 0; i < names.Length; i++)
					{
						keyColumnNames[names[i]] = persisters[i].IdentifierColumnNames;
					}
				}
				result = dialect.ApplyLocksToSql(sql, aliasedLockModes, keyColumnNames);
			}
			LogQuery(queryString, result.ToString());
			return result;
		}
Exemplo n.º 5
0
		protected void BuildSelectQuery(Dialect.Dialect dialect)
		{
			const string alias = "tbl";
			SqlString select = new SqlString(
				"select ", StringHelper.Qualify(alias, ValueColumnName), 
				" from ", TableName, " ", alias,
				" where ", StringHelper.Qualify(alias, SegmentColumnName), " = ", Parameter.Placeholder, 
				"  ");

			Dictionary<string, LockMode> lockOptions = new Dictionary<string, LockMode>();
			lockOptions[alias] = LockMode.Upgrade;

			Dictionary<string, string[]> updateTargetColumnsMap = new Dictionary<string, string[]>();
			updateTargetColumnsMap[alias] = new[] { ValueColumnName };

			selectQuery = dialect.ApplyLocksToSql(select, lockOptions, updateTargetColumnsMap);

			selectParameterTypes = new[] { SqlTypes.SqlTypeFactory.GetAnsiString(SegmentValueLength) };
		}
Exemplo n.º 6
0
		protected void BuildSelectQuery(Dialect.Dialect dialect)
		{
			const string alias = "tbl";
			SqlStringBuilder selectBuilder = new SqlStringBuilder(100);
			selectBuilder.Add("select ").Add(StringHelper.Qualify(alias, ValueColumnName))
				.Add(" from " + TableName + " " + alias + " where ")
				.Add(StringHelper.Qualify(alias, SegmentColumnName) + " = ")
				.AddParameter().Add("  ");

			Dictionary<string, LockMode> lockOptions = new Dictionary<string, LockMode>();
			lockOptions[alias] = LockMode.Upgrade;

			Dictionary<string, string[]> updateTargetColumnsMap = new Dictionary<string, string[]>();
			updateTargetColumnsMap[alias] = new[] { ValueColumnName };

			selectQuery = dialect.ApplyLocksToSql(selectBuilder.ToSqlString(), lockOptions, updateTargetColumnsMap);

			selectParameterTypes = new[] { SqlTypes.SqlTypeFactory.GetAnsiString(SegmentValueLength) };
		}
		protected override SqlString ApplyLocks(SqlString sqlSelectString, IDictionary lockModes, Dialect.Dialect dialect)
		{
			if (lockModes == null || lockModes.Count == 0)
			{
				return sqlSelectString;
			}

			IDictionary keyColumnNames = null;
			ILoadable[] persisters = EntityPersisters;
			string[] entityAliases = Aliases;

			if (dialect.ForUpdateOfColumns)
			{
				keyColumnNames = new Hashtable();
				for (int i = 0; i < entityAliases.Length; i++)
				{
					keyColumnNames[entityAliases[i]] = persisters[i].IdentifierColumnNames;
				}
			}

			return dialect.ApplyLocksToSql(sqlSelectString, lockModes, keyColumnNames);
		}