annotate m-toolbox/classes/@ltpda_uo/fromRepository.m @ 21:8be9deffe989 database-connection-manager

Update ltpda_uo.update
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents 69e3d49b4b0c
children 056f8e1e995e
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)
0
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
16
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 $';
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
18
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 requested_class = class(obj);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
20
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]);
19
69e3d49b4b0c Update ltpda_uo.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 % 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');
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
28
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
37
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
42
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
43 %%% check if using binary or not: 'yes'/'no' or true/false or
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
44 %%% 'true'/'false'
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
49
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
50 if ~isempty(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
51 for kk=1:numel(cids)
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
55 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
56 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
57
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
58 % Get each ID
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
59 Nids = length(ids);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
60 objs = [];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
61 plhout = [];
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
62
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
63 for kk=1:Nids
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
64
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
65 %---- copy the input plist because each object should get an other plist
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
66 plh = copy(pl, 1);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
67
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
68 %---- This id
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
69 id = ids(kk);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
70 utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
77 obj = ltpda_uo.retrieve(conn, id);
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
104 end
19
69e3d49b4b0c Update ltpda_uo.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 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
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
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
111 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
112
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
113 end
f0afece42f48 Import.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
114