changeset 8:2f5c9bd7d95d database-connection-manager

Clarify ltpda_uo.retrieve parameters handling
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents 1e91f84a4be8
children fbbfcd56e449
files m-toolbox/classes/@ltpda_uo/retrieve.m
diffstat 1 files changed, 44 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/m-toolbox/classes/@ltpda_uo/retrieve.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/@ltpda_uo/retrieve.m	Mon Dec 05 16:20:06 2011 +0100
@@ -41,19 +41,58 @@
   end
 
   import utils.const.*
-  utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
+  utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
 
-  if nargin == 0
-    help(mfilename);
-    error('### Incorrect inputs');
+  if numel(varargin) < 2
+    error('### invalid usage');
   end
 
-  objs = [];
+  % connection
   conn = varargin{1};
+  varargin = varargin(2:end);
   if ~isa(conn, 'java.sql.Connection')
     error('### the first argument should be a java.sql.Connection object');
   end
 
+  binary = false;
+  if ischar(varargin{1}) && strcmpi(varargin{1}, 'binary')
+    % binary
+    binary = true;
+    varargin = varargin(2:end);
+    utils.helper.msg(msg.PROC1, 'binary retrieve');
+  end
+
+  if ischar(varargin{1}) && strcmpi(varargin{1}, 'collection')
+    % collection
+    cid = varargin{2};
+    varargin = varargin(3:end);
+    if ~isempty(varargin)
+      error('### wrong number of arguments');
+    end
+    utils.helper.msg(msg.PROC1, 'retrieving collection %d', cid);
+
+    % get list of object IDs from the collection ID
+    rows = utils.mysql.execute(conn, 'SELECT nobjs, obj_ids FROM collections WHERE id = ?', cid);
+    nobjs = rows{1};
+    ids = strread(rows{2}, '%d', 'delimiter', ',');
+    if length(ids) ~= nobjs
+      error('### inconsistent collection description');
+    end
+
+  else
+    % IDs list
+    if isnumeric([varargin{:}])
+      ids = [varargin{:}];
+    else
+      error('### invalid usage');
+    end
+  end
+
+  utils.helper.msg(msg.PROC1, ['retrieving objects' sprintf(' %d', ids)]);
+
+  % output vector
+  objs = [];
+
   try
 
     % get username and user id
@@ -64,49 +103,6 @@
     end
     userid = rows{1};
 
-    binary = false;
-    if nargin >= 3 && ischar(varargin{2}) && strcmpi(varargin{2}, 'binary')
-      %%%  retrieve(conn, 'binary', obj_id_1, obj_id_2)
-      %%%  retrieve(conn, 'binary', 'Collection', coll_id)
-      binary = true;
-      if nargin == 4 && ischar(varargin{3}) && strcmpi(varargin{3}, 'Collection') && isnumeric(varargin{4}) && numel(varargin{4}) == 1
-        cid = varargin{4};
-        % Get a list of object IDs from the collection ID
-        rows = utils.mysql.execute(conn, 'SELECT nobjs, obj_ids FROM collections WHERE id = ?', cid);
-        nobjs = rows{1};
-        ids = strread(rows{2}, '%d', 'delimiter', ',');
-        if length(ids) ~= nobjs
-          error('### inconsistent collection description');
-        end
-      elseif nargin >= 3 && isnumeric([varargin{3:end}])
-        ids = [varargin{3:end}];
-      else
-        help(mfilename)
-        error('### Incorrect usage');
-      end
-
-    elseif nargin == 3 && ischar(varargin{2}) && strcmpi(varargin{2}, 'Collection') && isnumeric(varargin{3}) && numel(varargin{3}) == 1
-      %%%  retrieve(conn, 'Collection', coll_id)
-      cid = varargin{3};
-      % Get a list of object IDs from the collection ID
-      rows = utils.mysql.execute(conn, 'SELECT nobjs, obj_ids FROM collections WHERE id = ?', cid);
-      nobjs = rows{1};
-      ids = strread(rows{2}, '%d', 'delimiter', ',');
-      if length(ids) ~= nobjs
-        error('### inconsistent collection description');
-      end
-
-    elseif nargin >= 2 && isnumeric([varargin{2:end}])
-      %%%  retrieve(conn, obj_id_1, obj_id_2)
-      ids = [varargin{2:end}];
-
-    else
-      help(mfilename)
-      error('### incorrect usage');
-    end
-
-    utils.helper.msg(msg.PROC1, ['retrieving objects' sprintf(' %d', ids)]);
-
     v = ver('LTPDA');
     for j=1:length(ids)