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