# HG changeset patch # User Daniele Nicolodi # Date 1323098406 -3600 # Node ID 69e3d49b4b0c766ae98d209c122356f87dd846c1 # Parent 947e2ff4b1b99157cf3670a2745c577b7700d6e2 Update ltpda_uo.fromRepository diff -r 947e2ff4b1b9 -r 69e3d49b4b0c m-toolbox/classes/@ltpda_uo/fromRepository.m --- 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 @@ -12,7 +12,7 @@ % VERSION: $Id: fromRepository.m,v 1.4 2010/03/16 19:16:20 ingo Exp $ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function [objs, plhout, ii] = fromRepository(obj, pli, ii) +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 $'; @@ -20,22 +20,8 @@ % Set the method version string in the minfo object ii.setMversion([VERSION '-->' ii.mversion]); - - % Check if the user supplied a DB connection - conn = find(pli, 'conn'); - - % Add default values if necessary - if isempty(conn) - pl = combine(pli, ii.plists.pset('HOSTNAME', '')); - else - pl = pli; - end - + % Get parameters - hostname = find(pl, 'hostname'); - database = find(pl, 'database'); - user = find(pl, 'username'); - passwd = find(pl, 'password'); ids = find(pl, 'id'); cids = find(pl, 'cid'); bin = find(pl, 'binary'); @@ -57,28 +43,15 @@ %%% check if using binary or not: 'yes'/'no' or true/false or %%% 'true'/'false' bin = utils.prog.yes2true(bin); - - % do we have a connection? - closeConn = 0; - if isempty(conn) - closeConn = 1; - % Connect to repository - conn = utils.jmysql.connect(hostname, database, user, passwd); - end - if ~isa(conn, 'database') && ~isa(conn, 'mpipeline.repository.RepositoryConnection') - error('### connection to the database failed.'); - end + + % database connection + conn = LTPDADatabaseConnectionManager().connect(pl); if ~isempty(cids) for kk=1:numel(cids) cid = cids(kk); - if isa(conn, 'database') - % get the ids from the cid - ids = [ids utils.mysql.getObjIds(conn,cid)]; - else - c_ids = double(mpipeline.repository.MySQLUtils.getObjectIDsFromCollectionID(conn, cid)); - ids = [ids c_ids.']; - end + % get the ids from the cid + ids = [ids utils.repository.getCollectionIDs(conn, cid)]; end end @@ -96,62 +69,45 @@ id = ids(kk); utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id); - %---- call database constructor - if bin - try + try + %---- call database constructor + if bin obj = ltpda_uo.retrieve(conn, 'binary', id); - - catch - - if ~conn.isConnected() - error('### There is something wrong with the connection.') - end - - warning('!!! Unable to do binary retrieval for object %d; trying to retrieve XML instead.', id); + else obj = ltpda_uo.retrieve(conn, id); end - 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 connection object from plist first - if isempty(hostname) || isempty(database) - if isa(conn, 'database') - txt = textscan(conn.URL, '%s', 'Delimiter', '/', 'CollectOutput', 1); - plc = plist('hostname', txt{1}{3}, 'database', txt{1}{4}); - else - plc = plist('hostname', char(conn.getHostname), 'database', char(conn.getDatabase)); + + 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 - plh = combine(pli, plc); - end - - %---- remove the connection from the history plist - if plh.isparam('conn') - plh.remove('conn'); + + %---- Set only the ID of the current object to the plist + 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')) + conn.close(); + end + throw(ex) end - - %---- Set only the ID of the current object to the plist - plh.pset('ID', id); - - %---- Add history-plist to output array - plhout = [plhout plh]; - - %---- Add to output array - objs = [objs obj]; - + end - % close connection - if closeConn - if isa(conn, 'database') - close(conn); - else - conn.closeConnection; - end + % close connection if we own it + if isempty(find(pl, 'conn')) + conn.close(); end end