public static object GetValue(object tupleOrScalar, int ordinal) { SoodaTuple tuple = tupleOrScalar as SoodaTuple; if (tuple != null) { return(tuple.GetValue(ordinal)); } if (ordinal != 0) { throw new ArgumentException("Ordinal must be zero for scalar values"); } return(tupleOrScalar); }
public static object[] GetValuesArray(object tupleOrScalar) { SoodaTuple tuple = tupleOrScalar as SoodaTuple; if (tuple != null) { object[] retval = new object[tuple.Length]; for (int i = 0; i < tuple.Length; ++i) { retval[i] = tuple.GetValue(i); } return(retval); } else { return new object[] { tupleOrScalar } }; }
public override bool Equals(object obj) { SoodaTuple tuple2 = obj as SoodaTuple; if (tuple2 == null) { return(false); } if (_items.Length != tuple2._items.Length) { return(false); } for (int i = 0; i < _items.Length; ++i) { if (!_items[i].Equals(tuple2._items[i])) { return(false); } } return(true); }
protected void SetPrimaryKeySubValue(object keyValue, int valueOrdinal, int totalValues) { SoodaTuple tuple = (SoodaTuple) _primaryKeyValue; if (tuple == null) _primaryKeyValue = tuple = new SoodaTuple(totalValues); tuple.SetValue(valueOrdinal, keyValue); if (tuple.IsAllNotNull()) { if (_fieldValues != null) PropagatePrimaryKeyToFields(); if (IsRegisteredInTransaction()) throw new SoodaException("Cannot set primary key value more than once."); RegisterObjectInTransaction(); } }
static SoodaObject GetRefFromRecordHelper(SoodaTransaction tran, ISoodaObjectFactory factory, IDataRecord record, int firstColumnIndex, TableInfo[] loadedTables, int tableIndex, bool loadData) { object keyValue; Sooda.Schema.FieldInfo[] pkFields = factory.GetClassInfo().GetPrimaryKeyFields(); if (pkFields.Length == 1) { int pkFieldOrdinal = loadData ? firstColumnIndex + pkFields[0].OrdinalInTable : 0; try { keyValue = factory.GetPrimaryKeyFieldHandler().RawRead(record, pkFieldOrdinal); } catch (Exception ex) { logger.Error("Error while reading field {0}.{1}: {2}", factory.GetClassInfo().Name, pkFieldOrdinal, ex); throw ex; } } else { object[] pkParts = new object[pkFields.Length]; for (int currentPkPart = 0; currentPkPart < pkFields.Length; currentPkPart++) { int pkFieldOrdinal = loadData ? firstColumnIndex + pkFields[currentPkPart].OrdinalInTable : currentPkPart; SoodaFieldHandler handler = factory.GetFieldHandler(pkFieldOrdinal); pkParts[currentPkPart] = handler.RawRead(record, pkFieldOrdinal); } keyValue = new SoodaTuple(pkParts); //logger.Debug("Tuple: {0}", keyValue); } SoodaObject retVal = factory.TryGet(tran, keyValue); if (retVal != null) { if (loadData && !retVal.IsDataLoaded(0)) retVal.LoadDataFromRecord(record, firstColumnIndex, loadedTables, tableIndex); return retVal; } factory = GetFactoryFromRecord(tran, factory, record, firstColumnIndex, keyValue, loadData); retVal = factory.GetRawObject(tran); tran.Statistics.RegisterObjectUpdate(); SoodaStatistics.Global.RegisterObjectUpdate(); retVal.InsertMode = false; retVal.SetPrimaryKeyValue(keyValue); if (loadData) retVal.LoadDataFromRecord(record, firstColumnIndex, loadedTables, tableIndex); return retVal; }