Retrieving LTPDA objects from a repository


Objects can be retrieved from the repository either by specifying an object ID or a collection ID. The LTPDA Toolbox provides the function ltpda_uo.retrieve to retrieve objects. In additon, the constructors of each user class can be used to retrieve objects of that class.


The retrieval process

When an object is retrieved, the following steps are taken:

  1. The object type for the requested ID is retrieved from the objmeta table
  2. A call is made to the appropriate class constructor
  3. The class constructor retrieves the XML string from the objs table
  4. The XML string is then converted into an XML Xdoc object
  5. The Xdoc object is then parsed to recreate the desired object


Retrieving objects

To retrieve an object, you must know its object ID, or the ID of the collection that contains that object. The following script shows an example of retrieving a single object:

      % Connect to a repository
      [conn, username] = utils.mysql.connect('130.75.117.67', 'ltpda_test');
      
      % Retrieve the object
      q = ltpda_uo.retrieve(conn, 12);
      
      % Close connection
      close(conn);
      
  
Note that the retrieved object belongs, in general, to the class ltpda_uo, because the retrieve function is a method of that superclass.

If you already know the class of the object (for example, ao), you can directly call the class constructor method:

      % Define the hostname and database
      hostname = '130.75.117.67';
      database = 'ltpda_test';

      % Retrieve the object
      q = ao(plist('hostname', hostname, 'database', dbname, 'ID', 12));	
  

If you know the collection that contains the object, and the class, then you can directly call the class constructor method:

      % Retrieve the object
      q = ao(plist('hostname', hostname, 'database', dbname, 'CID', 2));	
  
In this case, all AOs in the collection with CID 2 will be retrieved and stored in q.


Multiple objects can be retrieved simultaneously by giving a list of object IDs. For example

      q = ltpda_uo.retrieve(conn, 1,2,3);
  
When multiple objects are requested, the results are returned in a cell array.


Retrieving object collections

Collections of objects can be retrieved by specifying the collection ID. The following script retrieves a collection:

      % Connect to a repository
      [conn, username] = utils.mysql.connect('130.75.117.67', 'ltpda_test');
      
      % Retrieve the collection
      q = ltpda_uo.retrieve(conn, 'Collection', 1);
      
      % Close connection
      close(conn);
      
  
The output is a cell array containing the objects retrieved.

Retrieving binary objects

The retrieval process may be speeded up by taking advantage of the fact that the objects are stored in the databases also in binary form. This can be achieved by using the parameter 'binary', that will build the object from the corresponding binary representation, if stored on the database.

      % Connect to a repository
      [conn, username] = utils.mysql.connect('130.75.117.67', 'ltpda_test');
      
      % Retrieve the collection
      q = ao(plist('hostname', hostname, 'database', dbname, 'ID', 12, 'binary', 'yes'));
      
      % Close connection
      close(conn);
      
  
If the binary representation is not in the database, the object will be built from the xml one.




©LTP Team