Mercurial > hg > ltpda
annotate m-toolbox/classes/@ltpda_uo/fromRepository.m @ 20:d58813ab1b92 database-connection-manager
Update ltpda_uo.submit
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | 69e3d49b4b0c |
children | 056f8e1e995e |
rev | line source |
---|---|
0 | 1 % Retrieve a ltpda_uo from a repository |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % FUNCTION: fromRepository | |
5 % | |
6 % DESCRIPTION: Retrieve a ltpda_uo from a repository | |
7 % | |
8 % CALL: obj = fromRepository(pl) | |
9 % | |
10 % PARAMETER: pl: Parameter list object | |
11 % | |
12 % VERSION: $Id: fromRepository.m,v 1.4 2010/03/16 19:16:20 ingo Exp $ | |
13 % | |
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
15 function [objs, plhout, ii] = fromRepository(obj, pl, ii) |
0 | 16 |
17 VERSION = 'ltpda_uo: $Id: fromRepository.m,v 1.4 2010/03/16 19:16:20 ingo Exp $'; | |
18 | |
19 requested_class = class(obj); | |
20 | |
21 % Set the method version string in the minfo object | |
22 ii.setMversion([VERSION '-->' ii.mversion]); | |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
23 |
0 | 24 % Get parameters |
25 ids = find(pl, 'id'); | |
26 cids = find(pl, 'cid'); | |
27 bin = find(pl, 'binary'); | |
28 | |
29 % Make sure that 'ids' or 'cids' are empty arrays if they are empty. | |
30 % It might be that the GUI return an empty string. | |
31 if isempty(ids) | |
32 ids = []; | |
33 end | |
34 if isempty(cids) | |
35 cids = []; | |
36 end | |
37 | |
38 % Check if some ID is defined | |
39 if isempty(ids) && isempty(cids) | |
40 error('### Please define at least one object ID or connection ID'); | |
41 end | |
42 | |
43 %%% check if using binary or not: 'yes'/'no' or true/false or | |
44 %%% 'true'/'false' | |
45 bin = utils.prog.yes2true(bin); | |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
46 |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
47 % database connection |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
48 conn = LTPDADatabaseConnectionManager().connect(pl); |
0 | 49 |
50 if ~isempty(cids) | |
51 for kk=1:numel(cids) | |
52 cid = cids(kk); | |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
53 % get the ids from the cid |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
54 ids = [ids utils.repository.getCollectionIDs(conn, cid)]; |
0 | 55 end |
56 end | |
57 | |
58 % Get each ID | |
59 Nids = length(ids); | |
60 objs = []; | |
61 plhout = []; | |
62 | |
63 for kk=1:Nids | |
64 | |
65 %---- copy the input plist because each object should get an other plist | |
66 plh = copy(pl, 1); | |
67 | |
68 %---- This id | |
69 id = ids(kk); | |
70 utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id); | |
71 | |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
72 try |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
73 %---- call database constructor |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
74 if bin |
0 | 75 obj = ltpda_uo.retrieve(conn, 'binary', id); |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
76 else |
0 | 77 obj = ltpda_uo.retrieve(conn, id); |
78 end | |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
79 |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
80 if ~strcmp(class(obj), requested_class) |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
81 error('### You have used the constructor ''%s'' but the object with id=%d is of class ''%s''', requested_class, id, class(obj)); |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
82 end |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
83 |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
84 %---- remove the connection from the history plist |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
85 if plh.isparam('conn') |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
86 plh.remove('conn'); |
0 | 87 end |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
88 |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
89 %---- Set only the ID of the current object to the plist |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
90 plh.pset('ID', id); |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
91 |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
92 %---- Add history-plist to output array |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
93 plhout = [plhout plh]; |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
94 |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
95 %---- Add to output array |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
96 objs = [objs obj]; |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
97 |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
98 catch ex |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
99 % close connection if we own it |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
100 if isempty(find(pl, 'conn')) |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
101 conn.close(); |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
102 end |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
103 throw(ex) |
0 | 104 end |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
105 |
0 | 106 end |
107 | |
19
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
108 % close connection if we own it |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
109 if isempty(find(pl, 'conn')) |
69e3d49b4b0c
Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
110 conn.close(); |
0 | 111 end |
112 | |
113 end | |
114 |