DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Package Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Protocol.QueryResult Class Reference
Inheritance diagram for Deveel.Data.Protocol.QueryResult:

Public Member Functions

QueryResultColumn GetColumn (int columnOffset)
 
void LockRoot ()
 
void Release ()
 
void Dispose ()
 
DataObject GetValue (int rowIndex, int columnIndex)
 
 QueryResult (SqlQuery query, Table result)
 Constructs the result set. More...
 
StreamableObject GetRef (long id)
 Returns a IRef that has been cached in this table object by its identifier value. More...
 
void RemoveRef (long id)
 Removes a IRef that has been cached in this table object by its identifier value. More...
 
void Dispose ()
 Disposes this object. More...
 
TObject GetCellContents (int column, int row)
 Gets the cell contents of the cell at the given row/column. More...
 
void LockRoot (int key)
 Locks the root of the result set. More...
 

Package Functions

 QueryResult (SqlQuery query, ITable result)
 

Properties

SqlQuery Query [get, private set]
 
ITable Result [get, private set]
 
int RowCount [get]
 Returns the row count. More...
 
int ColumnCount [get]
 Returns the column count. More...
 
QueryResultColumn[] Fields [get]
 Returns the QueryResultColumn array of all the columns in the result. More...
 

Private Member Functions

void FormColumns (ITable result)
 
void UnlockRoot (int key)
 Unlocks the root of the result set. More...
 

Private Attributes

QueryResultColumn[] columns
 
bool resultIsSimpleEnum
 
IList< int > rowIndexMap
 The IList<T> that contains the row index into the table for each row of the result. More...
 
int locked
 Incremented when we Lock roots. More...
 
SqlQuery query
 The SqlQuery that was executed to produce this result. More...
 
Table result
 The table that is the result. More...
 
QueryResultColumn[] colDesc
 A set of QueryResultColumn that describes each column in the ResultSet. More...
 
readonly bool resultIsSimpleEnum
 Set to true if the result table has a SimpleRowEnumerator, therefore guarenteeing we do not need to store a row lookup list. More...
 
readonly int resultRowCount
 The number of rows in the result. More...
 
readonly Dictionary< long, StreamableObjectstreamableBlobMap
 A Dictionary<TKey,TValue> of blob_reference_id values to IRef objects used to handle and streamable objects in this result. More...
 

Detailed Description

Definition at line 25 of file QueryResult.cs.

Constructor & Destructor Documentation

Deveel.Data.Protocol.QueryResult.QueryResult ( SqlQuery  query,
ITable  result 
)
inlinepackage

Definition at line 33 of file QueryResult.cs.

33  {
34  Query = query;
35  Result = result;
37 
38  locked = 0;
39  }
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
Table result
The table that is the result.
void FormColumns(ITable result)
Definition: QueryResult.cs:41
SqlQuery query
The SqlQuery that was executed to produce this result.
Deveel.Data.Protocol.QueryResult.QueryResult ( SqlQuery  query,
Table  result 
)
inline

Constructs the result set.

Parameters
query
result

Definition at line 72 of file QueryResult.old.cs.

