public static Native ( ObjectName tableName ) : |
||
tableName | ObjectName | |
Результат |
private ISequence CreateNativeTableSequence(ObjectName tableName) { var table = Transaction.GetMutableTable(SystemSchema.SequenceInfoTableName); var uniqueId = Transaction.NextTableId(SystemSchema.SequenceInfoTableName); var dataRow = table.NewRow(); dataRow.SetValue(0, DataObject.Number(uniqueId)); dataRow.SetValue(1, DataObject.VarChar(tableName.Parent.FullName)); dataRow.SetValue(2, DataObject.VarChar(tableName.Name)); dataRow.SetValue(3, DataObject.BigInt(1)); table.AddRow(dataRow); return(new Sequence(this, uniqueId, SequenceInfo.Native(tableName))); }
public ISequence GetSequence(ObjectName sequenceName) { // Is the generator already in the cache? Sequence sequence; if (!sequenceKeyMap.TryGetValue(sequenceName, out sequence)) { // This sequence generator is not in the cache so we need to query the // sequence table for this. var seqi = Transaction.GetTable(SystemSchema.SequenceInfoTableName); var schemaVal = DataObject.VarChar(sequenceName.Parent.FullName); var nameVal = DataObject.VarChar(sequenceName.Name); var list = seqi.SelectRowsEqual(2, nameVal, 1, schemaVal).ToList(); if (list.Count == 0) { throw new ArgumentException(String.Format("Sequence '{0}' not found.", sequenceName)); } else if (list.Count() > 1) { throw new Exception("Assert failed: multiple sequence keys with same name."); } int rowIndex = list.First(); var sid = seqi.GetValue(rowIndex, 0); var sschema = seqi.GetValue(rowIndex, 1); var sname = seqi.GetValue(rowIndex, 2); var stype = seqi.GetValue(rowIndex, 3); // Is this a custom sequence generator? // (stype == 1) == true if (stype.IsEqualTo(OneValue)) { // Native generator. sequence = new Sequence(this, (SqlNumber)sid.Value, SequenceInfo.Native(sequenceName)); } else { // Query the sequence table. var seq = Transaction.GetTable(SystemSchema.SequenceTableName); list = seq.SelectRowsEqual(0, sid).ToList(); if (!list.Any()) { throw new Exception("Sequence table does not contain sequence information."); } if (list.Count() > 1) { throw new Exception("Sequence table contains multiple generators for id."); } rowIndex = list.First(); var lastValue = (SqlNumber)seq.GetValue(rowIndex, 1).Value; var increment = (SqlNumber)seq.GetValue(rowIndex, 2).Value; var minvalue = (SqlNumber)seq.GetValue(rowIndex, 3).Value; var maxvalue = (SqlNumber)seq.GetValue(rowIndex, 4).Value; var start = (SqlNumber)seq.GetValue(rowIndex, 5).Value; var cache = (long)seq.GetValue(rowIndex, 6).AsBigInt(); bool cycle = seq.GetValue(rowIndex, 7).AsBoolean(); var info = new SequenceInfo(sequenceName, start, increment, minvalue, maxvalue, cache, cycle); sequence = new Sequence(this, (SqlNumber)sid.Value, lastValue, info); // Put the generator in the cache sequenceKeyMap[sequenceName] = sequence; } } // Return the generator return(sequence); }