bool DocumentAccessor::isObject () const { if (_current != nullptr) { return TRI_IsObjectJson(_current); } // ok, must be a document/edge return true; }
uint64_t TRI_HashJsonByAttributes (TRI_json_t const* json, char const *attributes[], int nrAttributes, bool docComplete, int* error) { if (error != nullptr) { *error = TRI_ERROR_NO_ERROR; } uint64_t hash = TRI_FnvHashBlockInitial(); if (TRI_IsObjectJson(json)) { for (int i = 0; i < nrAttributes; i++) { TRI_json_t const* subjson = TRI_LookupObjectJson(json, attributes[i]); if (subjson == nullptr && ! docComplete && error != nullptr) { *error = TRI_ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN; } hash = HashJsonRecursive(hash, subjson); } } return hash; }
KeyGenerator::GeneratorType KeyGenerator::generatorType (TRI_json_t const* parameters) { if (! TRI_IsObjectJson(parameters)) { return KeyGenerator::TYPE_TRADITIONAL; } TRI_json_t const* type = TRI_LookupObjectJson(parameters, "type"); if (! TRI_IsStringJson(type)) { return KeyGenerator::TYPE_TRADITIONAL; } char const* typeName = type->_value._string.data; if (TRI_CaseEqualString(typeName, TraditionalKeyGenerator::name().c_str())) { return KeyGenerator::TYPE_TRADITIONAL; } if (TRI_CaseEqualString(typeName, AutoIncrementKeyGenerator::name().c_str())) { return KeyGenerator::TYPE_AUTOINCREMENT; } // error return KeyGenerator::TYPE_UNKNOWN; }
KeyGenerator* KeyGenerator::factory (TRI_json_t const* options) { KeyGenerator::GeneratorType type; bool const readOptions = TRI_IsObjectJson(options); if (readOptions) { type = generatorType(options); } else { type = TYPE_TRADITIONAL; } if (type == TYPE_UNKNOWN) { return nullptr; } bool allowUserKeys = true; if (readOptions) { TRI_json_t* option = TRI_LookupObjectJson(options, "allowUserKeys"); if (TRI_IsBooleanJson(option)) { allowUserKeys = option->_value._boolean; } } if (type == TYPE_TRADITIONAL) { return new TraditionalKeyGenerator(allowUserKeys); } else if (type == TYPE_AUTOINCREMENT) { uint64_t offset = 0; uint64_t increment = 1; if (readOptions) { TRI_json_t* option; option = TRI_LookupObjectJson(options, "increment"); if (TRI_IsNumberJson(option)) { if (option->_value._number <= 0.0) { // negative or 0 offset is not allowed return nullptr; } increment = static_cast<uint64_t>(option->_value._number); if (increment == 0 || increment >= (1ULL << 16)) { return nullptr; } } option = TRI_LookupObjectJson(options, "offset"); if (TRI_IsNumberJson(option)) { if (option->_value._number < 0.0) { return nullptr; } offset = static_cast<uint64_t>(option->_value._number); if (offset >= UINT64_MAX) { return nullptr; } } } return new AutoIncrementKeyGenerator(allowUserKeys, offset, increment); } return nullptr; }