comparison m-toolbox/classes/@workspaceBrowser/cb_query.m @ 30:317b5f447f3e database-connection-manager

Update workspaceBrowser
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 16:20:06 +0100
parents f0afece42f48
children
comparison
equal deleted inserted replaced
29:54f14716c721 30:317b5f447f3e
7 % $Id: cb_query.m,v 1.12 2010/07/23 15:09:45 ingo Exp $ 7 % $Id: cb_query.m,v 1.12 2010/07/23 15:09:45 ingo Exp $
8 % 8 %
9 function cb_query(varargin) 9 function cb_query(varargin)
10 10
11 wb = getappdata(0, 'WorkspaceBrowser'); 11 wb = getappdata(0, 'WorkspaceBrowser');
12
13 % Get a connection from the database connection manager
14 conn = LTPDADatabaseConnectionManager().connect();
15
16 % Get submission info from the user
17 rqd = awtcreate('mpipeline.repository.RepositoryQueryDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.Connection;Z', [], false, conn, false);
18 awtinvoke(rqd, 'setVisible', 'true');
19
20 hExec = handle(rqd.getExecuteBtn(),'callbackproperties');
21 hExec.ActionPerformedCallback = @cb_executeQuery;
12 22
13 % Get a connection from the repository manager 23 hGuiCloses1 = handle(rqd, 'callbackproperties');
14 rm = LTPDARepositoryManager; 24 hGuiCloses1.WindowClosedCallback = @cb_guiClosed1;
15 conn = rm.manager.selectConnection([]);
16
17 if ~isempty(conn)
18 % Update
19 if ~isempty(rm.gui)
20 awtinvoke(rm.gui, 'reloadConnectionTable()');
21 end
22 % Get submission info from the user
23 rqd = awtcreate('mpipeline.repository.RepositoryQueryDialog', 'Lmpipeline.main.MainWindow;ZLmpipeline.repository.RepositoryConnection;Z', [], false, conn, false);
24 awtinvoke(rqd, 'setVisible', 'true');
25
26 hExec = handle(rqd.getExecuteBtn(),'callbackproperties');
27 hExec.ActionPerformedCallback = @cb_executeQuery;
28
29 hGuiCloses1 = handle(rqd, 'callbackproperties');
30 hGuiCloses1.WindowClosedCallback = @cb_guiClosed1;
31
32 end
33 25
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 function cb_guiClosed1(varargin) 27 function cb_guiClosed1(varargin)
36 % Delete callback handles 28 % Delete callback handles
37 if ishandle(hExec) 29 if ishandle(hExec)
51 function cb_executeQuery(varargin) 43 function cb_executeQuery(varargin)
52 44
53 jQueryTextField = awtinvoke(rqd, 'getQueryTxtField()'); 45 jQueryTextField = awtinvoke(rqd, 'getQueryTxtField()');
54 jQuery = awtinvoke(jQueryTextField, 'getText()'); 46 jQuery = awtinvoke(jQueryTextField, 'getText()');
55 47
56 if ~(awtinvoke(conn, 'isConnected()')) 48 jStmt = awtinvoke(conn, 'createStatement()');
57 awtinvoke(conn, 'openConnection()'); 49
50 try
51
52 jResult = awtinvoke(jStmt, 'executeQuery(Ljava.lang.String;)', jQuery);
53
54 % pass to query results table
55 qrt = awtcreate('mpipeline.repository.QueryResultsTableDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.ResultSet;Ljava.lang.String;Z', [], false, jResult, jQuery, false);
56 awtinvoke(qrt, 'setUsedConn(Ljava.sql.Connection;)', conn);
57 awtinvoke(qrt, 'setVisible(Z)', 'true');
58
59 hRetrieve = handle(qrt.getCreateConstructors,'callbackproperties');
60 hRetrieve.ActionPerformedCallback = @cb_retrieveObjectsFromTable;
61
62 hGuiCloses2 = handle(qrt, 'callbackproperties');
63 hGuiCloses2.WindowClosedCallback = @cb_guiClosed2;
64
65 catch err
66 fprintf(2, [err.message, '\n']);
58 end 67 end
59
60 if (awtinvoke(conn, 'isConnected()'))
61 68
62 % lock connection
63 awtinvoke(conn, 'setLocked(Z)', true);
64 jStmt = awtinvoke(conn, 'createStatement()');
65
66 try
67
68 jResult = awtinvoke(jStmt, 'executeQuery(Ljava.lang.String;)', jQuery);
69
70 % pass to query results table
71 qrt = awtcreate('mpipeline.repository.QueryResultsTableDialog', 'Lmpipeline.main.MainWindow;ZLjava.sql.ResultSet;Ljava.lang.String;Z', [], false, jResult, jQuery, false);
72 awtinvoke(qrt, 'setUsedConn(Lmpipeline.repository.RepositoryConnection;)', conn);
73 awtinvoke(qrt, 'setVisible(Z)', 'true');
74
75 hRetrieve = handle(qrt.getCreateConstructors,'callbackproperties');
76 hRetrieve.ActionPerformedCallback = @cb_retrieveObjectsFromTable;
77
78 hGuiCloses2 = handle(qrt, 'callbackproperties');
79 hGuiCloses2.WindowClosedCallback = @cb_guiClosed2;
80
81 catch err
82 fprintf(2, [err.message, '\n']);
83 end
84 awtinvoke(conn, 'setLocked(Z)', false);
85
86 end
87 69
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 function cb_guiClosed2(varargin) 71 function cb_guiClosed2(varargin)
90 % Delete callback handles 72 % Delete callback handles
91 if ishandle(hRetrieve) 73 if ishandle(hRetrieve)