changeset 30:317b5f447f3e database-connection-manager

Update workspaceBrowser
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents 54f14716c721
children a26669b59d7e
files m-toolbox/classes/@workspaceBrowser/cb_query.m m-toolbox/classes/@workspaceBrowser/cb_retrieve.m m-toolbox/classes/@workspaceBrowser/retrieveObjectsFromDialog.m m-toolbox/classes/@workspaceBrowser/workspaceBrowser.m
diffstat 4 files changed, 48 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/m-toolbox/classes/@workspaceBrowser/cb_query.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/@workspaceBrowser/cb_query.m	Mon Dec 05 16:20:06 2011 +0100
@@ -9,27 +9,19 @@
 function cb_query(varargin)
   
   wb = getappdata(0, 'WorkspaceBrowser');
-  
-  % Get a connection from the repository manager
-  rm = LTPDARepositoryManager;
-  conn = rm.manager.selectConnection([]);
+    
+  % Get a connection from the database connection manager
+  conn = LTPDADatabaseConnectionManager().connect();
+
+  % Get submission info from the user
+  rqd = awtcreate('mpipeline.repository.RepositoryQueryDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.Connection;Z', [], false, conn, false);
+  awtinvoke(rqd, 'setVisible', 'true');
+    
+  hExec = handle(rqd.getExecuteBtn(),'callbackproperties');
+  hExec.ActionPerformedCallback = @cb_executeQuery;
   
-  if ~isempty(conn)
-    % Update
-    if ~isempty(rm.gui)
-      awtinvoke(rm.gui, 'reloadConnectionTable()');
-    end
-    % Get submission info from the user
-    rqd = awtcreate('mpipeline.repository.RepositoryQueryDialog', 'Lmpipeline.main.MainWindow;ZLmpipeline.repository.RepositoryConnection;Z', [], false, conn, false);
-    awtinvoke(rqd, 'setVisible', 'true');
-    
-    hExec = handle(rqd.getExecuteBtn(),'callbackproperties');
-    hExec.ActionPerformedCallback = @cb_executeQuery;
-    
-    hGuiCloses1 = handle(rqd, 'callbackproperties');
-    hGuiCloses1.WindowClosedCallback = @cb_guiClosed1;
-    
-  end
+  hGuiCloses1 = handle(rqd, 'callbackproperties');
+  hGuiCloses1.WindowClosedCallback = @cb_guiClosed1;
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   function cb_guiClosed1(varargin)
@@ -53,37 +45,27 @@
     jQueryTextField = awtinvoke(rqd, 'getQueryTxtField()');
     jQuery = awtinvoke(jQueryTextField, 'getText()');
     
-    if ~(awtinvoke(conn, 'isConnected()'))
-      awtinvoke(conn, 'openConnection()');
-    end
-    
-    if (awtinvoke(conn, 'isConnected()'))
+    jStmt = awtinvoke(conn, 'createStatement()');
       
-      % lock connection
-      awtinvoke(conn, 'setLocked(Z)', true);
-      jStmt = awtinvoke(conn, 'createStatement()');
-      
-      try
-        
-        jResult = awtinvoke(jStmt, 'executeQuery(Ljava.lang.String;)', jQuery);
+    try
         
-        % pass to query results table
-        qrt = awtcreate('mpipeline.repository.QueryResultsTableDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.ResultSet;Ljava.lang.String;Z', [], false, jResult, jQuery, false);
-        awtinvoke(qrt, 'setUsedConn(Lmpipeline.repository.RepositoryConnection;)', conn);
-        awtinvoke(qrt, 'setVisible(Z)', 'true');
-        
-        hRetrieve = handle(qrt.getCreateConstructors,'callbackproperties');
-        hRetrieve.ActionPerformedCallback = @cb_retrieveObjectsFromTable;
-        
-        hGuiCloses2 = handle(qrt, 'callbackproperties');
-        hGuiCloses2.WindowClosedCallback = @cb_guiClosed2;
-        
-      catch err
-        fprintf(2, [err.message, '\n']);
-      end
-      awtinvoke(conn, 'setLocked(Z)', false);
+      jResult = awtinvoke(jStmt, 'executeQuery(Ljava.lang.String;)', jQuery);
+      
+      % pass to query results table
+      qrt = awtcreate('mpipeline.repository.QueryResultsTableDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.ResultSet;Ljava.lang.String;Z', [], false, jResult, jQuery, false);
+      awtinvoke(qrt, 'setUsedConn(Ljava.sql.Connection;)', conn);
+      awtinvoke(qrt, 'setVisible(Z)', 'true');
       
+      hRetrieve = handle(qrt.getCreateConstructors,'callbackproperties');
+      hRetrieve.ActionPerformedCallback = @cb_retrieveObjectsFromTable;
+      
+      hGuiCloses2 = handle(qrt, 'callbackproperties');
+      hGuiCloses2.WindowClosedCallback = @cb_guiClosed2;
+      
+    catch err
+      fprintf(2, [err.message, '\n']);
     end
+      
     
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     function cb_guiClosed2(varargin)
--- a/m-toolbox/classes/@workspaceBrowser/cb_retrieve.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/@workspaceBrowser/cb_retrieve.m	Mon Dec 05 16:20:06 2011 +0100
@@ -10,28 +10,16 @@
   
   wb = getappdata(0, 'WorkspaceBrowser');
   
