diff m-toolbox/m/helper/mc.m @ 26:ce4df2e95a55 database-connection-manager

Remove LTPDARepositoryManager initialization
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
line wrap: on
line diff
--- a/m-toolbox/m/helper/mc.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/m/helper/mc.m	Mon Dec 05 16:20:06 2011 +0100
@@ -13,40 +13,36 @@
 
 function mc()
   
-  setappdata(0, 'LTPDApreferences', []);
+  % remove preferences
+  try
+    rmappdata(0, 'LTPDApreferences');
+  end
   
-  % Remove the repository manager
-  rm = getappdata(0, 'LTPDARepositoryManager');
-  if ~isempty(rm)
-    % store the connections so they don't get lost
-    rm.manager.closeAllConnections;
-    conns = rm.manager.getConnections;
-    delete(rm);
-    setappdata(0, 'LTPDAConnections', conns);
+  % database connection manager
+  cm = getappdata(0, 'LTPDADatabaseConnenctionManager');
+  if ~isempty(cm)
+    % save cached credentials
+    setappdata(0, 'LTPDAcredentials', cm.credentials);
+    % remove database connection manager
+    rmappdata(0, 'LTPDADatabaseConnenctionManager');
   end
-  setappdata(0, 'LTPDARepositoryManager', []);
-  
-  evalin('caller', 'clear');         % Deletes the timer-objects
-  clear classes                      % Deletes the local variables
-  evalin('caller', 'clear classes'); % Deletes the variables in the caller function
-  evalin('base', 'clear classes');   % Deletes the variables in the 'base' workspace
   
-  % Load the preferences again
-  LTPDAprefs.loadPrefs;
+  evalin('caller', 'clear');         % delete the timer-objects
+  clear classes                      % delete the local variables
+  evalin('caller', 'clear classes'); % delete the variables in the caller function
+  evalin('base', 'clear classes');   % delete the variables in the 'base' workspace
+  
+  % load the preferences again
+  LTPDAprefs.loadPrefs();
   
-  % Make a new Repository Manager
-  conns = getappdata(0, 'LTPDAConnections');
-  rm = LTPDARepositoryManager;
-  if ~isempty(conns)
-    % and put back the existing connections
-    for kk = 1:conns.size
-      conn = conns.get(kk-1);
-      rm.newConnection(char(conn.getHostname), ...
-        char(conn.getDatabase), ...
-        char(conn.getUsername), ...
-        char(conn.getPassword));
-    end
+  % instantiate database connection manager if required
+  credentials = getappdata(0, 'LTPDAcredentials');
+  if ~isempty(credentials)
+    cm = LTPDAConnectionManager();
+    cm.credentials = credentials;
   end
-  setappdata(0, 'LTPDAConnections', []);
+  try
+    rmappdata(0, 'LTPDAcredentials');
+  end
   
 end