[libgda/libgda-vala] Fixed DataModelIterator build. API change on GdaData.Object for table property and build fixes.
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/libgda-vala] Fixed DataModelIterator build. API change on GdaData.Object for table property and build fixes.
- Date: Thu, 15 Dec 2011 00:31:48 +0000 (UTC)
commit 136d36f21325cd03d873324d70f11a3c0469c9b2
Author: Daniel Espinosa <despinosa src gnome org>
Date: Wed Dec 14 18:26:35 2011 -0600
Fixed DataModelIterator build. API change on GdaData.Object for table property and build fixes.
* Fixed implementation of Gee.AbstractCollection
* GdaData.Object.table property now allow to define a construct state to set its value to a internal variable is required like is done in Check Unit Test.
* Fixes on Unit Tests and API changes updates
* More work on SampleDataObject no compiles jet
libgda/data/DataModelIterator.vala | 2 +-
libgda/data/DataObject.vala | 2 +-
libgda/data/GdaData-5.0.gir | 173 ++++++++++++++++++++++++++++++++
samples/vala/SampleDataObject.vala | 72 +++++++++-----
tests/vala/CheckDataModelIterator.vala | 2 +-
tests/vala/CheckDataObject.vala | 18 ++--
6 files changed, 232 insertions(+), 37 deletions(-)
---
diff --git a/libgda/data/DataModelIterator.vala b/libgda/data/DataModelIterator.vala
index d564cc2..9cecdd3 100644
--- a/libgda/data/DataModelIterator.vala
+++ b/libgda/data/DataModelIterator.vala
@@ -560,7 +560,7 @@
}
}
} catch {}
- return l.iterator<A> ();
+ return l.iterator ();
}
}
}
diff --git a/libgda/data/DataObject.vala b/libgda/data/DataObject.vala
index b3b23bd..7f13fcb 100644
--- a/libgda/data/DataObject.vala
+++ b/libgda/data/DataObject.vala
@@ -28,7 +28,7 @@ namespace GdaData {
private Value? _id_value;
private DataModelIterable _model;
- public abstract string table { get; }
+ public abstract string table { get; construct; }
public DataModelIterable record {
get {
diff --git a/libgda/data/GdaData-5.0.gir b/libgda/data/GdaData-5.0.gir
new file mode 100644
index 0000000..d9e2f4c
--- /dev/null
+++ b/libgda/data/GdaData-5.0.gir
@@ -0,0 +1,173 @@
+<?xml version="1.0"?>
+<repository version="1.2" xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
+<include name="GObject" version="2.0"/>
+<include name="Gee" version="0.8"/>
+<include name="Gda" version="5.0"/>
+<package name="gdadata-5.0"/>
+<c:include name="libgdadata.h"/>
+<namespace name="GdaData" version="5.0" c:prefix="GdaData">
+ <annotation key="ccode.cheader-filename" value="libgdadata.h"/>
+ <class name="Object" c:type="GdaDataObject" glib:type-name="GdaDataObject" glib:get-type="gda_data_object_get_type" glib:type-struct="ObjectClass" parent="GObject.Object" abstract="1">
+ <field name="parent_instance">
+ <type name="GObject.Object" c:type="GObject"/>
+ </field>
+ <field name="priv">
+ <type name="ObjectPrivate" c:type="GdaDataObjectPrivate*"/>
+ </field>
+ <method name="get_field_id" c:identifier="gda_data_object_get_field_id">
+ <return-value transfer-ownership="full">
+ <type name="utf8" c:type="gchar*"/>
+ </return-value>
+ </method>
+ <method name="get_value_id" c:identifier="gda_data_object_get_value_id">
+ <parameters>
+ <parameter name="result" direction="out" transfer-ownership="full" caller-allocates="1">
+ <type name="GObject.Value" c:type="GValue"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="none">
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="set_id" c:identifier="gda_data_object_set_id" throws="1">
+ <parameters>
+ <parameter name="field" transfer-ownership="none">
+ <type name="utf8" c:type="const gchar*"/>
+ </parameter>
+ <parameter name="v" transfer-ownership="none">
+ <type name="GObject.Value" c:type="GValue"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="get_value" c:identifier="gda_data_object_get_value" throws="1">
+ <parameters>
+ <parameter name="field" transfer-ownership="none">
+ <type name="utf8" c:type="const gchar*"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="none" allow-none="1">
+ <type name="GObject.Value" c:type="GValue*"/>
+ </return-value>
+ </method>
+ <method name="set_value" c:identifier="gda_data_object_set_value" throws="1">
+ <parameters>
+ <parameter name="field" transfer-ownership="none">
+ <type name="utf8" c:type="const gchar*"/>
+ </parameter>
+ <parameter name="v" transfer-ownership="none">
+ <type name="GObject.Value" c:type="GValue"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="save" c:identifier="gda_data_object_save" throws="1">
+ <return-value transfer-ownership="full">
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="update" c:identifier="gda_data_object_update" throws="1">
+ <return-value transfer-ownership="full">
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="sql" c:identifier="gda_data_object_sql">
+ <return-value transfer-ownership="full">
+ <type name="Gda.SqlBuilder" c:type="GdaSqlBuilder*"/>
+ </return-value>
+ </method>
+ <property name="table" writable="1" construct-only="1">
+ <type name="utf8" c:type="gchar*"/>
+ </property>
+ <property name="record">
+ <type name="GdaData.DataModelIterable" c:type="GdaDataDataModelIterable*"/>
+ </property>
+ <property name="connection" writable="1">
+ <type name="Gda.Connection" c:type="GdaConnection*"/>
+ </property>
+ </class>
+ <record name="ObjectClass" c:type="GdaDataObjectClass" glib:is-gtype-struct-for="Object">
+ <field name="parent_class">
+ <type name="GObject.ObjectClass" c:type="GObjectClass"/>
+ </field>
+ </record>
+ <record name="ObjectPrivate" c:type="GdaDataObjectPrivate" disguised="1"/>
+ <class name="DataModelIterable" c:type="GdaDataDataModelIterable" glib:type-name="GdaDataDataModelIterable" glib:get-type="gda_data_data_model_iterable_get_type" glib:type-struct="DataModelIterableClass" parent="Gee.AbstractCollection">
+ <implements name="Gda.DataModel"/>
+ <field name="parent_instance">
+ <type name="Gee.AbstractCollection" c:type="GeeAbstractCollection"/>
+ </field>
+ <field name="priv">
+ <type name="DataModelIterablePrivate" c:type="GdaDataDataModelIterablePrivate*"/>
+ </field>
+ <constructor name="new" c:identifier="gda_data_data_model_iterable_new">
+ <parameters>
+ <parameter name="model" transfer-ownership="none">
+ <type name="Gda.DataModel" c:type="GdaDataModel*"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="GdaData.DataModelIterable" c:type="GdaDataDataModelIterable*"/>
+ </return-value>
+ </constructor>
+ <method name="foreach" c:identifier="gda_data_data_model_iterable_foreach">
+ <parameters>
+ <parameter name="f" transfer-ownership="none" closure="1">
+ <type name="Gee.ForallFunc" c:type="GeeForallFunc"/>
+ </parameter>
+ <parameter name="f_target" transfer-ownership="none" allow-none="1">
+ <type name="gpointer" c:type="void*"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="none"/>
+ </return-value>
+ </method>
+ <property name="element-type">
+ <type name="GObject.Type" c:type="GType"/>
+ </property>
+ </class>
+ <record name="DataModelIterableClass" c:type="GdaDataDataModelIterableClass" glib:is-gtype-struct-for="DataModelIterable">
+ <field name="parent_class">
+ <type name="Gee.AbstractCollectionClass" c:type="GeeAbstractCollectionClass"/>
+ </field>
+ </record>
+ <record name="DataModelIterablePrivate" c:type="GdaDataDataModelIterablePrivate" disguised="1"/>
+ <class name="DataModelIterator" c:type="GdaDataDataModelIterator" glib:type-name="GdaDataDataModelIterator" glib:get-type="gda_data_data_model_iterator_get_type" glib:type-struct="DataModelIteratorClass" parent="GObject.Object">
+ <implements name="Gee.Traversable"/>
+ <implements name="Gee.Iterator"/>
+ <field name="parent_instance">
+ <type name="GObject.Object" c:type="GObject"/>
+ </field>
+ <field name="priv">
+ <type name="DataModelIteratorPrivate" c:type="GdaDataDataModelIteratorPrivate*"/>
+ </field>
+ <constructor name="new" c:identifier="gda_data_data_model_iterator_new">
+ <parameters>
+ <parameter name="model" transfer-ownership="none">
+ <type name="Gda.DataModel" c:type="GdaDataModel*"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="GdaData.DataModelIterator" c:type="GdaDataDataModelIterator*"/>
+ </return-value>
+ </constructor>
+ <property name="current-column">
+ <type name="gint" c:type="gint"/>
+ </property>
+ <property name="current-row">
+ <type name="gint" c:type="gint"/>
+ </property>
+ </class>
+ <record name="DataModelIteratorClass" c:type="GdaDataDataModelIteratorClass" glib:is-gtype-struct-for="DataModelIterator">
+ <field name="parent_class">
+ <type name="GObject.ObjectClass" c:type="GObjectClass"/>
+ </field>
+ </record>
+ <record name="DataModelIteratorPrivate" c:type="GdaDataDataModelIteratorPrivate" disguised="1"/>
+</namespace>
+</repository>
diff --git a/samples/vala/SampleDataObject.vala b/samples/vala/SampleDataObject.vala
index ec96d33..0f8732a 100644
--- a/samples/vala/SampleDataObject.vala
+++ b/samples/vala/SampleDataObject.vala
@@ -26,6 +26,7 @@ namespace Sample {
public override string table {
get { return "book"; }
+ construct {}
}
public Collection accounts {
@@ -36,19 +37,7 @@ namespace Sample {
return (Collection) new DataModelIterable (accs);
}
}
-
- public static Book create ( Gda.Connection cnn, string name, string manager)
- requires (cnn.is_open ())
- throws Error
- {
- string table = this._table;
- string sql = @"INSERT INTO $table (name, manager) VALUES ($name, $manager)";
- cnn.execute_non_select_command(sql);
- var b = new Book ();
- b.connection = cnn;
- b.open (name);
- }
-
+
public bool open (string name)
throws Error
{
@@ -63,6 +52,7 @@ namespace Sample {
class Account : GdaData.Object {
public override string table {
get { return "account"; }
+ construct {}
}
public Book book { get; set; }
/* Is possible to create properties to easy access to any field in the database row */
@@ -92,7 +82,9 @@ namespace Sample {
var model_debit = this.connection.execute_select (sql_debit);
var credit = model_credit.get_value_at (0, 0);
var debit = model_debit.get_value_at (0, 0);
-
+ var balance = (double) credit - (double) debit;
+ var ret = new Gda.Numeric ();
+ ret.set_from_string (ret.parse ());
}
}
@@ -106,8 +98,21 @@ namespace Sample {
class Transaction : GdaData.Object {
public override string table {
get { return "transaction"; }
+ construct {}
+ }
+ public Account account {
+ get {
+ var acc = new Account ();
+ Value idacc = this.get_value ("account");
+ acc.set_id ("id", idacc);
+ return acc;
+ }
+ set {
+ Account acc = value;
+ var id = acc.get_value ("id");
+ this.set_value ("account", id);
+ }
}
- public Account account { get; set; }
public string description {
get {
this.get_value ("description");
@@ -117,21 +122,35 @@ namespace Sample {
}
}
- public Gda.Numeric debit {
+ public double debit {
get {
- this.get_value ("debit");
+ var credit = (bool) this.get_value ("credit");
+ if (!credit)
+ return (double) this.get_value ("amount");
+ else
+ return 0;
}
set {
- this.set_value ("debit", value);
+ this.set_value ("amount", value);
+ bool credit = false;
+ Value v = credit;
+ this.set_value ("debit", v);
}
}
- public Gda.Numeric credit {
+ public double credit {
get {
- this.get_value ("credit");
+ var credit = (bool) this.get_value ("credit");
+ if (credit)
+ return (double) this.get_value ("amount");
+ else
+ return -1;
}
set {
- this.set_value ("credit", value);
+ this.set_value ("amount", value);
+ bool credit = true;
+ Value v = credit;
+ this.set_value ("debit", v);
}
}
}
@@ -148,12 +167,15 @@ namespace Sample {
stdout.printf("Creating table 'user'...\n");
this.connection.execute_non_select_command("CREATE TABLE book (id int PRIMARY KEY AUTOINCREMENT, name string NOT NULL UNIQUE, manager string)");
- this.connection.execute_non_select_command("INSERT INTO book (name, manager) VALUES (\"General Book\", \"Jhon\")");
+ this.connection.execute_non_select_command("INSERT INTO book (id, name, manager) VALUES (1, \"General Book\", \"Jhon\")");
stdout.printf("Creating table 'company'...\n");
- this.connection.execute_non_select_command("CREATE TABLE account (id int PRIMARY KEY AUTOINCREMENT, name string, description string)");
- this.connection.execute_non_select_command("INSERT INTO account (name) VALUES (\"Incomes\"");
- this.connection.execute_non_select_command("INSERT INTO account (name) VALUES (\"Expenses\"");
+ this.connection.execute_non_select_command("CREATE TABLE account (id int PRIMARY KEY AUTOINCREMENT, name string UNIQUE, description string)");
+ this.connection.execute_non_select_command("INSERT INTO account (id, name) VALUES (1, \"Incomes\"");
+ this.connection.execute_non_select_command("INSERT INTO account (id, name) VALUES (2, \"Expenses\"");
+ this.connection.execute_non_select_command("CREATE TABLE transaction (id int PRIMARY KEY AUTOINCREMENT, account int, description string, amount double, credit bool)");
+ this.connection.execute_non_select_command("INSERT INTO account (id, description, amount, credit) VALUES (1, \"Salary\"", );
+ this.connection.execute_non_select_command("INSERT INTO account (id, name) VALUES (2, \"Expenses\"");
this.connection.update_meta_store(null);
}
catch (Error e) {
diff --git a/tests/vala/CheckDataModelIterator.vala b/tests/vala/CheckDataModelIterator.vala
index b5d6268..9155afe 100644
--- a/tests/vala/CheckDataModelIterator.vala
+++ b/tests/vala/CheckDataModelIterator.vala
@@ -204,7 +204,7 @@ namespace Check {
var model = this.connection.execute_select_command ("SELECT * FROM user");
var itermodel = new DataModelIterable (model);
-
+ return fails;
}
public static int main (string[] args) {
diff --git a/tests/vala/CheckDataObject.vala b/tests/vala/CheckDataObject.vala
index 7689b95..8d0f746 100644
--- a/tests/vala/CheckDataObject.vala
+++ b/tests/vala/CheckDataObject.vala
@@ -24,8 +24,8 @@ namespace Check {
class Tests : GdaData.Object {
private string t;
public override string table {
- set construct { this.t = "user"; }
get { return this.t; }
+ construct { this.t = "user"; }
}
Tests()
{
@@ -69,8 +69,8 @@ namespace Check {
stdout.printf ("Couln't set ID...\nFAILS: %i\nERROR: %s\n", fails, e.message);
}
- stdout.printf("DataObject points to, in table '%s':\n", this.table);
- stdout.printf("%s\n", this._model.dump_as_string());
+ stdout.printf("DataObject points to, in table "+ this.table + ":\n", this.table);
+ stdout.printf("%s\n", this.record.dump_as_string());
stdout.printf("Getting ID value...\n");
var i = (int) this.get_value_id();
@@ -95,13 +95,13 @@ namespace Check {
Value n = "Daniel Espinosa";
this.set_value ("name", n);
stdout.printf("DataObject points to in memory modified value, in table '%s':\n", this.table);
- stdout.printf("%s\n", this._model.dump_as_string());
+ stdout.printf("%s\n", this.record.dump_as_string());
stdout.printf("Saving changes...\n");
try {
this.save();
stdout.printf("DataObject points to modified value, in table '%s':\n", this.table);
- stdout.printf("%s\n", this._model.dump_as_string());
+ stdout.printf("%s\n", this.record.dump_as_string());
}
catch (Error e) {
fails++;
@@ -120,7 +120,7 @@ namespace Check {
try {
this.update();
stdout.printf("DataObject points to actual stored values, in table '%s':\n", this.table);
- stdout.printf("%s\n", this._model.dump_as_string());
+ stdout.printf("%s\n", this.record.dump_as_string());
}
catch (Error e) {
fails++;
@@ -128,12 +128,12 @@ namespace Check {
}
stdout.printf("No Common Operation: Setting a new Table... \n");
- this._t = "company";
+ this.t = "company";
stdout.printf("Updating values from database using a new table 'company'...\n");
try {
this.update();
stdout.printf("DataObject points to actual stored values, in table '%s':\n", this.table);
- stdout.printf("%s\n", this._model.dump_as_string());
+ stdout.printf("%s\n", this.record.dump_as_string());
}
catch (Error e) {
fails++;
@@ -145,7 +145,7 @@ namespace Check {
try {
this.set_id ("id", v);
stdout.printf("DataObject points to actual stored values, in table '%s':\n", this.table);
- stdout.printf("%s\n", this._model.dump_as_string());
+ stdout.printf("%s\n", this.record.dump_as_string());
}
catch (Error e) {
fails++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]