Mercurial > hg > ltpda
diff m-toolbox/classes/@ltpda_uo/fromRepository.m @ 24:056f8e1e995e database-connection-manager
Properly record history in fromRepository constructors
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | 69e3d49b4b0c |
children |
line wrap: on
line diff
--- a/m-toolbox/classes/@ltpda_uo/fromRepository.m Mon Dec 05 16:20:06 2011 +0100 +++ b/m-toolbox/classes/@ltpda_uo/fromRepository.m Mon Dec 05 16:20:06 2011 +0100 @@ -13,19 +13,19 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [objs, plhout, ii] = fromRepository(obj, pl, ii) - + VERSION = 'ltpda_uo: $Id: fromRepository.m,v 1.4 2010/03/16 19:16:20 ingo Exp $'; - + requested_class = class(obj); - + % Set the method version string in the minfo object ii.setMversion([VERSION '-->' ii.mversion]); - + % Get parameters ids = find(pl, 'id'); cids = find(pl, 'cid'); bin = find(pl, 'binary'); - + % Make sure that 'ids' or 'cids' are empty arrays if they are empty. % It might be that the GUI return an empty string. if isempty(ids) @@ -34,19 +34,18 @@ if isempty(cids) cids = []; end - + % Check if some ID is defined if isempty(ids) && isempty(cids) error('### Please define at least one object ID or connection ID'); end - - %%% check if using binary or not: 'yes'/'no' or true/false or - %%% 'true'/'false' + + % check if using binary download bin = utils.prog.yes2true(bin); % database connection conn = LTPDADatabaseConnectionManager().connect(pl); - + if ~isempty(cids) for kk=1:numel(cids) cid = cids(kk); @@ -54,21 +53,21 @@ ids = [ids utils.repository.getCollectionIDs(conn, cid)]; end end - + % Get each ID Nids = length(ids); objs = []; plhout = []; - + for kk=1:Nids - + %---- copy the input plist because each object should get an other plist plh = copy(pl, 1); - + %---- This id id = ids(kk); utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id); - + try %---- call database constructor if bin @@ -76,25 +75,23 @@ else obj = ltpda_uo.retrieve(conn, id); end - + if ~strcmp(class(obj), requested_class) error('### You have used the constructor ''%s'' but the object with id=%d is of class ''%s''', requested_class, id, class(obj)); end - - %---- remove the connection from the history plist - if plh.isparam('conn') - plh.remove('conn'); - end - + + %---- Set connection parameters in the plist + utils.repository.adjustPlist(conn, plh); + %---- Set only the ID of the current object to the plist - plh.pset('ID', id); - + plh.pset('id', id); + %---- Add history-plist to output array plhout = [plhout plh]; - + %---- Add to output array objs = [objs obj]; - + catch ex % close connection if we own it if isempty(find(pl, 'conn')) @@ -102,13 +99,13 @@ end throw(ex) end - + end - + % close connection if we own it if isempty(find(pl, 'conn')) conn.close(); end - + end