annotate m-toolbox/classes/@ltpda_uo/retrieve.m @ 7:1e91f84a4be8 database-connection-manager

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