private Key extractKey(IPersistent obj) { ByteBuffer buf = new ByteBuffer(); int dst = 0; for (int i = 0; i < types.Length; i++) { object val = mbr[i] is FieldInfo ? ((FieldInfo)mbr[i]).GetValue(obj) : ((PropertyInfo)mbr[i]).GetValue(obj, null); dst = packKeyPart(buf, dst, types[i], val); } return(new Key(buf.toArray())); }
private Key convertKey(Key key) { if (key == null) { return(null); } if (key.type != ClassDescriptor.FieldType.tpArrayOfObject) { throw new DatabaseException(DatabaseException.ErrorCode.INCOMPATIBLE_KEY_TYPE); } Object[] values = (Object[])key.oval; ByteBuffer buf = new ByteBuffer(); int dst = 0; for (int i = 0; i < values.Length; i++) { dst = packKeyPart(buf, dst, types[i], values[i]); } return(new Key(buf.toArray(), key.inclusion != 0)); }
Key createCompoundKey(ClassDescriptor.FieldType[] types, String[] values) { ByteBuffer buf = new ByteBuffer(); int dst = 0; for (int i = 0; i < types.Length; i++) { String val = values[i]; switch (types[i]) { case ClassDescriptor.FieldType.tpBoolean: dst = buf.packBool(dst, Int32.Parse(val) != 0); break; case ClassDescriptor.FieldType.tpByte: case ClassDescriptor.FieldType.tpSByte: dst = buf.packI1(dst, Int32.Parse(val)); break; case ClassDescriptor.FieldType.tpChar: case ClassDescriptor.FieldType.tpShort: case ClassDescriptor.FieldType.tpUShort: dst = buf.packI2(dst, Int32.Parse(val)); break; case ClassDescriptor.FieldType.tpInt: dst = buf.packI4(dst, Int32.Parse(val)); break; case ClassDescriptor.FieldType.tpEnum: case ClassDescriptor.FieldType.tpUInt: dst = buf.packI4(dst, (int)UInt32.Parse(val)); break; case ClassDescriptor.FieldType.tpObject: case ClassDescriptor.FieldType.tpOid: dst = buf.packI4(dst, mapId((int)UInt32.Parse(val))); break; case ClassDescriptor.FieldType.tpLong: dst = buf.packI8(dst, Int64.Parse(val)); break; case ClassDescriptor.FieldType.tpULong: dst = buf.packI8(dst, (long)UInt64.Parse(val)); break; case ClassDescriptor.FieldType.tpDate: dst = buf.packDate(dst, DateTime.Parse(val)); break; case ClassDescriptor.FieldType.tpFloat: dst = buf.packF4(dst, Single.Parse(val)); break; case ClassDescriptor.FieldType.tpDouble: dst = buf.packF8(dst, Double.Parse(val)); break; case ClassDescriptor.FieldType.tpDecimal: dst = buf.packDecimal(dst, Decimal.Parse(val)); break; case ClassDescriptor.FieldType.tpGuid: dst = buf.packGuid(dst, new Guid(val)); break; case ClassDescriptor.FieldType.tpString: dst = buf.packString(dst, val); break; case ClassDescriptor.FieldType.tpArrayOfByte: buf.extend(dst + 4 + (val.Length >> 1)); Bytes.pack4(buf.arr, dst, val.Length >> 1); dst += 4; for (int j = 0, n = val.Length; j < n; j += 2) { buf.arr[dst++] = (byte)((getHexValue(val[j]) << 4) | getHexValue(val[j + 1])); } break; default: throwException("Bad key type"); break; } } return new Key(buf.toArray()); }