Skip to content

Commit d2ac34e

Browse files
committedMar 17, 2020
WIP: SQLDEV-2076 Add ConnectionHelperClient
TODO: Get cancel (server) task working TODO: Negative testing TODO: Doc/Walkthrough
1 parent 1c67222 commit d2ac34e

File tree

7 files changed

+129
-15
lines changed

7 files changed

+129
-15
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void shutdown() {
7575

7676
// TODO Refactor to handle request from server
7777
public static void processPotentialConnectionRequest(String arg) {
78-
78+
processPotentialConnectionArgument(arg);
7979
}
8080

8181
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public void mainWindowOpened(IdeEvent e) {
3434
if (ConnectionHelperPreferenceModel.getInstance().isAcceptCommandLineConnections()) {
3535
ConnectionHelper.processCommandLineArgs();
3636
}
37+
if (ConnectionHelperPreferenceModel.getInstance().isAutostartExternalConnectionServer()) {
38+
ConnectionHelperServer.start();
39+
}
3740
}
3841

3942
@Override

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,21 @@ private void layoutControls() {
4343
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(svrPort, "###0"); //$NON-NLS-1$
4444
svrPort.setEditor(editor);
4545

46-
// Add action listeners for the enable check boxes
46+
// Add action listeners for the enable check boxes TODO: Add StructureChangeListener
47+
// in Addin to watch these ... or ... add buttons to manually execute/start them?
48+
// The more I think about it, I like this better than buttons. Maybe better than
49+
// the listener but the listener would also demonstrate how to listen for preference
50+
// changes.
4751
clAcceptConn.addActionListener(e -> {
4852
if (clAcceptConn.isSelected()) {
4953
ConnectionHelper.processCommandLineArgs();
5054
}
5155
});
56+
svrAutostart.addActionListener(e -> {
57+
if (svrAutostart.isSelected()) {
58+
ConnectionHelperServer.start();
59+
}
60+
});
5261

5362
final FieldLayoutBuilder builder = new FieldLayoutBuilder(this);
5463
builder.setAlignLabelsLeft(true);
@@ -64,11 +73,6 @@ private void layoutControls() {
6473
builder.add(builder.indentedField().label().withText(ConnectionHelperResources.getString(ConnectionHelperResources.EXT_CONN_SVR_PERSIST_CONN))
6574
.component(svrPersistConn));
6675
builder.addVerticalSpring();
67-
68-
// TODO TEMP until svr built
69-
svrAutostart.setEnabled(false);
70-
svrPort.setEnabled(false);
71-
svrPersistConn.setEnabled(false);
7276
}
7377

7478
/* (non-Javadoc)

‎sqldeveloper/extension/java/ConnectionHelper/src/oracle/db/example/sqldeveloper/extension/connectionHelper/ConnectionHelperServer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ protected Void doWork() throws TaskException {
5353
try (ServerSocket serverSocket = new ServerSocket(port)) {
5454
while (listening) {
5555
checkCanProceed();
56+
this.setMessage("Waiting for connection");
5657
ConnectionHelperTask helperTask = new ConnectionHelperTask(serverSocket.accept());
58+
this.setMessage("Initializing ConnectionHelperTask");
5759
RaptorTaskManager.getInstance().addTask(helperTask);
5860
}
5961
}
@@ -90,10 +92,8 @@ public String getQuery() {
9092
@Override
9193
protected Void doWork() throws TaskException {
9294
try (BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
93-
String inputLine;
94-
while ((inputLine = in.readLine()) != null) {
95-
ConnectionHelper.processPotentialConnectionRequest(inputLine);
96-
}
95+
String inputLine= in.readLine();
96+
ConnectionHelper.processPotentialConnectionRequest(inputLine);
9797
}
9898
catch (Throwable t) {
9999
throw asTaskException(t);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extension.id=ConnectionHelperClient
2+
extension.name=Connection Helper Client
3+
extension.descr=Example to send connection info to the ConnectionHelperServer
4+
extension.version=20.1.0
5+
extension.resources=ConnectionHelperClientResources
6+
7+
extension.lib=external:$oracle.fcp.home$/sqldeveloper/extensions/${extension.id}/lib
8+
osgi.bundle.classpath=.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="windows-1252" ?>
2+
<project name="ConnectionHelperClient" default="deploy">
3+
<import file="../../buildtools/ant/build.xml" />
4+
5+
<!-- This module has a custom compile classpath. It produces a standard
6+
executable jar file designed to be run from the command line. It can
7+
NOT depend on anything in SQL Developer. -->
8+
<path id="compile.classpath" />
9+
<path id="local.classpath" />
10+
11+
<!-- Raw jar, no osgi stuff
12+
<property name="osgi.required.bundles" value="${osgi.bundle.oracle.core},${osgi.bundle.jfxrt},${osgi.bundle.utils-nodeps}" />
13+
<property name="osgi.bundle.name" value="${osgi.bundle.jfx-nodeps}"/>
14+
-->
15+
16+
<target name="jar" depends="compile" description="Create the extension jar">
17+
<jar basedir="${built}/classes" destfile="${built}/${extension.filename}" excludes="**/.data/*" />
18+
<manifest file="${jar.manifest.template}" mode="update">
19+
<attribute name="Main-Class" value="ConnectionHelperClient" />
20+
</manifest>
21+
</target>
22+
<target name="deploy" depends="jar, manifest" description="Deploy plugins directory">
23+
<copy file="${built}/${extension.filename}" tofile="${ide.home}/sqldeveloper/lib/${extension.filename}" />
24+
<!-- Raw jar, no osgi stuff
25+
<antcall target="bundleupdate-inc">
26+
<param name="bundle.location" value="../sqldeveloper/lib/${extension.filename}"/>
27+
</antcall>
28+
-->
29+
</target>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.io.PrintWriter;
5+
import java.net.InetAddress;
6+
import java.net.Socket;
7+
import java.net.UnknownHostException;
8+
19
// Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
210

311
/**
412
* ConnectionHelperClient - a simple client for the ConnectionHelperServer<p/>
5-
* usage: java -jar ConnectionHelperClient.jar port connectionInfo
6-
*
7-
* @author <a href="mailto:brian.jeffries@oracle.com?subject=.ConnectionHelperClient">Brian Jeffries</a>
13+
* usage: <code>java -jar ConnectionHelperClient.jar connectionInfo [svrPort]</code><br/>
14+
* {@link #showUsage()}
15+
*
16+
* @author <a href="mailto:brian.jeffries@oracle.com?subject=ConnectionHelperClient">Brian Jeffries</a>
817
* @since SQL Developer 20.1
918
*/
1019
public class ConnectionHelperClient {
@@ -13,7 +22,67 @@ public class ConnectionHelperClient {
1322
* @param args
1423
*/
1524
public static void main(String[] args) {
16-
25+
int svrPort = 4444;
26+
try {
27+
if (args.length > 1) {
28+
svrPort = Integer.parseInt(args[1]);
29+
}
30+
String connectionInfo = args[0];
31+
InetAddress localhost = InetAddress.getLocalHost();
32+
try (
33+
Socket svrSocket = new Socket(localhost, svrPort);
34+
PrintWriter out =
35+
new PrintWriter(svrSocket.getOutputStream(), true);
36+
BufferedReader in =
37+
new BufferedReader(
38+
new InputStreamReader(svrSocket.getInputStream()));
39+
) {
40+
out.println(connectionInfo);
41+
System.out.println(in.readLine()); // TODO: What kind of responses do we want?
42+
} catch (UnknownHostException e) {
43+
System.err.println("Don't know about host " + localhost);
44+
System.exit(1);
45+
} catch (IOException e) {
46+
System.err.println("Couldn't get I/O for the connection to " +
47+
localhost);
48+
System.exit(1);
49+
}
50+
}
51+
catch (Throwable t) {
52+
t.printStackTrace();
53+
showUsage();
54+
}
1755
}
1856

57+
/** <pre>
58+
"Usage: java -jar ConnectionHelperClient.jar connectionInfo [svrPort]\n" +
59+
"connectionInfo = -conName=user[/[pw]]@host:port(:sid|/svc)[#role]" +
60+
"Where:\n" +
61+
"- connName is the name you would like for the connection\n" +
62+
"- user is the user name for the schema you want to use\n" +
63+
"- /password is the password for that user *(optional - if missing e.g., user@ or user/@, SQLDeveloper will prompt for it)*\n" +
64+
"- host is the host that the database is on\n" +
65+
"- port is the port the database is listening on\n" +
66+
"- :sid is the sid for the database *(One of :sid or /svc MUST be supplied)*\n" +
67+
"- /svc is the service name for the database *(One of :sid or /svc MUST be supplied)*\n" +
68+
"- #role is the role *(optional - one of SYSDBA, SYSOPER, SYSBACKUP, SYSDG, SYSKM, SYSASM if used)*\n" +
69+
"and\n" +
70+
"svrPort = the port the ConnectionHelperServer is listening on (optional default: 4444)\n";
71+
</pre>*/
72+
private static void showUsage() {
73+
String usage = "Usage: java -jar ConnectionHelperClient.jar connectionInfo [svrPort]\n" +
74+
"connectionInfo = -conName=user[/[pw]]@host:port(:sid|/svc)[#role]" +
75+
"Where:\n" +
76+
"- connName is the name you would like for the connection\n" +
77+
"- user is the user name for the schema you want to use\n" +
78+
"- /password is the password for that user *(optional - if missing e.g., user@ or user/@, SQLDeveloper will prompt for it)*\n" +
79+
"- host is the host that the database is on\n" +
80+
"- port is the port the database is listening on\n" +
81+
"- :sid is the sid for the database *(One of :sid or /svc MUST be supplied)*\n" +
82+
"- /svc is the service name for the database *(One of :sid or /svc MUST be supplied)*\n" +
83+
"- #role is the role *(optional - one of SYSDBA, SYSOPER, SYSBACKUP, SYSDG, SYSKM, SYSASM if used)*\n" +
84+
"and\n" +
85+
"svrPort = the port the ConnectionHelperServer is listening on (optional default: 4444)\n";
86+
System.out.println(usage);
87+
}
1988
}

0 commit comments

Comments
 (0)
Failed to load comments.