0001 function varargout = ltpda_obj_retrieve(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 ALGONAME = mfilename;
0041 VERSION = '$Id: ltpda_obj_retrieve.m,v 1.14 2008/02/24 10:16:58 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
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
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
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
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
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