/// <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; }