Home > classes > @ao > private > retrieve.m

retrieve

PURPOSE ^

RETRIEVE an AO from the MySQL server.

SYNOPSIS ^

function as = retrieve(varargin)

DESCRIPTION ^

 RETRIEVE an AO from the MySQL server.

 Usage: as = retrieve(AOids);

 M Hewitson 09-05-07

 $Id: retrieve.html,v 1.1 2007/06/08 14:15:04 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function as = retrieve(varargin)
0002 
0003 % RETRIEVE an AO from the MySQL server.
0004 %
0005 % Usage: as = retrieve(AOids);
0006 %
0007 % M Hewitson 09-05-07
0008 %
0009 % $Id: retrieve.html,v 1.1 2007/06/08 14:15:04 hewitson Exp $
0010 %
0011 
0012 type = '';
0013 ids = [];
0014 for j=1:nargin
0015   if isnumeric(varargin{j})
0016     ids = [ids varargin{j}];
0017   elseif ischar(varargin{j})
0018     type = varargin{j};
0019   end
0020 end
0021 
0022 as = [];
0023 
0024 %--------------------------------------------------------------------------
0025 % open mysql connection
0026 
0027 conn = mysql_connect();
0028 
0029 
0030 switch type
0031   case 'AO'
0032     %--------------------------------------------------------------------------
0033     % Retrieve requested AO(s)
0034     for j=1:length(ids)
0035       % get AO from db
0036       id = ids(j);
0037       a = getAO(conn, id);
0038       as = [as a];
0039 
0040       % update transactions table
0041       p = provenance;
0042       a = as(end);
0043       % Get UserID from Username
0044       [userid, dbuser] = mysql_getUserID(conn);
0045 
0046       submitted = reformate_date(sprintf('%s', datestr(now,31)));
0047       ip        = get(p, 'ip');
0048       hostname  = get(p, 'hostname');
0049 
0050       colnames = {'aoid','UserId','Tdate','SrcIP','Hostname','Direction'};
0051       exdata   = {a.tag,userid,submitted,ip,hostname,'out'};
0052       try
0053         fastinsert(conn, 'transactions', colnames, exdata);
0054       catch
0055         warning(sprintf('### error updating transaction table for submission of AO %s/%d', a.name, a.tag));
0056       end
0057 
0058     end
0059 
0060   case 'Collection'
0061 
0062     % Get AOids from collection
0063     curs     = exec(conn, sprintf('select aoids from collections where id=%d', ids(1)));
0064     curs     = fetch(curs);
0065     AOidsStr = curs.Data{1};
0066     close(curs);
0067     AOids = str2num(AOidsStr);
0068 
0069     % Retrieve requested AO(s)
0070     for j=1:length(AOids)
0071       % get AO from db
0072       id = AOids(j);
0073       a  = getAO(conn, id);
0074       as = [as a];
0075       % update transactions table
0076       p = provenance;
0077       a = as(end);
0078       % Get UserID from Username
0079       [userid, dbuser] = mysql_getUserID(conn);
0080 
0081       submitted = ltpda_reformate_date(sprintf('%s', datestr(now,31)));
0082       ip        = get(p, 'ip');
0083       hostname  = get(p, 'hostname');
0084 
0085       colnames = {'aoid','UserId','Tdate','SrcIP','Hostname','Direction'};
0086       exdata   = {a.tag,userid,submitted,ip,hostname,'out'};
0087       try
0088         fastinsert(conn, 'transactions', colnames, exdata);
0089       catch
0090         warning(sprintf('### error updating transaction table for submission of AO %s/%d', a.name, a.tag));
0091       end
0092     end
0093 end
0094 
0095 %--------------------------------------------------------------------------
0096 % close MySQL connection
0097 close(conn);
0098 
0099 
0100 %--------------------------------------------------------------------------
0101 % getAO from id
0102 function a = getAO(conn, id)
0103 
0104 curs = exec(conn, sprintf('select AO from aos where id=%d', id));
0105 curs = fetch(curs);
0106 Atxt  = char([curs.Data{1}].');
0107 close(curs);
0108 
0109 % convert to Java string
0110 str = java.lang.String(Atxt);
0111 % open stream on this string
0112 stream = java.io.StringBufferInputStream(str);
0113 % make parser
0114 factory = javaMethod('newInstance',...
0115   'javax.xml.parsers.DocumentBuilderFactory');
0116 builder = factory.newDocumentBuilder;
0117 
0118 xdoc = builder.parse(stream);
0119 a = xdoc2ao(xdoc);
0120 
0121 
0122 % END

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003