annotate m-toolbox/classes/@LTPDADatabaseConnectionManager/LTPDADatabaseConnectionManager.m @ 34:03d92954b939 database-connection-manager

Improve look of LTPDAPreferences diaolog
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents 5e7477b94d94
children 6def6533cb16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
1 classdef LTPDADatabaseConnectionManager < handle
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
3 properties(SetAccess=private)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
4
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
5 connections = {};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
6 credentials = {};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
7
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
8 end % private properties
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
9
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
10 properties(Dependent=true)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
11
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
12 credentialsExpiry; % seconds
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
13 cachePassword; % 0=no 1=yes 2=ask
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
14 maxConnectionsNumber;
33
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
15 knownRepositories; % known repositories stored into prefereces
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
16
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
17 end % dependent properties
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
18
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
19 methods(Static)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
20
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
21 function reset()
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
22 % RESET Resets the state of the connection manager.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
23 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
24 % This static method removes the LTPDADatabaseConnectionManager
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
25 % instance data from the appdata storage. Causes the reset of the
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
26 % credentials cache and the removal of all the connections from
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
27 % the connection pool.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
28
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
29 rmappdata(0, LTPDADatabaseConnectionManager.appdataKey);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
30 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
31
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
32
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
33 function key = appdataKey()
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
34 % APPDATAKEY Returns the key used to store instance data in appdata.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
35 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
36 % This is defined as static method, and not has an instance constant
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
37 % property, to to be accessible by the reset static method.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
38
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
39 key = 'LTPDADatabaseConnectionManager';
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
40 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
41
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
42 end % static methods
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
43
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
44 methods
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
45
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
46 function cm = LTPDADatabaseConnectionManager()
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
47 % LTPDACONNECTIONMANAGER Manages credentials and database connections.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
48 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
49 % This constructor returns an handler to a LTPDADatabaseConnectionManager
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
50 % class instance. Database connections can be obtained trough the
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
51 % obtained object with the connect() method.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
52 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
53 % The purpose of this class it to keep track of open database connections
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
54 % and to cache database credentials. It must be used in all LTPDA toolbox
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
55 % functions that required to obtain database connections. Its behaviour can
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
56 % be configured via LTPDA toolbox user preferences. The object status is
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
57 % persisted trough the appdata matlab facility.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
58
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
59 % import credentials class
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
60 import utils.credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
61
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
62 % load state from appdata
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
63 acm = getappdata(0, cm.appdataKey());
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
64
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
65 if isempty(acm)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
66 % store state in appdata
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
67 setappdata(0, cm.appdataKey(), cm);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
68
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
69 import utils.const.*
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
70 utils.helper.msg(msg.PROC1, 'new connection manager');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
71 else
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
72 cm = acm;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
73 end
33
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
74
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
75 % add known repositories from preferences
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
76 repos = cm.knownRepositories;
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
77 for kk = 1:numel(repos)
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
78 repo = repos{kk};
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
79 for jj = 1:3
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
80 % null empty parameters
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
81 if isempty(repo{jj})
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
82 repo{jj} = [];
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
83 end
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
84 end
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
85 cm.add(utils.credentials(repo{:}));
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
86 end
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
87 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
88
33
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
89
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
90 function str = disp(cm)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
91 disp(sprintf('%s()\n', class(cm)));
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
92 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
93
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
94
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
95 function val = get.credentialsExpiry(cm)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
96 % obtain from user preferences
4
e3c5468b1bfe Integrate with LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 2
diff changeset
97 p = getappdata(0, 'LTPDApreferences');
e3c5468b1bfe Integrate with LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 2
diff changeset
98 val = double(p.getRepoPrefs().getExpiry());
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
99 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
100
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
101
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
102 function val = get.cachePassword(cm)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
103 % obtain from user preferences
4
e3c5468b1bfe Integrate with LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 2
diff changeset
104 p = getappdata(0, 'LTPDApreferences');
e3c5468b1bfe Integrate with LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 2
diff changeset
105 val = double(p.getRepoPrefs().getCachePassword());
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
106 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
107
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
108
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
109 function val = get.maxConnectionsNumber(cm)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
110 % obtain from user preferences
4
e3c5468b1bfe Integrate with LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 2
diff changeset
111 p = getappdata(0, 'LTPDApreferences');
e3c5468b1bfe Integrate with LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 2
diff changeset
112 val = double(p.getRepoPrefs().getMaxConnectionsNumber());
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
113 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
114
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
115
33
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
116 function val = get.knownRepositories(cm)
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
117 % obtain from user preferences
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
118 p = getappdata(0, 'LTPDApreferences');
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
119 val = cell(p.getRepoPrefs().getRepositories().toArray());
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
120 end
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
121
5e7477b94d94 Add known repositories list to LTPDAPreferences
Daniele Nicolodi <nicolodi@science.unitn.it>
parents: 4
diff changeset
122
2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
123 function n = count(cm)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
124 % COUNT Returns the number of open connections in the connections pool.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
125 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
126 % This method has the side effect of removing all closed connections from
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
127 % the connections pool, so that the underlying objects can be garbage
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
128 % collected.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
129
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
130 import utils.const.*
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
131
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
132 % find closed connections in the pool
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
133 mask = false(numel(cm.connections), 1);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
134 for kk = 1:numel(cm.connections)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
135 if cm.connections{kk}.isClosed()
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
136 utils.helper.msg(msg.PROC1, 'connection id=%d closed', kk);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
137 mask(kk) = true;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
138 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
139 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
140
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
141 % remove them
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
142 cm.connections(mask) = [];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
143
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
144 % count remainig ones
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
145 n = numel(cm.connections);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
146 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
147
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
148 function clear(cm)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
149 % CLEAR Removes all cached credentials from the connection manager.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
150 cm.credentials = {};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
151 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
152
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
153
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
154 function conn = connect(cm, varargin)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
155 % CONNECT Uses provided credential to establish a database connection.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
156 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
157 % CONNECT(hostname, database, username, password) Returns an object
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
158 % implementing the java.sql.Connection interface handing a connection to
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
159 % the specified database. Any of the parameter is optional. The user will
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
160 % be queried for the missing information.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
161 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
162 % The returned connection are added to a connections pool. When the number
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
163 % of connections in the pool exceeds a configurable maximum, no more
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
164 % connection are instantiated. Closed connections are automatically
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
165 % removed from the pool.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
166 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
167 % CONNECT(pl) Works as the above but the parameters are obtained from the
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
168 % plist object PL. If the 'connection' parameter in the plist contains an
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
169 % object implementing the java.sql.Connection interface, this object is
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
170 % returned instead that opening a new connection. In this case the
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
171 % connection in not added to the connection pool.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
172
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
173 import utils.const.*
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
174
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
175 % save current credentials cache
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
176 cache = cm.credentials;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
177
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
178 % count open connections in the pool
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
179 count = cm.count();
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
180
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
181 % check parameters
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
182 if numel(varargin) == 1 && isa(varargin{1}, 'plist')
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
183
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
184 % extract parameters from plist
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
185 pl = varargin{1};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
186
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
187 % check if we have a connection parameter
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
188 conn = find(pl, 'conn');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
189 if ~isempty(conn)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
190 % check that it implements java.sql.Connection interface
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
191 if ~isa(conn, 'java.sql.Connection')
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
192 error('### connection is not valid database connection');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
193 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
194 % return this connection
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
195 return;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
196 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
197
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
198 % otherwise
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
199 hostname = find(pl, 'hostname');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
200 database = find(pl, 'database');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
201 username = find(pl, 'username');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
202 password = find(pl, 'password');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
203
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
204 % if there is no hostname ignore other parameters
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
205 if ~ischar(hostname) || isempty(hostname)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
206 varargin = {};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
207 % if there is no database ignore other parameters
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
208 elseif ~ischar(database) || isempty(database)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
209 varargin = {hostname};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
210 % if there is no username ignore other parameters
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
211 elseif ~ischar(username) || isempty(username)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
212 varargin = {hostname, database};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
213 % password can not be null but can be an empty string
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
214 elseif ~ischar(password)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
215 varargin = {hostname, database, username};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
216 else
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
217 varargin = {hostname, database, username, password};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
218 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
219 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
220
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
221 % check number of connections
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
222 if count > cm.maxConnectionsNumber
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
223 error('### too many open connections');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
224 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
225
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
226 % connect
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
227 try
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
228 conn = cm.getConnection(varargin{:});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
229
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
230 % add connection to pool
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
231 utils.helper.msg(msg.PROC1, 'add connection to pool');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
232 cm.connections{end+1} = conn;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
233
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
234 catch ex
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
235 % restore our copy of the credentials cache
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
236 utils.helper.msg(msg.PROC1, 'undo cache changes');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
237 cm.credentials = cache;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
238
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
239 % hide implementation details
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
240 ex.throw();
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
241 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
242 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
243
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
244
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
245 function close(cm, ids)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
246 % CLOSE Forces connections to be closed.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
247 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
248 % In the case bugs in other routines working with database connections
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
249 % produce orphan connections, this method can be used to force the close
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
250 % of those connections.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
251 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
252 % CLOSE(ids) Closes the connections with the corresponding IDs in the
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
253 % connections pool. If no ID is given all connections in the pool are
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
254 % closed.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
255
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
256 if nargin < 2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
257 ids = 1:numel(cm.connections);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
258 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
259 cellfun(@close, cm.connections(ids));
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
260
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
261 % remove closed connections from pool
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
262 cm.count();
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
263 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
264
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
265
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
266 function add(cm, c)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
267 % ADD Adds credentials to the credentials cache.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
268 %
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
269 % This method can be used to initialize or add to the cache, credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
270 % that will be used in subsequent connections attempts. This method accepts
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
271 % only credentials in the form of utils.credentials objects.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
272
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
273 % check input arguments
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
274 if nargin < 2 || ~isa(c, 'utils.credentials')
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
275 error('### invalid call');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
276 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
277
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
278 % add to the cache
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
279 cm.cacheCredentials(c);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
280 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
281
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
282 end % methods
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
283
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
284 methods(Access=private)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
285
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
286 function conn = getConnection(cm, varargin)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
287 % GETCONNECTION Where the implementation of the connect method really is.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
288
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
289 import utils.const.*
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
290
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
291 % handle variable number of arguments
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
292 switch numel(varargin)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
293 case 0
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
294 % find credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
295 [hostname, database, username] = cm.selectDatabase([cm.credentials{:}]);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
296 conn = cm.getConnection(hostname, database, username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
297
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
298 case 1
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
299 % find credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
300 cred = cm.findCredentials(varargin{:});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
301 if numel(cred) == 0
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
302 cred = utils.credentials(varargin{:});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
303 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
304 [hostname, database, username] = cm.selectDatabase(cred);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
305 conn = cm.getConnection(hostname, database, username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
306
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
307 case 2
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
308 % find credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
309 cred = cm.findCredentials(varargin{:});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
310 switch numel(cred)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
311 case 0
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
312 conn = cm.getConnection(varargin{1}, varargin{2}, []);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
313 case 1
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
314 conn = cm.getConnection(cred.hostname, cred.database, cred.username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
315 otherwise
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
316 [hostname, database, username] = cm.selectDatabase(cred);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
317 conn = cm.getConnection(hostname, database, username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
318 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
319
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
320 case 3
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
321 % find credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
322 cred = cm.findCredentials(varargin{1}, varargin{2}, varargin{3});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
323 switch numel(cred)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
324 case 0
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
325 % no credentials found
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
326 usernames = { varargin{3} };
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
327 if isempty(varargin{3})
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
328 % use usernames for same hostname
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
329 tmp = cm.findCredentials(varargin{1});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
330 if ~isempty(tmp)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
331 usernames = { tmp(:).username };
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
332 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
333 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
334 % build credentials objects
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
335 tmp = {};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
336 for kk = 1:numel(usernames)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
337 tmp{kk} = utils.credentials(varargin{1}, varargin{2}, usernames{kk});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
338 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
339 % convert from cell array to array
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
340 cred = [tmp{:}];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
341 case 1
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
342 % credentials in cache
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
343 utils.helper.msg(msg.PROC1, 'use cached credentials');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
344 otherwise
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
345 % we should not have more than one credentials set
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
346 error('### more than one credentials set matching');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
347 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
348
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
349 cache = false;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
350 if (numel(cred) > 1) || ~cred.complete
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
351 % ask for password
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
352 [username, password, cache] = cm.inputCredentials(cred);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
353
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
354 % cache credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
355 cred = utils.credentials(varargin{1}, varargin{2}, username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
356 cm.cacheCredentials(cred);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
357
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
358 % add password to credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
359 cred.password = password;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
360 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
361
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
362 % try to connect
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
363 try
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
364 conn = utils.mysql.connect(cred.hostname, cred.database, cred.username, cred.password);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
365 catch ex
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
366 % look for access denied errors
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
367 if strcmp(ex.identifier, 'utils:mysql:connect:AccessDenied')
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
368 % ask for new new credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
369 utils.helper.msg(msg.IMPORTANT, ex.message);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
370 conn = cm.getConnection(varargin{1}, varargin{2}, varargin{3});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
371 else
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
372 % error out
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
373 throw(ex);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
374 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
375 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
376
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
377 % cache password
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
378 if cache
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
379 utils.helper.msg(msg.PROC1, 'cache password');
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
380 cm.cacheCredentials(cred);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
381 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
382
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
383 case 4
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
384 % connect
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
385 conn = utils.mysql.connect(varargin{1}, varargin{2}, varargin{3}, varargin{4});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
386
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
387 if cm.cachePassword == 1
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
388 % cache credentials with password
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
389 cred = utils.credentials(varargin{1}, varargin{2}, varargin{3}, varargin{4});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
390 else
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
391 % cache credentials without password
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
392 cred = utils.credentials(varargin{1}, varargin{2}, varargin{3});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
393 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
394 cm.cacheCredentials(cred);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
395
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
396 otherwise
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
397 error('### invalid call')
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
398 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
399
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
400 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
401
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
402
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
403 function ids = findCredentialsId(cm, varargin)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
404 % FINDCREDENTIALSID Find credentials in the cache and returns their IDs.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
405
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
406 import utils.const.*
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
407 ids = [];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
408
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
409 for kk = 1:numel(cm.credentials)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
410 % invalidate expired passwords
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
411 if expired(cm.credentials{kk})
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
412 utils.helper.msg(msg.PROC1, 'cache entry id=%d expired', kk);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
413 cm.credentials{kk}.password = [];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
414 cm.credentials{kk}.expiry = 0;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
415 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
416
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
417 % match input with cache
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
418 if match(cm.credentials{kk}, varargin{:})
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
419 ids = [ ids kk ];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
420 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
421 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
422 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
423
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
424
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
425 function cred = findCredentials(cm, varargin)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
426 % FINDCREDENTIALS Find credentials in the cache and returns them in a list.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
427
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
428 % default
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
429 cred = [];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
430
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
431 % search
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
432 ids = findCredentialsId(cm, varargin{:});
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
433
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
434 % return a credentials objects array
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
435 if ~isempty(ids)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
436 cred = [cm.credentials{ids}];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
437 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
438 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
439
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
440
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
441 function cacheCredentials(cm, c)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
442 % CACHECREDENTIALS Adds to or updates the credentials cache.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
443
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
444 import utils.const.*
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
445
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
446 % find entry to update
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
447 ids = findCredentialsId(cm, c.hostname, c.database, c.username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
448
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
449 % set password expiry time
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
450 if ischar(c.password)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
451 c.expiry = double(time()) + cm.credentialsExpiry;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
452 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
453
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
454 if isempty(ids)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
455 % add at the end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
456 utils.helper.msg(msg.PROC1, 'add cache entry %s', char(c));
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
457 cm.credentials{end+1} = c;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
458 else
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
459 for id = ids
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
460 % update only if the cached informations are less than the one we have
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
461 if length(c) > length(cm.credentials{id})
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
462 utils.helper.msg(msg.PROC1, 'update cache entry id=%d %s', id, char(c));
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
463 cm.credentials{id} = c;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
464 else
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
465 % always update expiry time
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
466 cm.credentials{id}.expiry = c.expiry;
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
467 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
468 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
469 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
470 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
471
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
472
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
473 function [username, password, cache] = inputCredentials(cm, cred)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
474 % INPUTCREDENTIALS Queries the user for database username and password.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
475
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
476 % build a cell array of usernames
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
477 users = {};
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
478 for id = 1:numel(cred)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
479 if ~isempty(cred(id).username)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
480 users = [ users { cred(id).username } ];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
481 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
482 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
483 users = sort(unique(users));
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
484
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
485 parent = com.mathworks.mde.desk.MLDesktop.getInstance().getMainFrame();
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
486 dialog = javaObjectEDT('connectionmanager.CredentialsDialog', ...
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
487 parent, cred(1).hostname, cred(1).database, users, cm.cachePassword);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
488 dialog.show();
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
489 if dialog.cancelled
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
490 throw(MException('utils:mysql:connect:UserCancelled', '### user cancelled'));
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
491 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
492 username = char(dialog.username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
493 password = char(dialog.password);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
494 cache = logical(dialog.cache);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
495 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
496
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
497
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
498 function [hostname, database, username] = selectDatabase(cm, credentials)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
499 % SELECTDATABASE Makes the user choose to which database connect to.
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
500
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
501 parent = com.mathworks.mde.desk.MLDesktop.getInstance().getMainFrame();
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
502 dialog = javaObjectEDT('connectionmanager.DatabaseSelectorDialog', parent);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
503 for c = credentials
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
504 dialog.add(c.hostname, c.database, c.username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
505 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
506 dialog.show();
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
507 if dialog.cancelled
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
508 throw(MException('utils:mysql:connect:UserCancelled', '### user cancelled'));
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
509 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
510 hostname = char(dialog.hostname);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
511 database = char(dialog.database);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
512 username = char(dialog.username);
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
513 if isempty(username)
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
514 username = [];
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
515 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
516 end
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
517
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
518 end % private methods
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
519
18e956c96a1b Add LTPDADatabaseConnectionManager implementation. Matlab code
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff changeset
520 end % classdef