From 0be053a772822efd9f6cd9d2fc40d9dd89051a1c Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Fri, 13 Aug 2021 18:10:57 +0200 Subject: [PATCH] DRAFT: Add a lot of setters, getters, and helper functions --- src/CaosDB.jl | 2 + src/Connection.jl | 6 + src/Entity.jl | 1137 +++++++++++++++++++++++++++++++++++++++++++- src/Transaction.jl | 2 + test/runtests.jl | 19 +- 5 files changed, 1154 insertions(+), 12 deletions(-) diff --git a/src/CaosDB.jl b/src/CaosDB.jl index 8f71694..cf2cc35 100644 --- a/src/CaosDB.jl +++ b/src/CaosDB.jl @@ -173,9 +173,11 @@ authenticator object from a configuration. """ mutable struct _Authenticator wrapped_authenticator::Ptr{Cvoid} + _deletable::Bool function _Authenticator(managed_by_julia::Bool = false) auth = new() + auth._deletable = false if managed_by_julia # Only append a finalizer for this if the object is # actually managed by Julia and not created and destroyed diff --git a/src/Connection.jl b/src/Connection.jl index 0f8e140..dfe1aa3 100644 --- a/src/Connection.jl +++ b/src/Connection.jl @@ -34,9 +34,11 @@ to create an connection object from a configuration. """ mutable struct _Connection wrapped_connection::Ptr{Cvoid} + _deletable::Bool function _Connection(managed_by_julia::Bool = false) conn = new() + conn._deletable = false if managed_by_julia # Only append a finalizer for this if the object is # actually managed by Julia and not created and destroyed @@ -63,9 +65,11 @@ an certificate-provider object from a configuration. """ mutable struct _CertificateProvider wrapped_certificate_provider::Ptr{Cvoid} + _deletable::Bool function _CertificateProvider(managed_by_julia::Bool = false) prov = new() + prov._deletable = false if managed_by_julia # Only append a finalizer for this if the object is # actually managed by Julia and not created and destroyed @@ -92,9 +96,11 @@ an connection-configuration object from a configuration. """ mutable struct _Configuration wrapped_connection_configuration::Ptr{Cvoid} + _deletable::Bool function _Configuration(managed_by_julia::Bool = false) config = new() + config._deletable(false) if managed_by_julia # Only append a finalizer for this if the object is # actually managed by Julia and not created and destroyed diff --git a/src/Entity.jl b/src/Entity.jl index 8c9d443..c1a2593 100644 --- a/src/Entity.jl +++ b/src/Entity.jl @@ -22,12 +22,49 @@ # module Entity +# Creators export create_entity, create_parent, create_property, create_property_entity, create_record, create_recordtype -export get_id, get_role, get_name - -export set_id, set_role, set_name +# getters +export get_id, + get_role, + get_name, + get_description, + get_datatype, + get_unit, + get_value, + get_version_id, + get_property, + get_properties, + get_parent, + get_parents, + get_error, + get_errors, + get_warning, + get_warnings, + get_info, + get_infos, + get_importance, + get_code + +# setters +export append_parent, + append_parents, + append_property, + append_properties, + remove_parent, + remove_property, + set_id, + set_role, + set_name, + set_description, + set_datatype, + set_unit, + set_value + +# helper functions +export has_errors, has_warnings using CaosDB @@ -38,10 +75,12 @@ create an entity. """ mutable struct _Entity wrapped_entity::Ptr{Cvoid} + _deletable::Bool function _Entity(managed_by_julia::Bool = false) entity = new() + entity._deletable = false if managed_by_julia function f(t) @@ -67,10 +106,12 @@ create an parent. """ mutable struct _Parent wrapped_parent::Ptr{Cvoid} + _deletable::Bool function _Parent(managed_by_julia::Bool = false) parent = new() + parent._deletable = false if managed_by_julia function f(t) @@ -96,10 +137,12 @@ create an property. """ mutable struct _Property wrapped_property::Ptr{Cvoid} + _deletable::Bool function _Property(managed_by_julia::Bool = false) property = new() + property._deletable = false if managed_by_julia function f(t) @@ -117,6 +160,21 @@ mutable struct _Property end end +""" +Struct containing a pointer to the wrapped cpp messsage object. Meant +for internal use only; don't create it by yourself. +""" +mutable struct _Message + wrapped_message::Ptr{Cvoid} + _deletable::Bool + + function _Message() + mess = new() + mess._deletable = false + return mess + end +end + """ function create_entity(name::AbstractString = "") @@ -274,7 +332,8 @@ function create_parent(; name::AbstractString = "", id::AbstractString = "") err_code = ccall( (:caosdb_entity_create_parent, CaosDB.library_name), Cint, - (Ref{_Parent},)parent, + (Ref{_Parent},), + parent, ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -290,4 +349,1074 @@ function create_parent(; name::AbstractString = "", id::AbstractString = "") return parent end +""" + function get_id(entity::Ref{_Entity}) + +Return the id of the given `entity` +""" +function get_id(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_id, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_id(entity::Ref{_Parent}) + +Return the id of the given `parent` +""" +function get_id(parent::Ref{_Parent}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_parent_get_id, CaosDB.library_name), + Cint, + (Ref{_Parent}, Ptr{UInt8}), + parent, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_id(entity::Ref{_Property}) + +Return the id of the given `property` +""" +function get_id(property::Ref{_Property}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_property_get_id, CaosDB.library_name), + Cint, + (Ref{_Property}, Ptr{UInt8}), + property, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_role(entity::Ref{_Entity}) + +Return the role of the given `entity`. +""" +function get_role(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_role, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_name(entity::Ref{_Entity}) + +Return the name of the given `entity` +""" +function get_name(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_name, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_name(entity::Ref{_Parent}) + +Return the name of the given `parent` +""" +function get_name(parent::Ref{_Parent}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_parent_get_name, CaosDB.library_name), + Cint, + (Ref{_Parent}, Ptr{UInt8}), + parent, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_name(entity::Ref{_Property}) + +Return the name of the given `property` +""" +function get_name(property::Ref{_Property}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_property_get_name, CaosDB.library_name), + Cint, + (Ref{_Property}, Ptr{UInt8}), + property, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_description(entity::Ref{_Entity}) + +Return the description of the given `entity` +""" +function get_description(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_description, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_description(entity::Ref{_Parent}) + +Return the description of the given `parent` +""" +function get_description(parent::Ref{_Parent}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_parent_get_description, CaosDB.library_name), + Cint, + (Ref{_Parent}, Ptr{UInt8}), + parent, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_description(entity::Ref{_Property}) + +Return the description of the given `property` +""" +function get_description(property::Ref{_Property}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_property_get_description, CaosDB.library_name), + Cint, + (Ref{_Property}, Ptr{UInt8}), + property, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_description(entity::Ref{_Message}) + +Return the description of the given `message` +""" +function get_description(message::Ref{_Message}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_message_get_description, CaosDB.library_name), + Cint, + (Ref{_Message}, Ptr{UInt8}), + message, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_datatype(entity::Ref{_Entity}) + +Return the datatype of the given `entity` +""" +function get_datatype(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_datatype, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_datatype(entity::Ref{_Property}) + +Return the datatype of the given `property` +""" +function get_datatype(property::Ref{_Property}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_property_get_datatype, CaosDB.library_name), + Cint, + (Ref{_Property}, Ptr{UInt8}), + property, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_unit(entity::Ref{_Entity}) + +Return the unit of the given `entity` +""" +function get_unit(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_unit, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_unit(entity::Ref{_Property}) + +Return the unit of the given `property` +""" +function get_unit(property::Ref{_Property}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_property_get_unit, CaosDB.library_name), + Cint, + (Ref{_Property}, Ptr{UInt8}), + property, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_value(entity::Ref{_Entity}) + +Return the value of the given `entity` +""" +function get_value(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_value, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_value(entity::Ref{_Property}) + +Return the value of the given `property` +""" +function get_value(property::Ref{_Property}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_property_get_value, CaosDB.library_name), + Cint, + (Ref{_Property}, Ptr{UInt8}), + property, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_version_id(entity::Ref{_Entity}) + +Return the version_id of the given `entity` +""" +function get_version_id(entity::Ref{_Entity}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_entity_get_version_id, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + entity, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_code(message::Ref{_Message}) + +Return the code of the given `message`. +""" +function get_code(message::Ref{_Message}) + + code = Ref{Cint}(0) + + err_code = ccall( + (:caosdb_entity_message_get_code, CaosDB.library_name), + Cint, + (Ref{_Message}, Ref{Cint}), + message, + code, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return code + +end + +""" + function get_importance(property::Ref{_Property}) + +Return the importance of the given `property` +""" +function get_importance(property::Ref{_Property}) + + out = Vector{UInt8}(undef, 256) + + err_code = ccall( + (:caosdb_entity_property_get_importance, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ptr{UInt8}), + property, + out, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return GC.@preserve out unsafe_string(pointer(out)) +end + +""" + function get_error(entity::Ref{_Entity}, index::Cint) + +Return the error message of the given `entity` with the provided +`index`. +""" +function get_error(entity::Ref{_Entity}, index::Cint) + + error = Ref{_Message}(_Message()) + + err_code = ccall( + (:caosdb_entity_entity_get_error, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cint), + entity, + index - 1, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + message_text = get_description(error) + + code = get_code(error) + + return CaosDB.Exceptions.CaosDBMessage(message_text, code) +end + +""" + function get_warning(entity::Ref{_Entity}, index::Cint) + +Return the warning message of the given `entity` with the provided +`index`. +""" +function get_warning(entity::Ref{_Entity}, index::Cint) + + warning = Ref{_Message}(_Message()) + + err_code = ccall( + (:caosdb_entity_entity_get_warning, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cint), + entity, + index - 1, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + message_text = get_description(warning) + + code = get_code(warning) + + return CaosDB.Exceptions.CaosDBMessage(message_text, code) +end + + +""" + function get_info(entity::Ref{_Entity}, index::Cint) + +Return the info message of the given `entity` with the provided +`index`. +""" +function get_info(entity::Ref{_Entity}, index::Cint) + + info = Ref{_Message}(_Message()) + + err_code = ccall( + (:caosdb_entity_entity_get_info, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cint), + entity, + index - 1, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + message_text = get_description(info) + + code = get_code(info) + + return CaosDB.Exceptions.CaosDBMessage(message_text, code) +end + +""" + function get_errors(entity::Ref{_Entity}) + +Return a Vector of all error messages attached to the given `entity`. +""" +function get_errors(entity::Ref{_Entity}) + + size = Ref{Cint}(0) + + err_code = ccall( + (:caosdb_entity_entity_get_errors_size, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + size, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + errors = [get_error(entity, Cint(ii)) for ii = 1:size[]] + + return errors +end + +""" + function get_warnings(entity::Ref{_Entity}) + +Return a Vector of all warning messages attached to the given `entity`. +""" +function get_warnings(entity::Ref{_Entity}) + + size = Ref{Cint}(0) + + err_code = ccall( + (:caosdb_entity_entity_get_warnings_size, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + size, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + warnings = [get_warning(entity, Cint(ii)) for ii = 1:size[]] + + return warnings +end + + +""" + function get_warnings(entity::Ref{_Entity}) + +Return a Vector of all info messages attached to the given `entity`. +""" +function get_infos(entity::Ref{_Entity}) + + size = Ref{Cint}(0) + + err_code = ccall( + (:caosdb_entity_entity_get_infos_size, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + size, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + infos = [get_info(entity, Cint(ii)) for ii = 1:size[]] + + return infos +end + +""" + function get_parent(entity::Ref{_Entity}, index::Cint) + +Return the parent of the given `entity` at position `index`. +""" +function get_parent(entity::Ref{_Entity}, index::Cint) + + parent = Ref{_Parent}(_Parent()) + + err_code = ccall( + (:caosdb_entity_entity_get_parent, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + index - 1, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return parent +end + +""" + function get_parents(entity::Ref{_Entity}) + +Return the vector of all parents of the given `entity`. +""" +function get_parents(entity::Ref{_Entity}) + + size = Ref{Cint}(0) + + err_code = ccall( + (:caosdb_entity_entity_get_parents_size, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + size, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + parents = [get_parent(entity, Cint(ii)) for ii = 1:size[]] + + return parents +end + +""" + function get_property(entity::Ref{_Entity}, index::Cint) + +Return the property of the given `entity` at position `index`. +""" +function get_property(entity::Ref{_Entity}, index::Cint) + + property = Ref{_Property}(_Property()) + + err_code = ccall( + (:caosdb_entity_entity_get_property, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + index - 1, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return property +end + +""" + function get_properties(entity::Ref{_Entity}) + +Return the vector of all properties of the given `entity`. +""" +function get_properties(entity::Ref{_Entity}) + + size = Ref{Cint}(0) + + err_code = ccall( + (:caosdb_entity_entity_get_properties_size, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{Cint}), + entity, + size, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + properties = [get_property(entity, Cint(ii)) for ii = 1:size[]] + + return properties +end + +""" + function set_id(entity::Ref{_Entity}, id::AbstractString) + +Throws a `CaosDB.Exceptions.ClientException` since you are not allowed +to set the id of entities. +""" +function set_id(entity::Ref{_Entity}, id::AbstractString) + throw( + CaosDB.Exceptions.ClientException( + "You cannot set the id of an entity object. +If you want to update an entity with this id, you have to retrieve it first.", + ), + ) +end + +""" + function set_id(parent::Ref{_Parent}, id::AbstractString) + +Set the id of the given `parent` object. +""" +function set_id(parent::Ref{_Parent}, id::AbstractString) + err_code = ccall( + (:caosdb_entity_parent_set_id, CaosDB.library_name), + Cint, + (Ref{_Parent}, Cstring), + parent, + id, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_id(property::Ref{_Property}, id::AbstractString) + +Set the id of the given `property` object. +""" +function set_id(property::Ref{_Property}, id::AbstractString) + err_code = ccall( + (:caosdb_entity_property_set_id, CaosDB.library_name), + Cint, + (Ref{_Property}, Cstring), + property, + id, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_role(entity::Ref{_Entity}, role::AbstractString) + +Set the role of the given `entity` object. +""" +function set_role(entity::Ref{_Entity}, role::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_role, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cstring), + entity, + role, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + + +""" + function set_name(entity::Ref{_Entity}, name::AbstractString) + +Set the name of the given `entity` object. +""" +function set_name(entity::Ref{_Entity}, name::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_name, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cstring), + entity, + name, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + + +""" + function set_name(property::Ref{_Property}, name::AbstractString) + +Set the name of the given `property` object. +""" +function set_name(property::Ref{_Property}, name::AbstractString) + err_code = ccall( + (:caosdb_entity_property_set_name, CaosDB.library_name), + Cint, + (Ref{_Property}, Cstring), + property, + name, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + + +""" + function set_name(parent::Ref{_Parent}, name::AbstractString) + +Set the name of the given `parent` object. +""" +function set_name(parent::Ref{_Parent}, name::AbstractString) + err_code = ccall( + (:caosdb_entity_parent_set_name, CaosDB.library_name), + Cint, + (Ref{_Parent}, Cstring), + parent, + name, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_description(entity::Ref{_Entity}, description::AbstractString) + +Set the description of the given `entity` object. +""" +function set_description(entity::Ref{_Entity}, description::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_description, CaosDB.library_description), + Cint, + (Ref{_Entity}, Cstring), + entity, + description, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_datatype(entity::Ref{_Entity}, datatype::AbstractString) + +Set the datatype of the given `entity` object. +""" +function set_datatype(entity::Ref{_Entity}, datatype::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_datatype, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cstring), + entity, + datatype, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + + +""" + function set_datatype(property::Ref{_Property}, datatype::AbstractString) + +Set the datatype of the given `property` object. +""" +function set_datatype(property::Ref{_Property}, datatype::AbstractString) + err_code = ccall( + (:caosdb_entity_property_set_datatype, CaosDB.library_name), + Cint, + (Ref{_Property}, Cstring), + property, + datatype, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_unit(entity::Ref{_Entity}, unit::AbstractString) + +Set the unit of the given `entity` object. +""" +function set_unit(entity::Ref{_Entity}, unit::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_unit, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cstring), + entity, + unit, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + + +""" + function set_unit(property::Ref{_Property}, unit::AbstractString) + +Set the unit of the given `property` object. +""" +function set_unit(property::Ref{_Property}, unit::AbstractString) + err_code = ccall( + (:caosdb_entity_property_set_unit, CaosDB.library_name), + Cint, + (Ref{_Property}, Cstring), + property, + unit, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_value(entity::Ref{_Entity}, value::AbstractString) + +Set the value of the given `entity` object. +""" +function set_value(entity::Ref{_Entity}, value::AbstractString) + err_code = ccall( + (:caosdb_entity_entity_set_value, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cstring), + entity, + value, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + + +""" + function set_value(property::Ref{_Property}, value::AbstractString) + +Set the value of the given `property` object. +""" +function set_value(property::Ref{_Property}, value::AbstractString) + err_code = ccall( + (:caosdb_entity_property_set_value, CaosDB.library_name), + Cint, + (Ref{_Property}, Cstring), + property, + value, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function set_importance(property::Ref{_Property}, importance::AbstractString) + +Set the importance of the given `property` object. +""" +function set_importance(property::Ref{_Property}, importance::AbstractString) + err_code = ccall( + (:caosdb_entity_property_set_importance, CaosDB.library_name), + Cint, + (Ref{_Property}, Cstring), + property, + importance, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function append_parent(entity::Ref{_Entity}, parent::Ref{_Parent}) + +Append the given `parent` to the parents of the given `entity`. +""" +function append_parent(entity::Ref{_Entity}, parent::Ref{_Parent}) + + err_code = ccall( + (:caosdb_entity_entity_append_parent, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{_Parent}), + entity, + parent, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function append_parents(entity::Ref{_Entity}, parents::Vector{Base.RefValue{_Parent}}) + +Append all given `parents` to the parents of the given `entity`. +""" +function append_parents(entity::Ref{_Entity}, parents::Vector{Base.RefValue{_Parent}}) + + for parent in parents + append_parent(entity, parent) + end +end + +""" + function remove_parent(entity::Ref{_Entity}, index::Cint) + +Remove the parent at position `index` from the parents of the given +entity. +""" +function remove_parent(entity::Ref{_Entity}, index::Cint) + + err_code = ccall( + (:caosdb_entity_entity_remove_parent, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cint), + entity, + index - 1, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function append_property(entity::Ref{_Entity}, property::Ref{_Property}) + +Append the given `property` to the properties of the given `entity`. +""" +function append_property(entity::Ref{_Entity}, property::Ref{_Property}) + + err_code = ccall( + (:caosdb_entity_entity_append_property, CaosDB.library_name), + Cint, + (Ref{_Entity}, Ref{_Property}), + entity, + property, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function append_properties(entity::Ref{_Entity}, properties::Vector{Base.RefValue{_Property}}) + +Append all given `properties` to the properties of the given `entity`. +""" +function append_properties( + entity::Ref{_Entity}, + properties::Vector{Base.RefValue{_Property}}, +) + + for property in properties + append_property(entity, property) + end +end + +""" + function remove_property(entity::Ref{_Entity}, index::Cint) + +Remove the property at position `index` from the properties of the given +entity. +""" +function remove_property(entity::Ref{_Entity}, index::Cint) + + err_code = ccall( + (:caosdb_entity_entity_remove_property, CaosDB.library_name), + Cint, + (Ref{_Entity}, Cint), + entity, + index - 1, + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) +end + +""" + function has_errors(entity::Ref{_Entity}) + +Return true if the given `entity` has errors, false otherwise. +""" +function has_errors(entity::Ref{_Entity}) + + return get_errors(entity) > 0 + +end + +""" + function has_warnings(entity::Ref{_Entity}) + +Return true if the given `entity` has warnings, false otherwise. +""" +function has_warnings(entity::Ref{_Entity}) + + return get_warnings(entity) > 0 + +end + end diff --git a/src/Transaction.jl b/src/Transaction.jl index 32cef2b..990b9f0 100644 --- a/src/Transaction.jl +++ b/src/Transaction.jl @@ -35,8 +35,10 @@ object. """ mutable struct _Transaction wrapped_transaction::Ptr{Cvoid} + _deletable::Bool function _Transaction(managed_by_julia::Bool = false) trans = new() + trans._deletable = false if managed_by_julia function f(t) ccall( diff --git a/test/runtests.jl b/test/runtests.jl index 7662464..6350b16 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -68,7 +68,7 @@ using CaosDB # return the correct code (Change it if this ever changes in # libcaosdb) client_err = CaosDB.Exceptions.ClientException("Client error") - @test client_err.msg == "Client_Err" + @test client_err.msg == "Client error" @test client_err.code == 9999 end @@ -107,25 +107,28 @@ using CaosDB rec_with_parent_and_props = CaosDB.Entity.create_record("TestRec") # cannot set an ID - @test_throws CaosDB.Exceptions.ClientException CaosDB.Entity.set_id("some_id") + @test_throws CaosDB.Exceptions.ClientException CaosDB.Entity.set_id( + rec_with_parent_and_props, + "some_id", + ) par1 = CaosDB.Entity.create_parent(name = "Parent1") par2 = CaosDB.Entity.create_parent(name = "Parent2", id = "id_of_parent_2") CaosDB.Entity.append_parents(rec_with_parent_and_props, [par1, par2]) @test length(CaosDB.Entity.get_parents(rec_with_parent_and_props)) == 2 @test CaosDB.Entity.get_name( - CaosDB.Entity.get_parent(rec_with_parent_and_props, 1), + CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(1)), ) == "Parent1" @test CaosDB.Entity.get_name( - CaosDB.Entity.get_parent(rec_with_parent_and_props, 2), + CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(2)), ) == "Parent2" @test CaosDB.Entity.get_id( - CaosDB.Entity.get_parent(rec_with_parent_and_props, 2), + CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(2)), ) == "id_of_parent_2" - CaosDB.Entity.remove_parent(rec_with_parent_and_props, 1) + CaosDB.Entity.remove_parent(rec_with_parent_and_props, Cint(1)) @test length(CaosDB.Entity.get_parents(rec_with_parent_and_props)) == 1 @test CaosDB.Entity.get_name( - CaosDB.Entity.get_parent(rec_with_parent_and_props, 1), + CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(1)), ) == "Parent2" prop1 = CaosDB.Entity.create_property(name = "Property1", value = "2") @@ -144,7 +147,7 @@ using CaosDB @test CaosDB.Entity.get_id( CaosDB.Entity.get_properties(rec_with_parent_and_props)[2], ) == "id_of_property_2" - CaosDB.Entity.remove_property(rec_with_parent_and_props, 2) + CaosDB.Entity.remove_property(rec_with_parent_and_props, Cint(2)) @test length(CaosDB.Entity.get_properties(rec_with_parent_and_props)) == 2 @test CaosDB.Entity.get_name( CaosDB.Entity.get_properties(rec_with_parent_and_props)[2], -- GitLab