72  {
73  this.query = query;
74  this.result = result;
75  streamableBlobMap = new Dictionary<long, StreamableObject>();
76 
77  resultRowCount = result.RowCount;
78 
79  // HACK: Read the contents of the first row so that we can pick up
80  // any errors with reading, and also to fix the 'uniquekey' bug
81  // that causes a new transaction to be started if 'uniquekey' is
82  // a column and the value is resolved later.
83  IRowEnumerator rowEnum = result.GetRowEnumerator();
84  if (rowEnum.MoveNext()) {
85  int rowIndex = rowEnum.RowIndex;
86  for (int c = 0; c < result.ColumnCount; ++c) {
87  result.GetCell(c, rowIndex);
88  }
89  }
90 
91  // If simple enum, note it here
92  resultIsSimpleEnum = (rowEnum is SimpleRowEnumerator);
93  rowEnum = null;
94 
95  // Build 'row_index_map' if not a simple enum
96  if (!resultIsSimpleEnum) {
97  rowIndexMap = new List<int>(result.RowCount);
98 
99  IRowEnumerator en = result.GetRowEnumerator();
100  while (en.MoveNext()) {
101  rowIndexMap.Add(en.RowIndex);
102  }
103  }
104 
105  // This is a safe operation provides we are shared.
106  // Copy all the TableField columns from the table to our own
107  // QueryResultColumn array, naming each column by what is returned from
108  // the 'GetResolvedVariable' method.
109  int colCount = result.ColumnCount;
110  colDesc = new QueryResultColumn[colCount];
111  for (int i = 0; i < colCount; ++i) {
112  VariableName v = result.GetResolvedVariable(i);
113  string fieldName;
114  if (v.TableName == null) {
115  // This means the column is an alias
116  fieldName = String.Format("@a{0}", v.Name);
117  } else {
118  // This means the column is an schema/table/column reference
119  fieldName = String.Format("@f{0}", v);
120  }
121 
122  colDesc[i] = new QueryResultColumn(fieldName, result.GetColumnInfo(i));
123  }
124 
125  locked = 0;
126  }
A long string in the system.
readonly int resultRowCount
The number of rows in the result.
readonly Dictionary< long, StreamableObject > streamableBlobMap
A Dictionary of blob_reference_id values to IRef objects used to handle and streamable o...
QueryResultColumn[] colDesc
A set of QueryResultColumn that describes each column in the ResultSet.
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
Table result
The table that is the result.
IList< int > rowIndexMap
The IList that contains the row index into the table for each row of the result.
Definition: QueryResult.cs:29
SqlQuery query
The SqlQuery that was executed to produce this result.

Member Function Documentation

void Deveel.Data.Protocol.QueryResult.Dispose ( )
inline

Definition at line 119 of file QueryResult.cs.

119  {
120  if (locked > 0) {
121  Release();
122  }
123 
124  Result = null;
125  Query = null;
126  columns = null;
127  rowIndexMap = null;
128  }
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
QueryResultColumn[] columns
Definition: QueryResult.cs:26
IList< int > rowIndexMap
The IList that contains the row index into the table for each row of the result.
Definition: QueryResult.cs:29
void Deveel.Data.Protocol.QueryResult.Dispose ( )
inline

Disposes this object.

Definition at line 154 of file QueryResult.old.cs.

154  {
155  while (locked > 0) {
156  UnlockRoot(-1);
157  }
158  result = null;
159  rowIndexMap = null;
160  colDesc = null;
161  }
QueryResultColumn[] colDesc
A set of QueryResultColumn that describes each column in the ResultSet.
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
Table result
The table that is the result.
void UnlockRoot(int key)
Unlocks the root of the result set.
IList< int > rowIndexMap
The IList that contains the row index into the table for each row of the result.
Definition: QueryResult.cs:29
void Deveel.Data.Protocol.QueryResult.FormColumns ( ITable  result)
inlineprivate

Definition at line 41 of file QueryResult.cs.

