Home > m > mysql > ltpda_obj_retrieve.m

ltpda_obj_retrieve

PURPOSE ^

LTPDA_OBJ_RETRIEVE retrieves a collection of objects from an LTPDA repository.

SYNOPSIS ^

function varargout = ltpda_obj_retrieve(varargin)

DESCRIPTION ^

 LTPDA_OBJ_RETRIEVE retrieves a collection of objects from an LTPDA repository.
 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: RETRIEVE a collection of objects from an LTPDA repository.
 
 CALL:    objs    = ltpda_obj_retrieve(conn, cid)
          [o1,o2] = ltpda_obj_retrieve(conn, cid)
 
 INPUTS:
          conn   - database connection object
          cid    - a collection id
 
 OUTPUTS:
          objs          - the retrieved object(s) as a cell array.*
          o1,o2,...,oN  - returns the first N objects
 
 
 If the collection contains mixed object types, 'objs' will be an array
 of structures with the fields id, type, obj. If all objects are of the
 same type, 'objs' will be a vector of objects.
 
 *NOTE: if only a single object is requested, it is returned as an object,
 not packed in a cell array.
 
 VERSION:     $Id: submit.m,v 1.14 2007/08/16 06:55:25 hewitson Exp $

 HISTORY: 30-08-07 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = ltpda_obj_retrieve(varargin)
0002 
0003 % LTPDA_OBJ_RETRIEVE retrieves a collection of objects from an LTPDA repository.
0004 %
0005 %
0006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0007 %
0008 % DESCRIPTION: RETRIEVE a collection of objects from an LTPDA repository.
0009 %
0010 % CALL:    objs    = ltpda_obj_retrieve(conn, cid)
0011 %          [o1,o2] = ltpda_obj_retrieve(conn, cid)
0012 %
0013 % INPUTS:
0014 %          conn   - database connection object
0015 %          cid    - a collection id
0016 %
0017 % OUTPUTS:
0018 %          objs          - the retrieved object(s) as a cell array.*
0019 %          o1,o2,...,oN  - returns the first N objects
0020 %
0021 %
0022 % If the collection contains mixed object types, 'objs' will be an array
0023 % of structures with the fields id, type, obj. If all objects are of the
0024 % same type, 'objs' will be a vector of objects.
0025 %
0026 % *NOTE: if only a single object is requested, it is returned as an object,
0027 % not packed in a cell array.
0028 %
0029 % VERSION:     $Id: submit.m,v 1.14 2007/08/16 06:55:25 hewitson Exp $
0030 %
0031 % HISTORY: 30-08-07 M Hewitson
0032 %             Creation
0033 %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 
0036 objs = [];
0037 if nargin ~= 2
0038   help(mfilename)
0039   error('### Incorrect inputs');
0040 end
0041 conn = varargin{1};
0042 if ~isa(conn, 'database')
0043   error('### the first argument should be a database connection object.');
0044 end
0045 cid = varargin{2};
0046 if ~isnumeric(cid)
0047   error('### the second argument should be a collection id.');
0048 end
0049 
0050 %%%%%%%%%%%% Get a list of object IDs from the collection ID
0051 ids = mysql_getObjIds(conn, cid);
0052 
0053 disp([sprintf('*** retrieving collection %d [objects ', cid) num2str(ids) ']'])
0054 
0055 for j=1:length(ids)
0056   tt = mysql_getObjType(conn, ids(j));
0057   cmd = sprintf('obj = %s(conn, ids(j));', tt);
0058   eval(cmd);
0059   
0060 %   % retrieve the hash for this object
0061 %   md5hash = mysql_getMD5hash(conn, ids(j));
0062 %
0063 %   % compute hash of object
0064 %   x    = xml(obj);
0065 %   otxt = xmlwrite(x.docNode);
0066 %   h    = ltpda_hash(otxt, 'MD5');
0067 %
0068 %   if ~strcmp(h, md5hash)
0069 %     disp(['! compared: ' md5hash ' - ' h])
0070 %     error('### MD5 check failed for object %d.', ids(j));
0071 %   else
0072     if j==1
0073       objs = {obj};
0074     else
0075       objs = [objs {obj}];
0076     end    
0077 %   end
0078 end
0079 
0080 if nargout == 1  
0081   if length(objs) == 1
0082     varargout{1} = objs{1};
0083   else
0084     varargout{1} = objs;
0085   end
0086 else
0087   for k=1:nargout
0088     varargout{k} = objs{k};
0089   end  
0090 end
0091 % END

Generated on Thu 01-Nov-2007 09:42:34 by m2html © 2003