[libgda] Ported to Gee 0.8. Vamp to Vala 0.17.7. * Fixed RecordCollection and RecordCollectionIterator * Set
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Ported to Gee 0.8. Vamp to Vala 0.17.7. * Fixed RecordCollection and RecordCollectionIterator * Set
- Date: Tue, 25 Sep 2012 00:12:19 +0000 (UTC)
commit b89b24b9264fcb982c33f4c81bda17ed0d952744
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Sep 24 19:07:21 2012 -0500
Ported to Gee 0.8. Vamp to Vala 0.17.7.
* Fixed RecordCollection and RecordCollectionIterator
* Set Vala and Gee to 0.17.7 (almost 0.18) and 0.8.0 respectively
configure.ac | 4 +-
libgda/data/RecordCollectionIterator.vala | 109 +--------------------
tests/vala/CheckDataModelIterator.vala | 146 ++++++++++++-----------------
3 files changed, 66 insertions(+), 193 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 986f059..1996826 100644
--- a/configure.ac
+++ b/configure.ac
@@ -479,11 +479,11 @@ AC_ARG_ENABLE([vala-extensions],
[enable_vala_ext=$enableval],[enable_vala_ext=no])
AS_CASE([$enable_vala_ext],[yes],[
- VAPIGEN_CHECK([0.17.5],[0.18])
+ VAPIGEN_CHECK([0.17.7],[0.18])
AS_CASE([$enable_vala],[yes],[
dnl Check for libgee
enable_vala_ext=yes
- GEE_REQUIRED="0.7.90"
+ GEE_REQUIRED="0.8.0"
PKG_CHECK_MODULES(GEE, gee-0.8 >= $GEE_REQUIRED)
AC_SUBST(GEE_CFLAGS)
AC_SUBST(GEE_LIBS)
diff --git a/libgda/data/RecordCollectionIterator.vala b/libgda/data/RecordCollectionIterator.vala
index f2d7cc3..0e18a71 100644
--- a/libgda/data/RecordCollectionIterator.vala
+++ b/libgda/data/RecordCollectionIterator.vala
@@ -25,91 +25,13 @@ namespace GdaData {
{
private DataModelIter _iter;
private DbTable _table;
- private int _length = -1;
- private int init_row = -1;
- private HashMap<int,int> _elements;
- private int filter_pos = -1;
public RecordCollectionIterator (DataModelIter iter, DbTable table)
{
_iter = iter;
_table = table;
- _elements = new HashMap<int,int>();
}
- private RecordCollectionIterator.filtered (DataModelIter iter, DbTable table,
- int init, int offset, int length,
- HashMap<int,int> elements, int filter_pos)
- {
- _iter = iter;
- _table = table;
- _elements = elements;
- this.filter_pos = filter_pos;
- if (init < 0 && offset >= 0) init = 0;
- if (init >= 0 && init < _iter.data_model.get_n_rows ()
- && init + offset >= 0
- && init + offset < _iter.data_model.get_n_rows ())
- {
- _iter.move_to_row (init + offset);
- init_row = _iter.current_row;
- if (length >= 0 && init + length < _iter.data_model.get_n_rows ())
- {
- _length = length;
- }
- }
- else
- init_row = -10; // Invalidate all the interator
- if (_elements.size > 0)
- init_row = -1; // Validate interator due to filtered values
- }
-
- // Traversable Interface
- public Iterator<A> stream<A> (owned StreamFunc<DbRecord, A> f) {
- var l = new Gee.ArrayList<A> ();
- Traversable.Stream str;
- Lazy<A>? initial = null;
- DbRecord r;
-
- str = f (Stream.YIELD, null, out initial);
- while (this.next ()) {
- if (this.valid) {
- r = this.get ();
- str = f (Stream.CONTINUE, new Lazy<DbRecord> (() => {return r;}), out initial);
- switch (str) {
- case Stream.CONTINUE:
- break;
- case Stream.YIELD:
- if (initial != null) {
- l.add (initial.value);
- }
- break;
- case Stream.END:
- return l.iterator();
- }
- }
- }
- return l.iterator ();
- }
-
- public Gee.Iterator<DbRecord> chop (int offset, int length = -1)
- {
- var iter = _iter.data_model.create_iter ();
- return new RecordCollectionIterator.filtered (iter, _table, _iter.current_row,
- offset, length, _elements, filter_pos);
- }
- public Gee.Iterator<DbRecord> filter (owned Gee.Predicate<DbRecord> f)
- {
- var elements = new Gee.HashMap <int,int> ();
- int pos = -1;
- while (this.next ()) {
- var r = this.get ();
- if (f(r)) {
- elements.set (++pos, _iter.current_row);
- }
- }
- var iter = _iter.data_model.create_iter ();
- return new RecordCollectionIterator.filtered (iter, _table, -1, 0, -1, elements, -1);
- }
public new bool @foreach (Gee.ForallFunc<DbRecord> f)
{
var r = this.get ();
@@ -136,25 +58,14 @@ namespace GdaData {
}
public bool has_next ()
{
- if ((_length >= 0) && (_iter.current_row + 1 < _length + init_row)
- && (_iter.current_row + 1 > _iter.data_model.get_n_rows ()))
- return false;
- if (_elements.size > 0)
- return filter_pos + 1 < _elements.size ? true : false;
-
return _iter.current_row + 1 <= _iter.data_model.get_n_rows () ? true : false;
}
public bool next ()
{
- if (this.has_next ()) {
- if (_elements.size > 0) {
- _iter.move_to_row (_elements.get (++filter_pos));
- return true;
- }
- else
- return _iter.move_next ();
- }
- return false;
+ if (this.has_next ())
+ return _iter.move_next ();
+ else
+ return false;
}
public void remove ()
{
@@ -172,17 +83,7 @@ namespace GdaData {
}
public bool valid {
get {
- if (init_row == -10)
- return false;
-
- if (_length >= 0)
- return (_iter.current_row >= init_row)
- && (_iter.current_row < _length + init_row) ? true : false;
- if (_elements.size > 0)
- return filter_pos < _elements.size;
-
- return (_iter.current_row >= 0) &&
- (_iter.current_row < _iter.data_model.get_n_rows ())? true : false;
+ return _iter.is_valid ();
}
}
}
diff --git a/tests/vala/CheckDataModelIterator.vala b/tests/vala/CheckDataModelIterator.vala
index 8622daa..576bbef 100644
--- a/tests/vala/CheckDataModelIterator.vala
+++ b/tests/vala/CheckDataModelIterator.vala
@@ -97,61 +97,76 @@ namespace Check {
{
int fails = 0;
stdout.printf (">>> TESTING: Chopping...\n");
- stdout.printf (" to get the 2nd DbRecord...\n");
+ stdout.printf (" to get from the 2nd DbRecord to the 6th...\n");
var iter = itermodel.chop (1);
- if (!iter.valid)
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
- else {
- stdout.printf (iter.get ().to_string () + "\n");
+ int i = 0;
+ while(iter.next()) {
+ stdout.printf (iter.get().to_string () + "\n");
+ i++;
var name = (string) iter.get().get_value ("name");
- if (name == "Jhon")
- stdout.printf ("+++++ PASS\n");
- else {
- fails++;
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
+ switch (i) {
+ case 1:
+ if (name != "Jhon")
+ fails++;
+ break;
+ case 2:
+ if (name != "James")
+ fails++;
+ break;
+ case 3:
+ if (name != "Jack")
+ fails++;
+ break;
+ case 4:
+ if (name != "Elsy")
+ fails++;
+ break;
+ case 5:
+ if (name != "Mayo")
+ fails++;
+ break;
}
}
-
+ if (fails != 0 || i != 5)
+ stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
+ else
+ stdout.printf ("+++++ PASS\n");
+
stdout.printf ("Choping to get the 4th to 5th DbRecords...\n");
var iter2 = itermodel.chop (3,2);
- if (!iter2.valid)
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
- else {
- stdout.printf ("Iterating over chopped records...\n");
- int i = 0;
- while (iter2.valid) {
- i++;
- stdout.printf (iter2.get ().to_string () + "\n");
- var name2 = (string) iter2.get().get_value ("name");
- if (i==1) {
- if (name2 != "Jack") {
- fails++;
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
- break;
- }
- }
- if (i==2) {
- if (name2 != "Elsy") {
- fails++;
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
- break;
- }
+ i = 0;
+ while (iter2.next ()) {
+ i++;
+ stdout.printf (iter2.get ().to_string () + "\n");
+ var name2 = (string) iter2.get().get_value ("name");
+ if (i==1) {
+ if (name2 != "Jack") {
+ fails++;
+ stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
+ break;
}
- iter2.next ();
}
- if (i!=2) {
- fails++;
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
+ if (i==2) {
+ if (name2 != "Elsy") {
+ fails++;
+ stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
+ break;
+ }
}
- stdout.printf ("+++++ PASS\n");
}
+ if (i!=2) {
+ fails++;
+ stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
+ }
+ else
+ stdout.printf ("+++++ PASS\n");
stdout.printf ("Choping offset = 7 must fail...\n");
var iter3 = itermodel.chop (7);
- if (iter3.valid)
+ if (iter3.has_next ())
stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
else {
- if (!iter3.next ())
+ if (iter3.next ())
stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
if (fails == 0)
stdout.printf ("+++++ PASS\n");
@@ -159,10 +174,10 @@ namespace Check {
stdout.printf ("Choping offset = 6 length = 0 must fail...\n");
var iter4 = itermodel.chop (6,0);
- if (iter4.valid)
+ if (iter4.has_next ())
stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
else {
- if (!iter4.next ())
+ if (iter4.next ())
stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
if (fails == 0)
stdout.printf ("+++++ PASS\n");
@@ -170,7 +185,7 @@ namespace Check {
stdout.printf ("Choping offset = 5 length = 1...\n");
var iter5 = itermodel.chop (5,1);
- if (!iter5.valid)
+ if (!iter5.next ())
stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
else {
if (iter5.next ())
@@ -178,17 +193,6 @@ namespace Check {
if (fails == 0)
stdout.printf ("+++++ PASS\n");
}
-
- stdout.printf ("Choping offset = 3 length = 1...\n");
- var iter6 = itermodel.chop (3,2);
- if (!iter6.valid)
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
- else {
- var tr = iter6.get().get_value ("name");
- if (tr==null)
- stdout.printf ("----- FAIL: " + (++fails).to_string () + "\n");
- }
-
if (fails == 0)
stdout.printf ("+++++ PASS: " + "\n");
return fails;
@@ -288,7 +292,7 @@ namespace Check {
{
stdout.printf (">>> INITIALIZING: DbRecordCollection/RecordCollection\n");
int fails = 0;
- var model = this.connection.execute_select_command ("SELECT * FROM user");
+ var model = this.connection.execute_select_command ("SELECT * FROM user ORDER BY id");
stdout.printf ("Setting up Table...");
var t = new Table ();
t.connection = this.connection;
@@ -301,38 +305,6 @@ namespace Check {
return fails;
}
- public int t2 ()
- {
- stdout.printf (">>> NEW TEST: GdaData.RecordCollection & RecordCollectionIterator API tests\n"
- + ">>> Testing Collection, Iterator, Traversable Interfaces implementation\n");
- int fails = 0;
- var model = this.connection.execute_select_command ("SELECT * FROM user");
- ((DataSelect) model).compute_modification_statements ();
- var pxy = new Gda.DataProxy.with_data_model (model);
- var t = new Table ();
- t.connection = this.connection;
- t.name = "user";
- var itermodel = new RecordCollection (pxy,t);
- var row = new Record ();
- row.table = t;
- var f = new Field ("id", DbField.Attribute.NONE);
- f.value = 10;
- row.set_field (f);
- f.name = "name";
- f.value = "Samanta";
- row.set_field (f);
- f.name = "city";
- f.value = "San Francisco";
- row.set_field (f);
- if ( itermodel.add (row)) {
- stdout.printf("New contents in DataModel:\n" + itermodel.to_string ());
- }
- else
- fails++;
-
- return fails;
- }
-
public static int main (string[] args) {
stdout.printf ("Checking Gda.DataModelIterator implementation...\n");
int failures = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]