41  {
42  // HACK: Read the contents of the first row so that we can pick up
43  // any errors with reading, and also to fix the 'uniquekey' bug
44  // that causes a new transaction to be started if 'uniquekey' is
45  // a column and the value is resolved later.
46  var columnCount = result.TableInfo.ColumnCount;
47  using (var rowEnum = result.GetEnumerator()) {
48  if (rowEnum.MoveNext()) {
49  int rowIndex = rowEnum.Current.RowId.RowNumber;
50  for (int c = 0; c < columnCount; ++c) {
51  result.GetValue(rowIndex, c);
52  }
53  }
54 
55  // If simple enum, note it here
57  }
58 
59  // Build 'row_index_map' if not a simple enum
60  if (!resultIsSimpleEnum) {
61  rowIndexMap = new List<int>(result.RowCount);
62 
63  var en = result.GetEnumerator();
64  while (en.MoveNext()) {
65  rowIndexMap.Add(en.Current.RowId.RowNumber);
66  }
67  }
68 
69  // This is a safe operation provides we are shared.
70  // Copy all the TableField columns from the table to our own
71  // QueryResultColumn array, naming each column by what is returned from
72  // the 'GetResolvedVariable' method.
73  int colCount = result.TableInfo.ColumnCount;
74  columns = new QueryResultColumn[colCount];
75  for (int i = 0; i < colCount; ++i) {
76  var v = result.GetResolvedColumnName(i);
77  string fieldName;
78  if (v.ParentName == null) {
79  // This means the column is an alias
80  fieldName = String.Format("@a{0}", v.Name);
81  } else {
82  // This means the column is an schema/table/column reference
83  fieldName = String.Format("@f{0}", v);
84  }
85 
86  columns[i] = new QueryResultColumn(fieldName, result.TableInfo[i]);
87  }
88  }
A long string in the system.
DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
QueryResultColumn[] columns
Definition: QueryResult.cs:26
TableInfo TableInfo
Gets the metadata information of the table, used to resolve the column sources.
Definition: ITable.cs:47
int RowCount
Gets the total number of rows in the table.
Definition: ITable.cs:52
IList< int > rowIndexMap
The IList that contains the row index into the table for each row of the result.
Definition: QueryResult.cs:29
int ColumnCount
Gets a count of the columns defined by this object.
Definition: TableInfo.cs:159
TObject Deveel.Data.Protocol.QueryResult.GetCellContents ( int  column,
int  row 
)
inline

Gets the cell contents of the cell at the given row/column.

Parameters
column
row

Safe only if roots are locked.

Returns

Definition at line 172 of file QueryResult.old.cs.

172  {
173  if (locked <= 0)
174  throw new Exception("Table roots not locked!");
175 
176  int realRow = resultIsSimpleEnum ? row : rowIndexMap[row];
177  TObject tob = result.GetCell(column, realRow);
178 
179  // If this is a large object reference then cache it so a streamable
180  // object can reference it via this result.
181  if (tob.Object is IRef) {
182  var reference = (IRef) tob.Object;
183  streamableBlobMap[reference.Id] =
184  new StreamableObject(reference.Type, reference.RawSize, reference.Id);
185  }
186 
187  return tob;
188  }
readonly Dictionary< long, StreamableObject > streamableBlobMap
A Dictionary of blob_reference_id values to IRef objects used to handle and streamable o...
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
Table result
The table that is the result.
IList< int > rowIndexMap
The IList that contains the row index into the table for each row of the result.
Definition: QueryResult.cs:29
QueryResultColumn Deveel.Data.Protocol.QueryResult.GetColumn ( int  columnOffset)
inline

Definition at line 102 of file QueryResult.cs.

102  {
103  if (columnOffset < 0 || columnOffset >= ColumnCount)
104  throw new ArgumentOutOfRangeException("columnOffset");
105 
106  return columns[columnOffset];
107  }
int ColumnCount
Returns the column count.
Definition: QueryResult.cs:98
QueryResultColumn[] columns
Definition: QueryResult.cs:26
StreamableObject Deveel.Data.Protocol.QueryResult.GetRef ( long  id)
inline

Returns a IRef that has been cached in this table object by its identifier value.

Parameters
id
Returns

Definition at line 134 of file QueryResult.old.cs.

134  {
135  StreamableObject reference;
136  if (!streamableBlobMap.TryGetValue(id, out reference))
137  return null;
138 
139  return reference;
140  }
readonly Dictionary< long, StreamableObject > streamableBlobMap
A Dictionary of blob_reference_id values to IRef objects used to handle and streamable o...
DataObject Deveel.Data.Protocol.QueryResult.GetValue ( int  rowIndex,
int  columnIndex 
)
inline

Definition at line 130 of file QueryResult.cs.

130  {
131  if (locked <= 0)
132  throw new Exception("Table roots not locked!");
133 
134  int realRow = resultIsSimpleEnum ? rowIndex : rowIndexMap[rowIndex];
135  var obj = Result.GetValue(realRow, columnIndex);
136 
137  // TODO: support large object references
138 
139  return obj;
140  }
DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
IList< int > rowIndexMap
The IList that contains the row index into the table for each row of the result.
Definition: QueryResult.cs:29
void Deveel.Data.Protocol.QueryResult.LockRoot ( )
inline

