Mercurial > hg > ltpda
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:1e91f84a4be8 | 8:2f5c9bd7d95d |
---|---|
39 varargout{1} = getInfo(varargin{3}); | 39 varargout{1} = getInfo(varargin{3}); |
40 return | 40 return |
41 end | 41 end |
42 | 42 |
43 import utils.const.* | 43 import utils.const.* |
44 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | 44 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); |
45 | 45 |
46 if nargin == 0 | 46 if numel(varargin) < 2 |
47 help(mfilename); | 47 error('### invalid usage'); |
48 error('### Incorrect inputs'); | 48 end |
49 end | 49 |
50 | 50 % connection |
51 objs = []; | |
52 conn = varargin{1}; | 51 conn = varargin{1}; |
52 varargin = varargin(2:end); | |
53 if ~isa(conn, 'java.sql.Connection') | 53 if ~isa(conn, 'java.sql.Connection') |
54 error('### the first argument should be a java.sql.Connection object'); | 54 error('### the first argument should be a java.sql.Connection object'); |
55 end | 55 end |
56 | |
57 binary = false; | |
58 if ischar(varargin{1}) && strcmpi(varargin{1}, 'binary') | |
59 % binary | |
60 binary = true; | |
61 varargin = varargin(2:end); | |
62 utils.helper.msg(msg.PROC1, 'binary retrieve'); | |
63 end | |
64 | |
65 if ischar(varargin{1}) && strcmpi(varargin{1}, 'collection') | |
66 % collection | |
67 cid = varargin{2}; | |
68 varargin = varargin(3:end); | |
69 if ~isempty(varargin) | |
70 error('### wrong number of arguments'); | |
71 end | |
72 utils.helper.msg(msg.PROC1, 'retrieving collection %d', cid); | |
73 | |
74 % get list of object IDs from the collection ID | |
75 rows = utils.mysql.execute(conn, 'SELECT nobjs, obj_ids FROM collections WHERE id = ?', cid); | |
76 nobjs = rows{1}; | |
77 ids = strread(rows{2}, '%d', 'delimiter', ','); | |
78 if length(ids) ~= nobjs | |
79 error('### inconsistent collection description'); | |
80 end | |
81 | |
82 else | |
83 % IDs list | |
84 if isnumeric([varargin{:}]) | |
85 ids = [varargin{:}]; | |
86 else | |
87 error('### invalid usage'); | |
88 end | |
89 end | |
90 | |
91 utils.helper.msg(msg.PROC1, ['retrieving objects' sprintf(' %d', ids)]); | |
92 | |
93 % output vector | |
94 objs = []; | |
56 | 95 |
57 try | 96 try |
58 | 97 |
59 % get username and user id | 98 % get username and user id |
60 username = utils.mysql.execute(conn, 'SELECT SUBSTRING_INDEX(USER(),''@'',1)'); | 99 username = utils.mysql.execute(conn, 'SELECT SUBSTRING_INDEX(USER(),''@'',1)'); |
61 rows = utils.mysql.execute(conn, 'SELECT id FROM users WHERE username = ?', username{1}); | 100 rows = utils.mysql.execute(conn, 'SELECT id FROM users WHERE username = ?', username{1}); |
62 if isempty(rows) | 101 if isempty(rows) |
63 error('### could not determine user id'); | 102 error('### could not determine user id'); |
64 end | 103 end |
65 userid = rows{1}; | 104 userid = rows{1}; |
66 | |
67 binary = false; | |
68 if nargin >= 3 && ischar(varargin{2}) && strcmpi(varargin{2}, 'binary') | |
69 %%% retrieve(conn, 'binary', obj_id_1, obj_id_2) | |
70 %%% retrieve(conn, 'binary', 'Collection', coll_id) | |
71 binary = true; | |
72 if nargin == 4 && ischar(varargin{3}) && strcmpi(varargin{3}, 'Collection') && isnumeric(varargin{4}) && numel(varargin{4}) == 1 | |
73 cid = varargin{4}; | |
74 % Get a list of object IDs from the collection ID | |
75 rows = utils.mysql.execute(conn, 'SELECT nobjs, obj_ids FROM collections WHERE id = ?', cid); | |
76 nobjs = rows{1}; | |
77 ids = strread(rows{2}, '%d', 'delimiter', ','); | |
78 if length(ids) ~= nobjs | |
79 error('### inconsistent collection description'); | |
80 end | |
81 elseif nargin >= 3 && isnumeric([varargin{3:end}]) | |
82 ids = [varargin{3:end}]; | |
83 else | |
84 help(mfilename) | |
85 error('### Incorrect usage'); | |
86 end | |
87 | |
88 elseif nargin == 3 && ischar(varargin{2}) && strcmpi(varargin{2}, 'Collection') && isnumeric(varargin{3}) && numel(varargin{3}) == 1 | |
89 %%% retrieve(conn, 'Collection', coll_id) | |
90 cid = varargin{3}; | |
91 % Get a list of object IDs from the collection ID | |
92 rows = utils.mysql.execute(conn, 'SELECT nobjs, obj_ids FROM collections WHERE id = ?', cid); | |
93 nobjs = rows{1}; | |
94 ids = strread(rows{2}, '%d', 'delimiter', ','); | |
95 if length(ids) ~= nobjs | |
96 error('### inconsistent collection description'); | |
97 end | |
98 | |
99 elseif nargin >= 2 && isnumeric([varargin{2:end}]) | |
100 %%% retrieve(conn, obj_id_1, obj_id_2) | |
101 ids = [varargin{2:end}]; | |
102 | |
103 else | |
104 help(mfilename) | |
105 error('### incorrect usage'); | |
106 end | |
107 | |
108 utils.helper.msg(msg.PROC1, ['retrieving objects' sprintf(' %d', ids)]); | |
109 | 105 |
110 v = ver('LTPDA'); | 106 v = ver('LTPDA'); |
111 for j=1:length(ids) | 107 for j=1:length(ids) |
112 | 108 |
113 rows = utils.mysql.execute(conn, 'SELECT version, obj_type FROM objmeta WHERE obj_id = ?', ids(j)); | 109 rows = utils.mysql.execute(conn, 'SELECT version, obj_type FROM objmeta WHERE obj_id = ?', ids(j)); |