|
38 | 38 | import com.arcadedb.database.Database; |
39 | 39 | import com.arcadedb.database.DatabaseContext; |
40 | 40 | import com.arcadedb.database.DatabaseInternal; |
| 41 | +import com.arcadedb.database.ProtocolContext; |
41 | 42 | import com.arcadedb.exception.CommandParsingException; |
42 | 43 | import com.arcadedb.index.Index; |
43 | 44 | import com.arcadedb.index.TypeIndex; |
@@ -123,6 +124,9 @@ private enum State { |
123 | 124 | // Transaction state |
124 | 125 | private boolean explicitTransaction = false; |
125 | 126 |
|
| 127 | + // GQL session state for this connection (SESSION SET/RESET/CLOSE parameters). |
| 128 | + private final BoltSession session = new BoltSession(); |
| 129 | + |
126 | 130 | /** |
127 | 131 | * Current result set for streaming results. |
128 | 132 | * Thread-safety: This class is designed to handle a single connection in a dedicated thread. |
@@ -162,6 +166,7 @@ public BoltNetworkExecutor(final ArcadeDBServer server, final Socket socket, fin |
162 | 166 |
|
163 | 167 | @Override |
164 | 168 | public void run() { |
| 169 | + ProtocolContext.set("bolt"); |
165 | 170 | try { |
166 | 171 | state = State.NEGOTIATION; |
167 | 172 |
|
@@ -215,6 +220,7 @@ public void run() { |
215 | 220 | } catch (final Exception e) { |
216 | 221 | LogManager.instance().log(this, Level.SEVERE, "BOLT connection error", e); |
217 | 222 | } finally { |
| 223 | + ProtocolContext.clear(); |
218 | 224 | cleanup(); |
219 | 225 | } |
220 | 226 | } |
@@ -479,6 +485,11 @@ private void handleReset() throws IOException { |
479 | 485 | } |
480 | 486 | } |
481 | 487 |
|
| 488 | + // NOTE: do not clear the GQL session parameters here. The Bolt RESET message is connection-level |
| 489 | + // housekeeping the driver sends when recycling a pooled connection, not a user request to reset GQL |
| 490 | + // session state; clearing here would drop SESSION SET parameters between auto-commit queries. GQL |
| 491 | + // session parameters are cleared only by an explicit SESSION RESET / SESSION CLOSE statement. |
| 492 | + |
482 | 493 | explicitTransaction = false; |
483 | 494 | currentResultSet = null; |
484 | 495 | currentFields = null; |
@@ -530,7 +541,8 @@ private void handleRun(final RunMessage message) throws IOException { |
530 | 541 | firstRecordTime = 0; |
531 | 542 | syntheticResults = null; |
532 | 543 |
|
533 | | - // Ensure database is open (maps "system"/"neo4j" to default database) |
| 544 | + // Ensure database is open (maps "system"/"neo4j" to default database). This also attaches the |
| 545 | + // connection's GQL session to the thread context, which the engine reads for SESSION statements. |
534 | 546 | if (!ensureDatabase()) |
535 | 547 | return; |
536 | 548 |
|
@@ -944,8 +956,11 @@ private boolean ensureDatabase() throws IOException { |
944 | 956 | if (user != null) { |
945 | 957 | final DatabaseContext.DatabaseContextTL ctx = |
946 | 958 | DatabaseContext.INSTANCE.getContextIfExists(((DatabaseInternal) database).getDatabasePath()); |
947 | | - if (ctx != null) |
| 959 | + if (ctx != null) { |
948 | 960 | ctx.setCurrentUser(user.getDatabaseUser(database)); |
| 961 | + // Attach this connection's GQL session so SESSION statements and param merging can reach it. |
| 962 | + ctx.setQuerySession(session); |
| 963 | + } |
949 | 964 | } |
950 | 965 | return true; |
951 | 966 | } |
@@ -976,8 +991,12 @@ private boolean ensureDatabase() throws IOException { |
976 | 991 | state = State.FAILED; |
977 | 992 | return false; |
978 | 993 | } |
979 | | - if (user != null) |
980 | | - DatabaseContext.INSTANCE.init((DatabaseInternal) database).setCurrentUser(user.getDatabaseUser(database)); |
| 994 | + if (user != null) { |
| 995 | + final DatabaseContext.DatabaseContextTL ctx = DatabaseContext.INSTANCE.init((DatabaseInternal) database); |
| 996 | + ctx.setCurrentUser(user.getDatabaseUser(database)); |
| 997 | + // Attach this connection's GQL session so SESSION statements and param merging can reach it. |
| 998 | + ctx.setQuerySession(session); |
| 999 | + } |
981 | 1000 | return true; |
982 | 1001 | } catch (final Exception e) { |
983 | 1002 | final String message = e.getMessage() != null ? e.getMessage() : "Unknown error"; |
|
0 commit comments