From 5e511f79d5fcae7fe2c4037ee9285297d10992db Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Tue, 5 Jul 2022 04:48:24 +0700 Subject: [PATCH] Change databases to use new collections --- sources/Data/Database/Database.uc | 8 +- sources/Data/Database/Local/DBRecord.uc | 133 +++++++------- .../Database/Local/LocalDatabaseInstance.uc | 6 +- sources/Data/Database/Tasks/DBKeysTask.uc | 8 +- .../Data/Database/Tests/TEST_LocalDatabase.uc | 162 +++++++++--------- 5 files changed, 166 insertions(+), 151 deletions(-) diff --git a/sources/Data/Database/Database.uc b/sources/Data/Database/Database.uc index bf9afdd..e1f6f83 100644 --- a/sources/Data/Database/Database.uc +++ b/sources/Data/Database/Database.uc @@ -7,7 +7,7 @@ * All of the methods are asynchronous - they do not return requested * values immediately and instead require user to provide a handler function * that will be called once operation is completed. - * Copyright 2021 Anton Tarasenko + * Copyright 2021-2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -99,7 +99,7 @@ public function DBReadTask ReadData( * Schedules writing `data` at the location inside the caller database, * given by the `pointer`. * - * Only `AssociativeArray` (that represents JSON object) can be recorded as + * Only `HashTable` (that represents JSON object) can be recorded as * a database's root value (referred to by an empty JSON pointer ""). * * @param pointer JSON pointer to the location in the database, where `data` @@ -121,7 +121,7 @@ public function DBReadTask ReadData( * * Data is actually written inside the database iff * `result == DBR_Success`; * * `result == DBR_InvalidData` iff either given `data`'s type is not - * JSON-compatible or a non-`AssociativeArray` was attempted to be + * JSON-compatible or a non-`HashTable` was attempted to be * recorded as caller database's root value; * * `DBR_InvalidPointer` can be produced if either `pointer == none` or * container of the value `pointer` points at does not exist. @@ -230,7 +230,7 @@ public function DBSizeTask GetDataSize(JSONPointer pointer) * * Use it to connect a handler for when reading task is complete: * `GetDataKeys(...).connect = handler`, * where `handler` must have the following signature: - * `connect(DBQueryResult result, DynamicArray keys)`. + * `connect(DBQueryResult result, ArrayList keys)`. * * Ownership of `keys` array returned in the `connect()` is considered * to be transferred to whoever handled result of this query. * It must be deallocated once no longer needed. diff --git a/sources/Data/Database/Local/DBRecord.uc b/sources/Data/Database/Local/DBRecord.uc index 0107919..3cf2b38 100644 --- a/sources/Data/Database/Local/DBRecord.uc +++ b/sources/Data/Database/Local/DBRecord.uc @@ -7,7 +7,7 @@ * Auxiliary data object that can store either a JSON array or an object in * the local Acedia database. It is supposed to be saved and loaded * to / from packages. - * Copyright 2021 Anton Tarasenko + * Copyright 2021-2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -414,7 +414,7 @@ public final function bool SaveObject( return false; } EmptySelf(); - isJSONArray = (newItemAsCollection.class == class'DynamicArray'); + isJSONArray = (newItemAsCollection.class == class'ArrayList'); FromCollection(newItemAsCollection); return true; } @@ -558,11 +558,10 @@ public final function int GetObjectSize(JSONPointer jsonPointer) * @return If `pointer` refers to the JSON object - all available keys. * `none` otherwise (including case of JSON arrays). */ -public final function DynamicArray GetObjectKeys(JSONPointer jsonPointer) +public final function ArrayList GetObjectKeys(JSONPointer jsonPointer) { local int i; - local TextAPI api; - local DynamicArray resultKeys; + local ArrayList resultKeys; local array items; local DBRecord referredObject; local DBRecordPointer pointer; @@ -573,11 +572,10 @@ public final function DynamicArray GetObjectKeys(JSONPointer jsonPointer) referredObject = pointer.record; if (referredObject.isJSONArray) return none; - api = __().text; - resultKeys = __().collections.EmptyDynamicArray(); + resultKeys = __().collections.EmptyArrayList(); items = referredObject.storage; for (i = 0; i < items.length; i += 1) { - resultKeys.AddItem(api.FromString(items[i].k)); + resultKeys.AddString(items[i].k); } return resultKeys; } @@ -604,7 +602,7 @@ public final function Database.DBQueryResult IncrementObject( local int index; local string itemKey; local DBRecord directContainer; - local AssociativeArray objectAsAssociativeArray; + local HashTable objectAsHashTable; local DBRecordPointer pointer; if (jsonPointer == none) { return DBR_InvalidPointer; @@ -612,11 +610,11 @@ public final function Database.DBQueryResult IncrementObject( if (jsonPointer.IsEmpty()) { // Special case - incrementing caller `DBRecord` itself - objectAsAssociativeArray = AssociativeArray(object); - if (objectAsAssociativeArray == none) { + objectAsHashTable = HashTable(object); + if (objectAsHashTable == none) { return DBR_InvalidData; } - FromCollection(objectAsAssociativeArray); + FromCollection(objectAsHashTable); return DBR_Success; } // All the work will be done by the separate `IncrementItem()` method; @@ -768,7 +766,7 @@ private final function bool IncrementItem( /** * Extracts JSON object or array data from caller `DBRecord` as either - * `AssociativeArray` (for JSON objects) or `DynamicArray` (for JSON arrays). + * `HashTable` (for JSON objects) or `ArrayList` (for JSON arrays). * * Type conversion rules in immutable case: * 1. 'null' -> `none`; @@ -776,8 +774,8 @@ private final function bool IncrementItem( * 3. 'number' -> either `IntBox` or `FloatBox`, depending on * what seems to fit better; * 4. 'string' -> `Text`; - * 5. 'array' -> `DynamicArray`; - * 6. 'object' -> `AssociativeArray`. + * 5. 'array' -> `ArrayList`; + * 6. 'object' -> `HashTable`. * * Type conversion rules in mutable case: * 1. 'null' -> `none`; @@ -785,13 +783,13 @@ private final function bool IncrementItem( * 3. 'number' -> either `IntRef` or `FloatRef`, depending on * what seems to fit better; * 4. 'string' -> `MutableText`; - * 5. 'array' -> `DynamicArray`; - * 6. 'object' -> `AssociativeArray`. + * 5. 'array' -> `ArrayList`; + * 6. 'object' -> `HashTable`. * * @param makeMutable `false` if you want this method to produce * immutable types and `true` otherwise. - * @return `AssociativeArray` if caller `DBRecord` represents a JSON object - * and `DynamicArray` if it represents JSON array. + * @return `HashTable` if caller `DBRecord` represents a JSON object + * and `ArrayList` if it represents JSON array. * Returned collection must have all of it's keys deallocated before being * discarded. * `none` iff caller `DBRecord` was not initialized as either. @@ -804,10 +802,10 @@ public final function Collection ToCollection(bool makeMutable) } lockToCollection = true; if (isJSONArray) { - result = ToDynamicArray(makeMutable); + result = ToArrayList(makeMutable); } else { - result = ToAssociativeArray(makeMutable); + result = ToHashTable(makeMutable); } lockToCollection = false; return result; @@ -815,28 +813,37 @@ public final function Collection ToCollection(bool makeMutable) // Does not do any validation check, assumes caller `DBRecord` // represents an array. -private final function Collection ToDynamicArray(bool makeMutable) +private final function Collection ToArrayList(bool makeMutable) { local int i; - local DynamicArray result; - result = __().collections.EmptyDynamicArray(); - for (i = 0; i < storage.length; i += 1) { - result.AddItem(ConvertItemToObject(storage[i], makeMutable)); + local ArrayList result; + local AcediaObject nextObject; + result = __().collections.EmptyArrayList(); + for (i = 0; i < storage.length; i += 1) + { + nextObject = ConvertItemToObject(storage[i], makeMutable); + result.AddItem(nextObject); + __().memory.Free(nextObject); } return result; } // Does not do any validation check, assumes caller `DBRecord` // represents an object. -private final function Collection ToAssociativeArray(bool makeMutable) +private final function Collection ToHashTable(bool makeMutable) { - local int i; - local AssociativeArray result; - result = __().collections.EmptyAssociativeArray(); + local int i; + local HashTable result; + local Text nextKey; + local AcediaObject nextObject; + result = __().collections.EmptyHashTable(); for (i = 0; i < storage.length; i += 1) { - result.SetItem( __().text.FromString(storage[i].k), - ConvertItemToObject(storage[i], makeMutable)); + nextKey = __().text.FromString(storage[i].k); + nextObject = ConvertItemToObject(storage[i], makeMutable); + result.SetItem(nextKey, nextObject); + __().memory.Free(nextKey); + __().memory.Free(nextObject); } return result; } @@ -874,11 +881,11 @@ public final function EmptySelf() * in case of the conflict. * * Can only convert items in passed collection that return `true` for - * `_.json.IsCompatible()` check. Any other values will be treated as `none`. + * `__().json.IsCompatible()` check. Any other values will be treated as `none`. * * Only works as long as caller `DBRecord` has the same container type as - * `source`. `isJSONArray` iff `source.class == class'DynamicArray` and - * `!isJSONArray` iff `source.class == class'AssociativeArray`. + * `source`. `isJSONArray` iff `source.class == class'ArrayList` and + * `!isJSONArray` iff `source.class == class'HashTable`. * * Values that cannot be converted into JSON will be replaced with `none`. * @@ -886,42 +893,47 @@ public final function EmptySelf() */ public final function FromCollection(Collection source) { - local DynamicArray asDynamicArray; - local AssociativeArray asAssociativeArray; - asDynamicArray = DynamicArray(source); - asAssociativeArray = AssociativeArray(source); - if (asDynamicArray != none && isJSONArray) { - FromDynamicArray(asDynamicArray); + local ArrayList asArrayList; + local HashTable asHashTable; + asArrayList = ArrayList(source); + asHashTable = HashTable(source); + if (asArrayList != none && isJSONArray) { + FromArrayList(asArrayList); } - if (asAssociativeArray != none && !isJSONArray) { - FromAssociativeArray(asAssociativeArray); + if (asHashTable != none && !isJSONArray) { + FromHashTable(asHashTable); } } // Does not do any validation check. -private final function FromDynamicArray(DynamicArray source) +private final function FromArrayList(ArrayList source) { - local int i, length; + local int i, length; + local AcediaObject nextObject; length = source.GetLength(); - for (i = 0; i < length; i += 1) { - storage[storage.length] = ConvertObjectToItem(source.GetItem(i)); + for (i = 0; i < length; i += 1) + { + nextObject = source.GetItem(i); + storage[storage.length] = ConvertObjectToItem(nextObject); + __().memory.Free(nextObject); } } // Does not do any validation check. -private final function FromAssociativeArray(AssociativeArray source) +private final function FromHashTable(HashTable source) { - local int i, originalStorageLength; - local Iter iter; - local string nextKey; - local bool isNewKey; + local int i, originalStorageLength; + local Iter iter; + local string nextKey; + local bool isNewKey; + local AcediaObject nextObject; originalStorageLength = storage.length; for (iter = source.Iterate(); !iter.HasFinished(); iter.Next()) { if (iter.GetKey() == none) { continue; } - nextKey = Text(iter.GetKey()).ToString(); + nextKey = __().text.ToString(BaseText(iter.GetKey())); isNewKey = true; for (i = 0; i < originalStorageLength; i += 1) { @@ -931,8 +943,11 @@ private final function FromAssociativeArray(AssociativeArray source) break; } } - if (isNewKey) { - SetItem(storage.length, ConvertObjectToItem(iter.Get()), nextKey); + if (isNewKey) + { + nextObject = iter.Get(); + SetItem(storage.length, ConvertObjectToItem(nextObject), nextKey); + __().memory.Free(nextObject); } } iter.FreeSelf(); @@ -952,7 +967,7 @@ private final function StorageItem ConvertObjectToItem(AcediaObject data) { result.t = DBAT_Reference; newDBRecord = NewRecordFor(package); - newDBRecord.isJSONArray = (data.class == class'DynamicArray'); + newDBRecord.isJSONArray = (data.class == class'ArrayList'); newDBRecord.FromCollection(Collection(data)); result.s = string(newDBRecord.name); } @@ -1063,11 +1078,11 @@ private final function bool IncrementItemByObject( { itemRecord = NewRecordFor(package); // DB was broken somehow item.s = string(itemRecord.name); - itemRecord.isJSONArray = (object.class == class'DynamicArray'); + itemRecord.isJSONArray = (object.class == class'ArrayList'); } - if ( (itemRecord.isJSONArray && object.class != class'DynamicArray') + if ( (itemRecord.isJSONArray && object.class != class'ArrayList') || ( !itemRecord.isJSONArray - && object.class != class'AssociativeArray')) + && object.class != class'HashTable')) { return false; } diff --git a/sources/Data/Database/Local/LocalDatabaseInstance.uc b/sources/Data/Database/Local/LocalDatabaseInstance.uc index 4cb2725..ec986b5 100644 --- a/sources/Data/Database/Local/LocalDatabaseInstance.uc +++ b/sources/Data/Database/Local/LocalDatabaseInstance.uc @@ -4,7 +4,7 @@ * This class SHOULD NOT be deallocated manually. * This name was chosen so that more readable `LocalDatabase` could be * used in config for defining local databases through per-object-config. - * Copyright 2021 Anton Tarasenko + * Copyright 2021-2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -223,7 +223,7 @@ public function DBWriteTask WriteData(JSONPointer pointer, AcediaObject data) // We can only write JSON array as the root value if (data != none && pointer.GetLength() <= 0) { - isDataStorable = (data.class == class'AssociativeArray'); + isDataStorable = (data.class == class'HashTable'); } else { isDataStorable = _.json.IsCompatible(data); @@ -294,7 +294,7 @@ public function DBSizeTask GetDataSize(JSONPointer pointer) public function DBKeysTask GetDataKeys(JSONPointer pointer) { - local DynamicArray keys; + local ArrayList keys; local DBKeysTask keysTask; keysTask = DBKeysTask(MakeNewTask(class'DBKeysTask')); if (!ValidatePointer(pointer, keysTask)) return keysTask; diff --git a/sources/Data/Database/Tasks/DBKeysTask.uc b/sources/Data/Database/Tasks/DBKeysTask.uc index 2c25057..f074609 100644 --- a/sources/Data/Database/Tasks/DBKeysTask.uc +++ b/sources/Data/Database/Tasks/DBKeysTask.uc @@ -1,6 +1,6 @@ /** * Variant of `DBTask` for `GetDataKeys()` query. - * Copyright 2021 Anton Tarasenko + * Copyright 2021-2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -19,11 +19,11 @@ */ class DBKeysTask extends DBTask; -var private DynamicArray queryKeysResponse; +var private ArrayList queryKeysResponse; delegate connect( Database.DBQueryResult result, - DynamicArray keys, + ArrayList keys, Database source) {} protected function Finalizer() @@ -33,7 +33,7 @@ protected function Finalizer() connect = none; } -public function SetDataKeys(DynamicArray keys) +public function SetDataKeys(/* take */ ArrayList keys) { queryKeysResponse = keys; } diff --git a/sources/Data/Database/Tests/TEST_LocalDatabase.uc b/sources/Data/Database/Tests/TEST_LocalDatabase.uc index c05ab5d..ecd6d04 100644 --- a/sources/Data/Database/Tests/TEST_LocalDatabase.uc +++ b/sources/Data/Database/Tests/TEST_LocalDatabase.uc @@ -1,6 +1,6 @@ /** * Set of tests for `DBRecord` class. - * Copyright 2020 Anton Tarasenko + * Copyright 2021-2022 Anton Tarasenko *------------------------------------------------------------------------------ * This file is part of Acedia. * @@ -22,10 +22,10 @@ class TEST_LocalDatabase extends TestCase // Results of callback are written here var protected int resultSize; -var protected DynamicArray resultKeys; +var protected ArrayList resultKeys; var protected Database.DBQueryResult resultType; var protected Database.DataType resultDataType; -var protected AssociativeArray resultData; +var protected HashTable resultData; var protected AcediaObject resultObject; protected function DBReadingHandler( @@ -35,12 +35,12 @@ protected function DBReadingHandler( { default.resultType = result; default.resultObject = data; - default.resultData = AssociativeArray(data); + default.resultData = HashTable(data); } protected function DBKeysHandler( Database.DBQueryResult result, - DynamicArray keys, + ArrayList keys, Database source) { default.resultType = result; @@ -112,11 +112,11 @@ contains it: local string source; local Parser parser; -local AssociativeArray root; +local HashTable root; local LocalDatabaseInstance db; source = GetJSONTemplateString(); parser = __().text.ParseString(source); -root = AssociativeArray(__().json.ParseWith(parser)); +root = HashTable(__().json.ParseWith(parser)); db = __().db.NewLocal(P("TEST_ReadOnly")); db.WriteData(__().json.Pointer(), root); */ @@ -253,11 +253,11 @@ protected static function SubTest_LoadingPreparedSuccessRoot( TEST_ExpectTrue(default.resultType == DBR_Success); TEST_ExpectTrue(default.resultData.GetLength() == 1); TEST_ExpectTrue(default.resultData - .GetAssociativeArrayBy(P("/web-app")).GetLength() == 3); + .GetHashTableBy(P("/web-app")).GetLength() == 3); TEST_ExpectTrue(default.resultData - .GetDynamicArrayBy(P("/web-app/servlet")).GetLength() == 5); + .GetArrayListBy(P("/web-app/servlet")).GetLength() == 5); TEST_ExpectTrue(default.resultData - .GetAssociativeArrayBy(P("/web-app/servlet/0/init-param")) + .GetHashTableBy(P("/web-app/servlet/0/init-param")) .GetLength() == 42); TEST_ExpectTrue(default.resultData .GetTextBy(P("/web-app/servlet/2/servlet-class")) @@ -536,18 +536,18 @@ protected static function Test_TaskChaining() __().db.DeleteLocal(P("TEST_DB")); } -protected static function AssociativeArray GetJSONSubTemplateObject() +protected static function HashTable GetJSONSubTemplateObject() { local Parser parser; parser = __().text.ParseString("{\"A\":\"simpleValue\",\"B\":11.12}"); - return AssociativeArray(__().json.ParseWith(parser)); + return HashTable(__().json.ParseWith(parser,, true)); } -protected static function DynamicArray GetJSONSubTemplateArray() +protected static function ArrayList GetJSONSubTemplateArray() { local Parser parser; parser = __().text.ParseString("[true, null, \"huh\"]"); - return DynamicArray(__().json.ParseWith(parser)); + return ArrayList(__().json.ParseWith(parser,, true)); } /* @@ -568,9 +568,9 @@ the database by using templates provided by `GetJSONSubTemplateObject()` and */ protected static function SubTest_WritingSuccess(LocalDatabaseInstance db) { - local DBWriteTask task; - local DynamicArray templateArray; - local AssociativeArray templateObject; + local DBWriteTask task; + local ArrayList templateArray; + local HashTable templateObject; templateObject = GetJSONSubTemplateObject(); templateArray = GetJSONSubTemplateArray(); Issue("`WriteData()` call that is supposed to succeed reports failure."); @@ -666,9 +666,9 @@ protected static function SubTest_WritingDataCheck_Mutable( protected static function SubTest_WritingFailure(LocalDatabaseInstance db) { - local DBWriteTask task; - local DynamicArray templateArray; - local AssociativeArray templateObject; + local DBWriteTask task; + local ArrayList templateArray; + local HashTable templateObject; templateObject = GetJSONSubTemplateObject(); templateArray = GetJSONSubTemplateArray(); Issue("`WriteData()` does not report error when attempting writing data at" @@ -712,10 +712,10 @@ protected static function SubTest_WritingIntoSimpleValues( protected static function SubTest_WritingArrayIndicies(LocalDatabaseInstance db) { - local DBWriteTask writeTask; - local DynamicArray resultArray; - local DynamicArray templateArray; - local AssociativeArray templateObject; + local DBWriteTask writeTask; + local ArrayList resultArray; + local ArrayList templateArray; + local HashTable templateObject; templateObject = GetJSONSubTemplateObject(); templateArray = GetJSONSubTemplateArray(); db.WriteData(__().json.Pointer(P("")), templateObject); @@ -731,7 +731,7 @@ protected static function SubTest_WritingArrayIndicies(LocalDatabaseInstance db) Issue("Database cannot extend stored JSON array's length by assigning to" @ "the out-of-bounds index or \"-\"."); ReadFromDB(db, "/A"); - resultArray = DynamicArray(default.resultObject); + resultArray = ArrayList(default.resultObject); TEST_ExpectTrue(resultArray.GetLength() == 102); TEST_ExpectNone(resultArray.GetItem(99)); TEST_ExpectTrue(resultArray.GetInt(100) == -342); @@ -741,9 +741,9 @@ protected static function SubTest_WritingArrayIndicies(LocalDatabaseInstance db) protected static function SubTest_TaskChaining(LocalDatabaseInstance db) { - local DBWriteTask writeTask; - local DynamicArray templateArray; - local AssociativeArray templateObject; + local DBWriteTask writeTask; + local ArrayList templateArray; + local HashTable templateObject; templateObject = GetJSONSubTemplateObject(); templateArray = GetJSONSubTemplateArray(); db.WriteData(__().json.Pointer(P("")), templateObject); @@ -759,16 +759,16 @@ protected static function SubTest_TaskChaining(LocalDatabaseInstance db) TEST_ExpectTrue(Text(default.resultObject).ToString() == "huh"); ReadFromDB(db, "/B/2"); TEST_ExpectTrue(default.resultType == DBR_Success); - TEST_ExpectTrue(default.resultObject.class == class'DynamicArray'); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetLength() == 3); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetBool(0) ); + TEST_ExpectTrue(default.resultObject.class == class'ArrayList'); + TEST_ExpectTrue(ArrayList(default.resultObject).GetLength() == 3); + TEST_ExpectTrue(ArrayList(default.resultObject).GetBool(0) ); } protected static function Test_Removal() { local LocalDatabaseInstance db; - local DynamicArray templateArray; - local AssociativeArray templateObject; + local ArrayList templateArray; + local HashTable templateObject; templateObject = GetJSONSubTemplateObject(); templateArray = GetJSONSubTemplateArray(); db = __().db.NewLocal(P("TEST_DB")); @@ -828,9 +828,9 @@ protected static function SubTest_RemovalCheckValuesAfter( TEST_ExpectTrue(default.resultData.GetLength() == 1); TEST_ExpectTrue(default.resultData.HasKey(P("A"))); TEST_ExpectTrue( - default.resultData.GetDynamicArray(P("A")).GetLength() == 2); - TEST_ExpectTrue(default.resultData.GetDynamicArray(P("A")).GetBool(0)); - TEST_ExpectTrue(default.resultData.GetDynamicArray(P("A")) + default.resultData.GetArrayList(P("A")).GetLength() == 2); + TEST_ExpectTrue(default.resultData.GetArrayList(P("A")).GetBool(0)); + TEST_ExpectTrue(default.resultData.GetArrayList(P("A")) .GetText(1).ToString() == "huh"); } @@ -852,8 +852,8 @@ protected static function SubTest_RemovalRoot(LocalDatabaseInstance db) protected static function Test_Increment() { local LocalDatabaseInstance db; - local DynamicArray templateArray; - local AssociativeArray templateObject; + local ArrayList templateArray; + local HashTable templateObject; templateObject = GetJSONSubTemplateObject(); templateArray = GetJSONSubTemplateArray(); db = __().db.NewLocal(P("TEST_DB")); @@ -911,8 +911,8 @@ protected static function SubTest_IncrementNull(LocalDatabaseInstance db) task.TryCompleting(); TEST_ExpectTrue(default.resultType == DBR_Success); ReadFromDB(db, "/B/A/1/"); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetLength() == 3); - TEST_ExpectNone(DynamicArray(default.resultObject).GetItem(1)); + TEST_ExpectTrue(ArrayList(default.resultObject).GetLength() == 3); + TEST_ExpectNone(ArrayList(default.resultObject).GetItem(1)); task = db.IncrementData( __().json.Pointer(P("/B/A/1//1")), GetJSONSubTemplateArray()); task.connect = DBIncrementHandler; @@ -924,10 +924,10 @@ protected static function SubTest_IncrementNull(LocalDatabaseInstance db) task.TryCompleting(); TEST_ExpectTrue(default.resultType == DBR_Success); ReadFromDB(db, "/B/A/1/"); - TEST_ExpectTrue(default.resultObject.class == class'DynamicArray'); - TEST_ExpectNotNone(DynamicArray(default.resultObject).GetDynamicArray(1)); + TEST_ExpectTrue(default.resultObject.class == class'ArrayList'); + TEST_ExpectNotNone(ArrayList(default.resultObject).GetArrayList(1)); TEST_ExpectTrue( - DynamicArray(default.resultObject).GetDynamicArray(1).GetInt(1) == 2); + ArrayList(default.resultObject).GetArrayList(1).GetInt(1) == 2); } protected static function SubTest_IncrementBool(LocalDatabaseInstance db) @@ -1009,10 +1009,10 @@ protected static function SubTest_IncrementString(LocalDatabaseInstance db) Text(default.resultObject).ToString() == "simpleValue!?"); } -protected static function AssociativeArray GetHelperObject() +protected static function HashTable GetHelperObject() { - local AssociativeArray result; - result = __().collections.EmptyAssociativeArray(); + local HashTable result; + result = __().collections.EmptyHashTable(); result.SetItem(P("A"), __().text.FromString("complexString")); result.SetItem(P("E"), __().text.FromString("str")); result.SetItem(P("F"), __().ref.float(45)); @@ -1024,7 +1024,7 @@ protected static function SubTest_IncrementObject(LocalDatabaseInstance db) local DBIncrementTask task; Issue("JSON objects are not incremented properly."); task = db.IncrementData(__().json.Pointer(P("")), - __().collections.EmptyAssociativeArray()); + __().collections.EmptyHashTable()); task.connect = DBIncrementHandler; task.TryCompleting(); TEST_ExpectTrue(default.resultType == DBR_Success); @@ -1046,16 +1046,16 @@ protected static function SubTest_IncrementObject(LocalDatabaseInstance db) default.resultData.GetText(P("E")).ToString() == "str"); TEST_ExpectTrue(default.resultData.GetFloat(P("F")) == 45); TEST_ExpectTrue( - default.resultData.GetItem(P("B")).class == class'AssociativeArray'); + default.resultData.GetItem(P("B")).class == class'HashTable'); Issue("Incrementing JSON objects can overwrite existing data."); TEST_ExpectTrue( default.resultData.GetText(P("A")).ToString() == "simpleValue!?"); } -protected static function DynamicArray GetHelperArray() +protected static function ArrayList GetHelperArray() { - local DynamicArray result; - result = __().collections.EmptyDynamicArray(); + local ArrayList result; + result = __().collections.EmptyArrayList(); result.AddItem(__().text.FromString("complexString")); result.AddItem(__().ref.float(45)); result.AddItem(none); @@ -1068,45 +1068,45 @@ protected static function SubTest_IncrementArray(LocalDatabaseInstance db) local DBIncrementTask task; Issue("JSON arrays are not incremented properly."); task = db.IncrementData(__().json.Pointer(P("/B/A")), - __().collections.EmptyDynamicArray()); + __().collections.EmptyArrayList()); task.connect = DBIncrementHandler; task.TryCompleting(); TEST_ExpectTrue(default.resultType == DBR_Success); ReadFromDB(db, "/B/A"); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetLength() == 3); + TEST_ExpectTrue(ArrayList(default.resultObject).GetLength() == 3); TEST_ExpectTrue( - DynamicArray(default.resultObject).GetText(2).ToString() == "huh"); + ArrayList(default.resultObject).GetText(2).ToString() == "huh"); task = db.IncrementData(__().json.Pointer(P("/B/A")), GetHelperArray()); task.connect = DBIncrementHandler; task.TryCompleting(); TEST_ExpectTrue(default.resultType == DBR_Success); ReadFromDB(db, "/B/A"); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetLength() == 7); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetBool(0)); + TEST_ExpectTrue(ArrayList(default.resultObject).GetLength() == 7); + TEST_ExpectTrue(ArrayList(default.resultObject).GetBool(0)); TEST_ExpectNotNone( - DynamicArray(default.resultObject).GetAssociativeArray(1)); + ArrayList(default.resultObject).GetHashTable(1)); TEST_ExpectTrue( - DynamicArray(default.resultObject).GetText(2).ToString() == "huh"); + ArrayList(default.resultObject).GetText(2).ToString() == "huh"); TEST_ExpectTrue( - DynamicArray(default.resultObject).GetText(3).ToString() + ArrayList(default.resultObject).GetText(3).ToString() == "complexString"); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetFloat(4) == 45); - TEST_ExpectNone(DynamicArray(default.resultObject).GetItem(5)); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetBool(6)); + TEST_ExpectTrue(ArrayList(default.resultObject).GetFloat(4) == 45); + TEST_ExpectNone(ArrayList(default.resultObject).GetItem(5)); + TEST_ExpectTrue(ArrayList(default.resultObject).GetBool(6)); } -protected static function CheckValuesAfterIncrement(AssociativeArray root) +protected static function CheckValuesAfterIncrement(HashTable root) { - local DynamicArray jsonArray; + local ArrayList jsonArray; TEST_ExpectTrue(root.GetBoolBy(P("/D"))); TEST_ExpectTrue(root.GetFloatBy(P("/B/B")) == 10.12); TEST_ExpectTrue( root.GetTextBy(P("/A")).ToString() == "simpleValue!?"); - jsonArray = root.GetDynamicArrayBy(P("/B/A")); + jsonArray = root.GetArrayListBy(P("/B/A")); TEST_ExpectTrue(jsonArray.GetBool(0)); - TEST_ExpectNotNone(jsonArray.GetAssociativeArray(1)); + TEST_ExpectNotNone(jsonArray.GetHashTable(1)); TEST_ExpectTrue(jsonArray.GetText(2).ToString() == "huh"); TEST_ExpectTrue(jsonArray.GetText(3).ToString() == "complexString"); TEST_ExpectTrue(jsonArray.GetFloat(4) == 45); @@ -1115,7 +1115,7 @@ protected static function CheckValuesAfterIncrement(AssociativeArray root) // Test root itself TEST_ExpectTrue(root.GetLength() == 6); TEST_ExpectTrue(root.GetText(P("A")).ToString() == "simpleValue!?"); - TEST_ExpectTrue(root.GetItem(P("B")).class == class'AssociativeArray'); + TEST_ExpectTrue(root.GetItem(P("B")).class == class'HashTable'); TEST_ExpectTrue(root.GetFloat(P("C")) == 5.5); TEST_ExpectTrue(root.GetBool(P("D"))); TEST_ExpectTrue(root.GetText(P("E")).ToString() == "str"); @@ -1142,8 +1142,8 @@ protected static function IncrementExpectingFail( protected static function SubTest_IncrementRewriteBool( LocalDatabaseInstance db, - DynamicArray templateArray, - AssociativeArray templateObject) + ArrayList templateArray, + HashTable templateObject) { Issue("JSON boolean values are rewritten by non-boolean values."); IncrementExpectingFail(db, "/D", none); @@ -1159,8 +1159,8 @@ protected static function SubTest_IncrementRewriteBool( protected static function SubTest_IncrementRewriteNumeric( LocalDatabaseInstance db, - DynamicArray templateArray, - AssociativeArray templateObject) + ArrayList templateArray, + HashTable templateObject) { Issue("JSON numeric values are rewritten by non-numeric values."); IncrementExpectingFail(db, "/B/B", none); @@ -1175,8 +1175,8 @@ protected static function SubTest_IncrementRewriteNumeric( protected static function SubTest_IncrementRewriteString( LocalDatabaseInstance db, - DynamicArray templateArray, - AssociativeArray templateObject) + ArrayList templateArray, + HashTable templateObject) { Issue("JSON string values are rewritten by non-`Text`/`MutableText`" @ "values."); @@ -1193,10 +1193,10 @@ protected static function SubTest_IncrementRewriteString( protected static function SubTest_IncrementRewriteObject( LocalDatabaseInstance db, - DynamicArray templateArray, - AssociativeArray templateObject) + ArrayList templateArray, + HashTable templateObject) { - Issue("JSON objects are rewritten by non-`AssociativeArray` values."); + Issue("JSON objects are rewritten by non-`HashTable` values."); IncrementExpectingFail(db, "", none); IncrementExpectingFail(db, "", db); IncrementExpectingFail(db, "", __().box.bool(true)); @@ -1210,10 +1210,10 @@ protected static function SubTest_IncrementRewriteObject( protected static function SubTest_IncrementRewriteArray( LocalDatabaseInstance db, - DynamicArray templateArray, - AssociativeArray templateObject) + ArrayList templateArray, + HashTable templateObject) { - Issue("JSON arrays are rewritten by non-`DynamicArray` values."); + Issue("JSON arrays are rewritten by non-`ArrayList` values."); IncrementExpectingFail(db, "/B/A", none); IncrementExpectingFail(db, "/B/A", db); IncrementExpectingFail(db, "/B/A", __().box.bool(true)); @@ -1243,8 +1243,8 @@ protected static function SubTest_IncrementMissing(LocalDatabaseInstance db) db.CheckDataType(__().json.Pointer(P("/L"))).connect = DBCheckHandler; ReadFromDB(db, "/B/A/1/"); TEST_ExpectTrue(default.resultDataType == JSON_Number); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetLength() == 12); - TEST_ExpectTrue(DynamicArray(default.resultObject).GetInt(11) == 85); + TEST_ExpectTrue(ArrayList(default.resultObject).GetLength() == 12); + TEST_ExpectTrue(ArrayList(default.resultObject).GetInt(11) == 85); } defaultproperties