[gom] gom: Add GomResource property metadata
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gom] gom: Add GomResource property metadata
- Date: Tue, 15 Apr 2014 22:35:20 +0000 (UTC)
commit a8094cf57213f383a48c2f76e12654c872955741
Author: Bastien Nocera <hadess hadess net>
Date: Tue Apr 15 18:20:51 2014 +0200
gom: Add GomResource property metadata
Add "new-in-version" and "is-mapped" metadata for GomResource
sub-class properties. This allows application developers to
control which properties will be mapped to column names, and
tell the automated migration tool which columns to add.
gom/gom-command-builder.c | 15 +++++++++++----
gom/gom-resource.c | 43 +++++++++++++++++++++++++++++++++++++++++++
gom/gom-resource.h | 11 +++++++++++
3 files changed, 65 insertions(+), 4 deletions(-)
---
diff --git a/gom/gom-command-builder.c b/gom/gom-command-builder.c
index 9ef9fcb..efb1a74 100644
--- a/gom/gom-command-builder.c
+++ b/gom/gom-command-builder.c
@@ -76,19 +76,26 @@ is_mapped (GParamSpec *pspec)
{
gboolean ret;
- /*
- * TODO: Make this better, like let classes opt in to what
- * fields they want mapped.
- */
ret = (pspec->owner_type != GOM_TYPE_RESOURCE);
if (!ret)
return FALSE;
ret = (sql_type_for_column(pspec) != NULL);
+ if (!ret)
+ return FALSE;
+
+ ret = !GPOINTER_TO_INT(g_param_spec_get_qdata(pspec, GOM_RESOURCE_NOT_MAPPED));
return ret;
}
+static gboolean
+is_new_in_version (GParamSpec *pspec,
+ guint version)
+{
+ return GPOINTER_TO_UINT(g_param_spec_get_qdata(pspec, GOM_RESOURCE_NEW_IN_VERSION)) == version;
+}
+
static void
add_fields (GString *str,
GomResourceClass *klass)
diff --git a/gom/gom-resource.c b/gom/gom-resource.c
index 6a39520..43affe3 100644
--- a/gom/gom-resource.c
+++ b/gom/gom-resource.c
@@ -55,6 +55,37 @@ gom_resource_class_set_primary_key (GomResourceClass *resource_class,
}
void
+gom_resource_class_set_property_new_in_version (GomResourceClass *resource_class,
+ const gchar *property_name,
+ guint version)
+{
+ GParamSpec *pspec;
+
+ g_return_if_fail(GOM_IS_RESOURCE_CLASS(resource_class));
+ g_return_if_fail(version >= 1);
+
+ pspec = g_object_class_find_property(G_OBJECT_CLASS(resource_class), property_name);
+ g_assert(pspec);
+
+ g_param_spec_set_qdata(pspec, GOM_RESOURCE_NEW_IN_VERSION, GUINT_TO_POINTER(version));
+}
+
+void
+gom_resource_class_set_property_set_mapped (GomResourceClass *resource_class,
+ const gchar *property_name,
+ gboolean is_mapped)
+{
+ GParamSpec *pspec;
+
+ g_return_if_fail(GOM_IS_RESOURCE_CLASS(resource_class));
+
+ pspec = g_object_class_find_property(G_OBJECT_CLASS(resource_class), property_name);
+ g_assert(pspec);
+
+ g_param_spec_set_qdata(pspec, GOM_RESOURCE_NOT_MAPPED, GINT_TO_POINTER(!is_mapped));
+}
+
+void
gom_resource_class_set_table (GomResourceClass *resource_class,
const gchar *table)
{
@@ -809,3 +840,15 @@ gom_resource_error_quark (void)
{
return g_quark_from_static_string("gom_resource_error_quark");
}
+
+GQuark
+gom_resource_new_in_version_quark (void)
+{
+ return g_quark_from_static_string("gom_resource_new_in_version_quark");
+}
+
+GQuark
+gom_resource_not_mapped_quark (void)
+{
+ return g_quark_from_static_string("gom_resource_not_mapped_quark");
+}
diff --git a/gom/gom-resource.h b/gom/gom-resource.h
index e216700..320f1d5 100644
--- a/gom/gom-resource.h
+++ b/gom/gom-resource.h
@@ -33,6 +33,8 @@ G_BEGIN_DECLS
#define GOM_IS_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOM_TYPE_RESOURCE))
#define GOM_RESOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOM_TYPE_RESOURCE,
GomResourceClass))
#define GOM_RESOURCE_ERROR (gom_resource_error_quark())
+#define GOM_RESOURCE_NEW_IN_VERSION (gom_resource_new_in_version_quark())
+#define GOM_RESOURCE_NOT_MAPPED (gom_resource_not_mapped_quark())
typedef struct _GomResource GomResource;
typedef struct _GomResourceClass GomResourceClass;
@@ -66,6 +68,13 @@ void gom_resource_class_set_table (GomResourceClass *resource
const gchar *table);
void gom_resource_class_set_primary_key (GomResourceClass *resource_class,
const gchar *primary_key);
+void gom_resource_class_set_property_new_in_version (GomResourceClass *resource_class,
+ const gchar *property_name,
+ guint version);
+void gom_resource_class_set_property_set_mapped (GomResourceClass *resource_class,
+ const gchar *property_name,
+ gboolean is_mapped);
+
void gom_resource_delete_async (GomResource *resource,
GAsyncReadyCallback callback,
gpointer user_data);
@@ -75,6 +84,8 @@ gboolean gom_resource_delete_finish (GomResource *reso
gboolean gom_resource_delete_sync (GomResource *resource,
GError **error);
GQuark gom_resource_error_quark (void) G_GNUC_CONST;
+GQuark gom_resource_new_in_version_quark (void) G_GNUC_CONST;
+GQuark gom_resource_not_mapped_quark (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]