This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 130869 - Unable to select connection in SQL Editor
Summary: Unable to select connection in SQL Editor
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Text (show other bugs)
Version: 6.x
Hardware: All All
: P1 blocker (vote)
Assignee: Vitezslav Stejskal
URL:
Keywords:
: 130934 131192 131293 131306 131759 131782 133635 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-03-23 17:25 UTC by David Vancouvering
Modified: 2008-12-22 13:50 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Vancouvering 2008-03-23 17:25:56 UTC
Bring up SQL editor (e.g. from Execute Command...) on a connection.  The drop-down is empty and thus you can't use a
connection or execute any SQL.  Probably a regression from the recent change I made to the DB explorer.
Comment 1 David Vancouvering 2008-03-24 06:31:55 UTC
Further investigation has shown this is not related to my recent changes, as I can reproduce in a repository that
doesn't have those changes.  

This worked about a week ago, as I was using this functionality regularly to test a bugfix in the SQL editor (issue
84276, fixed March 17th).  Since then I have made *no* changes in this area, and scans of the history for the relevant
modules shows nothing apparent.

What is happening is that when the SQL Editor does a Lookup for an implementation of SQLExecution, it finds *no*
implementations.  

What's even stranger to me is I can find no implementations of SQLExecution myself, except for one as a private class in
db.core under SQLCloneableEditor.   This appears to be registered as a lookup instance when the SQL editor is opened.

So I am a bit stumped, I can't see what is causing this.  I have asked Andrei for some pointers as he was the
author/maintainer of this code for some while.   Meanwhile I'll continue to try and track this down.

I did noticed that some settings were changed in the db.sql.editor layer and preferences files to manage MIME types,
between the time it was working for me last time.  This is a potential cause, but my first glance at this didn't seem to
show anything out of the ordinary.

See revisions 8e1ffd3bc07a and 813eb7021054

This last one is particularly interesting, as it adds this method to SQLOptions.java:

+
+    protected String getContentType() {
+        return SQLEditorKit.MIME_TYPE;
+    }


SQLEditorKit.MIME_TYPE is text/x-sql

But I wonder if this is causing the SQLCloneableEditor to not be loaded.  I'll investigate and see if the editor is
actually getting loaded - because if it is, its SQLExecution should be registered in the lookup...

Comment 2 David Vancouvering 2008-03-24 06:48:12 UTC
More information:

When a SQL Editor window is opened, SQLCloneableEditor *is* loaded.  I also stepped through and detected that its method
getLookup() is getting called, and it is returning an implementation of ProxyLookup.  This Lookup has an array of
InstanceContent which contains the SQLExecutionImpl class which is an implementation of SQLExecution.

Then, *after* this method is called, the method in SQLExecutionBaseAction in the SQL Editor (eg.sql.editor) does the
lookup for implementations of SQLExecution, and it gets an empty list!

So there is something that has changed with lookup, sch that even though getLookup() is called for the editor class, and
by all appearances the class is properly registered, it's not being found.

Note that the way the lookup is done is as follows:

            result = actionContext.lookup(new Lookup.Template(SQLExecution.class));

Perhaps there is a better way to do this?  This is all magical incantations to me...



Comment 3 David Vancouvering 2008-03-24 07:27:07 UTC
I am reassigning this to openide, although I really am not sure if that's the history.

Please see the history for this issue.  I'm willing to be convinced otherwise, but the reasons I don't believe this is
an issue I can resolve (or which is mine to resolve) are:

* none of the code I own that is in question has changed in any significant way in the last week, and this bug surfaced
some time between March 17th and now.

* the editor implementation appears to be loaded correctly and is returning its lookup implementation correctly, but
when the lookup actually happens, the instance is not found

I will respond ASAP to any questions you have, and please let me know if there are any other ways I can help.

Comment 4 David Vancouvering 2008-03-24 07:37:37 UTC
Typo: "I'm not really sure that's the history" shd be "I'm not really sure that's the right place."  Sorry, it's late...

Here are some details to reproduce:

- Open the IDE, and go to Services->Databases
- Create a connection if there's not one already there
- Right-click and choose "Execute Command..."

There is a drop-down at the top, try to use this to select a connection.  Notice that whatever connection you select,
the drop-down remains blank and the exeucte SQL icon remains grayed out.

Look in db.mysql/src/org/netbeans/modules/db/sql/editor/ui/actions/SQLExecutionBaseAction.  The connection combo toolbar
is a subclass of this action.

Look at the constructor for the ContextAwareDelegate.  Note how it does a lookup within the action context for a
SQLExecution class using Lookup.Template.  This lookup returns an empty list, as you can tell when you walk through the
resultChanged() method.  This is the cause of the behavior we're seeing.

The implementation of SQLExecution is in db.core/src/org/netbeans/modules/db/sql/loader/SQLCloneableEditor, which is the
registered editor for .sql files.  The implementation is a private class which is registered as an instance for the
proxy lookup class SQLCloneableEditorLookup provided here and returned by getLookup().  

As I mentioned, this class does get loaded when a SQL editor is brought up, and the getLookup() method appears to be
doing the right thing.

So something is breaking down between the call to getLookup() in SQLCloneableEditor and the actual lookup in
SQLExecutionBaseAction.

