Mercurial > hg > ltpda
annotate m-toolbox/classes/@collection/fromRepository.m @ 27:29276498ebdb database-connection-manager
Remove LTPDARepositoryManager implementation
* * *
Remove GUI helper
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | 056f8e1e995e |
children |
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.8 2010/10/29 16:09:11 ingo Exp $ | |
13 % | |
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
15 function coll = fromRepository(coll, pl) |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
16 |
0 | 17 VERSION = '$Id: fromRepository.m,v 1.8 2010/10/29 16:09:11 ingo Exp $'; |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
18 |
0 | 19 % get object info |
20 ii = collection.getInfo('collection', 'From Repository'); | |
21 % Set the method version string in the minfo object | |
22 ii.setMversion([VERSION '-->' ii.mversion]); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
23 |
0 | 24 plh = copy(pl, 1); |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
25 |
0 | 26 % Get parameters |
27 ids = find(pl, 'id'); | |
28 cids = find(pl, 'cid'); | |
29 bin = find(pl, 'binary'); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
30 |
0 | 31 collFound = false; |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
32 |
24
056f8e1e995e
Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
22
diff
changeset
|
33 % check if using binary download |
0 | 34 bin = utils.prog.yes2true(bin); |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
35 |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
36 % database connection |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
37 conn = LTPDADatabaseConnectionManager().connect(pl); |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
38 |
0 | 39 if ~isempty(cids) |
40 for kk=1:numel(cids) | |
41 cid = cids(kk); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
42 ids = utils.repository.getCollectionIDs(conn, cid); |
0 | 43 end |
44 end | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
45 |
0 | 46 % Get each ID |
47 Nids = length(ids); | |
48 collObjs = {}; | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
49 |
0 | 50 for kk=1:Nids |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
51 |
0 | 52 %---- copy the input plist because each object should get an other plist |
53 plh = copy(pl, 1); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
54 |
0 | 55 %---- This id |
56 id = ids(kk); | |
57 utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
58 |
0 | 59 try |
60 %---- call database constructor | |
61 if bin | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
62 robj = ltpda_uo.retrieve(conn, 'binary', id); |
0 | 63 else |
64 robj = ltpda_uo.retrieve(conn, id); | |
65 end | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
66 |
24
056f8e1e995e
Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
22
diff
changeset
|
67 %---- Set connection parameters in the plist |
056f8e1e995e
Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
22
diff
changeset
|
68 utils.repository.adjustPlist(conn, plh); |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
69 |
0 | 70 %---- Set only the ID of the current object to the plist |
71 plh.pset('ID', id); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
72 |
0 | 73 %---- Add history |
74 robj.addHistoryWoChangingUUID(robj.getInfo(class(robj), 'From Repository'), plh, [], robj.hist); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
75 |
0 | 76 %---- Add to output array |
77 if isa(robj, 'collection') | |
78 if numel(ids) == 1 | |
79 coll = robj; | |
80 return | |
81 end | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
82 |
0 | 83 if numel(robj.objs)>0 |
84 collFound = true; | |
85 collObjs = [collObjs; robj.objs(:)]; | |
86 end | |
87 else | |
88 collObjs = [collObjs; {robj}]; | |
89 end | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
90 |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
91 catch ex |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
92 % close connection if we own it |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
93 if isempty(find(pl, 'conn')) |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
94 conn.close(); |
0 | 95 end |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
96 throw(ex) |
0 | 97 end |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
98 |
0 | 99 end |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
100 |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
101 % close connection if we own it |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
102 if isempty(find(pl, 'conn')) |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
103 conn.close(); |
0 | 104 end |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
105 |
0 | 106 if collFound |
107 warning(sprintf(['!!! The output collection contains the contents of at least one retrieved collection.' ... | |
108 '\nThe history of those collection objects is discarded. The internal objects of those ' ... | |
109 'objects is retained.'])); | |
110 end | |
111 if isempty(collObjs) | |
112 warning('!!! No objects were retrieved from the ids %s and/or collection id %s', mat2str(ids), mat2str(cid)); | |
113 end | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
114 |
0 | 115 % Define collection-plist for the history |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
116 plh.pset('id', pl.find('id')); |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
117 plh.pset('cid', pl.find('cid')); |
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
118 |
0 | 119 % Set properties from the plist |
120 coll.setProperties(pl); | |
121 coll.objs = collObjs; | |
122 coll.addHistory(ii, plh, [], []); | |
22
b11e88004fca
Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
123 |
0 | 124 end |