DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
CreateSequenceNode.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 using System.Linq.Expressions;
4 
6 
7 namespace Deveel.Data.Sql.Parser {
9  public string SequenceName { get; private set; }
10 
11  public IExpressionNode IncrementBy { get; private set; }
12 
13  public IExpressionNode MinValue { get; private set; }
14 
15  public IExpressionNode MaxValue { get; private set; }
16 
17  public IExpressionNode StartWith { get; private set; }
18 
19  public bool Cycle { get; private set; }
20 
21  public IExpressionNode Cache { get; private set; }
22 
23  protected override ISqlNode OnChildNode(ISqlNode node) {
24  if (node is ObjectNameNode) {
25  SequenceName = ((ObjectNameNode) node).Name;
26  } else if (node.NodeName.Equals("start_opt")) {
27  StartWith = node.FindNode<IExpressionNode>();
28  } else if (node.NodeName.Equals("increment_opt")) {
29  IncrementBy = node.FindNode<IExpressionNode>();
30  } else if (node.NodeName.Equals("minvalue_opt")) {
31  MinValue = node.FindNode<IExpressionNode>();
32  } else if (node.NodeName.Equals("maxvalue_opt")) {
33  MaxValue = node.FindNode<IExpressionNode>();
34  } else if (node.NodeName.Equals("cycle_opt")) {
35  Cycle = node.ChildNodes.Any();
36  } else if (node.NodeName.Equals("cache_opt")) {
37  Cache = node.FindNode<IExpressionNode>();
38  }
39 
40  return base.OnChildNode(node);
41  }
42 
43  protected override void BuildStatement(StatementBuilder builder) {
44  var seqName = ObjectName.Parse(SequenceName);
45  var statement = new CreateSequenceStatement(seqName);
46 
47  if (IncrementBy != null)
48  statement.IncrementBy = ExpressionBuilder.Build(IncrementBy);
49  if (Cache != null)
50  statement.Cache = ExpressionBuilder.Build(Cache);
51  if (StartWith != null)
52  statement.StartWith = ExpressionBuilder.Build(StartWith);
53  if (MinValue != null)
54  statement.MinValue = ExpressionBuilder.Build(MinValue);
55  if (MaxValue != null)
56  statement.MaxValue = ExpressionBuilder.Build(MaxValue);
57 
58  statement.Cycle = Cycle;
59 
60  builder.Statements.Add(statement);
61  }
62  }
63 }
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
Defines the contract for nodes in an AST model for a SQL grammar analysis and parsing.
Definition: ISqlNode.cs:25
Represents a composed name for an object within the system.
string NodeName
Gets the name of the node analyzed from the parser.
Definition: ISqlNode.cs:29
static SqlExpression Build(IExpressionNode node)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
ICollection< IStatement > Statements
IEnumerable< ISqlNode > ChildNodes
Gets a read-only enumeration of the children nodes, if any.
Definition: ISqlNode.cs:39
override void BuildStatement(StatementBuilder builder)
This interface acts like a marker that indicates if a ISqlNode represents a SQL expression.
override ISqlNode OnChildNode(ISqlNode node)
During the initialization of the node from the parser, this method is called for every child node add...