annotate m-toolbox/classes/@ltpda_uo/fromRepository.m @ 31:a26669b59d7e database-connection-manager

Update LTPDAworkbench
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +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.4 2010/03/16 19:16:20 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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)
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
16
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
17 VERSION = 'ltpda_uo: $Id: fromRepository.m,v 1.4 2010/03/16 19:16:20 ingo Exp $';
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
18
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 requested_class = class(obj);
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
20
0
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]);
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
23
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
24 % Get parameters
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
25 ids = find(pl, 'id');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
26 cids = find(pl, 'cid');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
27 bin = find(pl, 'binary');
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
28
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
29 % Make sure that 'ids' or 'cids' are empty arrays if they are empty.
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
30 % It might be that the GUI return an empty string.
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
31 if isempty(ids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
32 ids = [];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
33 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
34 if isempty(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
35 cids = [];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
36 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
37
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
38 % Check if some ID is defined
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
39 if isempty(ids) && isempty(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
40 error('### Please define at least one object ID or connection ID');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
41 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
42
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
43 % check if using binary download
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
44 bin = utils.prog.yes2true(bin);
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
45
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
46 % database connection
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
47 conn = LTPDADatabaseConnectionManager().connect(pl);
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
48
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
49 if ~isempty(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
50 for kk=1:numel(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
51 cid = cids(kk);
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
52 % get the ids from the cid
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
53 ids = [ids utils.repository.getCollectionIDs(conn, cid)];
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
54 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
55 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
56
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
57 % Get each ID
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
58 Nids = length(ids);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
59 objs = [];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
60 plhout = [];
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
61
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
62 for kk=1:Nids
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
63
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
64 %---- copy the input plist because each object should get an other plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
65 plh = copy(pl, 1);
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
66
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
67 %---- This id
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
68 id = ids(kk);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
69 utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id);
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
70
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
71 try
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
72 %---- call database constructor
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
73 if bin
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
74 obj = ltpda_uo.retrieve(conn, 'binary', id);
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
75 else
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
76 obj = ltpda_uo.retrieve(conn, id);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
77 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
78
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
79 if ~strcmp(class(obj), requested_class)
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
80 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
81 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
82
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
83 %---- Set connection parameters in the plist
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
84 utils.repository.adjustPlist(conn, plh);
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
85
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
86 %---- Set only the ID of the current object to the plist
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
87 plh.pset('id', id);
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
88
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
89 %---- Add history-plist to output array
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
90 plhout = [plhout plh];
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
91
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
92 %---- Add to output array
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
93 objs = [objs obj];
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
94
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
95 catch ex
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
96 % close connection if we own it
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
97 if isempty(find(pl, 'conn'))
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
98 conn.close();
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
99 end
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
100 throw(ex)
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
101 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
102
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
103 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
104
19
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
105 % close connection if we own it
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
106 if isempty(find(pl, 'conn'))
69e3d49b4b0c Update ltpda_uo.fromRepository
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 0
diff changeset
107 conn.close();
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
108 end
24
056f8e1e995e Properly record history in fromRepository constructors
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 19
diff changeset
109
0
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