[libgda/libgda-vala: 9/9] Progress to get libgdadata build and switching from libgdavala
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/libgda-vala: 9/9] Progress to get libgdadata build and switching from libgdavala
- Date: Fri, 25 Nov 2011 18:07:32 +0000 (UTC)
commit 1969ea2d0077244498bac078146e02059d2a167d
Author: Daniel Espinosa <despinosa src gnome org>
Date: Fri Nov 25 11:59:28 2011 -0600
Progress to get libgdadata build and switching from libgdavala
* Added --enable-vala-extensions (default to no) to build vala extensions
* Improved package search and messages output from configure
* Moved vala extensions from libgda/vala to libgda/data, more extensions wil get its own subdir and namespace
* Changed namespace from Gda to GdaData for this initial extensions
* Still changing from libgdavala to libgdadata
* Some improvements to Unity Test for GdaDataObject
configure.ac | 34 +++++++++--
libgda/Makefile.am | 2 +-
libgda/data/DataObject.vala | 100 +++++++++++++++++++++++++++++++
libgda/data/Makefile.am | 103 ++++++++++++++++++++++++++++++++
libgda/{vala => data}/SelectQuery.vala | 69 ++++++++++++---------
libgda/data/config.vapi | 11 ++++
libgda/vala/DataObject.vala | 78 ------------------------
tests/Makefile.am | 2 +-
tests/vala/CheckDataObject.vala | 47 ++++++++++-----
tests/vala/Makefile.am | 34 +++++------
10 files changed, 331 insertions(+), 149 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index eb5c795..f6df645 100644
--- a/configure.ac
+++ b/configure.ac
@@ -473,16 +473,20 @@ AC_ARG_ENABLE([vala],
AS_HELP_STRING([--enable-vala], [Enable support for Vala bindings generation [default=auto]]),
[enable_vala=$enableval],[enable_vala=auto])
+AC_ARG_ENABLE([vala-extensions],
+ AS_HELP_STRING([--enable-vala-extensions], [Enable support for Vala extensions [default=no]]),
+ [enable_vala_ext=$enableval],[enable_vala_ext=no])
+
have_vala=no
if test "x$found_introspection" = "xyes"
then
VALA_MODULES="libvala-0.14 >= 0.14"
PKG_CHECK_MODULES(VALA, $VALA_MODULES,
- if test "$enable_vala" = "yes" -o "$enable_vala" = "auto"
+ if test "$enable_vala" = "yes" -o "$enable_vala" = "auto"
then
- have_vala=yes
+ have_vala=yes
AC_DEFINE(HAVE_VALA, [], [Defined if Vala support is enabled])
- fi,
+ fi
if test "$enable_vala" = "yes"
then
AC_MSG_ERROR([Vala support requested but not found])
@@ -497,7 +501,23 @@ then
VALA_VAPIGEN=`pkg-config $VALA_MODULES --variable=vapigen`
AC_SUBST(VALA_VAPIGEN)
VALA_VAPIDIR=`pkg-config $VALA_MODULES --variable=vapidir`
- AC_SUBST(VALA_VAPIDIR)
+ AC_SUBST(VALA_VAPIDIR)
+
+ if test "x$enable_vala_ext" = "xyes"
+ then
+dnl Check for libgee
+ GEE_REQUIRED="0.6.1"
+
+ PKG_CHECK_MODULES(GEE, gee-1.0 >= $GEE_REQUIRED)
+ AC_SUBST(GEE_CFLAGS)
+ AC_SUBST(GEE_LIBS)
+ fi
+ else
+ if test "x$enable_vala_ext" = "xyes"
+ then
+ AC_MSG_ERROR([Vala extensions for Libgda are requested but Vala is not available or enable])
+ $enable_vala_ext = "no"
+ fi
fi
else
if test "x$enable_vala" = xyes
@@ -508,7 +528,7 @@ fi
enable_vala=$have_vala
AM_CONDITIONAL(ENABLE_VALA, [test "$enable_vala" = "yes"])
-
+AM_CONDITIONAL(ENABLE_VALA_EXTENSIONS, [test "$enable_vala_ext" = "yes"])
dnl ******************************
dnl Checks for libcrypto
@@ -878,6 +898,8 @@ libgda/sqlite/sqlite-src/Makefile
libgda/sqlite/virtual/libgda-virtual.h
libgda/sqlite/virtual/Makefile
libgda/thread-wrapper/Makefile
+libgda/data/Makefile
+libgda/data/libgdadata-1.0.pc
providers/Makefile
providers/reuseable/Makefile
providers/reuseable/postgres/Makefile
@@ -949,6 +971,7 @@ tests/providers/Makefile
tests/value-holders/Makefile
tests/meta-store/Makefile
tests/multi-threading/Makefile
+tests/vala/Makefile
doc/Makefile
doc/C/Makefile
doc/C/libgda.types
@@ -990,6 +1013,7 @@ echo " Building Libxslt extension: `if test x$have_xslt != xno; then echo yes;
echo " Building libgda GObject Introspection: `if test x$enable_gda_gi != xno; then echo yes; else echo no; fi`"
echo " Building libgda-ui GObject Introspection: `if test x$enable_gdaui_gi != xno; then echo yes; else echo no; fi`"
echo " Building Vala Bindings: `if test x$enable_vala != xno; then echo yes; else echo no; fi`"
+echo " Building Vala Extensions: `if test x$enable_vala_ext != xno; then echo yes; else echo no; fi`"
echo " Compiled providers:"
echo " Berkeley DB = $bdb_found"
echo " Berkeley DB SQL = $bdbsql_found"
diff --git a/libgda/Makefile.am b/libgda/Makefile.am
index e55c963..b7291be 100644
--- a/libgda/Makefile.am
+++ b/libgda/Makefile.am
@@ -2,7 +2,7 @@ QUIET_GEN = $(Q:@= echo ' GEN '$@;)
lib_LTLIBRARIES = libgda-5.0.la
-SUBDIRS = sqlite handlers binreloc sql-parser providers-support thread-wrapper
+SUBDIRS = sqlite handlers binreloc sql-parser providers-support thread-wrapper data
DEF_FLAGS=
if BDB
diff --git a/libgda/data/DataObject.vala b/libgda/data/DataObject.vala
new file mode 100644
index 0000000..6e25ca1
--- /dev/null
+++ b/libgda/data/DataObject.vala
@@ -0,0 +1,100 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdavala
+ * Copyright (C) Daniel Espinosa Ortiz 2011 <esodan gmail com>
+ *
+ * libgda 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libgda 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 program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gda;
+
+[CCode (cheader_filename="libgda/data/libgdadata.h")]
+namespace GdaData {
+
+ public abstract class Object : GLib.Object {
+
+ private DataModel? _model;
+ private string? _field_id;
+ private Value? _id_value;
+
+ protected string? _table;
+
+ public Connection connection { get; set; }
+
+ public string get_field_id ()
+ {
+ return this._field_id;
+ }
+
+ public Value get_value_id ()
+ {
+ return this._id_value;
+ }
+
+ /*
+ * Set a condition to get only one row data from the table in the database.
+ */
+ public void set_id (string field, Value v)
+ throws Error
+ requires (this._table != "")
+ {
+ this._field_id = field;
+ this._id_value = v;
+ var q = this.build ();
+ var s = q.get_statement ();
+ var m = this.connection.statement_execute_select (s, null);
+ ((DataSelect) m).compute_modification_statements ();
+ this._model = (DataProxy) DataProxy.new (m);
+ }
+
+ public unowned Value? get_value (string field)
+ throws Error
+ {
+ return this._model.get_value_at (this._model.get_column_index (field), 0);
+ }
+
+ public void set_value (string field, Value v)
+ throws Error
+ {
+ this._model.set_value_at (this._model.get_column_index (field), 0, v);
+ }
+
+ public void save ()
+ throws Error
+ {
+ ((DataProxy) this._model).apply_all_changes ();
+ }
+
+ public void update ()
+ throws Error
+ requires (this._table != "")
+ {
+ set_id (this._field_id, this._id_value);
+ }
+
+ private SqlBuilder build ()
+ requires (this._table != null || this._table != "")
+ requires (this._field_id != null || this._field_id != "")
+ requires (this._id_value != null)
+ {
+ var q = new SqlBuilder (SqlStatementType.SELECT);
+ q.select_add_target (this._table, null);
+ var f_id = q.add_id (this._field_id);
+ var e_id = q.add_expr_value (null, this._id_value);
+ var c_id = q.add_cond (SqlOperatorType.EQ, f_id, e_id, 0);
+ q.set_where (c_id);
+ return q;
+ }
+ }
+}
diff --git a/libgda/data/Makefile.am b/libgda/data/Makefile.am
new file mode 100644
index 0000000..cb78280
--- /dev/null
+++ b/libgda/data/Makefile.am
@@ -0,0 +1,103 @@
+NULL =
+
+if ENABLE_VALA_EXTENSIONS
+
+AM_CPPFLAGS = \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\"
+
+BUILT_SOURCES = gdadata.vala.stamp
+CLEANFILES = gdadata.vala.stamp
+
+AM_CFLAGS =\
+ -Wall\
+ -g \
+ -I$(top_srcdir) -I$(srcdir)/.. \
+ -I$(top_builddir) \
+ $(COREDEPS_CFLAGS) \
+ $(LIBGDA_WFLAGDS) \
+ $(LIBGDA_CFLAGS) \
+ $(GEE_CFLAGS) \
+ $(VALA_CFLAGS) \
+ $(NULL)
+
+lib_LTLIBRARIES = libgdadata.la
+
+VALAFLAGS = \
+ $(top_srcdir)/libgda/data/config.vapi \
+ --vapidir=$(top_srcdir)/libgda \
+ --pkg libxml-2.0 \
+ --pkg gee-1.0 \
+ --pkg libgda-5.0 \
+ $(NULL)
+
+libgdadata_la_VALASOURCES = \
+ DataObject.vala \
+ SelectQuery.vala \
+ $(NULL)
+
+libgdavala_la_SOURCES = \
+ gdadata.vala.stamp \
+ $(libgdadata_la_VALASOURCES:.vala=.c) \
+ $(NULL)
+
+gdadata-1.0.vapi gdadata.vala.stamp GdaData-1.0.gir: $(libgdadata_la_VALASOURCES)
+ $(VALA_COMPILER) $(VALAFLAGS) -C -H libgdadata.h --gir=GdaData-1.0.gir --library gdadata-1.0 $^
+ @touch $@
+
+CLEANFILES+= gdadata-1.0.vapi GdaData-1.0.gir
+
+libgdavala_la_LDFLAGS =
+
+libgdavala_la_LIBADD = \
+ $(LIBGDA_LIBS) \
+ $(GEE_LIBS) \
+ $(VALA_LIBS) \
+ $(NULL)
+
+include_HEADERS = \
+ libgdadata.h \
+ $(NULL)
+
+gdavalaincludedir = $(includedir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)/libgda/data
+gdavalainclude_HEADERS = libgdadata.h
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libgdadata-1.0.pc
+
+# GObject Introspection
+
+if ENABLE_GI_SYSTEM_INSTALL
+girdir = $(INTROSPECTION_GIRDIR)
+typelibsdir = $(INTROSPECTION_TYPELIBDIR)
+else
+girdir = $(datadir)/gir-1.0
+typelibsdir = $(libdir)/girepository-1.0
+endif
+
+# GIR files are generated automatically by Valac then is not necessary to scan source code to generate it
+INTROSPECTION_GIRS =
+INTROSPECTION_GIRS += GdaData-1.0.gir
+INTROSPECTION_COMPILER_ARGS =
+
+GdaData-1.0.typelib: $(INTROSPECTION_GIRS)
+ $(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) --includedir=. $< -o $@
+
+gir_DATA = $(INTROSPECTION_GIRS)
+typelibs_DATA = GdaData-1.0.typelib
+
+vapidir = $(VALA_VAPIDIR)
+vapi_DATA = gdadata-1.0.vapi
+
+CLEANFILES += $(INTROSPECTION_GIRS) $(typelibs_DATA) gdadata-1.0.vapi
+
+EXTRA_DIST = \
+ libgdadata-1.0.pc.in \
+ $(libgdadata_la_VALASOURCES) \
+ $(vapi_DATA) \
+ $(INTROSPECTION_GIRS) \
+ $(typelibs_DATA) \
+ gdadata.vala.stamp
+
+endif
diff --git a/libgda/vala/SelectQuery.vala b/libgda/data/SelectQuery.vala
similarity index 52%
rename from libgda/vala/SelectQuery.vala
rename to libgda/data/SelectQuery.vala
index a565571..d7fdd3c 100644
--- a/libgda/vala/SelectQuery.vala
+++ b/libgda/data/SelectQuery.vala
@@ -1,7 +1,7 @@
/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
- * libgda
- * Copyright (C) Daniel Espinosa Ortiz 2008 <esodan gmail com>
+ * libgdavala
+ * Copyright (C) Daniel Espinosa Ortiz 2011 <esodan gmail com>
*
* libgda is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
@@ -17,66 +17,77 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Gee;
+using Gda;
-namespace Gda {
- [Compact]
- private class SelectQuery {
+namespace GdaData {
+
+ private class SelectQuery : Object {
- public Gee.ArrayList<string> _fields;
+ private Gee.ArrayList<string> _fields;
private SqlBuilder _sql;
-
- public string table { set; get; }
+ private string _table;
+
+ public string table {
+ get {
+ return this._table;
+ }
+ set {
+ this._table = value;
+ this._sql.select_add_target (value, null);
+ }
+ }
+
public Connection connection { set; get; }
- SelectQuery()
+ public SelectQuery()
{
- this.fields.add("*");
- this._cond = 0;
+ this._fields.add ("*");
this.table = "";
}
public void add_field (string field)
{
- if (this._fields.get(0) == "*")
+ if (this._fields.get (0) == "*")
{
- this._fields.clear();
+ this._fields.clear ();
}
- this.fields.add(field);
+ this._fields.add (field);
}
- public SqlBuilder build (void)
+ public SqlBuilder build ()
+ requires (this.table != "")
{
- this._sql = new SqlBuilder(Gda.SqlStatementType.SELECT);
+ this._sql = new SqlBuilder (Gda.SqlStatementType.SELECT);
- foreach string f in this._fields {
+ foreach (string f in this._fields) {
this._sql.select_add_field (f, null, null);
}
- this._sql.select_add_target(this.table, null);
+ return this._sql;
}
- public void set_fields_to_all (void)
+ public void set_fields_to_all ()
{
- this._fields.clear();
- this._fields.add("*");
+ this._fields.clear ();
+ this._fields.add ("*");
}
public void set_condition (string field, Value v, SqlOperatorType op)
{
- var f_id = this._sql.add_id (c.field);
- var e_id = this._sql.add_expr_value (null, c.v);
- var c_id = this._sql.add_cond(c.op, f_id, e_id, 0);
- this._sql.set_where(c_id);
+ var f_id = this._sql.add_id (field);
+ var e_id = this._sql.add_expr_value (null, v);
+ var c_id = this._sql.add_cond (op, f_id, e_id, 0);
+ this._sql.set_where (c_id);
}
- public DataModel execute (void)
+ public DataModel execute ()
throws Error
requires (this.connection.is_opened())
{
/* Build Select Query */
- var b = this.build();
- var s = b.get_statement();
- return this.connection.statement_execute_select(s, null);
+ var b = this.build ();
+ var s = b.get_statement ();
+ return this.connection.statement_execute_select (s, null);
}
}
}
diff --git a/libgda/data/config.vapi b/libgda/data/config.vapi
new file mode 100644
index 0000000..ee98230
--- /dev/null
+++ b/libgda/data/config.vapi
@@ -0,0 +1,11 @@
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Config {
+ public const string GETTEXT_PACKAGE;
+ public const string SPRITE_DIR;
+ public const string BACKGROUND_DIR;
+ public const string PACKAGE_DATA_DIR;
+ public const string PACKAGE_LOCALE_DIR;
+ public const string PACKAGE_NAME;
+ public const string PACKAGE_VERSION;
+ public const string VERSION;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 98822ce..6e448d6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,7 +5,7 @@ TESTS = test-ddl-creator test-bin-converter test-sql-identifier test-identifiers
check_PROGRAMS = test-ddl-creator test-bin-converter test-sql-identifier test-identifiers-quotes test-sql-builder test-connection-string-split test-input-parsers
-SUBDIRS = providers parser value-holders meta-store data-models multi-threading
+SUBDIRS = providers parser value-holders meta-store data-models multi-threading vala
AM_CPPFLAGS = \
-I$(top_builddir) \
diff --git a/tests/vala/CheckDataObject.vala b/tests/vala/CheckDataObject.vala
index 052c9ab..ffc4008 100644
--- a/tests/vala/CheckDataObject.vala
+++ b/tests/vala/CheckDataObject.vala
@@ -16,41 +16,56 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
+
+using Gda;
+using GdaData;
+
namespace Check {
- class Tests : DataObject {
+ class Tests : GdaData.Object {
Tests()
{
- this._cnn = Connection.open_sqlite(null, "check_dataobject", true);
- this._cnn.execute_non_select_command("CREATE TABLE user (int id, string name, string city)");
- this._cnn.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (1, \"Daniel\", \"Mexico\")");
- this._cnn.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (2, \"Jhon\", \"USA\")");
+ try {
+ this.connection = Connection.open_sqlite(null, "check_dataobject", true);
+ this.connection.execute_non_select_command("CREATE TABLE user (int id, string name, string city)");
+ this.connection.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (1, \"Daniel\", \"Mexico\")");
+ this.connection.execute_non_select_command("INSERT INTO user (id, name, city) VALUES (2, \"Jhon\", \"USA\")");
- this._cnn.execute_non_select_command("CREATE TABLE company (int id, string name, string responsability)");
- this._cnn.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (1, \"Telcsa\", \"Programing\")");
- this._cnn.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (2, \"Viasa\", \"Accessories\")");
+ this.connection.execute_non_select_command("CREATE TABLE company (int id, string name, string responsability)");
+ this.connection.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (1, \"Telcsa\", \"Programing\")");
+ this.connection.execute_non_select_command("INSERT INTO company (id, name, city) VALUES (2, \"Viasa\", \"Accessories\")");
+ }
+ catch (Error e) {
+ stdout.printf ("Couln't create temporary database...\n");
+ }
}
public int t1()
+ throws Error
{
+ int fails = 0;
this._table = "user";
Value v = 1;
this.set_id ("id", v);
var f = this.get_field_id();
- if ( f == "id")
- return 0;
- else
- return 1;
+ if ( f != "id")
+ fails++;
var i = this.get_value_id();
- if ( )
+ if (i != 1 )
+ fails++;
+
+ var vdb = this.get_value ("name");
+ if ( vdb != "Daniel")
+ fails++;
+
+ return fails;
}
public static int main (string[] args) {
stdout.printf ("Checking Gda.DataObject implementation\n");
int failures = 0;
- failures += t1 ();
- failures += t2 ();
+ var app = new Tests ();
+ failures += app.t1 ();
return failures != 0 ? 1 : 0;
}
}
diff --git a/tests/vala/Makefile.am b/tests/vala/Makefile.am
index f132806..e99b493 100644
--- a/tests/vala/Makefile.am
+++ b/tests/vala/Makefile.am
@@ -1,35 +1,31 @@
-AM_CPPFLAGS = \
- -I$(top_srcdir) \
- -I$(top_srcdir)/libgda \
- -I$(top_builddir) \
- $(COREDEPS_CFLAGS) \
- $(COREDEPS_WFLAGS) \
- $(JSON_GLIB_CFLAGS) \
- -DROOT_DIR=\""$(top_srcdir)"\"
+NULL =
+if ENABLE_VALA_EXTENSIONS
-TESTS_ENVIRONMENT = GDA_TOP_SRC_DIR="$(abs_top_srcdir)" GDA_TOP_BUILD_DIR="$(abs_top_builddir)"
+TESTS_ENVIRONMENT =
TESTS = check_dataobject
check_PROGRAMS = check_dataobject
-common_sources = common.c common.h
-
BUILT_SOURCES = check_dataobject.vala.stamp
CLEANFILES = check_dataobject.vala.stamp
VALAFLAGS = \
--pkg gee-1.0 \
--pkg gobject-2.0 \
- $(GDA_TOP_SRC_DIR)/libgda-5.0.vapi
+ --pkg libxml-2.0 \
+ --pkg libgda-5.0 \
+ --pkg gdadata-1.0 \
+ --includedir=$(top_builddir) \
+ --vapidir=$(top_srcdir)/libgda \
+ --vapidir=$(top_builddir)/libgda/data \
+ $(NULL)
check_dataobject_VALASOURCES = \
CheckDataObject.vala
-
-check_holder_SOURCES = \
- check_dataobject.vala.stamp \
- $(check_dataobject_VALASOURCES:.vala=.c)
-check_holder_LDADD = \
- $(top_builddir)/libgda/libgda-5.0.la \
- $(COREDEPS_LIBS)
+check_dataobject check_dataobject.vala.stamp: $(check_dataobject_VALASOURCES)
+ $(VALA_COMPILER) $(VALAFLAGS) -o check_dataobject $^
+ @touch $@
EXTRA_DIST =
+
+endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]