-  % Get a connection from the repository manager
-  rm = LTPDARepositoryManager;
-  conn = rm.manager.selectConnection([]);
+  % Get a connection from the database connection manager
+  conn = LTPDADatabaseConnectionManager().connect();
   
-  if ~isempty(conn) && conn.isConnected
-    try
-      % Get submission info from the user
+  warning('off', 'MATLAB:JavaEDTAutoDelegation');
+  qb = mpipeline.repository.RepositoryRetrieveDialog([], true);
+  qb.setVisible(true);
+  warning('on', 'MATLAB:JavaEDTAutoDelegation');
       
-      warning('off', 'MATLAB:JavaEDTAutoDelegation');
-      qb = mpipeline.repository.RepositoryRetrieveDialog([], true);
-      qb.setVisible(true);
-      warning('on', 'MATLAB:JavaEDTAutoDelegation');
-      
-      if ~qb.isCancelled
-        
-        workspaceBrowser.retrieveObjectsFromDialog(qb, conn);
-        
-      end
-      
-    catch err
-      fprintf(2, [err.message, '\n']);
-    end
+  if ~qb.isCancelled        
+    workspaceBrowser.retrieveObjectsFromDialog(qb, conn);
   end
   
 end
--- a/m-toolbox/classes/@workspaceBrowser/retrieveObjectsFromDialog.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/@workspaceBrowser/retrieveObjectsFromDialog.m	Mon Dec 05 16:20:06 2011 +0100
@@ -6,8 +6,8 @@
   if ~isa(varargin{1}, 'mpipeline.repository.RepositoryRetrieveDialog')
     error('### The first input must be a mpipeline.repository.RepositoryRetrieveDialog');
   end
-  if ~isa(varargin{2}, 'mpipeline.repository.RepositoryConnection')
-    error('### The first input must be a mpipeline.repository.RepositoryConnection');
+  if ~isa(varargin{2}, 'java.sql.Connection')
+    error('### The first input must be a java.sql.Connection');
   end
     
   qb   = varargin{1};
@@ -75,9 +75,9 @@
     disp(sprintf('+ retrieving object %d', ids(j)));
     
     % determine object type
-    tt = char(mpipeline.repository.MySQLUtils.getObjectTypeForID(conn, ids(j)));
-    
-    if isempty(tt) || strcmp(tt, 'No Data')
+    try
+      tt = utils.repository.getObjectType(conn, ids(j));
+    catch
       utils.helper.errorDlg('Object type is unknown. Does this object really exist?');
       return
     end
@@ -89,13 +89,9 @@
     obj_names = [obj_names {objname}];
     
     % Retrieve object
-    hostname = char(conn.getHostname);
-    db = char(conn.getDatabase);
-    % add history
-    pl = plist('hostname', hostname, 'database', db, 'ID', ids(j), 'conn', conn);
+    pl = plist('id', ids(j), 'conn', conn);
     if retrieveBinary
-      pl.append('Binary', 'yes');
-      disp(sprintf('*** performing binary retrieval.'));
+      pl.append('binary', 'yes');
     end
     obj = eval(sprintf('%s(pl);', tt));
     
@@ -107,27 +103,17 @@
   for k=1:length(cids)
     
     % get Ids from Cid
-    ids = mpipeline.repository.MySQLUtils.getObjectIDsFromCollectionID(conn, cids(k));
+    ids = utils.repository.getCollectionIDs(conn, cids(k));
     if isempty(ids)
       error('### This collection doesn''t seem to exist.');
     end
     
     for j=1:length(ids)
       disp(sprintf('+ retrieving collection %d : %d', cids(k), ids(j)));
-      tt = char(mpipeline.repository.MySQLUtils.getObjectTypeForID(conn, ids(j)));
+      tt = utils.repository.getObjectType(conn, ids(j));
       if ismember(tt, utils.helper.ltpda_userclasses)
         % Retrieve object
-        if isa(conn, 'database')
-          ipbits = regexp(conn.URL, '([0-9]+)', 'match');
-          ip = [ipbits{1} '.' ipbits{2} '.' ipbits{3} '.' ipbits{4}];
-          db = regexp(conn.URL, '/', 'split');
-          db = db{end};
-        else
-          ip = conn.getHostname;
-          db = conn.getDatabase;
-        end
-        % add history
-        pl = plist('hostname', ip, 'database', db, 'ID', ids(j), 'conn', conn);
+        pl = plist('id', ids(j), 'conn', conn);
         obj = eval(sprintf('%s(pl);', tt));
         
         objname = sprintf('%sC%03d_%03d', prefix, cids(k), ids(j));
--- a/m-toolbox/classes/@workspaceBrowser/workspaceBrowser.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/@workspaceBrowser/workspaceBrowser.m	Mon Dec 05 16:20:06 2011 +0100
@@ -97,11 +97,7 @@
         %--- Retrieve button
         wb.h9 = handle(wb.hdl.getRetrieveBtn,'callbackproperties');
         wb.h9.ActionPerformedCallback = @workspaceBrowser.cb_retrieve;
-        
-        %--- repository Manager button
-        wb.h10 = handle(wb.hdl.getRepositoryManagerBtn,'callbackproperties');
-        wb.h10.ActionPerformedCallback = @workspaceBrowser.cb_repoManager;
-        
+                
         % Store the java gui in the application workspace
         setappdata(0, 'WorkspaceBrowser', wb);