MidgardCollector

MidgardCollector — Optimized database query that doesn't return objects

Synopsis

#include <midgard/midgard.h>

struct              MidgardCollector;
typedef             MidgardCollectorClass;
MidgardCollector *  midgard_collector_new               (MidgardConnection *mgd,
                                                         const gchar *typename,
                                                         const gchar *domain,
                                                         GValue *value);
gboolean            midgard_collector_set_key_property  (MidgardCollector *self,
                                                         const gchar *key,
                                                         GValue *value);
gboolean            midgard_collector_add_value_property
                                                        (MidgardCollector *self,
                                                         const gchar *value);
gboolean            midgard_collector_set               (MidgardCollector *self,
                                                         const gchar *key,
                                                         const gchar *subkey,
                                                         GValue *value);
GData *             midgard_collector_get               (MidgardCollector *self,
                                                         const gchar *key);
GValue *            midgard_collector_get_subkey        (MidgardCollector *self,
                                                         const gchar *key,
                                                         const gchar *subkey);
gchar **            midgard_collector_list_keys         (MidgardCollector *self);
gboolean            midgard_collector_merge             (MidgardCollector *self,
                                                         MidgardCollector *mc,
                                                         gboolean overwrite);
gboolean            midgard_collector_remove_key        (MidgardCollector *self,
                                                         const gchar *key);
gboolean            midgard_collector_add_constraint    (MidgardCollector *self,
                                                         const gchar *name,
                                                         const gchar *op,
                                                         const GValue *value);
gboolean            midgard_collector_add_constraint_with_property
                                                        (MidgardCollector *self,
                                                         const gchar *property_a,
                                                         const gchar *op,
                                                         const gchar *property_b);
gboolean            midgard_collector_begin_group       (MidgardCollector *self,
                                                         const gchar *type);
gboolean            midgard_collector_end_group         (MidgardCollector *self);
gboolean            midgard_collector_add_order         (MidgardCollector *self,
                                                         const gchar *name,
                                                         const gchar *dir);
void                midgard_collector_set_offset        (MidgardCollector *self,
                                                         guint offset);
void                midgard_collector_set_limit         (MidgardCollector *self,
                                                         guint limit);
void                midgard_collector_count             (MidgardCollector *self);
gboolean            midgard_collector_execute           (MidgardCollector *self);

Object Hierarchy

  GObject
   +----MidgardQueryBuilder
         +----MidgardCollector

Description

The main idea of MidgardCollector is code, resources and data reusability for all data values which are not objects itself and as part of any object could be retrieved from Midgard database without any need to retrieve full objects' records. MidgardCollector is special limited resource data handler and is optimized for performance and data accessibility.

Details

struct MidgardCollector

struct MidgardCollector;


MidgardCollectorClass

typedef struct MidgardCollectorClass MidgardCollectorClass;


midgard_collector_new ()

MidgardCollector *  midgard_collector_new               (MidgardConnection *mgd,
                                                         const gchar *typename,
                                                         const gchar *domain,
                                                         GValue *value);

typename should be any MidgardDBObject derived class name. domain is property name which is registered for given class, and should not be unique per object or record. In other words, domain is a common property (and value) for group of objects expected in collection. value must be of domain property type, and is owned by MidgardCollector instance. If you need reuse given value, make a copy.

Cases to return NULL:

  • mgd MidgardConnection instance is invalid

  • typename is not registered in GType system or it's not MidgardDBObject derived

  • domain property is not registered for given typename class

  • value is of invalid type

mgd :

MidgardConnection instance

typename :

name of given class, which collector is initialized for

domain :

collection' domain

value :

domain's constraint value

Returns :

MidgardCollector instance, or NULL on failure

midgard_collector_set_key_property ()

gboolean            midgard_collector_set_key_property  (MidgardCollector *self,
                                                         const gchar *key,
                                                         GValue *value);

If value is explicitly set to NULL , then all key property name's records are selected from database and set in internal collector's resultset. If not, key property name and its value is used as constraint to limit selected records from database. In latter case add_value_property method should be invoked. GValue value passed as third argument is owned by Midgard Collector. If value should be reused, its copy should be passed to constructor.

Cases to return FALSE:

  • self MidgardCollector instance is invalid

  • key property is not registered for the typename class

  • value is of invalid type

  • key property is already set for self MidgardCollector

self :

MidgardCollector instance

key :

property name which must be a key

value :

optional value of key's constraint

Returns :

TRUE if key has been set, FALSE otherwise

