Skip to content

Commit

Permalink
Prevent circular dependencies in the JDBC-backed SessionMap
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jun 8, 2020
1 parent 6828f52 commit 6bb623f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
1 change: 0 additions & 1 deletion java/server/src/org/openqa/selenium/grid/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ java_export(
":base-command",
"//java/server/src/org/openqa/selenium/cli",
"//java/server/src/org/openqa/selenium/grid/config",
"//java/server/src/org/openqa/selenium/grid/sessionmap/jdbc",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ java_export(
visibility = [
"//visibility:public",
],
exports = [
"//java/server/src/org/openqa/selenium/grid",
],
deps = [
"//java:auto-service",
"//java/client/src/org/openqa/selenium/json",
"//java/server/src/org/openqa/selenium/events",
"//java/client/src/org/openqa/selenium/remote",
"//java/server/src/org/openqa/selenium/grid/server",
"//java/server/src/org/openqa/selenium/grid/sessionmap",
"//java/server/src/org/openqa/selenium/grid/config",
"//java/server/src/org/openqa/selenium/grid/log",
"//java/server/src/org/openqa/selenium/grid/data",
"//java/server/src/org/openqa/selenium/grid",
artifact("com.beust:jcommander"),
artifact("com.google.guava:guava"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.openqa.selenium.grid.sessionmap.jdbc;

import static org.openqa.selenium.grid.data.SessionClosedEvent.SESSION_CLOSED;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.NoSuchSessionException;
Expand All @@ -43,6 +41,8 @@
import java.sql.SQLException;
import java.util.logging.Logger;

import static org.openqa.selenium.grid.data.SessionClosedEvent.SESSION_CLOSED;


public class JdbcBackedSessionMap extends SessionMap implements Closeable {

Expand Down Expand Up @@ -114,8 +114,8 @@ public Session get(SessionId id) throws NoSuchSessionException {
String rawCapabilities = sessions.getString(SESSION_CAPS_COL);

caps = rawCapabilities == null ?
new ImmutableCapabilities() :
JSON.toType(rawCapabilities, Capabilities.class);
new ImmutableCapabilities() :
JSON.toType(rawCapabilities, Capabilities.class);
try {
uri = new URI(rawUri);
} catch (URISyntaxException e) {
Expand Down Expand Up @@ -149,11 +149,12 @@ public void close() {
}

private PreparedStatement insertSessionStatement(Session session) throws SQLException {
PreparedStatement insertStatement = connection.prepareStatement(String.format("insert into %1$s (%2$s, %3$s, %4$s) values (?, ?, ?)",
TABLE_NAME,
SESSION_ID_COL,
SESSION_URI_COL,
SESSION_CAPS_COL));
PreparedStatement insertStatement = connection.prepareStatement(
String.format("insert into %1$s (%2$s, %3$s, %4$s) values (?, ?, ?)",
TABLE_NAME,
SESSION_ID_COL,
SESSION_URI_COL,
SESSION_CAPS_COL));

insertStatement.setString(1, session.getId().toString());
insertStatement.setString(2, session.getUri().toString());
Expand All @@ -163,9 +164,10 @@ private PreparedStatement insertSessionStatement(Session session) throws SQLExce
}

private PreparedStatement readSessionStatement(SessionId sessionId) throws SQLException {
PreparedStatement getSessionsStatement = connection.prepareStatement(String.format("select * from %1$s where %2$s = ?",
TABLE_NAME,
SESSION_ID_COL));
PreparedStatement getSessionsStatement = connection.prepareStatement(
String.format("select * from %1$s where %2$s = ?",
TABLE_NAME,
SESSION_ID_COL));

getSessionsStatement.setMaxRows(1);
getSessionsStatement.setString(1, sessionId.toString());
Expand All @@ -174,13 +176,13 @@ private PreparedStatement readSessionStatement(SessionId sessionId) throws SQLEx
}

private PreparedStatement getDeleteSqlForSession(SessionId sessionId) throws SQLException{
PreparedStatement deleteSessionStatement = connection.prepareStatement(String.format("delete from %1$s where %2$s = ?",
TABLE_NAME,
SESSION_ID_COL));
PreparedStatement deleteSessionStatement = connection.prepareStatement(
String.format("delete from %1$s where %2$s = ?",
TABLE_NAME,
SESSION_ID_COL));

deleteSessionStatement.setString(1, sessionId.toString());

return deleteSessionStatement;

}
}

0 comments on commit 6bb623f

Please sign in to comment.