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)
 
 PARAMETERS:
 
 
 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.html,v 1.12 2008/03/31 10:27:42 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 % PARAMETERS:
0015 %
0016 %
0017 % INPUTS:
0018 %          conn       - database connection object
0019 %          obj_id_N   - an object ID
0020 %          coll_id    - a collection ID
0021 %
0022 % OUTPUTS:
0023 %          objs          - the retrieved object(s) as a cell array.*
0024 %          o1,o2,...,oN  - returns the first N objects
0025 %
0026 %
0027 % If more than one object is retrieved and only one output is specified
0028 % then the output is a cell array of objects.
0029 %
0030 % If only a single object is requested, it is returned as an object,
0031 % not packed in a cell array.
0032 %
0033 % VERSION:     $Id: ltpda_obj_retrieve.html,v 1.12 2008/03/31 10:27:42 hewitson Exp $
0034 %
0035 % HISTORY: 30-08-07 M Hewitson
0036 %             Creation
0037 %
0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039 
0040 ALGONAME = mfilename;
0041 VERSION  = '$Id: ltpda_obj_retrieve.html,v 1.12 2008/03/31 10:27:42 hewitson Exp $';
0042 CATEGORY = 'Internal';
0043 
0044 if nargin == 0
0045   help(mfilename);
0046   error('### Incorrect inputs');
0047 end
0048 
0049 objs = [];
0050 conn = varargin{1};
0051 if ~isa(conn, 'database')
0052   error('### the first argument should be a database connection object.');
0053 end
0054 
0055 % Get username and user id
0056 username = conn.Username;
0057 userid   = mysql_getUserID(conn, username);
0058 if ~isempty(userid)
0059   disp(sprintf(' ** got user id %d for user: %s', userid, username))
0060   if userid < 1 || isnan(userid)  || strcmp(userid, 'No Data') || ischar(userid)
0061     error('### Unknown username.');
0062   end
0063 else
0064   error('### Could not determine user id. Can not proceed.');
0065 end
0066 
0067 if nargin == 3 && ischar(varargin{2}) && isnumeric(varargin{3})
0068   if strcmp(varargin{2}, 'Collection')
0069     cid = varargin{3};
0070     % Get a list of object IDs from the collection ID
0071     ids = mysql_getObjIds(conn, cid);
0072   else
0073     help(mfilename)
0074     error('### Incorrect usage');
0075   end
0076 elseif nargin > 1 && isnumeric(varargin{2})
0077   ids = [varargin{2:end}];
0078 else
0079   error('### Incorrect usage');
0080 end
0081 
0082 disp(['*** retrieving objects [' num2str(ids) ']'])
0083 
0084 for j=1:length(ids)
0085   % Get object
0086   xdoc = mysql_getXdoc(conn, ids(j));    
0087   if ~isempty(xdoc)
0088     obj = ltpda_xmlread(xdoc);    
0089     if j==1
0090       objs = {obj};
0091     else
0092       objs = [objs {obj}];
0093     end
0094     
0095     % make transaction entry
0096     t     = time();
0097     tdate = t.time_str;      
0098     try
0099       message = ltpda_insert(conn, 'transactions',...
0100         'obj_id', ids(j),...
0101         'user_id', userid,...
0102         'transdate', tdate,...
0103         'direction', 'out'...
0104         );
0105       disp(sprintf('  + updated transactions table'));
0106     catch
0107       error('### Failed to make entry in transactions table');
0108     end    
0109   else
0110     warning('!!! Error retrieving object: %d', ids(j));
0111   end
0112 end
0113 
0114 % Set outputs
0115 if nargout == 1  
0116   if length(objs) == 1
0117     varargout{1} = objs{1};
0118   else
0119     varargout{1} = objs;
0120   end
0121 else
0122   for k=1:nargout
0123     varargout{k} = objs{k};
0124   end  
0125 end
0126 % END

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003