comparison 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
comparison
equal deleted inserted replaced
23:a71a40911c27 24:056f8e1e995e
1 function adjustPlist(conn, pl)
2 % ADJUSTPLIST(CONN, PL) Removes CONN, USERNAME, PASSWORD parameters
3 % from plist PL, and adds or or substitutes HOSTNAME and DATABASE
4 % parameters with the ones used to establish connection CONN.
5 %
6 % The resulting plist may be used to set object history.
7
8 % check parameters
9 if ~isa(conn, 'java.sql.Connection')
10 error('### invalid call');
11 end
12 if ~isa(pl, 'plist')
13 error('### invalid call');
14 end
15
16 % get connection parameters
17 r = '^jdbc:mysql://(?<hostname>.+)/(?<database>.+)$';
18 c = regexp(char(conn.getMetaData().getURL()), r, 'names');
19
20 % remove unwanted parameters
21 prem(pl, 'conn');
22 prem(pl, 'username');
23 prem(pl, 'password');
24
25 % add essentials connections parameters
26 pset(pl, 'hostname', c.hostname);
27 pset(pl, 'database', c.database);
28
29 end
30
31
32 function prem(pl, key)
33 % PREM Remove parameter KEY if present in plist PL.
34 if isparam(pl, key)
35 remove(pl, key);
36 end
37 end