Package com.kuzudb

Class Connection

java.lang.Object
com.kuzudb.Connection
All Implemented Interfaces:
AutoCloseable

public class Connection extends Object implements AutoCloseable
Connection is used to interact with a Database instance. Each Connection is thread-safe. Multiple connections can connect to the same Database instance in a multi-threaded environment.
  • Constructor Details

    • Connection

      public Connection(Database db)
      Creates a connection to the database.
      Parameters:
      db - : Database instance.
  • Method Details

    • close

      public void close() throws ObjectRefDestroyedException
      Close the connection and release the underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.
      Specified by:
      close in interface AutoCloseable
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.
    • getMaxNumThreadForExec

      public long getMaxNumThreadForExec() throws ObjectRefDestroyedException
      Return the maximum number of threads used for execution in the current connection.
      Returns:
      The maximum number of threads used for execution in the current connection.
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.
    • setMaxNumThreadForExec

      public void setMaxNumThreadForExec(long numThreads) throws ObjectRefDestroyedException
      Sets the maximum number of threads to use for execution in the current connection.
      Parameters:
      numThreads - : The maximum number of threads to use for execution in the current connection
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.
    • query

      public QueryResult query(String queryStr) throws ObjectRefDestroyedException
      Executes the given query and returns the result.
      Parameters:
      queryStr - : The query to execute.
      Returns:
      The result of the query.
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.
    • prepare

      public PreparedStatement prepare(String queryStr) throws ObjectRefDestroyedException
      Prepares the given query and returns the prepared statement.
      Parameters:
      queryStr - : The query to prepare.
      Returns:
      The prepared statement.
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.
    • execute

      Executes the given prepared statement with args and returns the result.
      Parameters:
      ps - : The prepared statement to execute.
      m - : The parameter pack where each arg is a std::pair with the first element being parameter name and second element being parameter value
      Returns:
      The result of the query.
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.
    • interrupt

      public void interrupt() throws ObjectRefDestroyedException
      Interrupts all queries currently executed within this connection.
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.
    • setQueryTimeout

      public void setQueryTimeout(long timeoutInMs) throws ObjectRefDestroyedException
      Sets the query timeout value of the current connection. A value of zero (the default) disables the timeout.
      Parameters:
      timeoutInMs - : The query timeout value in milliseconds.
      Throws:
      ObjectRefDestroyedException - If the connection has been destroyed.