Skip to content

Commit ff3adb3

Browse files
committed
WIP: SQLDEV-2076 Cleanup code, doc, license blocks
TODO:? Replace button actions to start command line/server with property listeners on the preference properties so nothing happens until you OK the preference changes?<p/> TODO:? Show non-deprecated technique for doing something after the window finishes loading? See OptInHandler$DialogWaitTask (Note the ide is not being updated except for security issues so the deprecation is 'just' ugly. I.e., it shouldn't ever actually be removed.)<p/>
1 parent 31e0460 commit ff3adb3

File tree

12 files changed

+304
-117
lines changed

12 files changed

+304
-117
lines changed

sqldeveloper/extension/README.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
# [SQL Developer](http://www.oracle.com/technetwork/developer-tools/sql-developer/) Examples
2-
## Extensions
3-
You can add new folders and nodes to navigators, new actions on objects (*or sets of them*), and new editors or viewers.
4-
5-
Depending on requirements, this can be done in either XML or java and deployed by simply copying an XML file to the appropriate directory, or creating an extension jar -- or *check for updates* bundle for XML and/or java.
6-
7-
### New
8-
9-
* [Connection Helper](java/ConnectionHelper) - Accept connection info from the command line (and maybe on a [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html))
10-
11-
* Added resource reference for Philipp Salvisberg's [Example-based tutorials](https://github.com/PhilippSalvisberg/sqldev) to extend SQL Developer functionality. (external)
12-
13-
14-
### Contents
15-
16-
* [Set Up / Tutorial](./setup.md) - A step by step guide to building your first extension and check for updates bundle.
17-
18-
19-
* ["Simple" User Extensions (XML)](xml)
20-
21-
22-
* [XML Based Favorites Example](xml/favorites)
23-
24-
25-
* [Standard Extensions (java)](java)
26-
27-
28-
* [Check For Updates (cfu)](cfu)
29-
30-
31-
### External Resources
32-
Please note these are links to external resources. They are not supplied or supported by Oracle.
33-
34-
* [Example Update Center](https://github.com/bjeffrie/sqldev-update-center) (external) with pre-built cfu bundles for these examples.
35-
36-
* Philipp Salvisberg's [Example-based tutorials](https://github.com/PhilippSalvisberg/sqldev) to extend SQL Developer functionality. (external)
37-
1+
# [SQL Developer](http://www.oracle.com/technetwork/developer-tools/sql-developer/) Examples
2+
## Extensions
3+
You can add new folders and nodes to navigators, new actions on objects (*or sets of them*), and new editors or viewers.
4+
5+
Depending on requirements, this can be done in either XML or java and deployed by simply copying an XML file to the appropriate directory, or creating an extension jar -- or *check for updates* bundle for XML and/or java.
6+
7+
### New
8+
9+
* [ConnectionHelper](java/ConnectionHelper)
10+
Optionally accept connection info from the command line and/or on a [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html)
11+
12+
* [ConnectionHelperClient](java/ConnectionHelperClient)
13+
A simple command line client for the ConnectionHelper socket server.
14+
15+
* Added resource reference for Philipp Salvisberg's [Example-based tutorials](https://github.com/PhilippSalvisberg/sqldev) to extend SQL Developer functionality. (external)
16+
17+
18+
### Contents
19+
20+
* [Set Up / Tutorial](./setup.md) - A step by step guide to building your first extension and check for updates bundle.
21+
22+
23+
* ["Simple" User Extensions (XML)](xml)
24+
25+
26+
* [XML Based Favorites Example](xml/favorites)
27+
28+
29+
* [Standard Extensions (java)](java)
30+
31+
32+
* [Check For Updates (cfu)](cfu)
33+
34+
35+
### External Resources
36+
Please note these are links to external resources. They are not supplied or supported by Oracle.
37+
38+
* [Example Update Center](https://github.com/bjeffrie/sqldev-update-center) (external) with pre-built cfu bundles for these examples.
39+
40+
* Philipp Salvisberg's [Example-based tutorials](https://github.com/PhilippSalvisberg/sqldev) to extend SQL Developer functionality. (external)
41+
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# SQL Developer Examples
22
## ConnectionHelper
3-
Accept connection info from the command line (and maybe on a [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html))
3+
Optionally accept connection info from the command line and/or on a [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html)
44

55
### Command Line
6-
sqldeveloper -_conName_**=**_user_\[_**/**_\[_pw_]]**@**_host_**:**_port_(**:**_sid_|**/**_svc_)\[**#**_role_]
6+
sqldeveloper -_conName_**=**_user_\[**/**\[_pw_]]**@**_host_**:**_port_(**:**_sid_|**/**_svc_)\[**#**_role_]
77

88
Where:
99
- *connName* is the name you would like for the connection
@@ -15,24 +15,28 @@ Where:
1515
- */svc* is the service name for the database *(One of :sid or /svc MUST be supplied)*
1616
- *#role* is the role *(optional - one of SYSDBA, SYSOPER, SYSBACKUP, SYSDG, SYSKM, SYSASM if used)*
1717

18-
### [ConnectionHelperAddin](src/oracle/db/example/sqldeveloper/extension/connectionhelper/ConnectionHelperAddin.java)
19-
1. Creates the requested connection in a "Transient" folder
18+
### Overview
19+
[extension.xml](ext/extension.xml) declares [ConnectionHelperPreferencePanel](src/oracle/db/example/sqldeveloper/extension/connectionHelper/ConnectionHelperPreferencePanel.java) as a trigger hook so the extension will be fully loaded once the preference page is opened and [ConnectionHelperAddin](src/oracle/db/example/sqldeveloper/extension/connectionhelper/ConnectionHelperAddin.java) as an Addin whos initialize method will be called on SQLDeveloper start up.
20+
21+
[ConnectionHelper](src/oracle/db/example/sqldeveloper/extension/connectionhelper/ConnectionHelper.java) is where the 'do the work' stuff lives.
22+
1. Creates the requested connection in a "Persistent" or "Transient" folder
2023
2. Navigates to and opens the new connection
21-
3. Sets up a hook to remove the connection when SQLDeveloper shuts down
22-
23-
### TODO
24-
* Preference page _(May need/want preference page as a load trigger hook)_
25-
* Labelled sub-panel: Command Line
26-
* CheckBox: Accept connection info on command line [false]
27-
* CheckBox: Persist command line connections [false]
28-
* [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html)
29-
* Preference page
30-
* Labelled sub-panel: External Connection Server
31-
* NumericSpinner: Listener port [4444]
32-
* CheckBox: Persist external connections [false]
33-
* CheckBox: Autostart server
34-
* Button: Start now
35-
* Simple client test app for [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html)
24+
3. If transient, sets up a hook to remove the connection when SQLDeveloper shuts down
25+
26+
[ConnectionHelperAddin](src/oracle/db/example/sqldeveloper/extension/connectionhelper/ConnectionHelperAddin.java) adds an IdeListener to process ConnectionHelper options once the main window comes up. *(TODO:? Show non-deprecated technique for doing something after the window finishes loading? See OptInHandler$DialogWaitTask)*
27+
28+
[ConnectionHelperPreferenceModel](src/oracle/db/example/sqldeveloper/extension/connectionhelper/ConnectionHelperPreferenceModel.java) is the data class for managing connection helper preferences and integrating with the core preference storage.
29+
30+
[ConnectionHelperPreferencePanel](src/oracle/db/example/sqldeveloper/extension/connectionHelper/ConnectionHelperPreferencePanel.java)
31+
![ConnectionHelperPreferencePanel diagram](images/ConnectionHelperPreferencePanel.png)
32+
* Accept command line connections - Parse SQLDeveloper command line for connection request(s) when checked and on subsequent SQDeveloper start up. *[false]*
33+
* Persist command line connections - Persist connection(s) specified on the command line. Also controls (Persistent/Transient) folder the connection(s) will be placed in. *[false]*
34+
* Autostart connection server - Start the ConnectionHelperServer when checked and on subsequent SQDeveloper start up. *[false]*
35+
* External connection server port - the port to listen for connection requests on. *[51521]*
36+
* Persist external connections - Persist connection(s) received by the ConnectionHelperServer. Also controls (Persistent/Transient) folder the connection(s) will be placed in. *[false]*
37+
* *(TODO:? Replace button actions to start command line/server with property listeners on the preference properties so nothing happens until you OK the preference changes?)*
38+
39+
[ConnectionHelperServer](src/oracle/db/example/sqldeveloper/extension/connectionHelper/ConnectionHelperServer.java) is a [SocketServer](https://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html) that listens for connection requests on a specified port *[51521]*
3640

3741

3842
[//]: # (https://github.com/PhilippSalvisberg/sqldev)

sqldeveloper/extension/java/ConnectionHelper/etc/extension.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
1+
/*
2+
Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
216

317
package oracle.db.example.sqldeveloper.extension.connectionHelper;
418

19+
import java.util.ArrayList;
520
import java.util.regex.Matcher;
621
import java.util.regex.Pattern;
722

823
import oracle.dbtools.raptor.standalone.connection.ConnectionUtils;
24+
import oracle.dbtools.util.Logger;
925
import oracle.ide.Ide;
1026
import oracle.ide.cmd.ExitCommand;
1127
import oracle.ide.cmd.ShutdownHook;
@@ -18,17 +34,31 @@
1834
*/
1935
public class ConnectionHelper {
2036

37+
// Only process command line args once no matter how many times
38+
// the preference is changed while running
2139
private static boolean processedCommandLineArgs;
2240

41+
/**
42+
* Process each command line argument as a potential connection request
43+
*/
2344
public static void processCommandLineArgs() {
24-
// if (!processedCommandLineArgs) {
45+
if (!processedCommandLineArgs) {
2546
String[] args = Ide.getIdeArgs().getArgs();
47+
boolean persist = ConnectionHelperPreferenceModel.getInstance().isPersistCommandLineConnections();
2648
for (String arg : args) {
2749
System.out.println(arg);
28-
ConnectionHelper.processPotentialConnectionArgument(arg);
50+
ConnectionHelper.processPotentialConnectionArgument(arg, persist);
2951
}
3052
processedCommandLineArgs = true;
31-
// }
53+
}
54+
}
55+
56+
/**
57+
* Process the string received by the ConnectionHelperServer as a potential connection request
58+
* @param arg
59+
*/
60+
public static void processPotentialConnectionRequest(String arg) {
61+
processPotentialConnectionArgument(arg, ConnectionHelperPreferenceModel.getInstance().isPersistExternalConnectionServerConnections());
3262
}
3363

3464
// -system_DB120101=system/dbtools@llg00hon.uk.oracle.com:1521/DB12201
@@ -38,7 +68,8 @@ public static void processCommandLineArgs() {
3868
// 1 2 4 5 6 8 9 11
3969
private static final String conRegex = "-(.*)=([^\\/]*)(\\/([^@]*))?@([^:]*):([^:]*)(:([a-zA-Z0-9_]*)|\\/([a-zA-Z0-9_]*))(#([a-zA-Z0-9_]*))?"; //$NON-NLS-1$
4070
private static final Pattern conArg = Pattern.compile(conRegex);
41-
public static void processPotentialConnectionArgument(String arg) {
71+
72+
private static void processPotentialConnectionArgument(String arg, boolean persist) {
4273
Matcher m = conArg.matcher(arg);
4374
if (m.matches()) {
4475
String connName = m.group(1);
@@ -49,7 +80,7 @@ public static void processPotentialConnectionArgument(String arg) {
4980
String sid = m.group(8);
5081
String service = m.group(9);
5182
String role = m.group(11);
52-
String folder = ConnectionHelperPreferenceModel.getInstance().isPersistCommandLineConnections()
83+
String folder = persist
5384
? ConnectionHelperResources.getString(ConnectionHelperResources.PERSISTENT)
5485
: ConnectionHelperResources.getString(ConnectionHelperResources.TRANSIENT);
5586

@@ -58,24 +89,47 @@ public static void processPotentialConnectionArgument(String arg) {
5889
final String fqName = ConnectionUtils.getFqConnectionName(connName);
5990
ConnectionUtils.connect(fqName);
6091

61-
if (!ConnectionHelperPreferenceModel.getInstance().isPersistCommandLineConnections()) {
62-
ExitCommand.addShutdownHook(new ShutdownHook() {
63-
@Override
64-
public boolean canShutdown() {
65-
return true;
66-
}
67-
@Override
68-
public void shutdown() {
69-
ConnectionUtils.closeAndDeleteConnection(fqName);
70-
}
71-
});
92+
if (!persist) {
93+
if (null == shutdownHook) {
94+
shutdownHook = new ConnectionHelperShutdownHook();
95+
ExitCommand.addShutdownHook(shutdownHook);
96+
}
97+
shutdownHook.add(fqName);
7298
}
7399
}
74100
}
75-
76-
// TODO Refactor to handle request from server
77-
public static void processPotentialConnectionRequest(String arg) {
78-
processPotentialConnectionArgument(arg);
101+
102+
private static ConnectionHelperShutdownHook shutdownHook;
103+
104+
/**
105+
* ConnectionHelperShutdownHook - a shutdown hook to process transient connections
106+
*
107+
* @author <a href="mailto:brian.jeffries@oracle.com?subject=oracle.db.example.sqldeveloper.extension.connectionHelper.ConnectionHelper.ConnectionHelperShutdownHook">Brian Jeffries</a>
108+
* @since SQL Developer 20.1
109+
*/
110+
private static class ConnectionHelperShutdownHook implements ShutdownHook {
111+
public ArrayList<String> fqNames = new ArrayList<>();
112+
113+
public void add(String fqName) {
114+
fqNames.add(fqName);
115+
}
116+
117+
@Override
118+
public boolean canShutdown() {
119+
return true;
120+
}
121+
122+
@Override
123+
public void shutdown() {
124+
for (String fqName : fqNames) {
125+
try {
126+
ConnectionUtils.closeAndDeleteConnection(fqName);
127+
}
128+
catch (Throwable t) {
129+
Logger.warn(getClass(), fqName, t);
130+
}
131+
}
132+
}
79133
}
80134

81135
}

sqldeveloper/extension/java/ConnectionHelper/src/oracle/db/example/sqldeveloper/extension/connectionHelper/ConnectionHelperAddin.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
1+
/*
2+
Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
216

317
package oracle.db.example.sqldeveloper.extension.connectionHelper;
418

sqldeveloper/extension/java/ConnectionHelper/src/oracle/db/example/sqldeveloper/extension/connectionHelper/ConnectionHelperPreferenceModel.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
1+
/*
2+
Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
216

317
package oracle.db.example.sqldeveloper.extension.connectionHelper;
418

@@ -21,7 +35,7 @@ public class ConnectionHelperPreferenceModel extends HashStructureAdapter {
2135
private static final String COMMAND_LINE_PERSIST_CONN = "COMMAND_LINE_PERSIST_CONN"; //$NON-NLS-1$
2236

2337
private static final String EXT_CONN_SVR_PORT = "EXT_CONN_SVR_PORT"; //$NON-NLS-1$
24-
private static final Integer EXT_CONN_SVR_DEFAULT_PORT = 4444;
38+
private static final Integer EXT_CONN_SVR_DEFAULT_PORT = 51521; // 49152-65535 https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=1&page=24
2539
private static final String EXT_CONN_SVR_AUTOSTART = "EXT_CONN_SVR_AUTOSTART"; //$NON-NLS-1$
2640
private static final String EXT_CONN_SVR_PERSIST_CONN = "EXT_CONN_SVR_PERSIST_CONN"; //$NON-NLS-1$
2741

sqldeveloper/extension/java/ConnectionHelper/src/oracle/db/example/sqldeveloper/extension/connectionHelper/ConnectionHelperPreferencePanel.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
1+
/*
2+
Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
216

317
package oracle.db.example.sqldeveloper.extension.connectionHelper;
418

0 commit comments

Comments
 (0)