diff --git a/object_store.cpp b/object_store.cpp index 1d18fd2a..4bd9232b 100644 --- a/object_store.cpp +++ b/object_store.cpp @@ -164,6 +164,7 @@ std::vector ObjectStore::verify_object_schema(G ObjectSchema table_schema(group, target_schema.name); // check to see if properties are the same + Property *primary = nullptr; for (auto& current_prop : table_schema.properties) { auto target_prop = target_schema.property_for_name(current_prop.name); @@ -175,9 +176,38 @@ std::vector ObjectStore::verify_object_schema(G exceptions.emplace_back(MismatchedPropertiesException(table_schema.name, current_prop, *target_prop)); continue; } + + // check object_type existence if (current_prop.object_type.length() && schema.find(current_prop.object_type) == schema.end()) { exceptions.emplace_back(InvalidPropertyException(table_schema.name, current_prop, - "Target type '" + current_prop.object_type + "' doesn't exist for property '" + current_prop.name + "',")); + "Target type '" + current_prop.object_type + "' doesn't exist for property '" + current_prop.name + "'.")); + } + + // check nullablity + if (current_prop.is_nullable) { + if (current_prop.type != PropertyTypeObject) { + exceptions.emplace_back(InvalidPropertyException(table_schema.name, current_prop, + "Only 'Object' property types are nullable")); + } + } + else if (current_prop.type == PropertyTypeObject) { + exceptions.emplace_back(InvalidPropertyException(table_schema.name, current_prop, + "'Object' property '" + current_prop.name + "' must be nullable.")); + } + + // check primary keys + if (current_prop.is_primary) { + if (primary) { + exceptions.emplace_back(InvalidPropertyException(table_schema.name, current_prop, "Duplicate primary keys.")); + } + primary = ¤t_prop; + } + + // check indexable + if (current_prop.is_indexed) { + if (current_prop.type != PropertyTypeString && current_prop.type != PropertyTypeInt) { + exceptions.emplace_back(PropertyTypeNotIndexableException(table_schema.name, current_prop)); + } } // create new property with aligned column @@ -447,19 +477,19 @@ SchemaValidationException::SchemaValidationException(std::vector errors); - private: + std::vector &validation_errors() { return m_validation_errors; } + private: std::vector m_validation_errors; }; class ObjectSchemaValidationException : public ObjectStoreException { - public: + public: ObjectSchemaValidationException(std::string object_type) : m_object_type(object_type) {} ObjectSchemaValidationException(std::string object_type, std::string message) : m_object_type(object_type) { m_what = message; } - protected: + std::string object_type() { return m_object_type; } + protected: std::string m_object_type; }; - class PropertyTypeNotIndexableException : public ObjectSchemaValidationException { - public: + class ObjectSchemaPropertyException : public ObjectSchemaValidationException { + public: + ObjectSchemaPropertyException(std::string object_type, Property &property) : + ObjectSchemaValidationException(object_type), m_property(property) {} + Property &property() { return m_property; } + private: + Property m_property; + }; + + class PropertyTypeNotIndexableException : public ObjectSchemaPropertyException { + public: PropertyTypeNotIndexableException(std::string object_type, Property &property); - private: - Property m_property; }; - class ExtraPropertyException : public ObjectSchemaValidationException { - public: + class ExtraPropertyException : public ObjectSchemaPropertyException { + public: ExtraPropertyException(std::string object_type, Property &property); - private: - Property m_property; }; - class MissingPropertyException : public ObjectSchemaValidationException { - public: + class MissingPropertyException : public ObjectSchemaPropertyException { + public: MissingPropertyException(std::string object_type, Property &property); - private: - Property m_property; + }; + + class InvalidPropertyException : public ObjectSchemaPropertyException { + public: + InvalidPropertyException(std::string object_type, Property &property, std::string message) : + ObjectSchemaPropertyException(object_type, property) { m_what = message; } }; class MismatchedPropertiesException : public ObjectSchemaValidationException { - public: + public: MismatchedPropertiesException(std::string object_type, Property &old_property, Property &new_property); - private: + Property &old_property() { return m_old_property; } + Property &new_property() { return m_new_property; } + private: Property m_old_property, m_new_property; }; class ChangedPrimaryKeyException : public ObjectSchemaValidationException { - public: + public: ChangedPrimaryKeyException(std::string object_type, std::string old_primary, std::string new_primary); - private: + std::string old_primary() { return m_old_primary; } + std::string new_primary() { return m_new_primary; } + private: std::string m_old_primary, m_new_primary; }; class InvalidPrimaryKeyException : public ObjectSchemaValidationException { - public: - InvalidPrimaryKeyException(std::string object_type, std::string primary); - private: - std::string m_primary; - }; - - class InvalidPropertyException : public ObjectSchemaValidationException { - public: - InvalidPropertyException(std::string object_type, Property &property, std::string message) : - ObjectSchemaValidationException(object_type), m_property(property) { m_what = message; } - private: - Property m_property; + public: + InvalidPrimaryKeyException(std::string object_type, std::string primary_key); + std::string primary_key() { return m_primary_key; } + private: + std::string m_primary_key; }; }