Definition at line 109 of file QueryResult.cs.

109  {
110  Result.Lock();
111  locked++;
112  }
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
void Deveel.Data.Protocol.QueryResult.LockRoot ( int  key)
inline

Locks the root of the result set.

Parameters
key

Definition at line 215 of file QueryResult.old.cs.

215  {
216  result.LockRoot(key);
217  ++locked;
218  }
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
Table result
The table that is the result.
void Deveel.Data.Protocol.QueryResult.Release ( )
inline

Definition at line 114 of file QueryResult.cs.

114  {
115  Result.Release();
116  --locked;
117  }
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
void Deveel.Data.Protocol.QueryResult.RemoveRef ( long  id)
inline

Removes a IRef that has been cached in this table object by its identifier value.

Parameters
id

Definition at line 147 of file QueryResult.old.cs.

147  {
148  streamableBlobMap.Remove(id);
149  }
readonly Dictionary< long, StreamableObject > streamableBlobMap
A Dictionary of blob_reference_id values to IRef objects used to handle and streamable o...
void Deveel.Data.Protocol.QueryResult.UnlockRoot ( int  key)
inlineprivate

Unlocks the root of the result set.

Parameters
key

Definition at line 224 of file QueryResult.old.cs.

224  {
225  result.UnlockRoot(key);
226  --locked;
227  }
int locked
Incremented when we Lock roots.
Definition: QueryResult.cs:31
Table result
The table that is the result.

Member Data Documentation

QueryResultColumn [] Deveel.Data.Protocol.QueryResult.colDesc
private

A set of QueryResultColumn that describes each column in the ResultSet.

Definition at line 36 of file QueryResult.old.cs.

QueryResultColumn [] Deveel.Data.Protocol.QueryResult.columns
private

Definition at line 26 of file QueryResult.cs.

int Deveel.Data.Protocol.QueryResult.locked
private

Incremented when we Lock roots.

Definition at line 31 of file QueryResult.cs.

SqlQuery Deveel.Data.Protocol.QueryResult.query
private

The SqlQuery that was executed to produce this result.

Definition at line 26 of file QueryResult.old.cs.

Table Deveel.Data.Protocol.QueryResult.result
private

The table that is the result.

Definition at line 31 of file QueryResult.old.cs.

bool Deveel.Data.Protocol.QueryResult.resultIsSimpleEnum
private

Definition at line 28 of file QueryResult.cs.

readonly bool Deveel.Data.Protocol.QueryResult.resultIsSimpleEnum
private

Set to true if the result table has a SimpleRowEnumerator, therefore guarenteeing we do not need to store a row lookup list.

Definition at line 48 of file QueryResult.old.cs.

readonly int Deveel.Data.Protocol.QueryResult.resultRowCount
private

The number of rows in the result.

Definition at line 53 of file QueryResult.old.cs.

IList< int > Deveel.Data.Protocol.QueryResult.rowIndexMap
private

The IList<T> that contains the row index into the table for each row of the result.

Definition at line 29 of file QueryResult.cs.

readonly Dictionary<long, StreamableObject> Deveel.Data.Protocol.QueryResult.streamableBlobMap
private

A Dictionary<TKey,TValue> of blob_reference_id values to IRef objects used to handle and streamable objects in this result.

Definition at line 64 of file QueryResult.old.cs.

Property Documentation

int Deveel.Data.Protocol.QueryResult.ColumnCount
get

Returns the column count.

Definition at line 98 of file QueryResult.cs.

QueryResultColumn [] Deveel.Data.Protocol.QueryResult.Fields
get

Returns the QueryResultColumn array of all the columns in the result.

Definition at line 207 of file QueryResult.old.cs.

SqlQuery Deveel.Data.Protocol.QueryResult.Query
getprivate set

Definition at line 90 of file QueryResult.cs.

ITable Deveel.Data.Protocol.QueryResult.Result
getprivate set

Definition at line 92 of file QueryResult.cs.

int Deveel.Data.Protocol.QueryResult.RowCount
get

Returns the row count.

Definition at line 94 of file QueryResult.cs.


The documentation for this class was generated from the following files: