Skip to content

Commit 60f6002

Browse files
Handle unimplemented/unsupported cases.
1 parent c65ab2b commit 60f6002

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

src/NHibernate/Dialect/Dialect.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,16 @@ public virtual string ForUpdateString
526526
get { return " for update"; }
527527
}
528528

529-
/// <summary> Is <tt>FOR UPDATE OF</tt> syntax supported? </summary>
530-
/// <value> True if the database supports <tt>FOR UPDATE OF</tt> syntax; false otherwise. </value>
529+
/// <summary>Is <c>FOR UPDATE OF</c> syntax supported?</summary>
530+
/// <value><see langword="true"/> if the database supports <c>FOR UPDATE OF</c> syntax; <see langword="false"/> otherwise. </value>
531+
public virtual bool ForUpdateOf
532+
// By default, just check ForUpdateOfColumns. ForUpdateOf needs to be overriden only for dialect suppoting
533+
// "For Update Of" on table aliases.
534+
=> ForUpdateOfColumns;
535+
536+
/// <summary>Is <c>FOR UPDATE OF</c> syntax expecting columns?</summary>
537+
/// <value><see langword="true"/> if the database expects a column list with <c>FOR UPDATE OF</c> syntax,
538+
/// <see langword="false"/> if it expects table alias instead or do not support <c>FOR UPDATE OF</c> syntax.</value>
531539
public virtual bool ForUpdateOfColumns
532540
{
533541
// by default we report no support

src/NHibernate/Dialect/InformixDialect.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ public override string AddColumnString
175175
// throw new NotSupportedException();
176176
//}
177177

178-
/// <summary> Is <tt>FOR UPDATE OF</tt> syntax supported? </summary>
179-
/// <value> True if the database supports <tt>FOR UPDATE OF</tt> syntax; false otherwise. </value>
178+
/// <inheritdoc />
180179
public override bool ForUpdateOfColumns
181180
{
182181
get { return true; }

src/NHibernate/Dialect/PostgreSQLDialect.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ public override SqlString GetLimitString(SqlString queryString, SqlString offset
227227
return pagingBuilder.ToSqlString();
228228
}
229229

230+
/// <inheritdoc />
231+
public override bool ForUpdateOf => true;
232+
233+
/// <inheritdoc />
234+
public override bool SupportsOuterJoinForUpdate => false;
235+
230236
public override string GetForUpdateString(string aliases)
231237
{
232238
return ForUpdateString + " of " + aliases;
@@ -318,7 +324,6 @@ public override string CurrentTimestampSelectString
318324

319325
public override bool SupportsUnboundedLobLocatorMaterialization => false;
320326

321-
public override bool SupportsOuterJoinForUpdate => false;
322327
#endregion
323328

324329
[Serializable]

src/NHibernate/SqlCommand/SqlSelectBuilder.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,31 @@ private string GetForUpdateString()
305305
{
306306
if (!Dialect.SupportsOuterJoinForUpdate && HasOuterJoin())
307307
{
308-
if (Equals(lockMode, LockMode.Upgrade))
309-
return Dialect.GetForUpdateString(mainTableAlias);
310-
311-
if (Equals(lockMode, LockMode.UpgradeNoWait))
312-
return Dialect.GetForUpdateNowaitString(mainTableAlias);
308+
var isUpgrade = Equals(lockMode, LockMode.Upgrade);
309+
var isUpgradeNoWait = !isUpgrade && (
310+
Equals(lockMode, LockMode.UpgradeNoWait) || Equals(lockMode, LockMode.Force));
311+
if (!isUpgrade && !isUpgradeNoWait)
312+
return string.Empty;
313+
314+
if (!Dialect.ForUpdateOf)
315+
{
316+
log.Warn(
317+
"Unsupported 'for update' case: 'for update' query with an outer join using a dialect not" +
318+
"supporting it and not supporting 'for update of' clause. Discarding 'for" +
319+
"update' clause.");
320+
return string.Empty;
321+
}
322+
323+
if (Dialect.ForUpdateOfColumns)
324+
{
325+
log.Warn(
326+
"Unimplemented 'for update' case: 'for update' query with an outer join using a dialect not" +
327+
"supporting it and requiring columns for its 'for update of' syntax. Discarding 'for" +
328+
"update' clause.");
329+
return string.Empty;
330+
}
331+
332+
return isUpgrade ? Dialect.GetForUpdateString(mainTableAlias) : Dialect.GetForUpdateNowaitString(mainTableAlias);
313333
}
314334

315335
return Dialect.GetForUpdateString(lockMode);

0 commit comments

Comments
 (0)