[libgda] Interface hierarchy for DbCollection using Gee.



commit 04317b0316398dbe29ad24043219efe735ff1af7
Author: Daniel Espinosa <despinosa src gnome org>
Date:   Thu Dec 22 18:03:44 2011 -0600

    Interface hierarchy for DbCollection using Gee.
    
    * This are the first ideas on interface hierarchy for DbCollection
    * Added DbCollection, DbShema, DbTable, DbRecord, DbField, SqlWhere, SqlExpression interfaces

 libgda/data/DbCollection.vala  |   37 ++++++++++++++++++++++++++++++
 libgda/data/DbField.vala       |   48 ++++++++++++++++++++++++++++++++++++++++
 libgda/data/DbRecord.vala      |   30 +++++++++++++++++++++++++
 libgda/data/DbSchema.vala      |   30 +++++++++++++++++++++++++
 libgda/data/SqlExpression.vala |   47 +++++++++++++++++++++++++++++++++++++++
 libgda/data/SqlWhere.vala      |   43 +++++++++++++++++++++++++++++++++++
 6 files changed, 235 insertions(+), 0 deletions(-)
---
diff --git a/libgda/data/DbCollection.vala b/libgda/data/DbCollection.vala
new file mode 100644
index 0000000..e9a48c3
--- /dev/null
+++ b/libgda/data/DbCollection.vala
@@ -0,0 +1,37 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public interface DbCollection : Object 
+	{
+		public abstract Collection<DbSchema> schemas { get; }
+		
+		public static Collection<Table> get_tables (string schema) {
+			foreach (DbShema sh in shemas) {
+				if (sh.name == schema) {
+					return sh.tables;
+				}
+			}
+		}
+	}
+}
diff --git a/libgda/data/DbField.vala b/libgda/data/DbField.vala
new file mode 100644
index 0000000..01d0f34
--- /dev/null
+++ b/libgda/data/DbField.vala
@@ -0,0 +1,48 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public abstract class DbField<G> : Object
+	{
+		public abstract DbRecord record { get; set construct; };
+		public abstract G value { get; set; };
+		public abstract string name { get; set; }
+		public abstract string column_name { get; set; }
+		public abstract DbField.Attribute attributes { get; set construct; }
+		
+		[Flags]
+		public enum Attribute {
+			NONE,
+			IS_NULL,
+			CAN_BE_NULL,
+			IS_DEFAULT,
+			CAN_BE_DEFAULT,
+			IS_UNCHANGED,
+			ACTIONS_SHOWN,
+			DATA_NON_VALID,
+			HAS_VALUE_ORIG,
+			NO_MODIF,
+			UNUSED
+		}
+	}
+}
diff --git a/libgda/data/DbRecord.vala b/libgda/data/DbRecord.vala
new file mode 100644
index 0000000..cec6986
--- /dev/null
+++ b/libgda/data/DbRecord.vala
@@ -0,0 +1,30 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public interface DbRecord : Object
+	{
+		public abstract DbTable table { get; set construct; }
+		public abstract Collection<DbField> fields { get; }
+	}
+}
diff --git a/libgda/data/DbSchema.vala b/libgda/data/DbSchema.vala
new file mode 100644
index 0000000..01cd2ba
--- /dev/null
+++ b/libgda/data/DbSchema.vala
@@ -0,0 +1,30 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public interface DbSchema : Object
+	{
+		public abstract string name { get; set; }
+		public abstract Collection<DbTable> tables { get; }
+	}
+}
diff --git a/libgda/data/SqlExpression.vala b/libgda/data/SqlExpression.vala
new file mode 100644
index 0000000..9f4c54c
--- /dev/null
+++ b/libgda/data/SqlExpression.vala
@@ -0,0 +1,47 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public interface SqlExpression<A,G> : Object
+	{
+		public Gee.HashTable<A,G> fields { get; }
+		public Gee.HashTable<A,G> values { get; }
+		
+		public abstract bool verify (DbCollection db);
+		
+		enum DbExpressionOperator {
+			AND, OR, EQ, IS, LIKE, BETWEEN,
+			GT, LT, GEQ, LEQ, DIFF, REGEXP,
+			REGEXP_CI, NOT_REGEXP, NOT_REGEXP_CI,
+			SIMILAR, ISNULL, ISNOTNULL, NOT, IN,
+			NOTIN, CONCAT, PLUS, MINUS, STAR, DIV,
+			REM, BITAND, BITOR, BITNOT, ILIKE
+		}
+		
+		struct DbExpressionRelation {
+			A id;
+			DbExpressionOperator value;
+		}
+		
+	}
+}
diff --git a/libgda/data/SqlWhere.vala b/libgda/data/SqlWhere.vala
new file mode 100644
index 0000000..a5c2a10
--- /dev/null
+++ b/libgda/data/SqlWhere.vala
@@ -0,0 +1,43 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgdadata
+ * 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 Gee;
+using Gda;
+
+namespace GdaData
+{
+	public interface SqlWhere<Expression> : Object, Traversable<Expression>, Iterable<Expression>, Collection<Expression>
+	{
+		/**
+		 * Verify that all expressions are valid in the context of the given database collection
+		 */
+		public static Collection<Expression> verify (DbCollection db) 
+		{
+			var l = new Gee.List<Expression> ();
+			var iter = this.iterator ();
+			while (iter.next ())
+			{
+				var e = iter.get ();
+				if (!e.verify (db))
+					l.add (e);
+			}
+			return l;
+		}
+	}
+}



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