[libgda] GdaData.Object and GdaData.DataModelIterable API Change.
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaData.Object and GdaData.DataModelIterable API Change.
- Date: Thu, 22 Dec 2011 19:23:46 +0000 (UTC)
commit 8dbea343908c21b92b48b25bbb73bf1967372a9a
Author: Daniel Espinosa <despinosa src gnome org>
Date: Thu Dec 22 11:28:30 2011 -0600
GdaData.Object and GdaData.DataModelIterable API Change.
* GdaData.Object.record is now a Gda.DataModel
* GdaData.DataModelIterable no avoids to implement Gda.DataModel interface due to no public functions. Even that you can use most of the public functions as if it is a Gda.DataModel but you can't cast to.
* Work on samples continue.
libgda/data/DataModelIterator.vala | 49 +++++++++--------
libgda/data/DataObject.vala | 6 +-
libgda/data/GdaData-5.0.gir | 103 +++++++++++++++++++++++++++++++++++-
samples/vala/Makefile | 25 +++++++++
samples/vala/SampleDataObject.vala | 47 +++++++++-------
5 files changed, 181 insertions(+), 49 deletions(-)
---
diff --git a/libgda/data/DataModelIterator.vala b/libgda/data/DataModelIterator.vala
index c7f01f8..c6ec4da 100644
--- a/libgda/data/DataModelIterator.vala
+++ b/libgda/data/DataModelIterator.vala
@@ -22,7 +22,7 @@
namespace GdaData {
- public class DataModelIterable : Gee.AbstractCollection<Value?>, Gda.DataModel
+ public class DataModelIterable : Gee.AbstractCollection<Value?>
{
private Gda.DataModel model;
@@ -328,30 +328,31 @@
return this.model.get_value_at (col, row);
}
- public bool i_get_notify () {
- return ((Gda.DataSelect)this.model).i_get_notify ();
- }
+ // THIS FUNCTIONS HAVEN'T DEFAULT IMPLEMENTATION OR PUBLIC API AND THEN CAN'T BE IMPLEMENTED HERE
+// public bool i_get_notify () {
+// return this.model.notify_changes i_get_notify ();
+// }
- public bool i_iter_at_row (Gda.DataModelIter iter, int row) {
- return ((Gda.DataSelect)this.model).i_iter_at_row (iter, row);
- }
-
- public bool i_iter_next (Gda.DataModelIter iter) {
- return ((Gda.DataSelect)this.model).i_iter_next (iter);
- }
-
- public bool i_iter_prev (Gda.DataModelIter iter) {
- return ((Gda.DataSelect)this.model).i_iter_prev (iter);
- }
-
- public bool i_iter_set_value (Gda.DataModelIter iter, int col, GLib.Value value) throws GLib.Error {
- return ((Gda.DataSelect)this.model).i_iter_set_value (iter, col, value);
- }
-
- public void i_set_notify (bool do_notify_changes)
- {
- ((Gda.DataSelect)this.model).i_set_notify (do_notify_changes);
- }
+// public bool i_iter_at_row (Gda.DataModelIter iter, int row) {
+// return ((Gda.DataSelect)this.model).i_iter_at_row (iter, row);
+// }
+//
+// public bool i_iter_next (Gda.DataModelIter iter) {
+// return ((Gda.DataSelect)this.model).i_iter_next (iter);
+// }
+//
+// public bool i_iter_prev (Gda.DataModelIter iter) {
+// return ((Gda.DataSelect)this.model).i_iter_prev (iter);
+// }
+//
+// public bool i_iter_set_value (Gda.DataModelIter iter, int col, GLib.Value value) throws GLib.Error {
+// return ((Gda.DataSelect)this.model).i_iter_set_value (iter, col, value);
+// }
+//
+// public void i_set_notify (bool do_notify_changes)
+// {
+// ((Gda.DataSelect)this.model).i_set_notify (do_notify_changes);
+// }
public bool remove_row (int row) throws GLib.Error {
return this.model.remove_row (row);
}
diff --git a/libgda/data/DataObject.vala b/libgda/data/DataObject.vala
index c31d431..f926e98 100644
--- a/libgda/data/DataObject.vala
+++ b/libgda/data/DataObject.vala
@@ -26,11 +26,11 @@ namespace GdaData {
private string? _field_id;
private Value? _id_value;
- private DataModelIterable _model;
+ private DataModel _model;
public abstract string table { get; }
- public DataModelIterable record {
+ public DataModel record {
get {
return this._model;
}
@@ -61,7 +61,7 @@ namespace GdaData {
var s = q.get_statement ();
var m = this.connection.statement_execute_select (s, null);
((DataSelect) m).compute_modification_statements ();
- this._model= new DataModelIterable ((DataProxy) DataProxy.new (m));
+ this._model= (DataModel) DataProxy.new (m);
}
public unowned Value? get_value (string field)
diff --git a/libgda/data/GdaData-5.0.gir b/libgda/data/GdaData-5.0.gir
index 94a2ee3..062bf9b 100644
--- a/libgda/data/GdaData-5.0.gir
+++ b/libgda/data/GdaData-5.0.gir
@@ -86,7 +86,7 @@
<type name="utf8" c:type="gchar*"/>
</property>
<property name="record">
- <type name="GdaData.DataModelIterable" c:type="GdaDataDataModelIterable*"/>
+ <type name="Gda.DataModel" c:type="GdaDataModel*"/>
</property>
<property name="connection" writable="1">
<type name="Gda.Connection" c:type="GdaConnection*"/>
@@ -99,7 +99,6 @@
</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>
@@ -129,6 +128,106 @@
<type name="none"/>
</return-value>
</method>
+ <method name="append_row" c:identifier="gda_data_data_model_iterable_append_row" throws="1">
+ <return-value transfer-ownership="full">
+ <type name="gint" c:type="gint"/>
+ </return-value>
+ </method>
+ <method name="create_iter" c:identifier="gda_data_data_model_iterable_create_iter">
+ <return-value transfer-ownership="full">
+ <type name="Gda.DataModelIter" c:type="GdaDataModelIter*"/>
+ </return-value>
+ </method>
+ <method name="describe_column" c:identifier="gda_data_data_model_iterable_describe_column">
+ <parameters>
+ <parameter name="col" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="none">
+ <type name="Gda.Column" c:type="GdaColumn*"/>
+ </return-value>
+ </method>
+ <method name="get_access_flags" c:identifier="gda_data_data_model_iterable_get_access_flags">
+ <return-value transfer-ownership="full">
+ <type name="Gda.DataModelAccessFlags" c:type="GdaDataModelAccessFlags"/>
+ </return-value>
+ </method>
+ <method name="get_attributes_at" c:identifier="gda_data_data_model_iterable_get_attributes_at">
+ <parameters>
+ <parameter name="col" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ <parameter name="row" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="Gda.ValueAttribute" c:type="GdaValueAttribute"/>
+ </return-value>
+ </method>
+ <method name="get_n_columns" c:identifier="gda_data_data_model_iterable_get_n_columns">
+ <return-value transfer-ownership="full">
+ <type name="gint" c:type="gint"/>
+ </return-value>
+ </method>
+ <method name="get_n_rows" c:identifier="gda_data_data_model_iterable_get_n_rows">
+ <return-value transfer-ownership="full">
+ <type name="gint" c:type="gint"/>
+ </return-value>
+ </method>
+ <method name="get_value_at" c:identifier="gda_data_data_model_iterable_get_value_at" throws="1">
+ <parameters>
+ <parameter name="col" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ <parameter name="row" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="none" allow-none="1">
+ <type name="GObject.Value" c:type="GValue*"/>
+ </return-value>
+ </method>
+ <method name="remove_row" c:identifier="gda_data_data_model_iterable_remove_row" throws="1">
+ <parameters>
+ <parameter name="row" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="gboolean" c:type="gboolean"/>
+ </return-value>
+ </method>
+ <method name="send_hint" c:identifier="gda_data_data_model_iterable_send_hint">
+ <parameters>
+ <parameter name="hint" transfer-ownership="none">
+ <type name="Gda.DataModelHint" c:type="GdaDataModelHint"/>
+ </parameter>
+ <parameter name="hint_value" transfer-ownership="none" allow-none="1">
+ <type name="GObject.Value" c:type="GValue*"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="none"/>
+ </return-value>
+ </method>
+ <method name="set_value_at" c:identifier="gda_data_data_model_iterable_set_value_at" throws="1">
+ <parameters>
+ <parameter name="col" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ <parameter name="row" transfer-ownership="none">
+ <type name="gint" c:type="gint"/>
+ </parameter>
+ <parameter name="value" transfer-ownership="none">
+ <type name="GObject.Value" c:type="GValue"/>
+ </parameter>
+ </parameters>
+ <return-value transfer-ownership="full">
+ <type name="gboolean" c:type="gboolean"/>
+ </return-value>
+ </method>
<property name="element-type">
<type name="GObject.Type" c:type="GType"/>
</property>
diff --git a/samples/vala/Makefile b/samples/vala/Makefile
new file mode 100644
index 0000000..9189634
--- /dev/null
+++ b/samples/vala/Makefile
@@ -0,0 +1,25 @@
+NULL =
+CFLAGS = \
+ -Wall -g \
+ `pkg-config --cflags libgdadata-5.0` \
+ $(NULL)
+
+LDFLAGS = `pkg-config --libs libgdadata-5.0`
+
+VALAFLAGS = --pkg libgda-5.0 --pkg gdadata-5.0 --pkg gee-0.8 --pkg libxml-2.0
+
+all: sampledataobject
+
+SampleDataObject.c:
+ valac $(VALAFLAGS) -C SampleDataObject.vala
+
+sampledataobject: SampleDataObject.c
+ $(CC) -o sampledataobject SampleDataObject.c $(CFLAGS) $(LDFLAGS)
+
+
+clean:
+ rm -f *~
+ rm -f *.o
+ rm -f *.c
+ rm -f *.db
+ rm sampledataobject
diff --git a/samples/vala/SampleDataObject.vala b/samples/vala/SampleDataObject.vala
index d4b3da9..b44926c 100644
--- a/samples/vala/SampleDataObject.vala
+++ b/samples/vala/SampleDataObject.vala
@@ -86,24 +86,20 @@ namespace Sample {
class App : GLib.Object {
public Gda.Connection connection;
- App ()
+ public void init ()
+ throws Error
{
- try {
- GLib.FileUtils.unlink("dataobject.db");
- stdout.printf("Creating Database...\n");
- this.connection = Connection.open_from_string("SQLite",
- "DB_DIR=.;DB_NAME=dataobject", null,
- Gda.ConnectionOptions.NONE);
- stdout.printf("Creating table 'user'...\n");
- this.connection.execute_non_select_command("CREATE TABLE user (id int PRIMARY KEY AUTOINCREMENT, name string UNIQUE, functions string, security_number int)");
- this.connection.execute_non_select_command("INSERT INTO user (id, name, functions) VALUES (1, \"Martin Stewart\", \"Programmer, QA\", 2334556");
- this.connection.execute_non_select_command("INSERT INTO user (id, name, functions) VALUES (2, \"Jane Castle\", \"Accountant\", 3002884");
-
- this.connection.update_meta_store(null);
- }
- catch (Error e) {
- stdout.printf ("Can't create temporary database...\nERROR: " + e.message + "\n");
- }
+ GLib.FileUtils.unlink("dataobject.db");
+ stdout.printf("Creating Database...\n");
+ this.connection = Connection.open_from_string("SQLite",
+ "DB_DIR=.;DB_NAME=dataobject", null,
+ Gda.ConnectionOptions.NONE);
+ stdout.printf("Creating table 'user'...\n");
+ this.connection.execute_non_select_command("CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT, name string UNIQUE, functions string, security_number integer)");
+ this.connection.execute_non_select_command("INSERT INTO user (id, name, functions) VALUES (1, \"Martin Stewart\", \"Programmer, QA\", 2334556");
+ this.connection.execute_non_select_command("INSERT INTO user (id, name, functions) VALUES (2, \"Jane Castle\", \"Accountant\", 3002884");
+
+ this.connection.update_meta_store(null);
}
public void modify_record (string name)
@@ -112,11 +108,13 @@ namespace Sample {
var rcd = new DbRecord ();
rcd.open (name);
- stdout.printf ("Modifing user: " + rcd.name);
- foreach (Value v in rcd.record) {
+ stdout.printf ("Initial Values: " + rcd.name + "\n");
+ var record = new DataModelIterable (rcd.record);
+ foreach (Value v in record) {
stdout.printf ("Field Value: " + Gda.value_stringify (v));
}
+ stdout.printf ("Modifing user: " + rcd.name + "\n");
// Changing functions
rcd.functions += ", Hardware Maintenance";
@@ -126,13 +124,22 @@ namespace Sample {
// Changing non class property value in the record
// You must know the field name refer to
string v = (string) rcd.get_value ("security_number");
- stdout.printf ("Taken value from a field in the DB: " + Gda.value_stringify (v));
+ stdout.printf ("Taken value from a field in the DB: " + Gda.value_stringify (v) + "\n");
+
+ rcd.set_value ("security_number", 1002335);
+
+ stdout.printf ("Modified Values: " + rcd.name);
+ record = new DataModelIterable (rcd.record);
+ foreach (Value v2 in record) {
+ stdout.printf ("Field Value: " + Gda.value_stringify (v2) + "\n");
+ }
}
public static int main (string[] args) {
stdout.printf ("Gda.DataObject Example...\n");
var app = new App ();
try {
+ app.init ();
app.modify_record ("Martin Stewart");
app.modify_record ("Jane Castle");
return 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]