changeset 25:79dc7091dbbc database-connection-manager

Update tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents 056f8e1e995e
children ce4df2e95a55
files m-toolbox/classes/tests/database/@ltpda_ao_table/test_ao_data_id.m m-toolbox/classes/tests/database/@ltpda_cdata_table/getTableEntry.m m-toolbox/classes/tests/database/@ltpda_database/executeQuery.m m-toolbox/classes/tests/database/@ltpda_database/getDataIdFromAoTable.m m-toolbox/classes/tests/database/@ltpda_database/getTableEntry.m m-toolbox/classes/tests/database/@ltpda_database/init.m m-toolbox/classes/tests/database/@ltpda_database/ltpda_database.m m-toolbox/classes/tests/database/@ltpda_fsdata_table/getTableEntry.m m-toolbox/classes/tests/database/@ltpda_tsdata_table/getTableEntry.m m-toolbox/classes/tests/database/@ltpda_xydata_table/getTableEntry.m
diffstat 10 files changed, 31 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/m-toolbox/classes/tests/database/@ltpda_ao_table/test_ao_data_id.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_ao_table/test_ao_data_id.m	Mon Dec 05 16:20:06 2011 +0100
@@ -31,8 +31,8 @@
         dataID1 = getDataIdFromAoTable(utp, utp.objIds(nn));
         
         % Create query to get the field 'id' from the data table (e.g. 'fsdata')
-        query   = sprintf('SELECT id FROM %s ORDER BY id DESC LIMIT 0,1', class(utp.testData(nn).data));
-        dataID2 = executeQuery(utp, query);
+        query = sprintf('SELECT id FROM %s ORDER BY id DESC LIMIT 0,1', class(utp.testData(nn).data));
+        dataID2 = utils.mysql.execute(utp.conn, query);
         
         % ATTENTION: This test assumes that we have committed only one AO
         %            with each data-type.
--- a/m-toolbox/classes/tests/database/@ltpda_cdata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_cdata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
@@ -18,8 +18,8 @@
       assert(numel(dataID)==1, sprintf('Found more than one data ID for the given object ID %d', objID));
       
       % Create query to get the field 'xunits' from the 'cdata' table
-      query = sprintf('SELECT %s FROM %s WHERE %s.id=%d', tableField, dbTable, dbTable, dataID{1});
-      val   = executeQuery(utp, query);
+      query = sprintf('SELECT %s FROM %s WHERE %s.id = ?', tableField, dbTable, dbTable);
+      val = utils.mysql.execute(utp.conn, query, dataID{1});
     catch Me
       rethrow(Me);
     end
@@ -29,7 +29,5 @@
   else
     throw(MException('ltpda_cdata_table:getTableEntry', 'Unknown database layout.'));
   end
-  
-  utp.conn.setLocked(false);
-  utp.conn.closeConnection();
+
 end
--- a/m-toolbox/classes/tests/database/@ltpda_database/executeQuery.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_database/executeQuery.m	Mon Dec 05 16:20:06 2011 +0100
@@ -1,22 +1,11 @@
 %
 % DESCRIPTION: Returns the result for a given query.
 %
+% DEPRECATED! Use utils.mysql.execute instead.
+%
 % VERSION:     $Id: executeQuery.m,v 1.1 2011/05/25 16:20:25 ingo Exp $
 %
 function val = executeQuery(utp, query)
-  
-  utp.conn.setLocked(true);
-  utp.conn.openConnection();
-  c = utp.conn.getConn();
-  
-  try
-    val = utils.jmysql.execute(c, query);
-  catch Me
-    utp.conn.setLocked(false);
-    utp.conn.closeConnection();
-    rethrow(Me);
-  end
-  
-  utp.conn.setLocked(false);
-  utp.conn.closeConnection();
+  warning('!!! Deprecated! Use utils.mysql.execute instead');
+  val = utils.mysql.execute(utp.conn, query);
 end
--- a/m-toolbox/classes/tests/database/@ltpda_database/getDataIdFromAoTable.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_database/getDataIdFromAoTable.m	Mon Dec 05 16:20:06 2011 +0100
@@ -5,20 +5,8 @@
 % VERSION:     $Id: getDataIdFromAoTable.m,v 1.1 2011/05/25 16:23:53 ingo Exp $
 %
 function val = getDataIdFromAoTable(utp, objID)
-  
-  utp.conn.setLocked(true);
-  utp.conn.openConnection();
-  c = utp.conn.getConn();
-  
-  q = sprintf('SELECT data_id FROM ao WHERE ao.obj_id=%d', objID);
-  try
-    val = utils.jmysql.execute(c, q);
-  catch Me
-    utp.conn.setLocked(false);
-    utp.conn.closeConnection();
-    rethrow(Me);
-  end
-  
-  utp.conn.setLocked(false);
-  utp.conn.closeConnection();
+
+  q = sprintf('SELECT data_id FROM ao WHERE ao.obj_id = ?');
+  val = utils.mysql.execute(utp.conn, q, objID);
+
 end
--- a/m-toolbox/classes/tests/database/@ltpda_database/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_database/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
@@ -5,20 +5,8 @@
 % VERSION:     $Id: getTableEntry.m,v 1.2 2011/05/25 16:20:37 ingo Exp $
 %
 function val = getTableEntry(utp, dbTable, tableField, objID)
