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, obj_id_1, obj_id_2)
          [o1,o2] = ltpda_obj_retrieve(conn, obj_id_1, obj_id_2)
          objs    = ltpda_obj_retrieve(conn, 'Collection', coll_id)
 
 INPUTS:
          conn       - database connection object
          obj_id_N   - an object ID
          coll_id    - a collection ID
 
 OUTPUTS:
          objs          - the retrieved object(s) as a cell array.*
          o1,o2,...,oN  - returns the first N objects
 
 
 If more than one object is retrieved and only one output is specified
 then the output is a cell array of objects.
 
 If only a single object is requested, it is returned as an object,
 not packed in a cell array.
 
 VERSION:     $Id: ltpda_obj_retrieve.m,v 1.9 2007/11/14 10:11:40 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, obj_id_1, obj_id_2)
0011 %          [o1,o2] = ltpda_obj_retrieve(conn, obj_id_1, obj_id_2)
0012 %          objs    = ltpda_obj_retrieve(conn, 'Collection', coll_id)
0013 %
0014 % INPUTS:
0015 %          conn       - database connection object
0016 %          obj_id_N   - an object ID
0017 %          coll_id    - a collection ID
0018 %
0019 % OUTPUTS:
0020 %          objs          - the retrieved object(s) as a cell array.*
0021 %          o1,o2,...,oN  - returns the first N objects
0022 %
0023 %
0024 % If more than one object is retrieved and only one output is specified
0025 % then the output is a cell array of objects.
0026 %
0027 % If only a single object is requested, it is returned as an object,
0028 % not packed in a cell array.
0029 %
0030 % VERSION:     $Id: ltpda_obj_retrieve.m,v 1.9 2007/11/14 10:11:40 hewitson Exp $
0031 %
0032 % HISTORY: 30-08-07 M Hewitson
0033 %             Creation
0034 %
0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 objs = [];
0038 conn = varargin{1};
0039 if ~isa(conn, 'database')
0040   error('### the first argument should be a database connection object.');
0041 end
0042 
0043 if nargin == 3 && ischar(varargin{2}) && isnumeric(varargin{3})
0044   if strcmp(varargin{2}, 'Collection')
0045     cid = varargin{3};
0046     % Get a list of object IDs from the collection ID
0047     ids = mysql_getObjIds(conn, cid);
0048   else
0049     help(mfilename)
0050     error('### Incorrect usage');
0051   end
0052 elseif nargin > 1 && isnumeric(varargin{2})
0053   ids = [varargin{2:end}];
0054 else
0055   error('### Incorrect usage');
0056 end
0057 
0058 disp(['*** retrieving objects [' num2str(ids) ']'])
0059 
0060 for j=1:length(ids)
0061   tt = mysql_getObjType(conn, ids(j));
0062   cmd = sprintf('obj = %s(conn, ids(j));', tt);
0063   eval(cmd);
0064   
0065   % retrieve the hash for this object
0066 %   md5hash = mysql_getMD5hash(conn, ids(j));
0067   
0068   % compute hash of object
0069 %   x    = xml(obj);
0070 %   otxt = xmlwrite(x.docNode);
0071 %   h    = ltpda_hash(otxt, 'MD5');
0072   
0073 %   if ~strcmp(h, md5hash)
0074 %     disp(['! compared: ' md5hash ' - ' h])
0075 %     error('### MD5 check failed for object %d.', ids(j));
0076 %   else
0077     if j==1
0078       objs = {obj};
0079     else
0080       objs = [objs {obj}];
0081     end    
0082 %   end
0083 end
0084 
0085 if nargout == 1  
0086   if length(objs) == 1
0087     varargout{1} = objs{1};
0088   else
0089     varargout{1} = objs;
0090   end
0091 else
0092   for k=1:nargout
0093     varargout{k} = objs{k};
0094   end  
0095 end
0096 % END

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003