[libgda] Gda: New interface for DDL operations



commit 3347f5667d31daa011ad3909c2fb883b6de80bc7
Author: Pavlo Solntsev <p sun fun gmail com>
Date:   Wed May 27 13:26:05 2020 -0500

    Gda: New interface for DDL operations
    
    This interface will should be implemented by all GdaDb... objects
    to perform DDL operations.

 libgda/gda-ddl-modifiable.c | 93 +++++++++++++++++++++++++++++++++++++++++++++
 libgda/gda-ddl-modifiable.h | 74 ++++++++++++++++++++++++++++++++++++
 libgda/libgda.h.in          |  1 +
 libgda/meson.build          |  2 +
 4 files changed, 170 insertions(+)
---
diff --git a/libgda/gda-ddl-modifiable.c b/libgda/gda-ddl-modifiable.c
new file mode 100644
index 000000000..a02054cdb
--- /dev/null
+++ b/libgda/gda-ddl-modifiable.c
@@ -0,0 +1,93 @@
+/*
+ * gda-ddl-operation.c
+ *
+ * Copyright (C) 2020 Pavlo Solntsev <p sun fun gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#define G_LOG_DOMAIN "GDA-ddl-modifiable"
+#include "gda-ddl-modifiable.h"
+
+/**
+ * SECTION:gda-ddl-operation
+ * @title: GdaDdlModifiable
+ * @short_description: Interface to peform DDL operation
+ * @see_also: #GdaDbTable, #GdaDbView, #GdaDbIndex, #GdaDbColumn
+ * @stability: Stable
+ * @include: libgda/libgda.h
+ *
+ * This interface should be used to perform some DDL opration using objects that implement it.
+ * This interface is implemented by #GdaDbTable, #GdaDbColumn, #GdaDbIndex, and #GdaDbView. Calling
+ * gda_ddl_modifiable_create() on #GdaDbColumn operation will execute ADD COLUMN operation. The
+ * should pass a pointer to instance of GdaDbTable as user_data where column will be added (cretaed).
+ *
+ */
+
+G_DEFINE_INTERFACE (GdaDdlModifiable, gda_ddl_modifiable, G_TYPE_OBJECT)
+
+
+static void
+gda_ddl_modifiable_default_init (GdaDdlModifiableInterface *iface)
+{
+  /* add properties and signals to the interface here */
+}
+
+gboolean
+gda_ddl_modifiable_create (GdaDdlModifiable *self,
+                          GdaConnection *cnc,
+                          gpointer user_data,
+                          GError **error)
+{
+  GdaDdlModifiableInterface *iface = NULL;
+
+  g_return_val_if_fail (GDA_IS_DDL_MODIFIABLE (self), FALSE);
+  g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
+
+  iface = GDA_DDL_MODIFIABLE_GET_IFACE (self);
+  return iface->create (self, cnc, user_data, error);
+}
+
+gboolean
+gda_ddl_modifiable_drop (GdaDdlModifiable *self,
+                        GdaConnection *cnc,
+                        gpointer user_data,
+                        GError **error)
+{
+  GdaDdlModifiableInterface *iface = NULL;
+
+  g_return_val_if_fail (GDA_IS_DDL_MODIFIABLE (self), FALSE);
+  g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
+
+  iface = GDA_DDL_MODIFIABLE_GET_IFACE (self);
+  return iface->drop (self, cnc, user_data, error);
+}
+
+gboolean
+gda_ddl_modifiable_rename (GdaDdlModifiable *self,
+                          GdaConnection *cnc,
+                          gpointer user_data,
+                          GError **error)
+{
+  GdaDdlModifiableInterface *iface = NULL;
+
+  g_return_val_if_fail (GDA_IS_DDL_MODIFIABLE (self), FALSE);
+  g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
+
+  iface = GDA_DDL_MODIFIABLE_GET_IFACE (self);
+  return iface->rename (self, cnc, user_data, error);
+}
+
diff --git a/libgda/gda-ddl-modifiable.h b/libgda/gda-ddl-modifiable.h
new file mode 100644
index 000000000..838c369d7
--- /dev/null
+++ b/libgda/gda-ddl-modifiable.h
@@ -0,0 +1,74 @@
+/*
+ * gda-ddl-modifiable.h
+ *
+ * Copyright (C) 2020 Pavlo Solntsev <p sun fun gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+#ifndef GDA_DDL_MODIFIABLE_H
+#define GDA_DDL_MODIFIABLE_H
+
+#include <glib-object.h>
+#include <glib.h>
+#include "gda-connection.h"
+
+G_BEGIN_DECLS
+
+#define GDA_TYPE_DDL_MODIFIABLE gda_ddl_modifiable_get_type ()
+
+G_DECLARE_INTERFACE (GdaDdlModifiable, gda_ddl_modifiable, GDA, DDL_MODIFIABLE, GObject)
+
+struct _GdaDdlModifiableInterface
+{
+  GTypeInterface parent_iface;
+
+  gboolean (*create)(GdaDdlModifiable *self,
+                     GdaConnection *cnc,
+                     gpointer user_data,
+                     GError **error);
+
+  gboolean (*drop)(GdaDdlModifiable *self,
+                   GdaConnection *cnc,
+                   gpointer user_data,
+                   GError **error);
+
+  gboolean (*rename)(GdaDdlModifiable *self,
+                     GdaConnection *cnc,
+                     gpointer user_data,
+                     GError **error);
+};
+
+gboolean gda_ddl_modifiable_create (GdaDdlModifiable *self,
+                                    GdaConnection *cnc,
+                                    gpointer user_data,
+                                    GError **error);
+
+gboolean gda_ddl_modifiable_drop (GdaDdlModifiable *self,
+                                  GdaConnection *cnc,
+                                  gpointer user_data,
+                                  GError **error);
+
+gboolean gda_ddl_modifiable_rename (GdaDdlModifiable *self,
+                                    GdaConnection *cnc,
+                                    gpointer user_data,
+                                    GError **error);
+
+G_END_DECLS
+
+#endif /* end of include guard: GDA-DB-MODIFIABLE*/
+
+
+
diff --git a/libgda/libgda.h.in b/libgda/libgda.h.in
index 99a1e27e9..d24f00ce9 100644
--- a/libgda/libgda.h.in
+++ b/libgda/libgda.h.in
@@ -86,6 +86,7 @@
 
 #include <libgda/gda-db-catalog.h>
 #include <libgda/gda-db-index.h>
+#include <libgda/gda-ddl-modifiable.h>
 
 #include <libgda/sql-parser/gda-sql-parser.h>
 
diff --git a/libgda/meson.build b/libgda/meson.build
index 7295671b2..8f2197a58 100644
--- a/libgda/meson.build
+++ b/libgda/meson.build
@@ -87,6 +87,7 @@ libgda_headers = files([
         'gda-db-buildable.h',
         'gda-db-index-field.h',
         'gda-db-index.h',
+    'gda-ddl-modifiable.h',
        'gda-decl.h',
        'gda-holder.h',
        'gda-lockable.h',
@@ -167,6 +168,7 @@ libgda_sources= files([
         'gda-db-buildable.c',
         'gda-db-index-field.c',
         'gda-db-index.c',
+    'gda-ddl-modifiable.c',
        'gda-holder.c',
        'gda-init.c',
        'gda-lockable.c',


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