-  
-  utp.conn.setLocked(true);
-  utp.conn.openConnection();
-  c = utp.conn.getConn();
-  
-  q = sprintf('SELECT %s.%s FROM %s WHERE %s.obj_id=%d', dbTable, tableField, dbTable, dbTable, objID);
-  try
-    val = utils.jmysql.execute(c, q);
-  catch Me
-    utp.conn.setLocked(false);
-    utp.conn.closeConnection();
-    rethrow(Me);
-  end
-  
-  utp.conn.setLocked(false);
-  utp.conn.closeConnection();
+
+  q = sprintf('SELECT %s.%s FROM %s WHERE %s.obj_id = ?', dbTable, tableField, dbTable, dbTable);
+  val = utils.mysql.execute(utp.conn, q, objID);
+
 end
--- a/m-toolbox/classes/tests/database/@ltpda_database/init.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_database/init.m	Mon Dec 05 16:20:06 2011 +0100
@@ -19,16 +19,9 @@
   
   if ~utp.testRunner.skipRepoTests()
     
-    % Get the connection from the repository manager
-    rm = LTPDARepositoryManager();
-    conn = rm.findConnections(utp.testRunner.repositoryPlist);
-    if isempty(conn)
-      conn = rm.newConnection(utp.testRunner.repositoryPlist);
-    end
-    
-    % Check that we get only one connection
-    assert(numel(conn) == 1, sprintf('Found more than one connection in the repository manager for the PLIST: %s', char(utp.testRunner.repositoryPlist)));
-    
+    % Get database connection
+    conn = LTPDADatabaseConnectionManager().connect(utp.testRunner.repositoryPlist);
+
     % Store the connection
     utp.conn = conn;
     
--- a/m-toolbox/classes/tests/database/@ltpda_database/ltpda_database.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_database/ltpda_database.m	Mon Dec 05 16:20:06 2011 +0100
@@ -44,11 +44,8 @@
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     function delete(varargin)
       utp = varargin{1};
-      % Make sure that we remove the connection from the object and that it
-      % is not locked.
-      if isa(utp.conn, 'mpipeline.repository.RepositoryConnection')
-        utp.conn.setLocked(false);
-      end
+      % Close connection
+      utp.conn.close();
       utp.conn = [];
     end
   end
--- a/m-toolbox/classes/tests/database/@ltpda_fsdata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_fsdata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
@@ -18,8 +18,8 @@
       assert(numel(dataID)==1, sprintf('Found more than one data ID for the given object ID %d', objID));
       
       % Create query to get the field 'xunits' from the 'cdata' table
-      query = sprintf('SELECT %s FROM %s WHERE %s.id=%d', tableField, dbTable, dbTable, dataID{1});
-      val   = executeQuery(utp, query);
+      query = sprintf('SELECT %s FROM %s WHERE %s.id = ?', tableField, dbTable, dbTable);
+      val = utils.mysql.execute(utp.conn, query, dataID{1});
     catch Me
       rethrow(Me);
     end
@@ -29,7 +29,5 @@
   else
     throw(MException('ltpda_cdata_table:getTableEntry', 'Unknown database layout.'));
   end
-  
-  utp.conn.setLocked(false);
-  utp.conn.closeConnection();
+
 end
--- a/m-toolbox/classes/tests/database/@ltpda_tsdata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_tsdata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
@@ -18,8 +18,8 @@
       assert(numel(dataID)==1, sprintf('Found more than one data ID for the given object ID %d', objID));
       
       % Create query to get the field 'xunits' from the 'cdata' table
-      query = sprintf('SELECT %s FROM %s WHERE %s.id=%d', tableField, dbTable, dbTable, dataID{1});
-      val   = executeQuery(utp, query);
+      query = sprintf('SELECT %s FROM %s WHERE %s.id = ?', tableField, dbTable, dbTable);
+      val = utils.mysql.execute(utp.conn, query, dataID{1});
     catch Me
       rethrow(Me);
     end
@@ -29,7 +29,5 @@
   else
     throw(MException('ltpda_cdata_table:getTableEntry', 'Unknown database layout.'));
   end
-  
-  utp.conn.setLocked(false);
-  utp.conn.closeConnection();
+
 end
--- a/m-toolbox/classes/tests/database/@ltpda_xydata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/tests/database/@ltpda_xydata_table/getTableEntry.m	Mon Dec 05 16:20:06 2011 +0100
@@ -18,8 +18,8 @@
       assert(numel(dataID)==1, sprintf('Found more than one data ID for the given object ID %d', objID));
       
       % Create query to get the field 'xunits' from the 'cdata' table
-      query = sprintf('SELECT %s FROM %s WHERE %s.id=%d', tableField, dbTable, dbTable, dataID{1});
-      val   = executeQuery(utp, query);
+      query = sprintf('SELECT %s FROM %s WHERE %s.id = ?', tableField, dbTable, dbTable);
+      val = utils.mysql.execute(utp.conn, query, dataID{1});
     catch Me
       rethrow(Me);
     end
@@ -29,7 +29,5 @@
   else
     throw(MException('ltpda_cdata_table:getTableEntry', 'Unknown database layout.'));
   end
-  
-  utp.conn.setLocked(false);
-  utp.conn.closeConnection();
+
 end