Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@repository/adjustPlist.m @ 24:056f8e1e995e database-connection-manager
Properly record history in fromRepository constructors
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@repository/adjustPlist.m Mon Dec 05 16:20:06 2011 +0100 @@ -0,0 +1,37 @@ +function adjustPlist(conn, pl) +% ADJUSTPLIST(CONN, PL) Removes CONN, USERNAME, PASSWORD parameters +% from plist PL, and adds or or substitutes HOSTNAME and DATABASE +% parameters with the ones used to establish connection CONN. +% +% The resulting plist may be used to set object history. + + % check parameters + if ~isa(conn, 'java.sql.Connection') + error('### invalid call'); + end + if ~isa(pl, 'plist') + error('### invalid call'); + end + + % get connection parameters + r = '^jdbc:mysql://(?<hostname>.+)/(?<database>.+)$'; + c = regexp(char(conn.getMetaData().getURL()), r, 'names'); + + % remove unwanted parameters + prem(pl, 'conn'); + prem(pl, 'username'); + prem(pl, 'password'); + + % add essentials connections parameters + pset(pl, 'hostname', c.hostname); + pset(pl, 'database', c.database); + +end + + +function prem(pl, key) +% PREM Remove parameter KEY if present in plist PL. + if isparam(pl, key) + remove(pl, key); + end +end