Beispiel #1
0
        private static string FormatGetTimeoutsDueQuery(SqlDialect dialect, string tableName, uint batchSize)
        {
            var forUpdateStmt  = string.Empty;
            var skipLockedStmt = string.Empty;
            var lockPredicate  = string.Empty;
            var limitPredicate = string.Empty;

            if (dialect.SupportsSelectForUpdate && dialect.SupportsSkipLockedFunction)
            {
                forUpdateStmt  = dialect.ParameterSelectForUpdate;
                skipLockedStmt = dialect.ParameterSkipLocked;
            }
            else if (dialect.SupportsTryAdvisoryXactLockFunction)
            {
                lockPredicate = $"AND " + dialect.FormatTryAdvisoryXactLock(new[] { "id" });
            }
            else if (dialect.SupportsTryAdvisoryLockFunction)
            {
                lockPredicate = $"AND " + dialect.FormatTryAdvisoryLock(new[] { "id" });
            }

            if (batchSize != 0)
            {
                limitPredicate = "LIMIT " + batchSize;
            }

            return($"SELECT id, time_to_return, correlation_id, saga_id, reply_to, custom_data " +
                   $"FROM {tableName} " +
                   $"WHERE time_to_return <= @current_time {lockPredicate} " +
                   $"ORDER BY time_to_return ASC " +
                   $"{forUpdateStmt} {skipLockedStmt} " +
                   $"{limitPredicate}");
        }