Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDARepositoryManager/findConnections.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % FINDCONNECTIONS finds a managed connection. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: FINDCONNECTIONS finds a managed connection. | |
5 % | |
6 % CALL: conns = rm.findConnections(pl); | |
7 % conns = rm.findConnections('hostname'); | |
8 % conns = rm.findConnections('hostname', 'database'); | |
9 % conns = rm.findConnections('hostname', 'database', 'username'); | |
10 % | |
11 % findConneciton finds all connections which match the given input fields. | |
12 % If no matching connections are found then the method returns an emtpy | |
13 % array. To search for all 'hostnames' for a given 'username', enter an | |
14 % empty string. For example: | |
15 % | |
16 % 1) Find all connections for user 'bob' | |
17 % | |
18 % pl = plist('username', 'bob'); | |
19 % conns = rm.findConnections(pl); | |
20 % | |
21 % or | |
22 % | |
23 % conns = rm.findConnections('', '', 'bob'); | |
24 % | |
25 % 2) Find all connection to 'localhost' for database 'foo' | |
26 % | |
27 % pl = plist('hostname', 'localhost', 'database', 'foo') | |
28 % conns = rm.findConnections(pl); | |
29 % | |
30 % or | |
31 % | |
32 % conns = rm.findConnections('localhost', 'foo'); | |
33 % | |
34 % 3) Find all connections to 'localhost' for user 'bob' | |
35 % | |
36 % conns = rm.findConnections('localhost', '', 'bob'); | |
37 % | |
38 % <a href="matlab:web(LTPDARepositoryManager.getInfo('findConnections').tohtml, '-helpbrowser')">Parameters Description</a> | |
39 % | |
40 % VERSION: $Id: findConnections.m,v 1.7 2011/04/08 08:56:35 hewitson Exp $ | |
41 % | |
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
43 | |
44 function varargout = findConnections(varargin) | |
45 | |
46 % Check if this is a call for parameters | |
47 if utils.helper.isinfocall(varargin{:}) | |
48 varargout{1} = getInfo(varargin{3}); | |
49 return | |
50 end | |
51 | |
52 import utils.const.* | |
53 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
54 | |
55 % Get the repository manager - there should only be one! | |
56 [rm, invars, rest] = utils.helper.collect_objects(varargin(:), 'LTPDARepositoryManager'); | |
57 | |
58 % Collect all plists | |
59 [pl, invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
60 | |
61 | |
62 pl = combine(pl, getDefaultPlist); | |
63 hostname = pl.find('hostname'); | |
64 database = pl.find('database'); | |
65 username = pl.find('username'); | |
66 | |
67 % Check through 'rest' | |
68 if numel(rest) > 0 | |
69 hostname = rest{1}; | |
70 end | |
71 if numel(rest) > 1 | |
72 database = rest{2}; | |
73 end | |
74 if numel(rest) > 2 | |
75 username = rest{3}; | |
76 end | |
77 | |
78 % make sure that username are strings because JAVA interprets an empty | |
79 % array [] as a null-pointer. | |
80 if isempty(hostname), hostname = ''; end | |
81 if isempty(database), database = ''; end | |
82 if isempty(username), username = ''; end | |
83 | |
84 conns = rm.manager.findConnections(hostname, database, username); | |
85 | |
86 mconns = []; | |
87 for i=1:conns.size | |
88 mconns = [mconns conns.get(i-1)]; | |
89 end | |
90 | |
91 % if isempty(mconns) | |
92 % mconns = rm.newConnection(hostname, database, username); | |
93 % end | |
94 % | |
95 utils.helper.msg(utils.const.msg.PROC1, 'Matched %d managed connections', numel(mconns)); | |
96 | |
97 if nargout > 0 | |
98 varargout{1} = mconns; | |
99 end | |
100 | |
101 end | |
102 | |
103 %-------------------------------------------------------------------------- | |
104 % Get Info Object | |
105 %-------------------------------------------------------------------------- | |
106 function ii = getInfo(varargin) | |
107 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
108 sets = {}; | |
109 pl = []; | |
110 else | |
111 sets = {'Default'}; | |
112 pl = getDefaultPlist; | |
113 end | |
114 % Build info object | |
115 ii = minfo(mfilename, 'LTPDARepositoryManager', 'ltpda', utils.const.categories.gui, '$Id: findConnections.m,v 1.7 2011/04/08 08:56:35 hewitson Exp $', sets, pl); | |
116 end | |
117 | |
118 %-------------------------------------------------------------------------- | |
119 % Get Default Plist | |
120 %-------------------------------------------------------------------------- | |
121 function pl = getDefaultPlist() | |
122 | |
123 % Initialise plist | |
124 pl = plist(); | |
125 | |
126 % hostname | |
127 p = param({'hostname', 'The hostname of the repository to connect to.'}, paramValue.EMPTY_STRING); | |
128 pl.append(p); | |
129 | |
130 % database | |
131 p = param({'database', 'The database on the repository.'}, paramValue.EMPTY_STRING); | |
132 pl.append(p); | |
133 | |
134 % username | |
135 p = param({'username', 'The username to connect with.'}, paramValue.EMPTY_STRING); | |
136 pl.append(p); | |
137 | |
138 end | |
139 % END |