Gda Vala Extensions Interfaces

Vala Extensions defines a set of interfaces to define a generic behaviour. They expect to be the base for future implementations for Vala objects accessing a database.

Following diagram describes the available interfaces and its relations.

interfaces-uml.png

DbObject Interface

This interface requires that instantable classes implement basic functionallity.

  • update (). Retrives from the database the object structure or information.

  • save (). Any change made to the object properties, can be sent to database for permanent, this method is called when you want to update data too.

  • append (). Adds a new object to the database. You must setup the new object before call this method.

  • drop (). Delete this object from the database. This method can cascade any object depending on it by set cascade parameter to true.

To call that methods you must have a valid Gda.Connection object with an opened connection to a database.

This interface requires to implement the following properties:

  • connection. A Gda.Connection to work on a database.

  • update_metadata. If is set to true GDA metadata is retrieved from database, this could take some time.

DbTable Interface

This interface is used to describe and provide common implementations to any table in a database.

Check for tables compatibility

Table compatibility, as defined in Gda Vala Extensions, is a set of tests to garanty one table is able to copy data to another. Field compatibility are performed by compatible() method defined in DbFieldInfo interface.

The following tests are performed when A.compatible(B) is called:

  • Fields in table A are located in table B
  • Fields in table A are compatible with the one in table B

This codes checks for compatibility between two tables. create_definition() is a user defined method to initiate a table by adding fields definitions that will be used as a template.

   1 Table a = new Table ();
   2 a.name = "user2"; // set to a database's table name
   3 a.connection = connection;
   4 a.update (); // Get definition from database metadata
   5 Table b = new Table ();
   6 b.name = "users"; // set to a database's table name
   7 b.connection = connection;
   8 b.update (); // Get definition from database metadata
   9 if (a.compatible (b))
  10         stdout.printf (@"You can copy data from table $(a.name) to table $(b.name)");

Check for equivalent tables

Table equivalency, as defined in Gda Vala Extensions, is a set of tests to verify that most important parts of a hard coded table (template) definition are present in other table. Then is recomended to check equivalency of a hard coded definition, agains a database table that had been updated using update() method. Field equivalency are performed by equivalent() method defined in DbFieldInfo interface.

The following tests are performed when A.equivalent(B) is called:

  • Fields in table A are located in table B
  • Fields in table A are equivalent with the one in table B

This codes checks for equivalency between two tables.

   1 Table a = new Table ();
   2 a.name = "pre-defined";
   3 create_definition (a); // See at Table class to see how define a table
   4 Table b = new Table ();
   5 b.name = "users"; // set to a database's table name
   6 b.connection = connection;
   7 b.update (); // Get definition from database metadata
   8 if (a.equivalent (b))
   9         stdout.printf (@"Database table $(b.name) is based on template table $(a.name)");

DbFieldInfo Interface

This interface is used to describe and provide common implementations to any field in a table. To access and update values in a database, you must use DbField interface.

Check for table's field compatibility

Table compatibility, as defined in Gda Vala Extensions, is a set of tests to garanty one field is able to copy data to another.

The following tests are performed when F.compatible(F2) is called:

  • Values' type are equal
  • If F can be null, then F2 must allow null values too

This codes checks for compatibility between two table's fields definition.

   1 Table a = new Table ();
   2 a.name = "user2"; // set to a database's table name
   3 a.connection = connection;
   4 a.update (); // Get definition from database metadata
   5 Table b = new Table ();
   6 b.name = "users"; // set to a database's table name
   7 b.connection = connection;
   8 b.update (); // Get definition from database metadata
   9 var aid = a.get_field ("id");
  10 var bid = b.get_field ("id");
  11 if (aid.compatible (bid))
  12         stdout.printf (@"You can copy data from field  $(aid.name) to table $(bid.name)");

Check for table's field definition equivalent

Field equivalency, as defined in Gda Vala Extensions, is a set of tests to verify that most important properties and attributes are present in other field. Then is recomended to check equivalency of a hard coded definition, agains a database table's field that had been getted from a table using update() method. Field equivalency are performed by equivalent() defined in DbFieldInfo interface.

The following tests are performed when F.equivalent(F2) is called:

  • Name are equal
  • Type are equal
  • If one of the following attributes of type DbFieldInfo.Attribute are pressent, they must be pressent in the other field: PRIMARY_KEY, UNIQUE, CHECK, CAN_BE_NULL

This codes checks for equivalency between a template and a database field.

   1 Table a = new Table ();
   2 a.name = "pre-defined";
   3 create_definition (a); // See at Table class to see how define a table
   4 Table b = new Table ();
   5 b.name = "users"; // set to a database's table name
   6 b.connection = connection;
   7 b.update (); // Get definition from database metadata
   8 aid = a.get_field ("id");
   9 bid = b.get_field ("id");
  10 if (aid.equivalent (bid))
  11         stdout.printf (@"Database field $(bid.name) is based on template field $(aid.name)");

Projects/GdaValaExtensions/Interfaces (last edited 2014-01-17 17:27:03 by DanielEspinosaOrtiz)