DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
QueryContext.Sequences.cs
Go to the documentation of this file.
1 using System;
2 
3 using Deveel.Data.Sql.Objects;
5 
6 namespace Deveel.Data.Sql.Sequences {
7  public static class QueryContext {
8  public static ISequence GetSequence(this IQueryContext context, ObjectName sequenceName) {
9  return context.GetObject(DbObjectType.Sequence, sequenceName, AccessType.Read) as ISequence;
10  }
11 
25  public static SqlNumber GetNextValue(this IQueryContext context, ObjectName sequenceName) {
26  var sequence = context.GetSequence(sequenceName);
27  if (sequence == null)
28  throw new InvalidOperationException(String.Format("Sequence {0} was not found.", sequenceName));
29 
30  return sequence.NextValue();
31  }
32 
46  public static SqlNumber GetCurrentValue(this IQueryContext context, ObjectName sequenceName) {
47  var sequence = context.GetSequence(sequenceName);
48  if (sequence == null)
49  throw new InvalidOperationException(String.Format("Sequence {0} was not found.", sequenceName));
50 
51  return sequence.GetCurrentValue();
52  }
53 
64  public static void SetCurrentValue(this IQueryContext context, ObjectName sequenceName, SqlNumber value) {
65  var sequence = context.GetSequence(sequenceName);
66  if (sequence == null)
67  throw new InvalidOperationException(String.Format("Sequence {0} was not found.", sequenceName));
68 
69  sequence.SetValue(value);
70  }
71  }
72 }
static ISequence GetSequence(this IQueryContext context, ObjectName sequenceName)
static SqlNumber GetNextValue(this IQueryContext context, ObjectName sequenceName)
Increments the sequence and returns the computed value.
static void SetCurrentValue(this IQueryContext context, ObjectName sequenceName, SqlNumber value)
Sets the current value of the sequence, overriding the increment mechanism in place.
Provides a context for executing queries, accessing the system resources and evaluation context...
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static SqlNumber GetCurrentValue(this IQueryContext context, ObjectName sequenceName)
Gets the current value of the sequence.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
Represents a numberic sequence in a transaction.
Definition: ISequence.cs:25