Midgard Object


Enumerations

enum  

Functions

GType midgard_object_get_type (void)
MgdObjectmidgard_object_new (midgard *mgd, const gchar *name, GValue *value)
MgdObjectmidgard_object_new_by_id (midgard *mgd, const gchar *name, gchar *id)
gboolean midgard_object_get_by_id (MgdObject *object)
gboolean midgard_object_update (MgdObject *object)
gboolean midgard_object_create (MgdObject *object)
GObject ** midgard_object_find (MgdObject *object, guint *n_objects)
gboolean midgard_object_is_in_parent_tree (MgdObject *object, guint rootid, guint id)
gboolean midgard_object_is_in_tree (MgdObject *object, guint rootid, guint id)
gboolean midgard_object_get_by_guid (MgdObject *object)
gboolean midgard_object_purge (MgdObject *object)
MgdObjectmidgard_object_get_parent (MgdObject *object)
GObject ** midgard_object_list (MgdObject *object, guint *n_objects)
GObject ** midgard_object_list_children (MgdObject *object, const gchar *childname, guint *n_objects)
GObject ** midgard_object_get_languages (MgdObject *self, guint *n_objects)
MgdObjectmidgard_get_object_by_guid (MidgardConnection *mgd, const gchar *guid)
MgdObjectmidgard_object_get_by_path (midgard *mgd, const gchar *classname, const gchar *path)
const gchar * midgard_object_parent (MgdObject *object)
gboolean midgard_object_undelete (MidgardConnection *mgd, const gchar *guid)
gchar * midgard_object_export (MgdObject *self)
gboolean midgard_import_object (MidgardConnection *mgd, gchar *xml)

Variables

struct {
   int   verbose
MidgardObjectAction

Detailed Description

 include <midgard/midgard.h> 

Midgard Object MgdObject is an user defined type and object. Description of an object , its properties and database abstraction layer is made in xml files.

MgdObject is represented by MIDGARD_TYPE_OBJECT type and is not associated with some particular class or type name. It's database and user defined types ( classes ) abstraction layer.

MgdObject provides transparent , not client accessible "methods" for internal midgard core's data like connection handler, sitegroup and MidgardSchema (MgdSchema) data.


Enumeration Type Documentation

anonymous enum
 

MidgardObjectAction defines current state of an object if object is instatiated only by guid without type name information.

 enum
 {
           MGD_OBJECT_ACTION_NONE = 0,
           MGD_OBJECT_ACTION_CREATE,
           MGD_OBJECT_ACTION_UPDATE, 
           MGD_OBJECT_ACTION_DELETE,
           MGD_OBJECT_ACTION_PURGE
 }MidgardObjectAction;
 

  • MGD_OBJECT_ACTION_NONE , typical object state
  • MGD_OBJECT_ACTION_DELETE, object has been deleted and can be undeleted
  • MGD_OBJECT_ACTION_PURGE, object has been purged ( no recovery or undelete )

Definition at line 126 of file types.h.


Function Documentation

MgdObject* midgard_get_object_by_guid MidgardConnection mgd,
const gchar *  guid
 

Returns new object instance for the given guid identifier.

Parameters:
mgd,MidgardConnection pointer , object's identifier
Returns:
newly instatiated object or NULL
This is custom function and not object's method. It's important for language bindings. This function returns object which is identified by the given guid. Returned object's type may be any of the types registered in Midgard Schema.

Cases to return NULL:

