Mercurial > hg > ltpda
annotate m-toolbox/classes/@workspaceBrowser/cb_query.m @ 52:daf4eab1a51e database-connection-manager tip
Fix. Default password should be [] not an empty string
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 07 Dec 2011 17:29:47 +0100 |
parents | 317b5f447f3e |
children |
rev | line source |
---|---|
0 | 1 % CB_QUERY queries an LTPDA repository |
2 % | |
3 % CALL: workspaceBrowser.cb_query | |
4 % | |
5 % M Hewitson 13-11-08 | |
6 % | |
7 % $Id: cb_query.m,v 1.12 2010/07/23 15:09:45 ingo Exp $ | |
8 % | |
9 function cb_query(varargin) | |
10 | |
11 wb = getappdata(0, 'WorkspaceBrowser'); | |
30
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
12 |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
13 % Get a connection from the database connection manager |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
14 conn = LTPDADatabaseConnectionManager().connect(); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
15 |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
16 % Get submission info from the user |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
17 rqd = awtcreate('mpipeline.repository.RepositoryQueryDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.Connection;Z', [], false, conn, false); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
18 awtinvoke(rqd, 'setVisible', 'true'); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
19 |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
20 hExec = handle(rqd.getExecuteBtn(),'callbackproperties'); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
21 hExec.ActionPerformedCallback = @cb_executeQuery; |
0 | 22 |
30
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
23 hGuiCloses1 = handle(rqd, 'callbackproperties'); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
24 hGuiCloses1.WindowClosedCallback = @cb_guiClosed1; |
0 | 25 |
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
27 function cb_guiClosed1(varargin) | |
28 % Delete callback handles | |
29 if ishandle(hExec) | |
30 delete(hExec) | |
31 end | |
32 if ishandle(hGuiCloses1) | |
33 delete(hGuiCloses1) | |
34 end | |
35 | |
36 % Delete all variables | |
37 wb = []; | |
38 rm = []; | |
39 conn = []; | |
40 rqd = []; | |
41 end | |
42 | |
43 function cb_executeQuery(varargin) | |
44 | |
45 jQueryTextField = awtinvoke(rqd, 'getQueryTxtField()'); | |
46 jQuery = awtinvoke(jQueryTextField, 'getText()'); | |
47 | |
30
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
48 jStmt = awtinvoke(conn, 'createStatement()'); |
0 | 49 |
30
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
50 try |
0 | 51 |
30
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
52 jResult = awtinvoke(jStmt, 'executeQuery(Ljava.lang.String;)', jQuery); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
53 |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
54 % pass to query results table |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
55 qrt = awtcreate('mpipeline.repository.QueryResultsTableDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.ResultSet;Ljava.lang.String;Z', [], false, jResult, jQuery, false); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
56 awtinvoke(qrt, 'setUsedConn(Ljava.sql.Connection;)', conn); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
57 awtinvoke(qrt, 'setVisible(Z)', 'true'); |
0 | 58 |
30
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
59 hRetrieve = handle(qrt.getCreateConstructors,'callbackproperties'); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
60 hRetrieve.ActionPerformedCallback = @cb_retrieveObjectsFromTable; |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
61 |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
62 hGuiCloses2 = handle(qrt, 'callbackproperties'); |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
63 hGuiCloses2.WindowClosedCallback = @cb_guiClosed2; |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
64 |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
65 catch err |
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
66 fprintf(2, [err.message, '\n']); |
0 | 67 end |
30
317b5f447f3e
Update workspaceBrowser
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
0
diff
changeset
|
68 |
0 | 69 |
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
71 function cb_guiClosed2(varargin) | |
72 % Delete callback handles | |
73 if ishandle(hRetrieve) | |
74 delete(hRetrieve) | |
75 end | |
76 if ishandle(hGuiCloses2) | |
77 delete(hGuiCloses2) | |
78 end | |
79 | |
80 % Delete all variables | |
81 jQueryTextField = []; | |
82 jQuery = []; | |
83 jStmt = []; | |
84 jResult = []; | |
85 qrt = []; | |
86 end | |
87 | |
88 function cb_retrieveObjectsFromTable(varargin) | |
89 | |
90 try | |
91 jResultTable = awtinvoke(qrt, 'getResultsTable()'); | |
92 jColNames = awtinvoke(qrt, 'getColNames()'); | |
93 jObj_id_col = awtinvoke(jColNames, 'indexOf(Ljava.lang.Object;)', 'obj_id'); | |
94 | |
95 if (jObj_id_col == -1) | |
96 msg = 'The results must contain the field ''obj_id'' in order to create constructor blocks.'; | |
97 utils.helper.errorDlg(msg, 'Fields error'); | |
98 jResultTable = []; | |
99 jColNames = []; | |
100 jObj_id_col = []; | |
101 error(msg); | |
102 end | |
103 | |
104 numberStr = ''; | |
105 jRows = double(awtinvoke(jResultTable, 'getSelectedRows()')); | |
106 | |
107 jModel = []; | |
108 if numel(jRows) >= 1 | |
109 jModel = awtinvoke(jResultTable, 'getModel()'); | |
110 numberStr = num2str(awtinvoke(jModel, 'getValueAt(II), ', jRows(1), jObj_id_col)); | |
111 end | |
112 | |
113 for kk = 2:numel(jRows) | |
114 jModel = awtinvoke(jResultTable, 'getModel()'); | |
115 | |
116 objIDstr = num2str( awtinvoke(jModel, 'getValueAt(II)', jRows(kk), jObj_id_col)); | |
117 numberStr = [numberStr, ' ', objIDstr]; | |
118 end | |
119 | |
120 rrd = awtcreate('mpipeline.repository.RepositoryRetrieveDialog', 'Ljava.awt.Frame;Z', [], true); | |
121 | |
122 jObjIDTextField = awtinvoke(rrd, 'getObjectIDsTextField()'); | |
123 awtinvoke(jObjIDTextField, 'setText(Ljava.lang.String;)', numberStr); | |
124 awtinvoke(rrd, 'setVisible(Z)', true); | |
125 | |
126 hGuiCloses3 = handle(rrd, 'callbackproperties'); | |
127 hGuiCloses3.WindowClosedCallback = @cb_guiClosed3; | |
128 | |
129 catch err | |
130 fprintf(2, [err.message, '\n']); | |
131 end | |
132 | |
133 function cb_guiClosed3(varargin) | |
134 % Delete callback handles | |
135 if ishandle(hGuiCloses3) | |
136 delete(hGuiCloses3) | |
137 end | |
138 | |
139 if ~rrd.isCancelled | |
140 workspaceBrowser.retrieveObjectsFromDialog(rrd, conn); | |
141 end | |
142 | |
143 % Delete all variables | |
144 jResultTable = []; | |
145 jColNames = []; | |
146 jObj_id_col = []; | |
147 jRows = []; | |
148 jModel = []; | |
149 rrd = []; | |
150 jObjIDTextField = []; | |
151 end | |
152 | |
153 end % cb_retrieveObjectsFromTable | |
154 | |
155 end % cb_executeQuery | |
156 | |
157 end % cb_query | |
158 | |
159 |