Lines 42-49
Link Here
|
42 |
package org.netbeans.modules.db.explorer; |
42 |
package org.netbeans.modules.db.explorer; |
43 |
|
43 |
|
44 |
import java.awt.Component; |
44 |
import java.awt.Component; |
|
|
45 |
import java.beans.PropertyChangeListener; |
45 |
import java.beans.PropertyChangeSupport; |
46 |
import java.beans.PropertyChangeSupport; |
46 |
import java.beans.PropertyChangeListener; |
|
|
47 |
import java.beans.PropertyVetoException; |
47 |
import java.beans.PropertyVetoException; |
48 |
import java.io.ObjectStreamException; |
48 |
import java.io.ObjectStreamException; |
49 |
import java.sql.Connection; |
49 |
import java.sql.Connection; |
Lines 58-72
Link Here
|
58 |
import java.util.Set; |
58 |
import java.util.Set; |
59 |
import java.util.logging.Level; |
59 |
import java.util.logging.Level; |
60 |
import java.util.logging.Logger; |
60 |
import java.util.logging.Logger; |
61 |
import org.netbeans.modules.db.explorer.actions.ConnectAction; |
|
|
62 |
import org.openide.util.Lookup; |
61 |
import org.openide.util.Lookup; |
63 |
import org.openide.util.LookupEvent; |
62 |
import org.openide.util.LookupEvent; |
64 |
import org.openide.util.LookupListener; |
63 |
import org.openide.util.LookupListener; |
65 |
import org.openide.util.Mutex; |
|
|
66 |
|
64 |
|
67 |
import org.openide.util.NbBundle; |
65 |
import org.openide.util.NbBundle; |
68 |
import org.openide.util.RequestProcessor; |
|
|
69 |
import org.openide.util.Task ; |
70 |
|
66 |
|
71 |
import org.netbeans.lib.ddl.DBConnection; |
67 |
import org.netbeans.lib.ddl.DBConnection; |
72 |
import org.netbeans.lib.ddl.DDLException; |
68 |
import org.netbeans.lib.ddl.DDLException; |
Lines 75-85
Link Here
|
75 |
import org.netbeans.api.db.explorer.JDBCDriverManager; |
71 |
import org.netbeans.api.db.explorer.JDBCDriverManager; |
76 |
|
72 |
|
77 |
import org.netbeans.modules.db.ExceptionListener; |
73 |
import org.netbeans.modules.db.ExceptionListener; |
|
|
74 |
import org.netbeans.modules.db.explorer.actions.ConnectAction; |
78 |
import org.netbeans.modules.db.explorer.infos.ConnectionNodeInfo; |
75 |
import org.netbeans.modules.db.explorer.infos.ConnectionNodeInfo; |
79 |
import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo; |
76 |
import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo; |
|
|
77 |
import org.netbeans.modules.db.explorer.infos.RootNodeInfo; |
80 |
import org.netbeans.modules.db.explorer.nodes.DatabaseNode; |
78 |
import org.netbeans.modules.db.explorer.nodes.DatabaseNode; |
81 |
import org.netbeans.modules.db.explorer.nodes.RootNode; |
79 |
import org.netbeans.modules.db.explorer.nodes.RootNode; |
82 |
|
|
|
83 |
import org.netbeans.modules.db.runtime.DatabaseRuntimeManager; |
80 |
import org.netbeans.modules.db.runtime.DatabaseRuntimeManager; |
84 |
import org.netbeans.spi.db.explorer.DatabaseRuntime; |
81 |
import org.netbeans.spi.db.explorer.DatabaseRuntime; |
85 |
import org.openide.explorer.ExplorerManager; |
82 |
import org.openide.explorer.ExplorerManager; |
Lines 87-93
Link Here
|
87 |
import org.openide.nodes.NodeNotFoundException; |
84 |
import org.openide.nodes.NodeNotFoundException; |
88 |
import org.openide.nodes.NodeOp; |
85 |
import org.openide.nodes.NodeOp; |
89 |
import org.openide.util.Exceptions; |
86 |
import org.openide.util.Exceptions; |
|
|
87 |
import org.openide.util.Mutex; |
88 |
import org.openide.util.RequestProcessor; |
90 |
import org.openide.windows.TopComponent; |
89 |
import org.openide.windows.TopComponent; |
|
|
90 |
|
91 |
|
91 |
|
92 |
|
92 |
|
93 |
/** |
93 |
/** |
Lines 99-105
Link Here
|
99 |
* open connection. |
99 |
* open connection. |
100 |
*/ |
100 |
*/ |
101 |
public class DatabaseConnection implements DBConnection { |
101 |
public class DatabaseConnection implements DBConnection { |
102 |
|
102 |
|
103 |
private static final Logger LOGGER = Logger.getLogger(DatabaseConnection.class.getName()); |
103 |
private static final Logger LOGGER = Logger.getLogger(DatabaseConnection.class.getName()); |
104 |
private static final boolean LOG = LOGGER.isLoggable(Level.FINE); |
104 |
private static final boolean LOG = LOGGER.isLoggable(Level.FINE); |
105 |
|
105 |
|
Lines 131-137
Link Here
|
131 |
|
131 |
|
132 |
/** Connection name */ |
132 |
/** Connection name */ |
133 |
private String name; |
133 |
private String name; |
134 |
|
134 |
|
135 |
/** |
135 |
/** |
136 |
* The API DatabaseConnection (delegates to this instance) |
136 |
* The API DatabaseConnection (delegates to this instance) |
137 |
*/ |
137 |
*/ |
Lines 159-165
Link Here
|
159 |
openConnectionServices = null; |
159 |
openConnectionServices = null; |
160 |
} |
160 |
} |
161 |
} |
161 |
} |
162 |
}); |
162 |
}); |
163 |
} |
163 |
} |
164 |
|
164 |
|
165 |
/** Default constructor */ |
165 |
/** Default constructor */ |
Lines 167-173
Link Here
|
167 |
dbconn = DatabaseConnectionAccessor.DEFAULT.createDatabaseConnection(this); |
167 |
dbconn = DatabaseConnectionAccessor.DEFAULT.createDatabaseConnection(this); |
168 |
propertySupport = new PropertyChangeSupport(this); |
168 |
propertySupport = new PropertyChangeSupport(this); |
169 |
} |
169 |
} |
170 |
|
170 |
|
171 |
/** Advanced constructor |
171 |
/** Advanced constructor |
172 |
* Allows to specify all needed information. |
172 |
* Allows to specify all needed information. |
173 |
* @param driver Driver URL |
173 |
* @param driver Driver URL |
Lines 178-190
Link Here
|
178 |
public DatabaseConnection(String driver, String database, String user, String password) { |
178 |
public DatabaseConnection(String driver, String database, String user, String password) { |
179 |
this(driver, null, database, null, user, password, false); |
179 |
this(driver, null, database, null, user, password, false); |
180 |
} |
180 |
} |
181 |
|
181 |
|
182 |
public DatabaseConnection(String driver, String driverName, String database, |
182 |
public DatabaseConnection(String driver, String driverName, String database, |
183 |
String theschema, String user, String password) { |
183 |
String theschema, String user, String password) { |
184 |
this(driver, driverName, database, theschema, user, password, false); |
184 |
this(driver, driverName, database, theschema, user, password, false); |
185 |
} |
185 |
} |
186 |
|
186 |
|
187 |
public DatabaseConnection(String driver, String driverName, String database, |
187 |
public DatabaseConnection(String driver, String driverName, String database, |
188 |
String theschema, String user, String password, |
188 |
String theschema, String user, String password, |
189 |
boolean rememberPassword) { |
189 |
boolean rememberPassword) { |
190 |
this(); |
190 |
this(); |
Lines 197-203
Link Here
|
197 |
name = getName(); |
197 |
name = getName(); |
198 |
rpwd = Boolean.valueOf(rememberPassword); |
198 |
rpwd = Boolean.valueOf(rememberPassword); |
199 |
} |
199 |
} |
200 |
|
200 |
|
201 |
public JDBCDriver findJDBCDriver() { |
201 |
public JDBCDriver findJDBCDriver() { |
202 |
JDBCDriver[] drvs = JDBCDriverManager.getDefault().getDrivers(drv); |
202 |
JDBCDriver[] drvs = JDBCDriverManager.getDefault().getDrivers(drv); |
203 |
if (drvs.length <= 0) { |
203 |
if (drvs.length <= 0) { |
Lines 224-236
Link Here
|
224 |
private OpenConnectionInterface getOpenConnection() { |
224 |
private OpenConnectionInterface getOpenConnection() { |
225 |
if (openConnection != null) |
225 |
if (openConnection != null) |
226 |
return openConnection; |
226 |
return openConnection; |
227 |
|
227 |
|
228 |
openConnection = new OpenConnection(); |
228 |
openConnection = new OpenConnection(); |
229 |
String driver = getDriver(); |
229 |
String driver = getDriver(); |
230 |
if (driver == null) { |
230 |
if (driver == null) { |
231 |
return openConnection; |
231 |
return openConnection; |
232 |
} |
232 |
} |
233 |
|
233 |
|
234 |
// For Java Studio Enterprise. Create instanceof OpenConnection |
234 |
// For Java Studio Enterprise. Create instanceof OpenConnection |
235 |
try { |
235 |
try { |
236 |
Collection c = getOpenConnections(); |
236 |
Collection c = getOpenConnections(); |
Lines 246-252
Link Here
|
246 |
} |
246 |
} |
247 |
return openConnection; |
247 |
return openConnection; |
248 |
} |
248 |
} |
249 |
|
249 |
|
250 |
/** Returns driver class */ |
250 |
/** Returns driver class */ |
251 |
public String getDriver() { |
251 |
public String getDriver() { |
252 |
return drv; |
252 |
return drv; |
Lines 424-430
Link Here
|
424 |
if (LOG) { |
424 |
if (LOG) { |
425 |
LOGGER.log(Level.FINE, "createJDBCConnection()"); |
425 |
LOGGER.log(Level.FINE, "createJDBCConnection()"); |
426 |
} |
426 |
} |
427 |
|
427 |
|
428 |
if (drv == null || db == null || usr == null ) |
428 |
if (drv == null || db == null || usr == null ) |
429 |
throw new DDLException(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_InsufficientConnInfo")); |
429 |
throw new DDLException(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_InsufficientConnInfo")); |
430 |
|
430 |
|
Lines 440-449
Link Here
|
440 |
// For Java Studio Enterprise. |
440 |
// For Java Studio Enterprise. |
441 |
getOpenConnection().enable(); |
441 |
getOpenConnection().enable(); |
442 |
startRuntimes(); |
442 |
startRuntimes(); |
443 |
|
443 |
|
444 |
// hack for Derby |
444 |
// hack for Derby |
445 |
DerbyConectionEventListener.getDefault().beforeConnect(this); |
445 |
DerbyConectionEventListener.getDefault().beforeConnect(this); |
446 |
|
446 |
|
447 |
JDBCDriver useDriver = findJDBCDriver(); |
447 |
JDBCDriver useDriver = findJDBCDriver(); |
448 |
if (useDriver == null) { |
448 |
if (useDriver == null) { |
449 |
// will be loaded through DriverManager, make sure it is loaded |
449 |
// will be loaded through DriverManager, make sure it is loaded |
Lines 452-462
Link Here
|
452 |
|
452 |
|
453 |
Connection connection = DbDriverManager.getDefault().getConnection(db, dbprops, useDriver); |
453 |
Connection connection = DbDriverManager.getDefault().getConnection(db, dbprops, useDriver); |
454 |
setConnection(connection); |
454 |
setConnection(connection); |
455 |
|
455 |
|
456 |
DatabaseUILogger.logConnection(drv); |
456 |
DatabaseUILogger.logConnection(drv); |
457 |
|
457 |
|
458 |
propertySupport.firePropertyChange("connected", null, null); |
458 |
propertySupport.firePropertyChange("connected", null, null); |
459 |
|
459 |
|
460 |
// For Java Studio Enterprise. |
460 |
// For Java Studio Enterprise. |
461 |
getOpenConnection().disable(); |
461 |
getOpenConnection().disable(); |
462 |
|
462 |
|
Lines 471-477
Link Here
|
471 |
// message = MessageFormat.format(bundle.getString("EXC_PointbaseServerRejected"), new String[] {message, db}); // NOI18N |
471 |
// message = MessageFormat.format(bundle.getString("EXC_PointbaseServerRejected"), new String[] {message, db}); // NOI18N |
472 |
|
472 |
|
473 |
propertySupport.firePropertyChange("failed", null, null); |
473 |
propertySupport.firePropertyChange("failed", null, null); |
474 |
|
474 |
|
475 |
// For Java Studio Enterprise. |
475 |
// For Java Studio Enterprise. |
476 |
getOpenConnection().disable(); |
476 |
getOpenConnection().disable(); |
477 |
|
477 |
|
Lines 493-600
Link Here
|
493 |
} |
493 |
} |
494 |
} |
494 |
} |
495 |
|
495 |
|
496 |
public void connect() { |
496 |
public void connectSync() throws DatabaseException { |
|
|
497 |
try { |
498 |
doConnect(); |
499 |
|
500 |
// Let the CNI know we're connected and set things up |
501 |
// appropriately |
502 |
ConnectionNodeInfo cni = findConnectionNodeInfo(getName()); |
503 |
cni.connect(this); |
504 |
} catch (Exception exc) { |
505 |
try { |
506 |
getConnection().close(); |
507 |
} catch (SQLException e) { |
508 |
LOGGER.log(Level.FINE, null, e); |
509 |
} |
510 |
throw new DatabaseException(exc); |
511 |
} |
512 |
} |
513 |
|
514 |
private void doConnect() throws DDLException { |
515 |
if (drv == null || db == null || usr == null ) |
516 |
sendException(new DDLException(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_InsufficientConnInfo"))); |
517 |
|
518 |
Properties dbprops = new Properties(); |
519 |
if ( usr.length() > 0 ) { |
520 |
dbprops.put("user", usr); //NOI18N |
521 |
} |
522 |
if ((pwd != null && pwd.length() > 0)) { |
523 |
dbprops.put("password", pwd); //NOI18N |
524 |
} |
525 |
|
526 |
Connection conn = null; |
527 |
try { |
528 |
propertySupport.firePropertyChange("connecting", null, null); |
529 |
|
530 |
// For Java Studio Enterprise. |
531 |
getOpenConnection().enable(); |
532 |
|
533 |
startRuntimes(); |
534 |
|
535 |
// hack for Derby |
536 |
DerbyConectionEventListener.getDefault().beforeConnect(DatabaseConnection.this); |
537 |
|
538 |
JDBCDriver useDriver = findJDBCDriver(); |
539 |
if (useDriver == null) { |
540 |
// will be loaded through DriverManager, make sure it is loaded |
541 |
Class.forName(drv); |
542 |
} |
543 |
|
544 |
conn = DbDriverManager.getDefault().getConnection(db, dbprops, useDriver); |
545 |
setConnection(conn); |
546 |
|
547 |
DatabaseUILogger.logConnection(drv); |
548 |
|
549 |
propertySupport.firePropertyChange("connected", null, null); |
550 |
} catch (Exception e) { |
551 |
String message = MessageFormat.format( |
552 |
NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_CannotEstablishConnection"), |
553 |
db, drv, e.getMessage()); // NOI18N |
554 |
|
555 |
propertySupport.firePropertyChange("failed", null, null); |
556 |
|
557 |
if (e instanceof SQLException) { |
558 |
initSQLException((SQLException)e); |
559 |
} |
560 |
|
561 |
DDLException ddle = new DDLException(message); |
562 |
ddle.initCause(e); |
563 |
|
564 |
if (conn != null) { |
565 |
setConnection(null); |
566 |
try { |
567 |
conn.close(); |
568 |
} catch (SQLException sqle) { |
569 |
Logger.getLogger("global").log(Level.WARNING, null, sqle); // NOI18N |
570 |
} |
571 |
} |
572 |
|
573 |
throw ddle; |
574 |
} finally { |
575 |
getOpenConnection().disable(); |
576 |
} |
577 |
} |
578 |
|
579 |
public void connectAsync() { |
497 |
if (LOG) { |
580 |
if (LOG) { |
498 |
LOGGER.log(Level.FINE, "connect()"); |
581 |
LOGGER.log(Level.FINE, "connect()"); |
499 |
} |
582 |
} |
500 |
|
|
|
501 |
createConnectTask() ; |
502 |
} |
503 |
|
583 |
|
504 |
public Task createConnectTask() { |
584 |
RequestProcessor.getDefault().post(new Runnable() { |
505 |
return RequestProcessor.getDefault().post(new Runnable() { |
|
|
506 |
public void run() { |
585 |
public void run() { |
507 |
if (drv == null || db == null || usr == null ) |
|
|
508 |
sendException(new DDLException(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_InsufficientConnInfo"))); |
509 |
|
510 |
Properties dbprops = new Properties(); |
511 |
if ( usr.length() > 0 ) { |
512 |
dbprops.put("user", usr); //NOI18N |
513 |
} |
514 |
if ((pwd != null && pwd.length() > 0)) { |
515 |
dbprops.put("password", pwd); //NOI18N |
516 |
} |
517 |
|
518 |
Connection conn = null; |
519 |
try { |
586 |
try { |
520 |
propertySupport.firePropertyChange("connecting", null, null); |
587 |
doConnect(); |
521 |
|
588 |
} catch (Exception e) { |
522 |
// For Java Studio Enterprise. |
589 |
sendException(e); |
523 |
getOpenConnection().enable(); |
|
|
524 |
|
525 |
// For Java Studio Enterprise. |
526 |
getOpenConnection().enable(); |
527 |
startRuntimes(); |
528 |
|
529 |
// hack for Derby |
530 |
DerbyConectionEventListener.getDefault().beforeConnect(DatabaseConnection.this); |
531 |
|
532 |
JDBCDriver useDriver = findJDBCDriver(); |
533 |
if (useDriver == null) { |
534 |
// will be loaded through DriverManager, make sure it is loaded |
535 |
Class.forName(drv); |
536 |
} |
537 |
|
538 |
conn = DbDriverManager.getDefault().getConnection(db, dbprops, useDriver); |
539 |
setConnection(conn); |
540 |
|
541 |
DatabaseUILogger.logConnection(drv); |
542 |
|
543 |
propertySupport.firePropertyChange("connected", null, null); |
544 |
|
545 |
// For Java Studio Enterprise. |
546 |
getOpenConnection().disable(); |
547 |
|
548 |
} catch (SQLException e) { |
549 |
String message = MessageFormat.format(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_CannotEstablishConnection"), new String[] {db, drv, e.getMessage()}); // NOI18N |
550 |
|
551 |
//commented out for 3.6 release, need to solve for next Studio release |
552 |
// hack for Pointbase Network Server |
553 |
// if (drv.equals(PointbasePlus.DRIVER)) |
554 |
// if (e.getErrorCode() == PointbasePlus.ERR_SERVER_REJECTED) |
555 |
// message = MessageFormat.format(bundle.getString("EXC_PointbaseServerRejected"), new String[] {message, db}); // NOI18N |
556 |
|
557 |
propertySupport.firePropertyChange("failed", null, null); |
558 |
|
559 |
// For Java Studio Enterprise. |
560 |
getOpenConnection().disable(); |
561 |
|
562 |
initSQLException(e); |
563 |
DDLException ddle = new DDLException(message); |
564 |
ddle.initCause(e); |
565 |
sendException(ddle); |
566 |
|
567 |
if (conn != null) { |
568 |
setConnection(null); |
569 |
try { |
570 |
conn.close(); |
571 |
} catch (SQLException sqle) { |
572 |
Logger.getLogger("global").log(Level.WARNING, null, sqle); // NOI18N |
573 |
} |
574 |
} |
575 |
} catch (Exception exc) { |
576 |
propertySupport.firePropertyChange("failed", null, null); |
577 |
|
578 |
// For Java Studio Enterprise. |
579 |
getOpenConnection().disable(); |
580 |
|
581 |
sendException(exc); |
582 |
|
583 |
setConnection(null); |
584 |
if (conn != null) { |
585 |
try { |
586 |
conn.close(); |
587 |
} catch (SQLException sqle) { |
588 |
Logger.getLogger("global").log(Level.WARNING, null, sqle); // NOI18N |
589 |
} |
590 |
} |
591 |
} |
590 |
} |
592 |
} |
591 |
} |
593 |
}, 0); |
592 |
}, 0); |
594 |
} |
593 |
} |
595 |
|
594 |
|
596 |
/** Calls the initCause() for SQLException with the value |
595 |
/** Calls the initCause() for SQLException with the value |
597 |
* of getNextException() so this exception's stack trace contains |
596 |
* of getNextException() so this exception's stack trace contains |
598 |
* the complete data. |
597 |
* the complete data. |
599 |
*/ |
598 |
*/ |
600 |
private void initSQLException(SQLException e) { |
599 |
private void initSQLException(SQLException e) { |
Lines 613-619
Link Here
|
613 |
|
612 |
|
614 |
private void startRuntimes() { |
613 |
private void startRuntimes() { |
615 |
DatabaseRuntime[] runtimes = DatabaseRuntimeManager.getDefault().getRuntimes(drv); |
614 |
DatabaseRuntime[] runtimes = DatabaseRuntimeManager.getDefault().getRuntimes(drv); |
616 |
|
615 |
|
617 |
for (int i = 0; i < runtimes.length; i++) { |
616 |
for (int i = 0; i < runtimes.length; i++) { |
618 |
DatabaseRuntime runtime = runtimes[i]; |
617 |
DatabaseRuntime runtime = runtimes[i]; |
619 |
if (runtime.isRunning()) { |
618 |
if (runtime.isRunning()) { |
Lines 698-704
Link Here
|
698 |
} catch (Exception exc) { |
697 |
} catch (Exception exc) { |
699 |
//IGNORE - not stored in 3.6 and earlier |
698 |
//IGNORE - not stored in 3.6 and earlier |
700 |
} |
699 |
} |
701 |
|
700 |
|
702 |
// boston setting/pilsen setting? |
701 |
// boston setting/pilsen setting? |
703 |
if ((name != null) && (name.equals(DatabaseConnection.SUPPORT))) { |
702 |
if ((name != null) && (name.equals(DatabaseConnection.SUPPORT))) { |
704 |
// pilsen |
703 |
// pilsen |
Lines 708-714
Link Here
|
708 |
} |
707 |
} |
709 |
name = null; |
708 |
name = null; |
710 |
name = getName(); |
709 |
name = getName(); |
711 |
|
710 |
|
712 |
dbconn = DatabaseConnectionAccessor.DEFAULT.createDatabaseConnection(this); |
711 |
dbconn = DatabaseConnectionAccessor.DEFAULT.createDatabaseConnection(this); |
713 |
} |
712 |
} |
714 |
|
713 |
|
Lines 718-738
Link Here
|
718 |
out.writeObject(db); |
717 |
out.writeObject(db); |
719 |
out.writeObject(usr); |
718 |
out.writeObject(usr); |
720 |
out.writeObject(schema); |
719 |
out.writeObject(schema); |
721 |
out.writeObject(DatabaseConnection.SUPPORT); |
720 |
out.writeObject(DatabaseConnection.SUPPORT); |
722 |
out.writeObject(drvname); |
721 |
out.writeObject(drvname); |
723 |
} |
722 |
} |
724 |
|
723 |
|
725 |
public String toString() { |
724 |
public String toString() { |
726 |
return "Driver:" + getDriver() + "Database:" + getDatabase().toLowerCase() + "User:" + getUser().toLowerCase() + "Schema:" + getSchema().toLowerCase(); // NOI18N |
725 |
return "Driver:" + getDriver() + "Database:" + getDatabase().toLowerCase() + "User:" + getUser().toLowerCase() + "Schema:" + getSchema().toLowerCase(); // NOI18N |
727 |
} |
726 |
} |
728 |
|
727 |
|
729 |
/** |
728 |
/** |
730 |
* Gets the API DatabaseConnection which corresponds to this connection. |
729 |
* Gets the API DatabaseConnection which corresponds to this connection. |
731 |
*/ |
730 |
*/ |
732 |
public org.netbeans.api.db.explorer.DatabaseConnection getDatabaseConnection() { |
731 |
public org.netbeans.api.db.explorer.DatabaseConnection getDatabaseConnection() { |
733 |
return dbconn; |
732 |
return dbconn; |
734 |
} |
733 |
} |
735 |
|
734 |
|
736 |
public void selectInExplorer() { |
735 |
public void selectInExplorer() { |
737 |
String nodeName = null; |
736 |
String nodeName = null; |
738 |
try { |
737 |
try { |
Lines 741-754
Link Here
|
741 |
Exceptions.printStackTrace(e); |
740 |
Exceptions.printStackTrace(e); |
742 |
return; |
741 |
return; |
743 |
} |
742 |
} |
744 |
|
743 |
|
745 |
// find the Runtime panel top component |
744 |
// find the Runtime panel top component |
746 |
// quite hacky, but it will be replaced by the Server Navigator |
745 |
// quite hacky, but it will be replaced by the Server Navigator |
747 |
|
746 |
|
748 |
TopComponent runtimePanel = null; |
747 |
TopComponent runtimePanel = null; |
749 |
ExplorerManager runtimeExplorer = null; |
748 |
ExplorerManager runtimeExplorer = null; |
750 |
Node runtimeNode = null; |
749 |
Node runtimeNode = null; |
751 |
|
750 |
|
752 |
for (Iterator i = TopComponent.getRegistry().getOpened().iterator(); i.hasNext();) { |
751 |
for (Iterator i = TopComponent.getRegistry().getOpened().iterator(); i.hasNext();) { |
753 |
TopComponent component = (TopComponent)i.next(); |
752 |
TopComponent component = (TopComponent)i.next(); |
754 |
Component[] children = component.getComponents(); |
753 |
Component[] children = component.getComponents(); |
Lines 761-771
Link Here
|
761 |
} |
760 |
} |
762 |
} |
761 |
} |
763 |
} |
762 |
} |
764 |
|
763 |
|
765 |
if (runtimePanel == null) { |
764 |
if (runtimePanel == null) { |
766 |
return; |
765 |
return; |
767 |
} |
766 |
} |
768 |
|
767 |
|
769 |
Node node = null; |
768 |
Node node = null; |
770 |
try { |
769 |
try { |
771 |
node = NodeOp.findPath(runtimeNode, new String[] { "Databases", nodeName }); // NOI18N |
770 |
node = NodeOp.findPath(runtimeNode, new String[] { "Databases", nodeName }); // NOI18N |
Lines 773-789
Link Here
|
773 |
Exceptions.printStackTrace(e); |
772 |
Exceptions.printStackTrace(e); |
774 |
return; |
773 |
return; |
775 |
} |
774 |
} |
776 |
|
775 |
|
777 |
try { |
776 |
try { |
778 |
runtimeExplorer.setSelectedNodes(new Node[] { node }); |
777 |
runtimeExplorer.setSelectedNodes(new Node[] { node }); |
779 |
} catch (PropertyVetoException e) { |
778 |
} catch (PropertyVetoException e) { |
780 |
Exceptions.printStackTrace(e); |
779 |
Exceptions.printStackTrace(e); |
781 |
return; |
780 |
return; |
782 |
} |
781 |
} |
783 |
|
782 |
|
784 |
runtimePanel.requestActive(); |
783 |
runtimePanel.requestActive(); |
785 |
} |
784 |
} |
786 |
|
785 |
|
787 |
public void showConnectionDialog() { |
786 |
public void showConnectionDialog() { |
788 |
try { |
787 |
try { |
789 |
final ConnectionNodeInfo cni = findConnectionNodeInfo(getName()); |
788 |
final ConnectionNodeInfo cni = findConnectionNodeInfo(getName()); |
Lines 798-804
Link Here
|
798 |
Exceptions.printStackTrace(e); |
797 |
Exceptions.printStackTrace(e); |
799 |
} |
798 |
} |
800 |
} |
799 |
} |
801 |
|
800 |
|
802 |
public Connection getJDBCConnection() { |
801 |
public Connection getJDBCConnection() { |
803 |
try { |
802 |
try { |
804 |
ConnectionNodeInfo cni = findConnectionNodeInfo(getName()); |
803 |
ConnectionNodeInfo cni = findConnectionNodeInfo(getName()); |
Lines 810-839
Link Here
|
810 |
} |
809 |
} |
811 |
return null; |
810 |
return null; |
812 |
} |
811 |
} |
813 |
|
812 |
|
814 |
public void disconnect() throws DatabaseException { |
813 |
public void disconnect() throws DatabaseException { |
815 |
ConnectionNodeInfo cni = findConnectionNodeInfo(getName()); |
814 |
ConnectionNodeInfo cni = findConnectionNodeInfo(getName()); |
816 |
if (cni != null && cni.getConnection() != null) { |
815 |
if (cni != null && cni.getConnection() != null) { |
817 |
cni.disconnect(); |
816 |
cni.disconnect(); |
818 |
} |
817 |
} |
819 |
} |
818 |
} |
820 |
|
819 |
|
821 |
private ConnectionNodeInfo findConnectionNodeInfo(String connection) throws DatabaseException { |
820 |
private ConnectionNodeInfo findConnectionNodeInfo(String connection) throws DatabaseException { |
822 |
assert connection != null; |
821 |
assert connection != null; |
823 |
|
822 |
|
824 |
// We can't use the info classes here since surprisingly |
823 |
// We can't use the info classes here since surprisingly |
825 |
// the CNIs found in RootNode.getInstance().getInfo are different than |
824 |
// the CNIs found in RootNode.getInstance().getInfo are different than |
826 |
// the ones the ConnectionNodes in the Databases tree listen to. |
825 |
// the ones the ConnectionNodes in the Databases tree listen to. |
827 |
|
826 |
|
828 |
// This will account for the "Please wait" node. |
827 |
// This will account for the "Please wait" node. |
829 |
Node[] nodes = RootNode.getInstance().getChildren().getNodes(true); |
828 |
Node[] nodes = RootNode.getInstance().getChildren().getNodes(true); |
830 |
|
829 |
|
831 |
for (int i = 0; i < nodes.length; i++) { |
830 |
for (int i = 0; i < nodes.length; i++) { |
832 |
// Skip nodes registered by node providers |
831 |
// Skip nodes registered by node providers |
833 |
if ( ! (nodes[i] instanceof DatabaseNode) ) { |
832 |
if ( ! (nodes[i] instanceof DatabaseNode) ) { |
834 |
continue; |
833 |
continue; |
835 |
} |
834 |
} |
836 |
|
835 |
|
837 |
DatabaseNodeInfo info = (DatabaseNodeInfo)nodes[i].getCookie(DatabaseNodeInfo.class); |
836 |
DatabaseNodeInfo info = (DatabaseNodeInfo)nodes[i].getCookie(DatabaseNodeInfo.class); |
838 |
if (info == null) { |
837 |
if (info == null) { |
839 |
continue; |
838 |
continue; |
Lines 848-854
Link Here
|
848 |
} |
847 |
} |
849 |
return null; |
848 |
return null; |
850 |
} |
849 |
} |
851 |
|
850 |
|
852 |
private Object readResolve() throws ObjectStreamException { |
851 |
private Object readResolve() throws ObjectStreamException { |
853 |
// sometimes deserialized objects have a null propertySuppport, not sure why |
852 |
// sometimes deserialized objects have a null propertySuppport, not sure why |
854 |
if (propertySupport == null) { |
853 |
if (propertySupport == null) { |