DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
QueryExtensions.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
19 using Deveel.Data.Sql.Objects;
21 
22 namespace Deveel.Data.Sql.Sequences {
23  public static class QueryExtensions {
24  public static ISequence GetSequence(this IQuery context, ObjectName sequenceName) {
25  return context.GetObject(DbObjectType.Sequence, sequenceName, AccessType.Read) as ISequence;
26  }
27 
41  public static SqlNumber GetNextValue(this IQuery context, ObjectName sequenceName) {
42  var sequence = context.GetSequence(sequenceName);
43  if (sequence == null)
44  throw new InvalidOperationException(String.Format("Sequence {0} was not found.", sequenceName));
45 
46  return sequence.NextValue();
47  }
48 
62  public static SqlNumber GetCurrentValue(this IQuery context, ObjectName sequenceName) {
63  var sequence = context.GetSequence(sequenceName);
64  if (sequence == null)
65  throw new InvalidOperationException(String.Format("Sequence {0} was not found.", sequenceName));
66 
67  return sequence.GetCurrentValue();
68  }
69 
80  public static void SetCurrentValue(this IQuery context, ObjectName sequenceName, SqlNumber value) {
81  var sequence = context.GetSequence(sequenceName);
82  if (sequence == null)
83  throw new InvalidOperationException(String.Format("Sequence {0} was not found.", sequenceName));
84 
85  sequence.SetValue(value);
86  }
87  }
88 }
static ISequence GetSequence(this IQuery context, ObjectName sequenceName)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static SqlNumber GetCurrentValue(this IQuery context, ObjectName sequenceName)
Gets the current value of the sequence.
static SqlNumber GetNextValue(this IQuery context, ObjectName sequenceName)
Increments the sequence and returns the computed value.
static void SetCurrentValue(this IQuery context, ObjectName sequenceName, SqlNumber value)
Sets the current value of the sequence, overriding the increment mechanism in place.
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