Class GqlSession

java.lang.Object
dev.grafeo.gwp.GqlSession
All Implemented Interfaces:
AutoCloseable

public class GqlSession extends Object implements AutoCloseable
An active session with a GWP server.

Implements AutoCloseable for use with try-with-resources.


 try (GqlConnection conn = GqlConnection.connect("localhost:50051")) {
     try (GqlSession session = conn.createSession()) {
         ResultCursor cursor = session.execute("MATCH (n) RETURN n");
         for (List<Object> row : cursor) {
             System.out.println(row);
         }
     }
 }
 
  • Method Details

    • sessionId

      public String sessionId()
      The session identifier.
    • execute

      public ResultCursor execute(String statement)
      Execute a GQL statement.
      Parameters:
      statement - the GQL statement to execute
      Returns:
      a cursor over the results
    • execute

      public ResultCursor execute(String statement, Map<String,Object> parameters)
      Execute a GQL statement with parameters.
      Parameters:
      statement - the GQL statement to execute
      parameters - named parameters (may be null)
      Returns:
      a cursor over the results
    • beginTransaction

      public Transaction beginTransaction()
      Begin a new read-write transaction.
      Returns:
      the new transaction
    • beginTransaction

      public Transaction beginTransaction(boolean readOnly)
      Begin a new transaction.
      Parameters:
      readOnly - true for a read-only transaction
      Returns:
      the new transaction
    • setGraph

      public void setGraph(String name)
      Set the current graph for this session.
      Parameters:
      name - the graph name
    • setSchema

      public void setSchema(String name)
      Set the current schema for this session.
      Parameters:
      name - the schema name
    • setTimeZone

      public void setTimeZone(int offsetMinutes)
      Set the session timezone as a UTC offset in minutes.
      Parameters:
      offsetMinutes - the UTC offset in minutes (e.g. 60 for UTC+1)
    • reset

      public void reset()
      Reset session state to defaults.
    • ping

      public long ping()
      Ping the server. Returns a server timestamp.
      Returns:
      the server timestamp
    • close

      public void close()
      Close the session. Rolls back any active transaction on the server side.
      Specified by:
      close in interface AutoCloseable