[libgda] Oracle adaptations to make provider work correctly in case some files are missing



commit 4c16e1c404bbc72680f1503de201ccf543938c7d
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Feb 4 15:03:16 2015 +0100

    Oracle adaptations to make provider work correctly in case some files are missing

 providers/oracle/Makefile.am           |   16 ++++++++-
 providers/oracle/gda-oracle-provider.c |   56 +++++++++++++++++++------------
 providers/oracle/libmain.c             |    7 +++-
 providers/oracle/oracle.gresource.xml  |    8 ++++
 4 files changed, 61 insertions(+), 26 deletions(-)
---
diff --git a/providers/oracle/Makefile.am b/providers/oracle/Makefile.am
index 33193d1..7f70ef4 100644
--- a/providers/oracle/Makefile.am
+++ b/providers/oracle/Makefile.am
@@ -51,6 +51,7 @@ libgda_oracle_la_SOURCES = \
        gda-oracle-util.c \
        gda-oracle-util.h \
        gda-oracle.h \
+       oracle.gresources.c \
        libmain.c \
        parser.h \
         parser.c \
@@ -64,12 +65,22 @@ libgda_oracle_la_LIBADD = \
 xmldir   = $(datadir)/libgda-6.0
 xml_in_files = \
        oracle_specs_dsn.xml.in \
-       oracle_specs_create_table.xml.in 
+       oracle_specs_create_table.xml.in \
+       oracle_specs_drop_table.xml.in
 
 @INTLTOOL_XML_RULE@
 
 xml_DATA = $(xml_in_files:.xml.in=.xml) 
 
+# resources
+RESOURCES=$(xml_in_files:.xml.in=.raw.xml)
+oracle.gresources.c: oracle.gresource.xml $(RESOURCES)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
$(srcdir)/oracle.gresource.xml
+
+%.raw.xml:%.xml.in
+       @echo "  GEN      $@"
+       @cat $< | sed -e 's/_\([a-zA-Z0-9]*\)=/\1=/g' -e 's/<_\([a-ZA-Z0-9_]*\)>/<\1>/g' -e 
's/<\/_\([a-ZA-Z0-9_]*\)>/<\/\1>/g' -e 's/<!-- .* -->//'> $@
+
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libgda-oracle-6.0.pc
 
@@ -77,4 +88,5 @@ EXTRA_DIST = $(xml_in_files) libgda-oracle-6.0.pc.in parser.y gen_def.c $(keywor
 DISTCLEANFILES = $(xml_DATA)
 
 CLEANFILES = parser.h parser.c parser.out oracle_token_types.h gen_def$(EXEEXT_FOR_BUILD) \
-       mkkeywordhash$(EXEEXT_FOR_BUILD) keywords_hash.c
+       mkkeywordhash$(EXEEXT_FOR_BUILD) keywords_hash.c \
+       oracle.gresources.c
diff --git a/providers/oracle/gda-oracle-provider.c b/providers/oracle/gda-oracle-provider.c
index 1535bd0..914e450 100644
--- a/providers/oracle/gda-oracle-provider.c
+++ b/providers/oracle/gda-oracle-provider.c
@@ -882,23 +882,28 @@ gda_oracle_provider_create_operation (GdaServerProvider *provider, GdaConnection
        }
 
         file = g_utf8_strdown (gda_server_operation_op_type_to_string (type), -1);
-        str = g_strdup_printf ("oracle_specs_%s.xml", file);
+        str = g_strdup_printf ("oracle_specs_%s", file);
         g_free (file);
 
+       gchar *tmp;
+       tmp = g_strdup_printf ("%s.xml", str);
        dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
-        file = gda_server_provider_find_file (provider, dir, str);
+        file = gda_server_provider_find_file (provider, dir, tmp);
        g_free (dir);
+       g_free (tmp);
 
-        if (! file) {
-                g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_FILE_NOT_FOUND_ERROR,
-                            _("Missing spec. file '%s'"), str);
+        if (file) {
                g_free (str);
-                return NULL;
+               op = gda_server_operation_new (type, file);
+               g_free (file);
         }
-        g_free (str);
-
-        op = gda_server_operation_new (type, file);
-        g_free (file);
+       else {
+               file = g_strdup_printf ("/spec/oracle/%s.raw.xml", str);
+               g_free (str);
+               op = GDA_SERVER_OPERATION (g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", type,
+                                                        "spec-resource", file, NULL));
+               g_free (file);
+       }
 
         return op;
 }
@@ -922,25 +927,32 @@ gda_oracle_provider_render_operation (GdaServerProvider *provider, GdaConnection
 
        /* test @op's validity */
         file = g_utf8_strdown (gda_server_operation_op_type_to_string (gda_server_operation_get_op_type 
(op)), -1);
-        str = g_strdup_printf ("oracle_specs_%s.xml", file);
+        str = g_strdup_printf ("oracle_specs_%s", file);
         g_free (file);
 
+       gchar *tmp;
+       tmp = g_strdup_printf ("%s.xml", str);
        dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
-        file = gda_server_provider_find_file (provider, dir, str);
+        file = gda_server_provider_find_file (provider, dir, tmp);
        g_free (dir);
+       g_free (tmp);
 
-        if (! file) {
-                g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_FILE_NOT_FOUND_ERROR,
-                            _("Missing spec. file '%s'"), str);
+       if (file) {
                g_free (str);
-                return NULL;
-        }
-        g_free (str);
-        if (!gda_server_operation_is_valid (op, file, error)) {
-                g_free (file);
-                return NULL;
+               if (!gda_server_operation_is_valid (op, file, error)) {
+                       g_free (file);
+                       return NULL;
+               }
+       }
+       else {
+               file = g_strdup_printf ("/spec/oracle/%s.raw.xml", str);
+               g_free (str);
+               if (!gda_server_operation_is_valid_from_resource (op, file, error)) {
+                       g_free (file);
+                       return NULL;
+               }
         }
-        g_free (file);
+       g_free (file);
 
        /* actual rendering */
         switch (gda_server_operation_get_op_type (op)) {
diff --git a/providers/oracle/libmain.c b/providers/oracle/libmain.c
index d4c800e..606f8f1 100644
--- a/providers/oracle/libmain.c
+++ b/providers/oracle/libmain.c
@@ -2,7 +2,7 @@
  * Copyright (C) 2001 - 2003 Gonzalo Paniagua Javier <gonzalo gnome-db org>
  * Copyright (C) 2001 - 2004 Rodrigo Moya <rodrigo gnome-db org>
  * Copyright (C) 2002 Tim Coleman <tim timcoleman com>
- * Copyright (C) 2006 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2006 - 2015 Vivien Malerba <malerba gnome-db org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -80,7 +80,10 @@ plugin_get_dsn_spec (void)
        dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
        ret = gda_server_provider_load_file_contents (module_path, dir, "oracle_specs_dsn.xml");
        g_free (dir);
-       return ret;
+       if (ret)
+               return ret;
+       else
+               return gda_server_provider_load_resource_contents ("oracle", "oracle_specs_dsn.raw.xml");
 }
 
 GdaServerProvider *
diff --git a/providers/oracle/oracle.gresource.xml b/providers/oracle/oracle.gresource.xml
new file mode 100644
index 0000000..c50f869
--- /dev/null
+++ b/providers/oracle/oracle.gresource.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/spec/oracle">
+    <file compressed="true">oracle_specs_create_table.raw.xml</file>
+    <file compressed="true">oracle_specs_drop_table.raw.xml</file>
+    <file compressed="true">oracle_specs_dsn.raw.xml</file>
+  </gresource>
+</gresources>


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