[gom] gom: Add support for creating columns with references



commit f428c8f39f0b13da0a2b6492a777e83458af505a
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Apr 17 22:43:13 2014 +0200

    gom: Add support for creating columns with references

 gom/gom-command-builder.c |   17 +++++++++++++++++
 gom/gom-resource.c        |   36 ++++++++++++++++++++++++++++++++++++
 gom/gom-resource.h        |    8 ++++++++
 3 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/gom/gom-command-builder.c b/gom/gom-command-builder.c
index 12824e2..e41e939 100644
--- a/gom/gom-command-builder.c
+++ b/gom/gom-command-builder.c
@@ -177,6 +177,22 @@ add_table_name (GString          *str,
 }
 
 static void
+add_reference (GString           *str,
+               GParamSpec        *pspec)
+{
+   const gchar *table_name;
+   const gchar *property_name;
+
+   table_name = g_param_spec_get_qdata(pspec, GOM_RESOURCE_REF_TABLE_CLASS);
+   if (!table_name)
+      return;
+   property_name = g_param_spec_get_qdata(pspec, GOM_RESOURCE_REF_PROPERTY_NAME);
+   g_assert(property_name);
+
+   g_string_append_printf(str, " REFERENCES [%s]([%s]) ", table_name, property_name);
+}
+
+static void
 add_joins (GString          *str,
            GomResourceClass *klass)
 {
@@ -383,6 +399,7 @@ gom_command_builder_build_create (GomCommandBuilder *builder,
        g_string_append_printf(str, "'%s' %s",
                               pspecs[i]->name,
                               sql_type_for_column (pspecs[i]));
+       add_reference(str, pspecs[i]);
 
        command = g_object_new(GOM_TYPE_COMMAND,
                               "adapter", priv->adapter,
diff --git a/gom/gom-resource.c b/gom/gom-resource.c
index 618c4b5..232511c 100644
--- a/gom/gom-resource.c
+++ b/gom/gom-resource.c
@@ -108,6 +108,30 @@ gom_resource_class_set_property_transform (GomResourceClass         *resource_cl
 }
 
 void
+gom_resource_class_set_reference (GomResourceClass     *resource_class,
+                                  const gchar          *property_name,
+                                  const gchar          *ref_table_name,
+                                  const gchar          *ref_property_name)
+{
+   GParamSpec *pspec;
+
+   g_return_if_fail(GOM_IS_RESOURCE_CLASS(resource_class));
+   g_return_if_fail(property_name != NULL);
+   g_return_if_fail(ref_property_name != NULL);
+
+   pspec = g_object_class_find_property(G_OBJECT_CLASS(resource_class), property_name);
+   g_assert(pspec);
+
+   if (ref_table_name == NULL)
+     ref_table_name = G_OBJECT_CLASS_NAME(resource_class);
+
+   g_param_spec_set_qdata_full(pspec, GOM_RESOURCE_REF_TABLE_CLASS,
+                               g_strdup(ref_table_name), g_free);
+   g_param_spec_set_qdata_full(pspec, GOM_RESOURCE_REF_PROPERTY_NAME,
+                               g_strdup(ref_property_name), g_free);
+}
+
+void
 gom_resource_class_set_table (GomResourceClass *resource_class,
                               const gchar      *table)
 {
@@ -886,3 +910,15 @@ gom_resource_from_bytes_func_quark (void)
 {
    return g_quark_from_static_string("gom_resource_from_bytes_func_quark");
 }
+
+GQuark
+gom_resource_ref_table_class (void)
+{
+   return g_quark_from_static_string("gom_resource_ref_table_class");
+}
+
+GQuark
+gom_resource_ref_property_name (void)
+{
+   return g_quark_from_static_string("gom_resource_ref_property_name");
+}
diff --git a/gom/gom-resource.h b/gom/gom-resource.h
index 77ab73c..ebab1f4 100644
--- a/gom/gom-resource.h
+++ b/gom/gom-resource.h
@@ -37,6 +37,8 @@ G_BEGIN_DECLS
 #define GOM_RESOURCE_NOT_MAPPED      (gom_resource_not_mapped_quark())
 #define GOM_RESOURCE_TO_BYTES_FUNC   (gom_resource_to_bytes_func_quark())
 #define GOM_RESOURCE_FROM_BYTES_FUNC (gom_resource_from_bytes_func_quark())
+#define GOM_RESOURCE_REF_TABLE_CLASS (gom_resource_ref_table_class())
+#define GOM_RESOURCE_REF_PROPERTY_NAME (gom_resource_ref_property_name())
 
 typedef struct _GomResource        GomResource;
 typedef struct _GomResourceClass   GomResourceClass;
@@ -83,6 +85,10 @@ void              gom_resource_class_set_property_transform      (GomResourceCla
                                                                   const gchar              *property_name,
                                                                   GomResourceToBytesFunc    to_bytes_func,
                                                                   GomResourceFromBytesFunc  from_bytes_func);
+void              gom_resource_class_set_reference               (GomResourceClass         *resource_class,
+                                                                  const gchar              *property_name,
+                                                                  const gchar              *ref_table_name,
+                                                                  const gchar              
*ref_property_name);
 
 void              gom_resource_delete_async          (GomResource          *resource,
                                                       GAsyncReadyCallback   callback,
@@ -97,6 +103,8 @@ GQuark            gom_resource_new_in_version_quark  (void) G_GNUC_CONST;
 GQuark            gom_resource_not_mapped_quark      (void) G_GNUC_CONST;
 GQuark            gom_resource_to_bytes_func_quark   (void) G_GNUC_CONST;
 GQuark            gom_resource_from_bytes_func_quark (void) G_GNUC_CONST;
+GQuark            gom_resource_ref_table_class       (void) G_GNUC_CONST;
+GQuark            gom_resource_ref_property_name     (void) G_GNUC_CONST;
 GType             gom_resource_get_type              (void) G_GNUC_CONST;
 void              gom_resource_save_async            (GomResource          *resource,
                                                       GAsyncReadyCallback   callback,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]