


RETRIEVE retrieves a collection of objects from an LTPDA repository.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: RETRIEVE a collection of objects from an LTPDA repository.
CALL: objs = retrieve(conn, obj_id_1, obj_id_2)
[o1,o2] = retrieve(conn, obj_id_1, obj_id_2)
objs = 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.
M-FILE INFO: Get information about this methods by calling
>> ao.getInfo('retrieve')
Get information about a specified set-plist by calling:
>> ao.getInfo('retrieve', 'Default')
VERSION: $Id: retrieve.m,v 1.3 2008/08/08 14:52:24 hewitson Exp $
HISTORY: 30-08-07 M Hewitson
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


0001 % RETRIEVE retrieves a collection of objects from an LTPDA repository. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: RETRIEVE a collection of objects from an LTPDA repository. 0005 % 0006 % CALL: objs = retrieve(conn, obj_id_1, obj_id_2) 0007 % [o1,o2] = retrieve(conn, obj_id_1, obj_id_2) 0008 % objs = retrieve(conn, 'Collection', coll_id) 0009 % 0010 % PARAMETERS: 0011 % 0012 % 0013 % INPUTS: 0014 % conn - database connection object 0015 % obj_id_N - an object ID 0016 % coll_id - a collection ID 0017 % 0018 % OUTPUTS: 0019 % objs - the retrieved object(s) as a cell array.* 0020 % o1,o2,...,oN - returns the first N objects 0021 % 0022 % 0023 % If more than one object is retrieved and only one output is specified 0024 % then the output is a cell array of objects. 0025 % 0026 % If only a single object is requested, it is returned as an object, 0027 % not packed in a cell array. 0028 % 0029 % M-FILE INFO: Get information about this methods by calling 0030 % >> ao.getInfo('retrieve') 0031 % 0032 % Get information about a specified set-plist by calling: 0033 % >> ao.getInfo('retrieve', 'Default') 0034 % 0035 % VERSION: $Id: retrieve.m,v 1.3 2008/08/08 14:52:24 hewitson Exp $ 0036 % 0037 % HISTORY: 30-08-07 M Hewitson 0038 % Creation 0039 % 0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0041 0042 function varargout = retrieve(varargin) 0043 0044 % Check if this is a call for parameters 0045 if utils.helper.isinfocall(varargin{:}) 0046 varargout{1} = getInfo(varargin{3}); 0047 return 0048 end 0049 0050 import utils.const.* 0051 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0052 0053 if nargin == 0 0054 help(mfilename); 0055 error('### Incorrect inputs'); 0056 end 0057 0058 objs = []; 0059 conn = varargin{1}; 0060 if ~isa(conn, 'database') 0061 error('### the first argument should be a database connection object.'); 0062 end 0063 0064 % Get username and user id 0065 username = conn.Username; 0066 userid = utils.mysql.getUserID(conn, username); 0067 if ~isempty(userid) 0068 utils.helper.msg(msg.PROC1, 'got user id %d for user: %s', userid, username); 0069 if userid < 1 || isnan(userid) || strcmp(userid, 'No Data') || ischar(userid) 0070 error('### Unknown username.'); 0071 end 0072 else 0073 error('### Could not determine user id. Can not proceed.'); 0074 end 0075 0076 if nargin == 3 && ischar(varargin{2}) && isnumeric(varargin{3}) 0077 if strcmp(varargin{2}, 'Collection') 0078 cid = varargin{3}; 0079 % Get a list of object IDs from the collection ID 0080 ids = utils.mysql.getObjIds(conn, cid); 0081 else 0082 help(mfilename) 0083 error('### Incorrect usage'); 0084 end 0085 elseif nargin > 1 && isnumeric(varargin{2}) 0086 ids = [varargin{2:end}]; 0087 else 0088 error('### Incorrect usage'); 0089 end 0090 0091 utils.helper.msg(msg.PROC1, ['retrieving objects [' num2str(ids) ']']); 0092 0093 for j=1:length(ids) 0094 % Get object 0095 xdoc = utils.mysql.getXdoc(conn, ids(j)); 0096 if ~isempty(xdoc) 0097 obj = utils.helper.xmlread(xdoc); 0098 if j==1 0099 objs = {obj}; 0100 else 0101 objs = [objs {obj}]; 0102 end 0103 0104 % make transaction entry 0105 t = time(); 0106 tdate = t.format('yyyy-mm-dd HH:MM:SS'); 0107 try 0108 message = utils.mysql.insert(conn, ... 0109 'transactions',... 0110 'obj_id', ids(j),... 0111 'user_id', userid,... 0112 'transdate', tdate,... 0113 'direction', 'out'... 0114 ); 0115 utils.helper.msg(msg.PROC1, 'updated transactions table'); 0116 catch 0117 error('### Failed to make entry in transactions table'); 0118 end 0119 else 0120 warning('!!! Error retrieving object: %d', ids(j)); 0121 end 0122 end 0123 0124 % Set outputs 0125 if nargout == 1 0126 if length(objs) == 1 0127 varargout{1} = objs{1}; 0128 else 0129 varargout{1} = objs; 0130 end 0131 else 0132 for k=1:nargout 0133 varargout{k} = objs{k}; 0134 end 0135 end 0136 end 0137 0138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0139 % Local Functions % 0140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0141 0142 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0143 % 0144 function ii = getInfo(varargin) 0145 if nargin == 1 && strcmpi(varargin{1}, 'None') 0146 sets = {}; 0147 pl = []; 0148 else 0149 sets = {'Default'}; 0150 pl = getDefaultPlist; 0151 end 0152 % Build info object 0153 ii = minfo(mfilename, 'ltpda_uo', '', 'Internal', '$Id: retrieve.m,v 1.3 2008/08/08 14:52:24 hewitson Exp $', sets, pl); 0154 end 0155 0156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0157 % 0158 function plo = getDefaultPlist() 0159 plo = plist('conn', [], 'ids', []); 0160 end 0161 0162 0163