I am still open to this being something I'm doing wrong, but I'm wondering if something has changed in the lookup code
(or the ContextAwareAction code) that is causing this regression. 
Comment 5 Andrei Badea 2008-03-24 19:20:48 UTC
*** Issue 130934 has been marked as a duplicate of this issue. ***
Comment 6 Andrei Badea 2008-03-24 19:48:12 UTC
Probably caused by 917b620b06b0. When the editor toolbar is initialized, the editor hasn't yet been added to its parent
TopComponent, therefore NbEditorToolbar doesn't include the TC lookup in the lookup it passes to its context-aware actions.
Comment 7 David Vancouvering 2008-03-25 06:16:18 UTC
This issue appears to be causing another bug encountered by Matthew Bohm, see the stack trace below.

I don't fully understand what is going on, but it appears as though the editor was not properly registered ysing
wrapeEditorComponent(), so it's not found when this code tries to get it.

java.lang.ArrayIndexOutOfBoundsException: No such child: 0
>>    at java.awt.Container.getComponent(Container.java:281)
>>    at 
>> org.netbeans.modules.db.sql.loader.SQLCloneableEditor.createResultComponent(SQLCloneableEditor.java:123) 
>>
>>    at 
>> org.netbeans.modules.db.sql.loader.SQLCloneableEditor.getResultComponent(SQLCloneableEditor.java:110) 
>>
>> [catch] at 
>> org.netbeans.modules.db.sql.loader.SQLEditorSupport$2.run(SQLEditorSupport.java:334) 
>>
>>    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
>>    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
>>    at 
>> org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104) 
>>
Comment 8 Jaroslav Tulach 2008-03-25 16:45:11 UTC
changeset:   75244:0a1f833ebd03
user:        Jaroslav Tulach <jtulach@netbeans.org>
date:        Tue Mar 25 16:42:10 2008 +0100
summary:     #130869: Reverting back the old behaviour to open everything in AWT
Comment 9 David Vancouvering 2008-03-26 17:31:18 UTC
*** Issue 131192 has been marked as a duplicate of this issue. ***
Comment 10 David Vancouvering 2008-03-27 16:31:40 UTC
*** Issue 131293 has been marked as a duplicate of this issue. ***
Comment 11 David Vancouvering 2008-03-27 16:32:42 UTC
Issue 131293 is from the March 27 nightly build, so did we get this fixed?  I'll do a fresh pull and build and see if
it's still there.
Comment 12 David Vancouvering 2008-03-27 18:02:36 UTC
Yes, I have confirmed this is still a problem.  

In the module db.sql.editor, class
org.netbeans.modules.db.sql.editor.ui.actions.SQLExecutionBaseAction.ContextAwareDelegate, the constructor does a Lookup
for an implementation of SQLExecution and stores it in a result.  It later iterates and finds no elements (see the
resultChanged() method), and the iterator is empty.

I looked in the stack trace of the constructor for this class, and found where the ActionContext is created, it's in
org.netbeans.modules.editor.NbEditorToolbar.  

I then put a breakpoint in the getLookup method for SQLCloneableEditor (in the module db.core, package
org.netbeans.modules.db.sql.loader).  It has a getLookup() method, and this is not called until *after* the SQL Editor
pane has been initialized.  By that point it is too late for the ContextAwareDelegate, as the action context has already
been set.
Comment 13 Vitezslav Stejskal 2008-03-27 18:23:19 UTC
I have a fix for this. The previous attempt from Yarda didn't work, because in this case it does not really matter if
things run in AWT, but on the order in which they run. Specifically initDecorations() must not run before adding the
QuietEditorPane to the CloneableEditor (the TopComponent).
Comment 14 Vitezslav Stejskal 2008-03-27 21:32:20 UTC
It should work now. I tried the steps mentioned by David with MySQL. http://hg.netbeans.org/main/rev/67a83f316269

The SQLCloneableEditor still has to set "oldInitialization" property for some reason. If it does not the editor pane is
not properly wrapped and the results pane can't be found (ie. the 'No such child: 0' problem reported by Matthew). I
tried to figure out why, but it's some sort of race condition in DoInitialize.initVisual. The wrapping seems to be done
twice (!). Or at least that's what I saw when I logged a stacktrace generated from SQLEditorSupport.wrapEditorComponent.
I'll have a chat with Yarda tomorrow.
Comment 15 David Vancouvering 2008-03-27 21:58:10 UTC
Great, thanks!  I'm fetching now and will verify.
Comment 16 David Vancouvering 2008-03-27 22:40:05 UTC
*** Issue 131306 has been marked as a duplicate of this issue. ***
Comment 17 David Vancouvering 2008-03-28 07:05:32 UTC
Looks good to me.  Thanks!
Comment 18 Andrei Badea 2008-04-03 11:15:37 UTC
*** Issue 131782 has been marked as a duplicate of this issue. ***
Comment 19 Andrei Badea 2008-04-07 14:05:33 UTC
*** Issue 131759 has been marked as a duplicate of this issue. ***
Comment 20 Andrei Badea 2008-04-25 12:44:18 UTC
*** Issue 133635 has been marked as a duplicate of this issue. ***