  • There is no any record with given guid ( MGD_ERR_NOT_EXISTS )
  • Object has been deleted ( MGD_ERR_OBJECT_DELETED )
  • Object has been purged ( MGD_ERR_OBJECT_PURGED )
  • Repligard record with given guid exists , but there is no object's record in object's table with the given guid value ( MGD_ERR_INTERNAL )

Definition at line 2654 of file types.c.

References MidgardConnection::mgd, MGD_ERR_INTERNAL, MGD_ERR_NOT_EXISTS, MGD_ERR_OBJECT_DELETED, MGD_ERR_OBJECT_PURGED, MGD_ERR_OK, MIDGARD_ERRNO_SET, and midgard_object_new().

Referenced by midgard_import_object().

Here is the call graph for this function:

gboolean midgard_import_object MidgardConnection mgd,
gchar *  xml
 

Import Midgard Object from xml.

Parameters:
mgd,MidgardConnection handler's pointer
xml,xml string
Returns:
TRUE if import has been successfull, FALSE otherwise.
Imports object to database. Given xml is used as serialized object's data.

Cases to return FALSE:

  • object is already imported ( MGD_ERR_OBJECT_IMPORTED )

Import method determines whether create or update method should be invoked for imported object, so all error cases for create and update method are valid for import one.

Definition at line 2865 of file types.c.

References _MidgardTypePrivate::guid, _MgdObject::metadata, MidgardConnection::mgd, MGD_ERR_OBJECT_IMPORTED, MIDGARD_ERRNO_SET, midgard_get_object_by_guid(), midgard_object_create(), midgard_query_builder_add_constraint(), midgard_query_builder_execute(), midgard_query_builder_include_deleted(), midgard_query_builder_new(), and _MgdObject::private.

Here is the call graph for this function:

gboolean midgard_object_create MgdObject object  ) 
 

Creates new database record(s) for object.

Parameters:
object MgdObject
This function list all object's properties and creates query using properties values which are already initialized. Value of property which is not initialized is set to its default value.

Internally such properties are being set (overwritten):

  • sitegroup
  • guid (since Midgard 1.7.5)
  • id (if set as primary property)
  • metadata.creator (since Midgard 1.8)
  • metadata.created (since Midgard 1.8)
  • metadata.revisor (since Midgard 1.8)
  • metadata.revised (since Midgard 1.8)
  • metadata.revision (since Midgard 1.8)
  • metadata.published (since Midgard 1.8)

Midgard error set by this method:

  • MGD_ERR_OK
    1. Object's record has been created successfully Returns TRUE
  • MGD_ERR_NOT_EXISTS
    1. Storage table not defined in schema
    2. SQL query failed ( database query error is populated with warn log level ) Returns FALSE
  • MGD_ERR_DUPLICATE
    1. Object with the same name already exists in tree Returns FALSE
  • MGD_ERR_INTERNAL
    1. Repligard record hasn't been created for object's record
    2. Critical unknown reason Returns FALSE
  • MGD_ERR_INVALID_PROPERTY_VALUE
    1. Some property holds incorrect value. ( For example property with MGD_TYPE_GUID type holds string which doesn't contain at least 21 and at most 80 characters).
      1. GUID and UUID reference http://www.midgard-project.org/development/mrfc/0018.html

Since Midgard 1.8 , Midgard Administrator (Sitegroup 0) is able to specify sitegroup of created object.

Definition at line 1121 of file types.c.

Referenced by midgard_import_object(), and midgard_object_set_parameter().

gchar* midgard_object_export MgdObject self  ) 
 

Export given object to xml.

Parameters:
self,MidgardObject instance
Returns:
object serialized to xml format on success , NULL otherwise.
Returns newly allocated string as object with its properties serialized to xml format, and sets object's metadata exported value to current datetime. UTF-8 character encoding is set for returned xml.

Cases to return NULL:

  • Object has been recently exported ( MGD_ERR_OBJECT_EXPORTED )

Definition at line 2801 of file types.c.

References _midgard::_mgd, MidgardConnection::err, MidgardConnection::errstr, _MgdObject::mgd, MGD_ERR_INVALID_PROPERTY_VALUE, MGD_ERR_OK, MIDGARD_ERRNO_SET, and midgard_set_error().

Here is the call graph for this function:

GObject** midgard_object_find MgdObject object,
guint *  n_objects
 

Find object(s) record(s) in database for the properties being set for object instance.

