Mercurial > hg > ltpda
annotate m-toolbox/classes/@ltpda_uo/retrieve.m @ 8:2f5c9bd7d95d database-connection-manager
Clarify ltpda_uo.retrieve parameters handling
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | 1e91f84a4be8 |
children | fbbfcd56e449 |
rev | line source |
---|---|
0 | 1 % RETRIEVE retrieves a collection of objects from an LTPDA repository. |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: This static method retrieves a collection of objects from an | |
5 % LTPDA repository. | |
6 % | |
7 % CALL: objs = retrieve(conn, obj_id_1, obj_id_2) | |
8 % [o1,o2] = retrieve(conn, obj_id_1, obj_id_2) | |
9 % [o1,o2] = retrieve(conn, 'binary', obj_id_1, obj_id_2) | |
10 % objs = retrieve(conn, 'Collection', coll_id) | |
11 % objs = retrieve(conn, 'binary', 'Collection', coll_id) | |
12 % | |
13 % INPUTS: | |
14 % conn - database connection object | |
15 % obj_id_N - an object ID | |
16 % coll_id - a collection ID | |
17 % 'binary' - to retrieve a binary representation of the object | |
18 % (if stored) | |
19 % | |
20 % OUTPUTS: | |
21 % objs - the retrieved object(s) as a cell array.* | |
22 % o1,o2,...,oN - returns the first N objects | |
23 % | |
24 % | |
25 % If more than one object is retrieved and only one output is specified | |
26 % then the output is a cell array of objects. | |
27 % | |
28 % If only a single object is requested, it is returned as an object, | |
29 % not packed in a cell array. | |
30 % | |
31 % VERSION: $Id: retrieve.m,v 1.28 2011/07/01 14:38:57 ingo Exp $ | |
32 % | |
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
34 | |
35 function varargout = retrieve(varargin) | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
36 |
0 | 37 % Check if this is a call for parameters |
38 if utils.helper.isinfocall(varargin{:}) | |
39 varargout{1} = getInfo(varargin{3}); | |
40 return | |
41 end | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
42 |
0 | 43 import utils.const.* |
8
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
44 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
45 |
8
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
46 if numel(varargin) < 2 |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
47 error('### invalid usage'); |
0 | 48 end |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
49 |
8
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
50 % connection |
0 | 51 conn = varargin{1}; |
8
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
52 varargin = varargin(2:end); |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
53 if ~isa(conn, 'java.sql.Connection') |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
54 error('### the first argument should be a java.sql.Connection object'); |
0 | 55 end |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
56 |
8
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
57 binary = false; |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
58 if ischar(varargin{1}) && strcmpi(varargin{1}, 'binary') |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
59 % binary |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
60 binary = true; |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
61 varargin = varargin(2:end); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
62 utils.helper.msg(msg.PROC1, 'binary retrieve'); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
63 end |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
64 |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
65 if ischar(varargin{1}) && strcmpi(varargin{1}, 'collection') |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
66 % collection |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
67 cid = varargin{2}; |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
68 varargin = varargin(3:end); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
69 if ~isempty(varargin) |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
70 error('### wrong number of arguments'); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
71 end |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
72 utils.helper.msg(msg.PROC1, 'retrieving collection %d', cid); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
73 |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
74 % get list of object IDs from the collection ID |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
75 rows = utils.mysql.execute(conn, 'SELECT nobjs, obj_ids FROM collections WHERE id = ?', cid); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
76 nobjs = rows{1}; |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
77 ids = strread(rows{2}, '%d', 'delimiter', ','); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
78 if length(ids) ~= nobjs |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
79 error('### inconsistent collection description'); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
80 end |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
81 |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
82 else |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
83 % IDs list |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
84 if isnumeric([varargin{:}]) |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
85 ids = [varargin{:}]; |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
86 else |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
87 error('### invalid usage'); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
88 end |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
89 end |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
90 |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
91 utils.helper.msg(msg.PROC1, ['retrieving objects' sprintf(' %d', ids)]); |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
92 |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
93 % output vector |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
94 objs = []; |
2f5c9bd7d95d
Clarify ltpda_uo.retrieve parameters handling
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
7
diff
changeset
|
95 |
0 | 96 try |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
97 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
98 % get username and user id |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
99 username = utils.mysql.execute(conn, 'SELECT SUBSTRING_INDEX(USER(),''@'',1)'); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
100 rows = utils.mysql.execute(conn, 'SELECT id FROM users WHERE username = ?', username{1}); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
101 if isempty(rows) |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
102 error('### could not determine user id'); |
0 | 103 end |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
104 userid = rows{1}; |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
105 |
0 | 106 v = ver('LTPDA'); |
107 for j=1:length(ids) | |
108 | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
109 rows = utils.mysql.execute(conn, 'SELECT version, obj_type FROM objmeta WHERE obj_id = ?', ids(j)); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
110 if isempty(rows) |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
111 error('### object %d not found', ids(j)); |
0 | 112 end |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
113 objver = rows{1}; |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
114 objtype = rows{2}; |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
115 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
116 % it is only possible to download the object if the object in the |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
117 % database was submitted with the same or lower LTPDA version as |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
118 % the current version |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
119 if utils.helper.ver2num(v.Version) < utils.helper.ver2num(objver) |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
120 error(['### object %d was submitted with newer LTPDA version (%s) '... |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
121 'than this one (%s). please update'], ids(j), objver, v.Version); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
122 end |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
123 |
0 | 124 if binary |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
125 % binary download |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
126 |
0 | 127 % Retrieve the bytes |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
128 rows = utils.mysql.execute(conn, 'SELECT mat FROM bobjs WHERE obj_id = ?', ids(j)); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
129 if isempty(rows) |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
130 error('### failed to get binary data for object %d', ids(j)); |
0 | 131 end |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
132 dd = rows{1}; |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
133 |
0 | 134 % Write bytes out to a temp MAT file |
135 fname = [tempname '.mat']; | |
136 fd = fopen(fname, 'w+'); | |
137 fwrite(fd, dd, 'int8'); | |
138 fclose(fd); | |
139 % Load the MAT data to a structure | |
140 obj = load(fname); | |
141 % Delete temp file | |
142 delete(fname); | |
143 % Get the struct out | |
144 obj = obj.objs; | |
145 | |
146 % Check if the retrieved object is a struct | |
147 if isstruct(obj) | |
148 % Call the constructor with this struct | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
149 fcn_name = [objtype '.update_struct']; |
0 | 150 obj = feval(fcn_name, obj, obj.tbxver); |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
151 obj = feval(objtype, obj); |
0 | 152 end |
153 % Add tyo object array | |
154 objs = [objs {obj}]; | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
155 |
0 | 156 else |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
157 % xml download |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
158 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
159 % get xml |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
160 rows = utils.mysql.execute(conn, 'SELECT xml FROM objs WHERE id = ?', ids(j)); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
161 if isempty(rows) |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
162 error('### failed to get data for object %d', ids(j)); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
163 end |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
164 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
165 % parse xml |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
166 stream = java.io.StringBufferInputStream(java.lang.String(rows{1})); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
167 builder = javax.xml.parsers.DocumentBuilderFactory.newInstance.newDocumentBuilder(); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
168 xdoc = builder.parse(stream); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
169 obj = utils.xml.xmlread(xdoc); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
170 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
171 % add to output array |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
172 objs = [objs {obj}]; |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
173 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
174 % make transaction entry |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
175 t = time().format('yyyy-mm-dd HH:MM:SS', 'UTC'); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
176 utils.mysql.execute(conn, ['INSERT INTO transactions (obj_id, user_id, transdate, direction) ' ... |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
177 'VALUES (?, ?, ?, ?)'], ids(j), userid, t, 'out'); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
178 utils.helper.msg(msg.PROC1, 'updated transactions table'); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
179 end |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
180 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
181 end |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
182 |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
183 catch ex |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
184 utils.helper.msg(msg.PROC1, '### retrieve error'); |
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
185 rethrow(ex) |
0 | 186 end |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
187 |
0 | 188 % Set outputs |
189 if nargout == 1 | |
190 if length(objs) == 1 | |
191 varargout{1} = objs{1}; | |
192 else | |
193 varargout{1} = objs; | |
194 end | |
195 else | |
196 for k=1:nargout | |
197 varargout{k} = objs{k}; | |
198 end | |
199 end | |
200 end | |
201 | |
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
203 % Local Functions % | |
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
205 | |
206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
207 % | |
208 function ii = getInfo(varargin) | |
209 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
210 sets = {}; | |
211 pl = []; | |
212 else | |
213 sets = {'Default'}; | |
214 pl = getDefaultPlist; | |
215 end | |
216 % Build info object | |
217 ii = minfo(mfilename, 'ltpda_uo', 'ltpda', utils.const.categories.internal, '$Id: retrieve.m,v 1.28 2011/07/01 14:38:57 ingo Exp $', sets, pl); | |
218 ii.setModifier(false); | |
219 end | |
220 | |
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
222 % | |
223 function plout = getDefaultPlist() | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
224 persistent pl; |
0 | 225 if exist('pl', 'var')==0 || isempty(pl) |
226 pl = buildplist(); | |
227 end | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
228 plout = pl; |
0 | 229 end |
230 | |
231 function plo = buildplist() | |
232 plo = plist(); | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
233 |
0 | 234 p = param({'conn', 'A database object'}, paramValue.EMPTY_DOUBLE); |
235 plo.append(p); | |
7
1e91f84a4be8
Make ltpda_up.retrieve work with java.sql.Connection objects
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
236 |
0 | 237 p = param({'ids', 'IDs which should be collected'}, paramValue.EMPTY_DOUBLE); |
238 plo.append(p); | |
239 end |