Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDARepositoryManager/copyObjects.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % COPYOBJECTS This function copies objects from one repository to another. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % description: This static function copies objects from one repository to another. | |
5 % | |
6 % call: LTPDARepositoryManager.copyObjects(pl); | |
7 % LTPDARepositoryManager.copyObjects([1 2 3], | |
8 % 'hostname1', | |
9 % 'database1', | |
10 % 'username1', | |
11 % 'hostname2', | |
12 % 'database2', | |
13 % 'username2'); | |
14 % | |
15 % <a href="matlab:web(LTPDARepositoryManager.getInfo('LTPDARepositoryManager.copyObjects').tohtml, '-helpbrowser')">Parameters Description</a> | |
16 % | |
17 % version: $Id: copyObjects.m,v 1.5 2011/04/08 08:56:35 hewitson Exp $ | |
18 % | |
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
20 | |
21 function varargout = copyObjects(varargin) | |
22 | |
23 % Check if this is a call for parameters | |
24 if utils.helper.isinfocall(varargin{:}) | |
25 varargout{1} = getInfo(varargin{3}); | |
26 return | |
27 end | |
28 | |
29 import utils.const.* | |
30 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
31 | |
32 % Collect all plists | |
33 [pl, invars, rest] = utils.helper.collect_objects(varargin(:), 'plist'); | |
34 | |
35 pl = combine(pl, getDefaultPlist); | |
36 ids = pl.find('ids'); | |
37 hostname1 = pl.find('hostname1'); | |
38 database1 = pl.find('database1'); | |
39 username1 = pl.find('username1'); | |
40 hostname2 = pl.find('hostname2'); | |
41 database2 = pl.find('database2'); | |
42 username2 = pl.find('username2'); | |
43 | |
44 % Check through 'rest' | |
45 if numel(rest) > 0 | |
46 ids = rest{1}; | |
47 end | |
48 if numel(rest) > 1 | |
49 hostname1 = rest{2}; | |
50 end | |
51 if numel(rest) > 2 | |
52 database1 = rest{3}; | |
53 end | |
54 if numel(rest) > 3 | |
55 username1 = rest{4}; | |
56 end | |
57 if numel(rest) > 4 | |
58 hostname2 = rest{5}; | |
59 end | |
60 if numel(rest) > 5 | |
61 database2 = rest{6}; | |
62 end | |
63 if numel(rest) > 6 | |
64 username2 = rest{7}; | |
65 end | |
66 | |
67 % Some plausibility checks | |
68 if isempty(ids) | |
69 error('### This method needs at least one object id which you want to copy.'); | |
70 end | |
71 | |
72 % Get the repository manager - there should only be one! | |
73 rm = LTPDARepositoryManager(); | |
74 | |
75 % Get connection | |
76 conn1 = rm.findConnections(hostname1, database1, username1); | |
77 if numel(conn1) == 0 | |
78 conn1 = rm.newConnection(hostname1, database1, username1); | |
79 elseif numel(conn1) > 1 | |
80 conn1 = rm.manager.selectConnection([]); | |
81 end | |
82 | |
83 if isempty(conn1) | |
84 error('### It is necessary to create or select a connection.'); | |
85 end | |
86 | |
87 % open connection | |
88 conn1.openConnection(); | |
89 if ~conn1.isConnected() | |
90 error('### Can not open the connection.'); | |
91 end | |
92 | |
93 try | |
94 | |
95 objs = ltpda_uo.retrieve(conn1, ids); | |
96 if ~iscell(objs) | |
97 objs = {objs}; | |
98 end | |
99 sinfo = LTPDARepositoryManager.getSinfo(ids, ... | |
100 char(conn1.getHostname), char(conn1.getDatabase), char(conn1.getUsername)); | |
101 | |
102 pl = plist('hostname', hostname2, 'database', database2, 'username', username2, 'no dialog', true); | |
103 for oo = 1:numel(objs) | |
104 obj = objs{oo}; | |
105 obj.submit(sinfo(oo), pl); | |
106 end | |
107 catch Exception | |
108 disp(Exception.message); | |
109 error('### Copying failed.'); | |
110 end | |
111 | |
112 end | |
113 | |
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
115 % Local Functions % | |
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
117 | |
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
119 % | |
120 % FUNCTION: getInfo | |
121 % | |
122 % DESCRIPTION: Returns the method-info object | |
123 % | |
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
125 function ii = getInfo(varargin) | |
126 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
127 sets = {}; | |
128 pl = []; | |
129 else | |
130 sets = {'Default'}; | |
131 pl = getDefaultPlist; | |
132 end | |
133 % Build info object | |
134 ii = minfo(mfilename, 'LTPDARepositoryManager', 'ltpda', utils.const.categories.helper, '$Id: copyObjects.m,v 1.5 2011/04/08 08:56:35 hewitson Exp $', sets, pl); | |
135 end | |
136 | |
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
138 % | |
139 % FUNCTION: getDefaultPlist | |
140 % | |
141 % DESCRIPTION: Returns the default PLIST | |
142 % | |
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
144 function pl = getDefaultPlist() | |
145 | |
146 % Initialise plist | |
147 pl = plist(); | |
148 | |
149 % ids | |
150 p = param({'ids', 'Object identifications of which you want to copy.'}, paramValue.EMPTY_DOUBLE); | |
151 pl.append(p); | |
152 | |
153 % hostname1 | |
154 p = param({'hostname1', 'The hostname of the ''old'' repository.'}, paramValue.EMPTY_STRING); | |
155 pl.append(p); | |
156 | |
157 % database1 | |
158 p = param({'database1', 'The database of the ''old'' repository.'}, paramValue.EMPTY_STRING); | |
159 pl.append(p); | |
160 | |
161 % username1 | |
162 p = param({'username1', 'The username for the ''old'' repository.'}, paramValue.EMPTY_STRING); | |
163 pl.append(p); | |
164 | |
165 % hostname2 | |
166 p = param({'hostname2', 'The hostname of the ''new'' repository.'}, paramValue.EMPTY_STRING); | |
167 pl.append(p); | |
168 | |
169 % database2 | |
170 p = param({'database2', 'The database of the ''new'' repository.'}, paramValue.EMPTY_STRING); | |
171 pl.append(p); | |
172 | |
173 % username2 | |
174 p = param({'username2', 'The username for the ''new'' repository.'}, paramValue.EMPTY_STRING); | |
175 pl.append(p); | |
176 | |
177 end |