Class EmbeddedConnection

java.lang.Object
nl.cwi.monetdb.jdbc.MonetWrapper
nl.cwi.monetdb.jdbc.MonetConnection
nl.cwi.monetdb.embedded.jdbc.EmbeddedConnection
All Implemented Interfaces:
AutoCloseable, Connection, Wrapper

public final class EmbeddedConnection
extends nl.cwi.monetdb.jdbc.MonetConnection
A Connection suitable for the MonetDB database using an embedded connection.
Author:
Pedro Ferreira
  • Constructor Details

  • Method Details

    • getDirectory

      public String getDirectory()
      Gets the directory where the database is hosted. Null pointer means is running in-memory.
      Returns:
      The directory where the database is hosted. Null pointer means is running in-memory
    • isRunningInMemory

      public boolean isRunningInMemory()
      Is the connection running in memory?
      Returns:
      Is the connection running in memory?
    • isSilentFlag

      public boolean isSilentFlag()
      Is the silent flag set?
      Returns:
      Is the silent flag set?
    • isSequentialFlag

      public boolean isSequentialFlag()
      Is the sequential flag set?
      Returns:
      Is the sequential flag set?
    • getAsMonetDBEmbeddedConnection

      public MonetDBEmbeddedConnection getAsMonetDBEmbeddedConnection()
      Makes a conversion of this connection as a MonetDBEmbeddedConnection instance, making it possible to access the MonetDBEmbeddedConnection API on a JDBC embedded connection, although that API doesn't follow the JDBC specification.
      Returns:
      This connection as a MonetDBEmbeddedConnection instance
    • connect

      public List<String> connect​(String user, String pass) throws IOException, nl.cwi.monetdb.mcl.protocol.ProtocolException, nl.cwi.monetdb.mcl.connection.MCLException
      Connects to the existing database on the JVM process. If the database is not running, then it will start. However if the database is already running in a different directory, a MCLException will be thrown.
      At this moment, no user authentication is performed in an embedded connection, hence the username and password parameters can be ignored.
      Specified by:
      connect in class nl.cwi.monetdb.jdbc.MonetConnection
      Parameters:
      user - The user name to authenticate (ignored)
      pass - The user's password (ignored)
      Returns:
      Always a null list
      Throws:
      nl.cwi.monetdb.mcl.connection.MCLException - If the database is already running in a different directory
      IOException
      nl.cwi.monetdb.mcl.protocol.ProtocolException
    • getJDBCURL

      public String getJDBCURL()
      Gets the underlying connection JDBC String URL.
      Specified by:
      getJDBCURL in class nl.cwi.monetdb.jdbc.MonetConnection
      Returns:
      The underlying connection JDBC String URL
    • getBlockSize

      public int getBlockSize()
      Gets the underlying connection block size length. On an embedded connection, there is no boundary restrictions, so we always return the integer max value.
      Specified by:
      getBlockSize in class nl.cwi.monetdb.jdbc.MonetConnection
      Returns:
      The integer max value
    • getDefFetchsize

      public int getDefFetchsize()
      Gets the underlying connection default fetch size for DataBlock responses. On an embedded connection, there is no boundary restrictions, so we always return the integer max value.
      Specified by:
      getDefFetchsize in class nl.cwi.monetdb.jdbc.MonetConnection
      Returns:
      The integer max value
    • initialStringBuilderSize

      public int initialStringBuilderSize()
      Specified by:
      initialStringBuilderSize in class nl.cwi.monetdb.jdbc.MonetConnection
    • getSoTimeout

      public int getSoTimeout() throws SocketException
      In a embedded connection there is no timeout, so this methods always adds a SQLWarning and returns -1.
      Specified by:
      getSoTimeout in class nl.cwi.monetdb.jdbc.MonetConnection
      Returns:
      -1
      Throws:
      SocketException
    • setSoTimeout

      public void setSoTimeout​(int timeout) throws SocketException
      In a embedded connection there is no timeout, so this methods always adds a SQLWarning and the timeout parameter is ignored.
      Specified by:
      setSoTimeout in class nl.cwi.monetdb.jdbc.MonetConnection
      Parameters:
      timeout - The specified timeout, in milliseconds (ignored)
      Throws:
      SocketException
    • closeUnderlyingConnection

      public void closeUnderlyingConnection() throws IOException
      Closes the underlying connection implementation. On a embedded connection, after the connection is closed, if there are no more connections on the database, then the database is also shut down.
      Specified by:
      closeUnderlyingConnection in class nl.cwi.monetdb.jdbc.MonetConnection
      Throws:
      IOException - if an error happens while closing the connection or the database
    • sendControlCommand

      public void sendControlCommand​(int commandID, int data) throws SQLException
      Sends a control command to the server. On an embedded connection, a specific call is performed for each command on the server.
      Specified by:
      sendControlCommand in class nl.cwi.monetdb.jdbc.MonetConnection
      Parameters:
      commandID - the command identifier according to ControlCommands listing
      data - The integer to send according to the control command
      Throws:
      SQLException - if an IO exception or a database error occurs
    • executeNextQueryBatch

      protected boolean executeNextQueryBatch​(nl.cwi.monetdb.jdbc.MonetStatement statement, List<String> batch, int[] counts, BatchUpdateException e) throws SQLException
      Execute a batch query in an embedded connection.
      Specified by:
      executeNextQueryBatch in class nl.cwi.monetdb.jdbc.MonetConnection
      Parameters:
      statement - The original MonetStatement where the batch comes from
      batch - The list of queries to execute
      counts - The return of the update statement of each input query
      e - An exception to be thrown if an error occurs
      Returns:
      If all queries in the batch executed successfully or not
      Throws:
      SQLException - if an IO exception or a database error occurs