Parameters:
object MgdObject
[out] n_objects pointer to integer which stores number of returned objects
Returns:
objects
This function is a simple wrapper for Midgard Query Builder. Unlike QB it only uses equal operators while looking for object records in database storage. It should be usefull if used with properties like up and name ( get by name ), up or parent ( list ), or similiar ones.

Definition at line 1247 of file types.c.

References _MgdObject::cname, _MgdObject::mgd, MGD_ERR_INTERNAL, MGD_ERR_OK, MIDGARD_ERRNO_SET, midgard_query_builder_add_constraint(), and midgard_query_builder_new().

Here is the call graph for this function:

gboolean midgard_object_get_by_guid MgdObject object  ) 
 

Fetch object's record(s) from database using 'guid' property.

Parameters:
object MgdObject
Returns:
TRUE if object's record(s) is successfully fetched from database. FALSE otherwise.
Caller is responsible to set 'guid' property before calling this function.

MgdObject object instance must be created with midgard_object_new function. When midgard connection handler is not associated with object instance, application is terminated with 'assertion fails' error message being logged.

Object instance created with this function should be freed using g_object_unref.

Definition at line 1664 of file types.c.

References _MgdObject::cname, _MgdObject::data, _MgdObject::mgd, MGD_ERR_INTERNAL, MGD_ERR_NOT_EXISTS, MGD_ERR_OK, MIDGARD_ERRNO_SET, midgard_query_builder_add_constraint(), midgard_query_builder_execute(), and midgard_query_builder_new().

Referenced by midgard_object_new_by_id().

Here is the call graph for this function:

gboolean midgard_object_get_by_id MgdObject object  ) 
 

Fetch object's record(s) from database using 'id' property.

Parameters:
object MgdObject
Returns:
TRUE if object's record(s) is successfully fetched from database. FALSE otherwise.
Caller is responsible to set 'id' property before calling this function.

This is common practice to use 'id' property with integer type when table's id column stores unique value which identifies object and its record(s). However primary property with integer type is freely defined by user.

MgdObject object instance must be created with midgard_object_new function. When midgard connection handler is not associated with object instance, application is terminated with 'assertion fails' error message being logged.

Object instance created with this function should be freed using g_object_unref.

Definition at line 1178 of file types.c.

References _MgdObject::mgd, MGD_ERR_INTERNAL, MGD_ERR_NOT_EXISTS, MGD_ERR_OK, MIDGARD_ERRNO_SET, midgard_query_builder_add_constraint(), midgard_query_builder_execute(), and midgard_query_builder_new().

Referenced by midgard_object_get_by_path(), midgard_object_get_parent(), and midgard_object_new_by_id().

Here is the call graph for this function:

MgdObject* midgard_object_get_by_path midgard mgd,
const gchar *  classname,
const gchar *  path
 

Returns object by path

Definition at line 2334 of file types.c.

References _MgdObject::data, _MgdObject::mgd, MGD_ERR_NOT_EXISTS, MGD_ERR_OK, MIDGARD_ERRNO_SET, midgard_object_get_by_id(), midgard_object_new(), parent, _MgdSchemaTypeAttr::parent, _MgdSchemaTypeAttr::primary, _MgdSchemaTypeAttr::query, and _MgdSchemaTypeQuery::table.

Here is the call graph for this function:

GObject** midgard_object_get_languages MgdObject self,
guint *  n_objects
 

Returns midgard_language objects for the given Midgard Object instance.

Parameters:
self MgdObject instance
Returns:
midgard_language objects' array
Returned array is limited to midgard_language objects for which content exists for the given Midgard Object instance.

Definition at line 2559 of file types.c.

References _midgard::_mgd, MidgardConnection::err, _MgdObject::mgd, MGD_ERR_INVALID_PROPERTY_VALUE, MGD_ERR_USER_DATA, midgard_collector_add_constraint(), midgard_collector_execute(), midgard_collector_list_keys(), midgard_collector_new(), midgard_collector_set_key_property(), midgard_object_new_by_id(), and midgard_set_error().