midgard_collector_add_value_property ()

gboolean            midgard_collector_add_value_property
                                                        (MidgardCollector *self,
                                                         const gchar *value);

Cases to return FALSE:

Number of value properties added to Midgard Collector is limited by the number of properties registered for type which has been initialized for the given MidgardCollector instance.

See: midgard_query_builder_add_constraint() for available property name pattern

self :

MidgardCollector instance

value :

property name

Returns :

TRUE if named value property has been added, FALSE otherwise

midgard_collector_set ()

gboolean            midgard_collector_set               (MidgardCollector *self,
                                                         const gchar *key,
                                                         const gchar *subkey,
                                                         GValue *value);

Cases to return FALSE:

  • self, MidgardCollector instance is invalid

  • subkey property name is not registered for collestor's class

  • value is of invalid type

If the key is already added to MidgardCollector then its value (as subkey&value pair) is destroyed and new one is set. In other case new key and its subkey&value pair is added to collector.

Key used in this function is a value returned ( or set ) for collector's key. Keys are collection of values returned from property fields. Subkey is an explicit property name.

GValue value argument is owned by MidgardCollector. If value should be reused, its copy should be passed as method argument.

self :

MidgardCollector instance

key :

key name for which subkey&value pair should be set

subkey :

property name which is a subkey

value :

value for given subkey

Returns :

TRUE, if key's value has been set, FALSE otherwise

midgard_collector_get ()

GData *             midgard_collector_get               (MidgardCollector *self,
                                                         const gchar *key);

GData keys ( collector's subkeys ) are inserted to GData as Quarks , so you must call g_quark_to_string if you need to get strings ( e.g. implementing hash table for language bindings ).

self :

MidgardCollector instance

key :

name of the key to look for

Returns :

GData for the given key or NULL if key is not found in collection. [transfer full]

midgard_collector_get_subkey ()

GValue *            midgard_collector_get_subkey        (MidgardCollector *self,
                                                         const gchar *key,
                                                         const gchar *subkey);

self :

MidgardCollector instance

key :

name of the key

subkey :

name of key's subkey to look for

Returns :

subkey's GValue value or NULL if not found

midgard_collector_list_keys ()

gchar **            midgard_collector_list_keys         (MidgardCollector *self);


midgard_collector_merge ()

gboolean            midgard_collector_merge             (MidgardCollector *self,
                                                         MidgardCollector *mc,
                                                         gboolean overwrite);

If third overwrite parameter is set as TRUE then all keys which exists in self and mc collector's instance will be oberwritten in self colection instance. If set as FALSE , only those keys will be added, which do not exist in self collection and exist in mc collection.

Cases to return FALSE:

self :

MidgardCollector instance

mc :

MidgardCollector instance

overwrite :

whether overwrite collector's keys

Returns :

TRUE if collections has been merged, FALSE otherwise

midgard_collector_remove_key ()

gboolean            midgard_collector_remove_key        (MidgardCollector *self,
                                                         const gchar *key);

Removes key and associated value from the given MidgardCollector instance.

self :

MidgardCollector instance

key :

name of the key in collector's collection

Returns :

TRUE if key (and its value) has been removed from collection, FALSE otherwise

midgard_collector_add_constraint ()

gboolean            midgard_collector_add_constraint    (MidgardCollector *self,
                                                         const gchar *name,
                                                         const gchar *op,
                                                         const GValue *value);


midgard_collector_add_constraint_with_property ()

gboolean            midgard_collector_add_constraint_with_property
                                                        (MidgardCollector *self,
                                                         const gchar *property_a,
                                                         const gchar *op,
                                                         const gchar *property_b);


midgard_collector_begin_group ()

gboolean            midgard_collector_begin_group       (MidgardCollector *self,
                                                         const gchar *type);


midgard_collector_end_group ()

gboolean            midgard_collector_end_group         (MidgardCollector *self);


midgard_collector_add_order ()

gboolean            midgard_collector_add_order         (MidgardCollector *self,
                                                         const gchar *name,
                                                         const gchar *dir);


midgard_collector_set_offset ()

void                midgard_collector_set_offset        (MidgardCollector *self,
                                                         guint offset);


midgard_collector_set_limit ()

void                midgard_collector_set_limit         (MidgardCollector *self,
                                                         guint limit);


midgard_collector_count ()

void                midgard_collector_count             (MidgardCollector *self);


midgard_collector_execute ()

gboolean            midgard_collector_execute           (MidgardCollector *self);