changeset 14:6d43f39633b8 database-connection-manager

Remove unused functions from utils.jmysql
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents e05504b18072
children ce3fbb7ebe71
files m-toolbox/classes/+utils/@jmysql/dbconnTojconn.m m-toolbox/classes/+utils/@jmysql/execute.m m-toolbox/classes/+utils/@jmysql/getRepositoryVersion.m m-toolbox/classes/+utils/@jmysql/getUserID.m m-toolbox/classes/+utils/@jmysql/getXdoc.m m-toolbox/classes/+utils/@jmysql/insert.m m-toolbox/classes/+utils/@jmysql/jconnTodbconn.m m-toolbox/classes/+utils/@jmysql/jmysql.m
diffstat 8 files changed, 2 insertions(+), 325 deletions(-) [+]
line wrap: on
line diff
--- a/m-toolbox/classes/+utils/@jmysql/dbconnTojconn.m	Mon Dec 05 16:20:06 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-% DBCONNTOJCONN convert a MATLAB database connection to a java db connection.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% DESCRIPTION: DBCONNTOJCONN convert a MATLAB database toolbox connection
-%              to a java db connection.
-%
-% CALL:        jconn = utils.jmysql.dbconnTojconn(dbconn);
-%
-% INPUTS:
-%              dbconn - a database toolbox connecton
-% 
-% OUTPUTS:     
-%              jconn - a connection object like that returned from
-%                     utils.jmysql.connect.
-%
-%
-% VERSION:     $Id: dbconnTojconn.m,v 1.1 2009/07/28 06:46:09 hewitson Exp $
-%
-% HISTORY:     24-05-2007 M Hewitson
-%                 Creation
-%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-
-function jconn = dbconnTojconn(conn)
-  
-  if nargin ~= 1 || ~isa(conn, 'database')
-    error('### The first argument should be a database connection');
-  end
-
-  r = regexp(conn.URL, '//(.+)/', 'tokens');
-  host = r{1};
-  
-  db   = conn.Instance;
-  user = conn.UserName;
-  
-  jconn = utils.jmysql.connect(host, db, user, '');
-  
-  
-  
-end
-
--- a/m-toolbox/classes/+utils/@jmysql/execute.m	Mon Dec 05 16:20:06 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-function rows = execute(conn, query, varargin)
-  % execute the given SQL query with optional parameters varargin
-  % through connection conn. the results are returned in a 2d cell
-  % array
-  %
-  % differs from similar riutines in utils.jmysql by the use of proper
-  % SQL escaping of the query arguments. the connection object should
-  % be an object implementing the java.sql.Connection interface.
-
-  if nargin < 2
-    error('### incorrect usage');
-  end
-  if ~isjava(conn)
-    error('### invalid connection');
-  end
-
-  % return value
-  rows = {};
-
-  % build query
-  stmt = conn.prepareStatement(query);
-  for kk = 1:numel(varargin)
-    stmt.setObject(kk, varargin{kk});
-  end
-
-  % execute query
-  rs = stmt.executeQuery();
-
-  % get results into a cell array
-  ncols = rs.getMetaData.getColumnCount();
-  row = 1;
-  while rs.next()
-    for kk = 1:ncols
-      rows{row,kk} = java2matlab(rs.getObject(kk));
-    end
-    row = row + 1;
-  end
-
-end
-
-function val = java2matlab(val)
-  % matlab converts all base types. just add a conversion for datetime columns
-  switch class(val)
-    case 'java.sql.Timestamp'
-      val = time(plist('time', char(val), 'timezone', 'UTC'));
-  end
-end
--- a/m-toolbox/classes/+utils/@jmysql/getRepositoryVersion.m	Mon Dec 05 16:20:06 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-% getRepositoryVersion tries to get the version of the repository by
-% inspecting various fields in the database.
-% 
-% ver = utils.jmysql.getRepositoryVersion(conn)
-% 
-% Rules:
-%       objs table contains field 'uuid' => ver = 2.1
-% 
-% else: ver = 2.0;
-% 
-% M Hewitson 11-08-09
-% 
-% $Id: getRepositoryVersion.m,v 1.2 2009/08/11 12:33:19 ingo Exp $
-% 
-
-function ver = getRepositoryVersion(conn)
-  
-  ver = '2.0';
-  
-  q    = ['describe ' char(conn.getDatabase) '.objs'];
-  results = conn.query(q);
-  fields = {};
-  while results.next
-    fields = [fields {char(results.getString(1))}];
-  end
-
-  if utils.helper.ismember('uuid', fields)
-    ver = '2.1';
-  end
-  
-  
-end
-
--- a/m-toolbox/classes/+utils/@jmysql/getUserID.m	Mon Dec 05 16:20:06 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-% GETUSERID gets the user ID number corresponding to the given user name.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% DESCRIPTION: GETUSERID gets the user ID number corresponding to the
-%              user name that connected to the MySQL database.
-%
-% CALL:        userid = getUserID(conn)
-%
-% VERSION:     $Id: getUserID.m,v 1.1 2008/08/08 11:51:12 ingo Exp $
-%
-% HISTORY:     24-05-2007 M Hewitson
-%                 Creation
-%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-function [userid,dbuser] = getUserID(varargin)
-
-  userid = [];
-  conn = varargin{1};
-  if nargin > 1
-    username = varargin{2};
-  else
-    username = char(conn.getUsername);
-  end
-  try
-    if ~conn.isConnected
-      conn.openConnection;
-    end
-    if conn.isConnected
-      q    = sprintf('select id from users where username="%s"', username);
-      results = conn.query(q);
-      while results.next
-        userid = str2num(char(results.getString(1)));
-      end
-    end
-    dbuser = conn.getUsername;
-        
-  catch
-    warning('!!! Unable to retrieve user ID.');
-  end
-
-end
-
--- a/m-toolbox/classes/+utils/@jmysql/getXdoc.m	Mon Dec 05 16:20:06 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-% GETXDOC retrieves an object with given id from the LTPDA
-% repository specified by the input database connection. The object is
-% converted from its XML text format to an Xdoc. This can then be converted
-% into an object using the appropriate object constructor.
-%
-% Usage: xdoc = getXdoc(conn, id)
-%
-% Inputs:
-%         conn - a database connection object
-%         id   - the object id
-%
-% Outputs:
-%         xdoc - an Xdoc representation of the object.
-%
-% M Hewitson 30-08-07
-%
-% $Id: getXdoc.m,v 1.2 2009/06/17 11:05:53 ingo Exp $
-%
-%
-
-function xdoc = getXdoc(conn, id)
-
-  xdoc = '';
-  
-  try
-    results = conn.query(sprintf('select xml from objs where id="%d"', id));
-    while results.next
-      objTxt = char(results.getString(1));
-    end
-  catch curs
-    error('### Unable to read xml for ID %d. Server returned %s', id, curs.message);
-  end
-
-  if ~isempty(objTxt) && ~strcmp(objTxt(:), 'No Data')
-    % convert to Java string
-    str = java.lang.String(objTxt);
-    % open stream on this string
-    stream = java.io.StringBufferInputStream(str);
-    % make parser
-    builder = javax.xml.parsers.DocumentBuilderFactory.newInstance.newDocumentBuilder;
-
-    xdoc = builder.parse(stream);
-  else
-    xdoc = [];
-  end
-
-end
-
--- a/m-toolbox/classes/+utils/@jmysql/insert.m	Mon Dec 05 16:20:06 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-% INSERT inserts values into a single row of a table using JDBC driver
-% specified by the input connection.
-%
-% Usage: message = insert(conn, table, 'field1', value1, 'field2', value2,...)
-%
-% M Hewitson
-%
-% 31-07-07
-%
-% $Id: insert.m,v 1.4 2009/09/16 13:38:58 hewitson Exp $
-%
-
-function message = insert(conn, table, varargin)
-
-  message = '';
-  q = sprintf('INSERT INTO %s SET ',  table);
-  
-  for j=1:2:length(varargin)
-    
-    col = varargin{j};
-    val = varargin{j+1};
-    if isnumeric(val)
-      if ~any(isnan(val))
-        q = [q col '=' num2str(val) ','];
-      end
-    elseif ischar(val)
-      q = [q col '=' '''' val '''' ','];
-    else
-      error('### val class [%s]', class(val))
-    end
-        
-  end
-  
-  q = deblank([q(1:end-1) ';']);
-
-  if length(q) > 50
-    qdisp = [q(1:50) '...'];
-    utils.helper.msg(utils.const.msg.PROC1, 'running query %s', qdisp);
-  else
-    utils.helper.msg(utils.const.msg.PROC1, 'running query %s', q);
-  end
-  
-  try
-    stmt = conn.createStatement;
-    stmt.execute(q);
-  catch Me
-    error('### insert: failed to execute query');
-  end
-end
-
--- a/m-toolbox/classes/+utils/@jmysql/jconnTodbconn.m	Mon Dec 05 16:20:06 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-% JCONNTODBCONN convert a java db connection to a MATLAB database
-% connection.
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% DESCRIPTION: JCONNTODBCONN convert a java db connection to a MATLAB
-%              database Toolbox connection.
-%
-% CALL:        dbconn = utils.jmysql.jconnTodbconn(jconn);
-%
-% INPUTS:
-%              jconn - a connection object like that returned from
-%                     utils.jmysql.connect.
-% 
-% OUTPUTS:     dbconn - a database toolbox connecton
-%
-%
-% VERSION:     $Id: jconnTodbconn.m,v 1.1 2009/07/28 06:46:09 hewitson Exp $
-%
-% HISTORY:     24-05-2007 M Hewitson
-%                 Creation
-%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-
-function conn = jconnTodbconn(jconn)
-  
-  if nargin ~= 1 || ~isa(jconn, 'mpipeline.repository.RepositoryConnection')
-    error('### The first argument should be a RepositoryConnection');
-  end
-
-  host = char(jconn.getHostname);
-  db   = char(jconn.getDatabase);
-  user = char(jconn.getUsername);
-  pw   = char(jconn.getPassword);
-  
-  dbdriver = getappdata(0, 'mysql_driver');
-  dburl    = sprintf('jdbc:mysql://%s/%s',host,db);
-
-  disp(sprintf('** Connecting to %s as %s...', host, user))
-
-  conn     = database(db,user,pw,dbdriver,dburl);
-  disp('** Connection status:')
-  disp(ping(conn))
-  
-  
-end
-
--- a/m-toolbox/classes/+utils/@jmysql/jmysql.m	Mon Dec 05 16:20:06 2011 +0100
+++ b/m-toolbox/classes/+utils/@jmysql/jmysql.m	Mon Dec 05 16:20:06 2011 +0100
@@ -25,24 +25,13 @@
     varargout = getsinfo(varargin) % return sinfo structure of repository object
 
     %%% MYSQL TOOLS
-    varargout = connect(varargin) % connects to an LTPDA repository and returns the connection object.
-    varargout = query(varargin) % perform a query on an LTPDA repository and returns the results.
+    varargout = connect(varargin) % connects to an LTPDA repository and returns the connection object
+    varargout = query(varargin) % perform a query on an LTPDA repository and returns the results
     varargout = resultsToCell(varargin) % convert a ResultSet to a cell-array
     varargout = displayResults(varargin) % display a ResultSet in a table
     varargout = queryDialog(varargin) % show a query builder dialog
     varargout = submitDialog(varargin) % show a submission dialog
-    varargout = jconnTodbconn(varargin) % convert a java connection to database toolbox connection
-    varargout = dbconnTojconn(varargin) % convert a database toolbox connection to java connection
-    varargout = getUserID(varargin)
-    varargout = getXdoc(varargin)
-    varargout = insert(varargin)
-    varargout = getRepositoryVersion(varargin)
     varargout = dbquery(varargin)
-    varargout = insertObjMetadata(varargin)
-    varargout = updateObjMetadata(varargin)
-    varargout = insertObjMetadataV1(varargin) % back-compatibility for old database schema
-    varargout = updateObjMetadataV1(varargin) % back-compatibility for old database schema
-    varargout = execute(varargin)
 
   end % End static methods