Here is the call graph for this function:

MgdObject* midgard_object_get_parent MgdObject object  ) 
 

Fetch parent object.

Parameters:
object MgdObject
Returns:
new MgdObject object instance or NULL if parent object can not be fetched from database.
This function fetch "upper" object of the same type, and then parent object if object's up property holds empty value. Object is root object in tree when NULL is returned.

Definition at line 1556 of file types.c.

References _MgdObject::cname, _MidgardObjectClass::data, _MgdObject::data, _MgdObject::klass, _MgdObject::mgd, midgard_object_get_by_id(), midgard_object_new(), and _MgdSchemaTypeAttr::parent.

Here is the call graph for this function:

GType midgard_object_get_type void   ) 
 

Returns Midgard Object type. Registers the type as a fundamental GType unless already registered.

Definition at line 1414 of file types.c.

References _MgdSchemaTypeAttr::base_index, _MgdSchemaTypeAttr::num_properties, and _MgdSchemaTypeAttr::params.

gboolean midgard_object_is_in_parent_tree MgdObject object,
guint  rootid,
guint  id
 

Checks whether object exists in parent's type tree.

Parameters:
object MgdObject
rootid guint which identifies parent's type primary property
id guint which identify object's primary property
Returns:
TRUE when object exists in parent tree, FALSE otherwise.
Midgard tree in MgdSchema reference: http://www.midgard-project.org/midcom-permalink-a4e185a08fb2d0e278ef1ba3a739f77e

Parent type in midgard tree is a type which can be "container" with object nodes of different types.

Definition at line 444 of file tree_core.c.

References _MidgardObjectClass::data, _MgdObject::mgd, midgard_object_new(), midgard_object_parent(), parent, _MgdSchemaTypeAttr::query, and _MgdSchemaTypeQuery::upfield.

Here is the call graph for this function:

gboolean midgard_object_is_in_tree MgdObject object,
guint  rootid,
guint  id
 

Checks whether object exists in tree ( of the same type ).

Parameters:
object MgdObject
rootid guint value which identifies type's primary property
id guint value which identifies object's primary property
Returns:
TRUE when object exists in tree, FALSE otherwise.
Midgard tree in MgdSchema reference: http://www.midgard-project.org/midcom-permalink-a4e185a08fb2d0e278ef1ba3a739f77e

This function checks only objects of the same type.

Definition at line 482 of file tree_core.c.

References _MidgardObjectClass::data, _MgdObject::mgd, _MgdSchemaTypeAttr::query, and _MgdSchemaTypeQuery::upfield.

GObject** midgard_object_list MgdObject object,
guint *  n_objects
 

Return objects which up property is equal with object primary property

Parameters:
object MgdObject object instance
[out] n_objects pointer to integer which stores number of returned objects
Returns:
objects
Caller is reponsible to unref objects returned unless n_objects is 0.

Definition at line 2203 of file types.c.

References _MgdObject::mgd, MGD_ERR_INTERNAL, MGD_ERR_NOT_EXISTS, MGD_ERR_OK, MIDGARD_ERRNO_SET, midgard_query_builder_add_constraint(), midgard_query_builder_execute(), and midgard_query_builder_new().

Here is the call graph for this function:

GObject** midgard_object_list_children MgdObject object,
const gchar *  childname,
guint *  n_objects
 

Return child objects

Parameters:
object MgdObject object instance
childname of child typename
[out] n_objects pointer to integer which stores number of returned objects
Returns:
child objects
Caller is reponsible to unref objects returned unless n_objects is 0.

Definition at line 2255 of file types.c.

