Home > classes > @ltpda_uoh > fromRepository.m

fromRepository

PURPOSE ^

Retrieve a ltpda_uo from a repository

SYNOPSIS ^

function objs = fromRepository(obj, pli)

DESCRIPTION ^

 Retrieve a ltpda_uo from a repository
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 FUNCTION:    fromRepository

 DESCRIPTION: Retrieve a ltpda_uo from a repository

 CALL:        obj = fromRepository(pl)

 PARAMETER:   pl: Parameter list object

 VERSION:     $Id: fromRepository.m,v 1.3 2008/09/04 13:37:14 ingo Exp $

 HISTORY:     07-05-2007 Hewitson
              Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Retrieve a ltpda_uo from a repository
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % FUNCTION:    fromRepository
0005 %
0006 % DESCRIPTION: Retrieve a ltpda_uo from a repository
0007 %
0008 % CALL:        obj = fromRepository(pl)
0009 %
0010 % PARAMETER:   pl: Parameter list object
0011 %
0012 % VERSION:     $Id: fromRepository.m,v 1.3 2008/09/04 13:37:14 ingo Exp $
0013 %
0014 % HISTORY:     07-05-2007 Hewitson
0015 %              Creation
0016 %
0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0018 function objs = fromRepository(obj, pli)
0019 
0020   VERSION = '$Id: fromRepository.m,v 1.3 2008/09/04 13:37:14 ingo Exp $';
0021 
0022   % get object info
0023   ii = obj.getInfo(class(obj), 'From Repository');
0024   % Set the method version string in the minfo object
0025   ii.setMversion([VERSION '-->' ii.mversion]);
0026 
0027   % Add default values
0028   pl = combine(pli, ii.plists);
0029 
0030   % Get parameters
0031   conn     = find(pl, 'conn');
0032   hostname = find(pl, 'hostname');
0033   database = find(pl, 'database');
0034   ids      = find(pl, 'id');
0035   cid      = find(pl, 'cid');
0036 
0037   % do we have a connection?
0038   closeConn = 0;
0039   if isempty(conn)
0040     closeConn = 1;
0041     % Connect to repository
0042     conn = utils.mysql.connect(hostname, database);
0043   end
0044   if ~isa(conn, 'database')
0045     error('### connection to the database failed.');
0046   end
0047   
0048   if isempty(ids) && ~isempty(cid)
0049     % get the ids from the cid
0050     ids = utils.mysql.getObjIds(conn,cid);
0051   end  
0052 
0053   % Get each ID
0054   Nids = length(ids);
0055   objs = [];
0056 
0057   for kk=1:Nids
0058 
0059     %---- This id
0060     id = ids(kk);
0061     utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id);
0062 
0063     %---- check ID object type
0064     tt = utils.mysql.getObjType(conn, id);
0065 
0066     %---- If this is an AO
0067     if strcmp(tt, class(obj))
0068       %---- call database constructor
0069       obj = ltpda_uo.retrieve(conn, id);
0070       %---- Add history
0071 
0072       % make a new history object
0073       %  - remove connection object from plist first
0074       txt = textscan(conn.URL, '%s', 'Delimiter', '/', 'CollectOutput', 1);
0075       plc = plist('hostname', txt{1}{3}, 'database', txt{1}{4});
0076       pl = combine(pli, plc);
0077       pl.remove('conn');
0078       obj.addHistory(ii, pl, [], obj.hist);
0079 
0080       %---- Add to output array
0081       objs = [objs obj];
0082     else
0083       warning('    !skipping ID %d, type %s', id, tt);
0084     end
0085 
0086   end
0087 
0088   % close connection
0089   if closeConn
0090     close(conn);
0091   end
0092 end
0093

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003