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.1 2008/08/22 14:17:26 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.1 2008/08/22 14:17:26 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.1 2008/08/22 14:17:26 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 
0036   % do we have a connection?
0037   closeConn = 0;
0038   if isempty(conn)
0039     closeConn = 1;
0040     % Connect to repository
0041     conn = utils.mysql.connect(hostname, database);
0042   end
0043   if ~isa(conn, 'database')
0044     error('### connection to the database failed.');
0045   end
0046 
0047   % Get each ID
0048   Nids = length(ids);
0049   objs = [];
0050 
0051   for kk=1:Nids
0052 
0053     %---- This id
0054     id = ids(kk);
0055     utils.helper.msg(utils.const.msg.OPROC2, 'retrieving ID %d', id);
0056 
0057     %---- check ID object type
0058     tt = utils.mysql.getObjType(conn, id);
0059 
0060     %---- If this is an AO
0061     if strcmp(tt, class(obj))
0062       %---- call database constructor
0063       obj = ltpda_uo.retrieve(conn, id);
0064       %---- Add history
0065 
0066       % make a new history object
0067       %  - remove connection object from plist first
0068       txt = textscan(conn.URL, '%s', 'Delimiter', '/', 'CollectOutput', 1);
0069       plc = plist('hostname', txt{1}{3}, 'database', txt{1}{4});
0070       combine(pli, plc);
0071       pli.remove('conn');
0072       obj.addHistory(ii, pli, [], obj.hist);
0073 
0074       %---- Add to output array
0075       objs = [objs obj];
0076     else
0077       warning('    !skipping ID %d, type %s', id, tt);
0078     end
0079 
0080   end
0081 
0082   % close connection
0083   if closeConn
0084     close(conn);
0085   end
0086 end
0087

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003