References _MgdSchemaTypeAttr::childs, _MgdObject::cname, _MgdObject::data, _MgdObject::klass, _MgdObject::mgd, MGD_ERR_INTERNAL, MGD_ERR_NOT_EXISTS, MGD_ERR_OK, MIDGARD_ERRNO_SET, midgard_object_new(), midgard_query_builder_add_constraint(), midgard_query_builder_execute(), midgard_query_builder_new(), and _MgdSchemaTypeAttr::primary.

Here is the call graph for this function:

MgdObject* midgard_object_new midgard mgd,
const gchar *  name,
GValue *  value
 

Creates new MgdObject object instance.

Parameters:
mgd,midgard struct connection handler
name,object's type name , optional value which holds id or guid if object should be fetched from database.
Returns:
New MidgardObjectClass instance
This function is mandatory one for new midgard object initialization. Unlike g_object_new ( which is typical function to create new GObject instance ), midgard_object_new initializes data which are accessible internally by object instance itself or by object's class:

  • midgard connection handler is associated with object
  • 'sitegroup' property of an object is being set

Sitegroup value is returned from midgard connection handler and may be overwritten only by SG0 Midgard Administrator only when object is created. Setting this property is forbidden when object is already fetched from database.

Object's contructor tries to determine third optional parameter value. If it's of G_TYPE_STRING type , then midgard_is_guid is called to check weather passed string is a guid , in any other case id property is used with G_TYPE_UINT type.

Any object instance created with this function should be freed using g_object_unref function.

Definition at line 1455 of file types.c.

References midgard_is_guid(), midgard_query_builder_add_constraint(), midgard_query_builder_execute(), and midgard_query_builder_new().

Referenced by midgard_get_object_by_guid(), midgard_object_get_by_path(), midgard_object_get_parent(), midgard_object_is_in_parent_tree(), midgard_object_list_children(), midgard_object_new_by_id(), midgard_object_set_parameter(), and midgard_query_builder_join().

Here is the call graph for this function:

MgdObject* midgard_object_new_by_id midgard mgd,
const gchar *  name,
gchar *  id
 

Creates new Midgard object instance and fetch record(s) from database using object's primary property.

Parameters:
mgd Midgard structure
name name for registered type(class)
identifier value
Returns:
new MgdObject instance
The main purpose of this function is to query object's record(s) from database without any knowledge which object's property holds value of primary field and what is the type of this property. midgard_object_new_by_id also minimize the need to write full reflected code which could be used for the same purpose.

Third prameter's value must be always type casted to gchar ( even if it's integer type ). Internally check for primary property and its type is made and midgard_object_get_by_id or midgard_object_get_by_guid is called to return correct object's instance.

NULL is returned when object can not be queried from database.

Definition at line 1522 of file types.c.

References _MgdObject::data, midgard_object_get_by_guid(), midgard_object_get_by_id(), midgard_object_new(), and _MgdSchemaTypeAttr::primary.

Referenced by midgard_object_get_languages().

Here is the call graph for this function:

const gchar* midgard_object_parent MgdObject object  ) 
 

Returns type name of parent object ( in content tree ).

Definition at line 2644 of file types.c.

References _MgdObject::data, and _MgdSchemaTypeAttr::parent.

Referenced by midgard_object_is_in_parent_tree().

gboolean midgard_object_purge MgdObject object  ) 
 

Purge object's record(s) from database.

Parameters:
object MgdObject
Returns:
TRUE if object has been succesfully purged from database. FALSE otherwise.
Caller is responsible to set 'guid' property before calling this function.

FALSE is returned in such cases:

  • Midgard Schema is not set for this object ( MGD_ERR_INTERNAL )
  • Object's has no storage defined ( MGD_ERR_OBJECT_NO_STORAGE )
  • Object's property guid is empty ( MGD_ERR_INVALID_PROPERTY_VALUE )
  • Object's property id is less then 1 ( MGD_ERR_INVALID_PROPERTY_VALUE ) ( only if class is multilang )
  • No record has been deleted from database ( MGD_ERR_NOT_EXISTS )

