DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Static Public Member Functions | List of all members
Deveel.Data.Sql.Tables.MutableTableExtensions Class Reference

Static Public Member Functions

static bool RemoveRow (this IMutableTable table, int rowIndex)
 
static void DeleteRows (this IMutableTable table, IEnumerable< int > rows)
 
static Row NewRow (this IMutableTable table)
 Creates a new row that is compatible with the table context, ready to be populated and added. More...
 
static int Delete (this IMutableTable table, ITable t)
 
static int Delete (this IMutableTable table, ITable other, int limit)
 
static bool Delete (this IMutableTable table, int columnOffset, DataObject value)
 
static int Update (this IMutableTable mutableTable, IQuery context, ITable table, IEnumerable< SqlAssignExpression > assignList, int limit)
 

Detailed Description

Definition at line 25 of file MutableTableExtensions.cs.

Member Function Documentation

static int Deveel.Data.Sql.Tables.MutableTableExtensions.Delete ( this IMutableTable  table,
ITable  t 
)
inlinestatic

Definition at line 59 of file MutableTableExtensions.cs.

59  {
60  return Delete(table, t, -1);
61  }
static int Delete(this IMutableTable table, ITable t)
static int Deveel.Data.Sql.Tables.MutableTableExtensions.Delete ( this IMutableTable  table,
ITable  other,
int  limit 
)
inlinestatic

Definition at line 63 of file MutableTableExtensions.cs.

63  {
64  List<int> rowSet = new List<int>(other.RowCount);
65  var e = other.GetEnumerator();
66  while (e.MoveNext()) {
67  rowSet.Add(e.Current.RowId.RowNumber);
68  }
69 
70  // HACKY: Find the first column of this table in the search table. This
71  // will allow us to generate a row set of only the rows in the search
72  // table.
73  int firstColumn = other.IndexOfColumn(table.GetResolvedColumnName(0));
74 
75  if (firstColumn == -1)
76  throw new DatabaseSystemException("Search table does not contain any reference to table being deleted from");
77 
78  // Generate a row set that is in this tables domain.
79  var rowsToDelete = other.ResolveRows(firstColumn, rowSet, table).ToList();
80 
81  // row_set may contain duplicate row indices, therefore we must sort so
82  // any duplicates are grouped and therefore easier to find.
83  rowSet.Sort();
84 
85  // If limit less than zero then limit is whole set.
86  if (limit < 0)
87  limit = Int32.MaxValue;
88 
89  // Remove each row in row set in turn. Make sure we don't remove the
90  // same row index twice.
91  int len = System.Math.Min(rowsToDelete.Count, limit);
92  int lastRemoved = -1;
93  int removeCount = 0;
94  for (int i = 0; i < len; ++i) {
95  int toRemove = rowsToDelete[i];
96  if (toRemove < lastRemoved)
97  throw new DatabaseSystemException("Internal error: row sorting error or row set not in the range > 0");
98 
99  if (toRemove != lastRemoved) {
100  table.RemoveRow(toRemove);
101  lastRemoved = toRemove;
102  ++removeCount;
103  }
104  }
105 
106  if (removeCount > 0)
107  // Perform a referential integrity check on any changes to the table.
108  table.AssertConstraints();
109 
110  return removeCount;
111  }
static bool Deveel.Data.Sql.Tables.MutableTableExtensions.Delete ( this IMutableTable  table,
int  columnOffset,
DataObject  value 
)
inlinestatic

Definition at line 113 of file MutableTableExtensions.cs.

113  {
114  var list = table.SelectRowsEqual(columnOffset, value).ToArray();
115  if (list.Length == 0)
116  return false;
117 
118  return table.RemoveRow(list[0]);
119  }
static void Deveel.Data.Sql.Tables.MutableTableExtensions.DeleteRows ( this IMutableTable  table,
IEnumerable< int >  rows 
)
inlinestatic

Definition at line 30 of file MutableTableExtensions.cs.

30  {
31  foreach (var row in rows) {
32  table.RemoveRow(row);
33  }
34  }
static Row Deveel.Data.Sql.Tables.MutableTableExtensions.NewRow ( this IMutableTable  table)
inlinestatic

Creates a new row that is compatible with the table context, ready to be populated and added.

When this method is called, a new RowId is generated and persisted: when a subsequent call to this method will be issued, another new row identifier will be generated, even if the row was not persisted into the table.

Returns
Returns an instance of Row that belongs to this table and can be added or updated through IMutableTable.AddRow or IMutableTable.UpdateRow method calls.

Definition at line 55 of file MutableTableExtensions.cs.

55  {
56  return new Row(table);
57  }
A single ROW in a database table, that holds tabular data as configured by the table specifications...
static bool Deveel.Data.Sql.Tables.MutableTableExtensions.RemoveRow ( this IMutableTable  table,
int  rowIndex 
)
inlinestatic

Definition at line 26 of file MutableTableExtensions.cs.

26  {
27  return table.RemoveRow(new RowId(table.TableInfo.Id, rowIndex));
28  }
static int Deveel.Data.Sql.Tables.MutableTableExtensions.Update ( this IMutableTable  mutableTable,
IQuery  context,
ITable  table,
IEnumerable< SqlAssignExpression assignList,
int  limit 
)
inlinestatic

Definition at line 121 of file MutableTableExtensions.cs.

122  {
123 
124  // Get the rows from the input table.
125  var rowSet = new List<int>();
126  var e = table.GetEnumerator();
127  while (e.MoveNext()) {
128  rowSet.Add(e.Current.RowId.RowNumber);
129  }
130 
131  // HACKY: Find the first column of this table in the search table. This
132  // will allow us to generate a row set of only the rows in the search
133  // table.
134  int firstColumn = table.FindColumn(mutableTable.GetResolvedColumnName(0));
135  if (firstColumn == -1)
136  throw new InvalidOperationException("Search table does not contain any " +
137  "reference to table being updated from");
138 
139  // Convert the row_set to this table's domain.
140  rowSet = table.ResolveRows(firstColumn, rowSet, mutableTable).ToList();
141 
142  // NOTE: Assume there's no duplicate rows.
143 
144  // If limit less than zero then limit is whole set.
145  if (limit < 0)
146  limit = Int32.MaxValue;
147 
148  // Update each row in row set in turn up to the limit.
149  int len = System.Math.Min(rowSet.Count, limit);
150 
151  int updateCount = 0;
152  for (int i = 0; i < len; ++i) {
153  int toUpdate = rowSet[i];
154 
155  // Make a row object from this row (plus keep the original intact
156  // in case we need to roll back to it).
157  var row = mutableTable.GetRow(toUpdate);
158  row.SetFromTable();
159 
160  // Run each assignment on the row.
161  foreach (var assignment in assignList) {
162  row.EvaluateAssignment(assignment, context);
163  }
164 
165  // Update the row
166  mutableTable.UpdateRow(row);
167 
168  ++updateCount;
169  }
170 
171  if (updateCount > 0)
172  // Perform a referential integrity check on any changes to the table.
173  mutableTable.AssertConstraints();
174 
175  return updateCount;
176  }

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