0001
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
0041
0042 function varargout = retrieve(varargin)
0043
0044
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
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
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
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
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
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
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
0153 ii = minfo(mfilename, 'ltpda_uo', '', utils.const.categories.internal, '$Id: retrieve.m,v 1.4 2008/09/04 15:29:30 ingo Exp $', sets, pl);
0154 end
0155
0156
0157
0158 function plo = getDefaultPlist()
0159 plo = plist('conn', [], 'ids', []);
0160 end
0161
0162
0163