DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
CursorInfo.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 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
20 using System.Linq;
21 
23 using Deveel.Data.Sql.Query;
24 
25 namespace Deveel.Data.Sql.Cursors {
26  public sealed class CursorInfo : IObjectInfo {
27  public CursorInfo(string cursorName, SqlQueryExpression queryExpression)
28  : this(cursorName, CursorFlags.Insensitive, queryExpression) {
29  }
30 
31  public CursorInfo(string cursorName, CursorFlags flags, SqlQueryExpression queryExpression) {
32  if (cursorName == null)
33  throw new ArgumentNullException("cursorName");
34  if (queryExpression == null)
35  throw new ArgumentNullException("queryExpression");
36 
37  CursorName = cursorName;
38  QueryExpression = queryExpression;
39  Parameters = new ParameterCollection();
40 
41  Flags = flags;
42  }
43 
44  public string CursorName { get; private set; }
45 
46  public ICollection<CursorParameter> Parameters { get; private set; }
47 
48  public CursorFlags Flags { get; set; }
49 
50  public bool IsInsensitive {
51  get { return (Flags & CursorFlags.Insensitive) != 0; }
52  }
53 
54 
55  public bool IsScroll {
56  get { return (Flags & CursorFlags.Scroll) != 0; }
57  }
58 
59  public SqlQueryExpression QueryExpression { get; private set; }
60 
62  get { return DbObjectType.Cursor; }
63  }
64 
66  get { return new ObjectName(CursorName); }
67  }
68 
69  #region ParameterCollection
70 
71  class ParameterCollection : Collection<CursorParameter> {
72  protected override void InsertItem(int index, CursorParameter item) {
73  if (Items.Any(x => x.ParameterName == item.ParameterName))
74  throw new ArgumentException(String.Format("Argument '{0}' was already added to the collection.", item.ParameterName));
75 
76  if (item.Offset < 0) {
77  item.Offset = index;
78  } else {
79  index = item.Offset;
80  }
81 
82  base.InsertItem(index, item);
83  }
84 
85  protected override void SetItem(int index, CursorParameter item) {
86  item.Offset = index;
87  base.SetItem(index, item);
88  }
89  }
90 
91  #endregion
92  }
93 }
override void InsertItem(int index, CursorParameter item)
Definition: CursorInfo.cs:72
Describes the name of an object within a database.
Definition: ObjectName.cs:44
override void SetItem(int index, CursorParameter item)
Definition: CursorInfo.cs:85
CursorInfo(string cursorName, CursorFlags flags, SqlQueryExpression queryExpression)
Definition: CursorInfo.cs:31
CursorInfo(string cursorName, SqlQueryExpression queryExpression)
Definition: CursorInfo.cs:27
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27