private AbstractObjectInfo GetNativeObjectInfoInternal(OdbType type, object o, bool recursive, IDictionary<object, NonNativeObjectInfo> alreadyReadObjects, IIntrospectionCallback callback) { AbstractObjectInfo aoi = null; if (type.IsAtomicNative()) { if (o == null) aoi = new NullNativeObjectInfo(type.Id); else aoi = new AtomicNativeObjectInfo(o, type.Id); } else if (type.IsArray()) { if (o == null) aoi = new ArrayObjectInfo(null); else { // Gets the type of the elements of the array var realArrayClassName = OdbClassNameResolver.GetFullName(o.GetType().GetElementType()); var arrayObjectInfo = recursive ? IntrospectArray(o, alreadyReadObjects, type, callback) : new ArrayObjectInfo((object[]) o); arrayObjectInfo.SetRealArrayComponentClassName(realArrayClassName); aoi = arrayObjectInfo; } } else if (type.IsEnum()) { var enumObject = (Enum) o; // Here we must check if the enum is already in the meta model. Enum must be stored in the meta // model to optimize its storing as we need to keep track of the enum class // for each enum stored. So instead of storing the enum class name, we can store enum class id, a long // instead of the full enum class name string var classInfo = GetClassInfo(enumObject.GetType()); var enumValue = enumObject.ToString(); aoi = new EnumNativeObjectInfo(classInfo, enumValue); } return aoi; }
public override AbstractObjectInfo CreateCopy(IDictionary <OID, AbstractObjectInfo> cache, bool onlyData) { var array = GetArray(); var length = array.Length; var atomicNativeObjectInfos = new AtomicNativeObjectInfo[length]; for (var i = 0; i < length; i++) { var aoi = (AbstractObjectInfo)array[i]; atomicNativeObjectInfos[i] = aoi.CreateCopy(cache, onlyData) as AtomicNativeObjectInfo; } var arrayOfAoi = new ArrayObjectInfo(atomicNativeObjectInfos); arrayOfAoi.SetRealArrayComponentClassName(_realArrayComponentClassName); arrayOfAoi.SetComponentTypeId(_componentTypeId); return(arrayOfAoi); }
public override AbstractObjectInfo CreateCopy(IDictionary<OID, AbstractObjectInfo> cache, bool onlyData) { var array = GetArray(); var length = array.Length; var atomicNativeObjectInfos = new AtomicNativeObjectInfo[length]; for (var i = 0; i < length; i++) { var aoi = (AbstractObjectInfo) array[i]; atomicNativeObjectInfos[i] = aoi.CreateCopy(cache, onlyData) as AtomicNativeObjectInfo; } var arrayOfAoi = new ArrayObjectInfo(atomicNativeObjectInfos); arrayOfAoi.SetRealArrayComponentClassName(_realArrayComponentClassName); arrayOfAoi.SetComponentTypeId(_componentTypeId); return arrayOfAoi; }
/// <summary> /// Builds an instance of an array /// </summary> private object BuildArrayInstance(ArrayObjectInfo aoi) { // first check if array element type is native (int,short, for example) var type = OdbType.GetFromName(aoi.GetRealArrayComponentClassName()); var arrayClazz = type.GetNativeClass(); object array = Array.CreateInstance(arrayClazz, aoi.GetArray().Length); for (var i = 0; i < aoi.GetArrayLength(); i++) { var abstractObjectInfo = (AbstractObjectInfo) aoi.GetArray()[i]; if (abstractObjectInfo == null || abstractObjectInfo.IsDeletedObject() || abstractObjectInfo.IsNull()) continue; var instance = BuildOneInstance(abstractObjectInfo); ((Array) array).SetValue(instance, i); } return array; }
/// <summary> /// <pre>Write an array to the database /// This is done by writing : /// - the array type : array /// - the array element type (String if it os a String []) /// - the position of the non native type, if element are non java / C# native /// - the number of element s and then the position of all elements. /// </pre> /// </summary> /// <remarks> /// <pre>Write an array to the database /// This is done by writing : /// - the array type : array /// - the array element type (String if it os a String []) /// - the position of the non native type, if element are non java / C# native /// - the number of element s and then the position of all elements. /// Example : an array with two string element : 'ola' and 'chico' /// write 22 : array /// write 20 : array of STRING /// write 0 : it is a java native object /// write 2 (as an int) : the number of elements /// write two times 0 (as long) to reserve the space for the elements positions /// then write the string 'ola', and keeps its position in the 'positions' array of long /// then write the string 'chico' and keeps its position in the 'positions' array of long /// Then write back all the positions (in this case , 2 positions) after the size of the array /// Example : an array with two User element : user1 and user2 /// write 22 : array /// write 23 : array of NON NATIVE Objects /// write 251 : if 250 is the position of the user class info in database /// write 2 (as an int) : the number of elements /// write two times 0 (as long) to reserve the space for the elements positions /// then write the user user1, and keeps its position in the 'positions' array of long /// then write the user user2 and keeps its position in the 'positions' array of long /// <pre> /// @param object /// @param odbType /// @param position /// @param writeInTransaction /// @</pre> /// </remarks> private long WriteArray(ArrayObjectInfo aoi, bool writeInTransaction) { var startPosition = FileSystemProcessor.FileSystemInterface.GetPosition(); WriteNativeObjectHeader(aoi.GetOdbTypeId(), aoi.IsNull(), BlockTypes.BlockTypeArrayObject, writeInTransaction); if (aoi.IsNull()) return startPosition; var array = aoi.GetArray(); var arraySize = array.Length; // Writes the fact that it is an array FileSystemProcessor.FileSystemInterface.WriteString(aoi.GetRealArrayComponentClassName(), writeInTransaction); // write the size of the array FileSystemProcessor.FileSystemInterface.WriteInt(arraySize, writeInTransaction); // build a n array to store all element positions var attributeIdentifications = new long[arraySize]; // Gets the current position, to know later where to put the // references var firstObjectPosition = FileSystemProcessor.FileSystemInterface.GetPosition(); // reserve space for object positions : write 'arraySize' long // with zero to store each object position for (var i = 0; i < arraySize; i++) FileSystemProcessor.FileSystemInterface.WriteLong(0, writeInTransaction); // array element pos for (var i = 0; i < arraySize; i++) { var element = (AbstractObjectInfo) array[i]; if (element == null || element.IsNull()) { // TODO Check this attributeIdentifications[i] = StorageEngineConstant.NullObjectIdId; continue; } attributeIdentifications[i] = InternalStoreObjectWrapper(element); } var positionAfterWrite = FileSystemProcessor.FileSystemInterface.GetPosition(); // now that all objects have been stored, sets their position in the // space that have been reserved FileSystemProcessor.FileSystemInterface.SetWritePosition(firstObjectPosition, writeInTransaction); for (var i = 0; i < arraySize; i++) { FileSystemProcessor.FileSystemInterface.WriteLong(attributeIdentifications[i], writeInTransaction); //array real element pos } // Gos back to the end of the array FileSystemProcessor.FileSystemInterface.SetWritePosition(positionAfterWrite, writeInTransaction); return startPosition; }