annotate m-toolbox/classes/@collection/fromRepository.m @ 52:daf4eab1a51e database-connection-manager tip

Fix. Default password should be [] not an empty string
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:29:47 +0100
parents 056f8e1e995e
children
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 a ltpda_uo from a 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 % FUNCTION: fromRepository
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
5 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
6 % DESCRIPTION: Retrieve a ltpda_uo from a repository
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
7 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
8 % CALL: obj = fromRepository(pl)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
9 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
10 % PARAMETER: pl: Parameter list object
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
11 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
12 % VERSION: $Id: fromRepository.m,v 1.8 2010/10/29 16:09:11 ingo Exp $
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
13 %
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 % get object info
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
20 ii = collection.getInfo('collection', 'From Repository');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
21 % Set the method version string in the minfo object
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
22 ii.setMversion([VERSION '-->' ii.mversion]);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
23
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
24 plh = copy(pl, 1);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
25
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
26 % Get parameters
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
27 ids = find(pl, 'id');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
28 cids = find(pl, 'cid');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
29 bin = find(pl, 'binary');
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
30
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
39 if ~isempty(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
40 for kk=1:numel(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
43 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
44 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
45
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
46 % Get each ID
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
47 Nids = length(ids);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
48 collObjs = {};
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
49
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
50 for kk=1:Nids
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
51
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
52 %---- copy the input plist because each object should get an other plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
53 plh = copy(pl, 1);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
54
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
55 %---- This id
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
56 id = ids(kk);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
59 try
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
60 %---- call database constructor
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
63 else
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
64 robj = ltpda_uo.retrieve(conn, id);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
70 %---- Set only the ID of the current object to the plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
71 plh.pset('ID', id);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
72
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
73 %---- Add history
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
76 %---- Add to output array
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
77 if isa(robj, 'collection')
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
78 if numel(ids) == 1
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
79 coll = robj;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
80 return
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
81 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
82
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
83 if numel(robj.objs)>0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
84 collFound = true;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
85 collObjs = [collObjs; robj.objs(:)];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
86 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
87 else
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
88 collObjs = [collObjs; {robj}];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
95 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
96 throw(ex)
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
97 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
98
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
104 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
105
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
106 if collFound
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
107 warning(sprintf(['!!! The output collection contains the contents of at least one retrieved collection.' ...
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
108 '\nThe history of those collection objects is discarded. The internal objects of those ' ...
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
109 'objects is retained.']));
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
110 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
111 if isempty(collObjs)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
112 warning('!!! No objects were retrieved from the ids %s and/or collection id %s', mat2str(ids), mat2str(cid));
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
113 end
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
114
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
119 % Set properties from the plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
120 coll.setProperties(pl);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
121 coll.objs = collObjs;
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
122 coll.addHistory(ii, plh, [], []);
22
b11e88004fca Update collection.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
123
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
124 end