Definition at line 1948 of file types.c.

References _MgdObject::cname, _MgdObject::data, _MidgardTypePrivate::guid, _MgdObject::mgd, MGD_ERR_INTERNAL, MGD_ERR_INVALID_PROPERTY_VALUE, MGD_ERR_NOT_EXISTS, MGD_ERR_OBJECT_NO_STORAGE, MGD_ERR_OK, MIDGARD_ERRNO_SET, midgard_quota_remove(), _midgard::msql, _midgard_mysql::mysql, and _MgdObject::private.

Here is the call graph for this function:

gboolean midgard_object_undelete MidgardConnection mgd,
const gchar *  guid
 

Undelete object

Parameters:
mgd,MidgardConnection pointer , identifier for deleted object
Returns:
TRUE if object has been undeleted, FALSE otherwise.
Cases to return FALSE:

  • There is no record in repligard's table with the given guid's value ( MGD_ERR_NOT_EXISTS )
  • Object can not be undeleted ( MGD_ERR_INTERNAL )
  • Object is already purged ( MGD_ERR_OBJECT_PURGED )
  • Object is not deleted ( MGD_ERR_USER_DATA )

Definition at line 2720 of file types.c.

References MidgardConnection::err, MidgardConnection::mgd, MGD_ERR_INTERNAL, MGD_ERR_NOT_EXISTS, MGD_ERR_OBJECT_PURGED, MGD_ERR_OK, MGD_ERR_USER_DATA, MIDGARD_ERRNO_SET, and midgard_set_error().

Here is the call graph for this function:

gboolean midgard_object_update MgdObject object  ) 
 

Update object's record(s).

Parameters:
object MgdObject
Returns:
TRUE when object's record(s) is successfully updated. FALSE otherwise.
This function list all object's properties and creates query using properties values which are already initialized. Value of property which is not initialized is ignored.

Internally such properties are being set (overwritten):

  • sitegroup
  • revisor ( object's metadata property )
  • revision ( object's metadata property )
  • revised ( object's metadata property )

FALSE is returned in such cases:

  • There is no midgard_person object associated with connection handler.
  • Midgard Schema is not set for this object ( this is internal fatal error )
  • Object's has no storage defined.
  • Object has property 'name' defined and such named record already exists in object's table
  • Quota size is reached
  • Database query failed ( this is internal fatal error )
  • Sitegroup property of an object was changed ( critical error )

Midgard error set by this method:

  • MGD_ERR_OK
    1. Object's record has been updated successfully. Returns TRUE
  • MGD_ERR_SITEGROUP_VIOLATION
    1. Sitegroup of an object has been chnaged
  • MGD_ERR_DUPLICATE
    1. Another object with the same name already exists in tree
  • MGD_ERR_QUOTA
    1. Quota limit is reached
  • MGD_ERR_INTERNAL
    1. SQL query failed
    2. No table defined for object's type
  • MGD_ERR_INVALID_PROPERTY_VALUE
    1. Some property holds incorrect value.

Definition at line 924 of file types.c.

Referenced by midgard_object_set_parameter().


Variable Documentation

enum { ... } MidgardObjectAction
 

MidgardObjectAction defines current state of an object if object is instatiated only by guid without type name information.

 enum
 {
           MGD_OBJECT_ACTION_NONE = 0,
           MGD_OBJECT_ACTION_CREATE,
           MGD_OBJECT_ACTION_UPDATE, 
           MGD_OBJECT_ACTION_DELETE,
           MGD_OBJECT_ACTION_PURGE
 }MidgardObjectAction;
 

  • MGD_OBJECT_ACTION_NONE , typical object state
  • MGD_OBJECT_ACTION_DELETE, object has been deleted and can be undeleted
  • MGD_OBJECT_ACTION_PURGE, object has been purged ( no recovery or undelete )


Generated on Thu Feb 22 06:15:21 2007 for midgard-core by  doxygen 1.4.6