Class MonetNative

java.lang.Object
org.monetdb.monetdbe.MonetNative

public class MonetNative
extends Object
Interface for C native methods in MonetDBe-Java. Loads the compiled monetdbe_lowlevel C library and the libraries on which it depends (found in the lib/ directories of the jar). Because Java can't read libraries from inside the JAR, they are copied to a temporary location before load.
  • Constructor Details

  • Method Details

    • monetdbe_open

      protected static String monetdbe_open​(String dbdir, MonetConnection conn)
      Open connection to memory or local directory database with default options.
      Parameters:
      dbdir - Directory for database, NULL for memory DBs
      conn - Parent Connection, needed for setting the created connection
      Returns:
      Error message
    • monetdbe_open

      protected static String monetdbe_open​(String dbdir, MonetConnection conn, int sessiontimeout, int querytimeout, int memorylimit, int nr_threads)
      Open connection to memory or local directory database.
      Parameters:
      dbdir - Directory for database, NULL for memory DBs
      conn - Parent Connection, needed for setting the created connection
      sessiontimeout - Option for monetdbe_open() library function
      querytimeout - Option for monetdbe_open() library function
      memorylimit - Option for monetdbe_open() library function
      nr_threads - Option for monetdbe_open() library function
      Returns:
      Error message
    • monetdbe_open

      protected static String monetdbe_open​(String dbdir, MonetConnection conn, int sessiontimeout, int querytimeout, int memorylimit, int nr_threads, String host, int port, String database, String user, String password)
      Open connection to remote connection database.
      Parameters:
      dbdir - Directory for database, NULL for memory DBs
      conn - Parent Connection, needed for setting the created connection
      sessiontimeout - Option for monetdbe_open() library function
      querytimeout - Option for monetdbe_open() library function
      memorylimit - Option for monetdbe_open() library function
      nr_threads - Option for monetdbe_open() library function
      host - Remote host to connect to
      port - Remote port to connect to
      database - Remote database
      user - Username in the remote database
      password - Password in the remote database
      Returns:
      Error message
    • monetdbe_close

      protected static String monetdbe_close​(ByteBuffer db)
      Close the database connection.
      Parameters:
      db - C pointer to database
      Returns:
      Error message
    • monetdbe_query

      protected static String monetdbe_query​(ByteBuffer db, String sql, MonetStatement statement, boolean largeUpdate, int maxrows)
      Executes an SQL statement and returns either one result set for DQL queries, an update count for DML queries or Statement.SUCCESS_NO_INFO (-2) for DDL queries. The Java result (result set or update count) is set within this function. Currently, if the query can return multiple results, only the first one is actually returned.
      Parameters:
      db - C pointer to database
      sql - Query to execute
      statement - Parent Statement, needed for setting result set/update count
      largeUpdate - If this function was called from an executeLarge method
      maxrows - Maximum amount of rows to be returned in case a result set is returned
      Returns:
      Error message
    • monetdbe_result_fetch_all

      protected static MonetColumn[] monetdbe_result_fetch_all​(ByteBuffer nativeResult, int nrows, int ncols)
      Retrieve result from monetdbe_result pointer to MonetColumn, the Java representation of the result columns. Static length types are returned as a ByteBuffer, while variable length types are returned as Object[]. The constructor for MonetColumn is called within this function.
      Parameters:
      nativeResult - C pointer to result
      nrows - Number of rows in result
      ncols - Number of columns in result
      Returns:
      Java object representation of result columns
    • monetdbe_result_cleanup

      protected static String monetdbe_result_cleanup​(ByteBuffer db, ByteBuffer nativeResult)
      Cleans up and closes a result set.
      Parameters:
      db - C pointer to database
      nativeResult - C pointer to result
      Returns:
      Error message
    • monetdbe_error

      protected static String monetdbe_error​(ByteBuffer db)
      Returns latest error message from the database.
      Parameters:
      db - C pointer to database
      Returns:
      Latest error message
    • monetdbe_set_autocommit

      protected static String monetdbe_set_autocommit​(ByteBuffer db, int value)
      Sets auto-commit mode.
      Parameters:
      db - C pointer to database
      value - true or false
      Returns:
      Error message
    • monetdbe_get_autocommit

      protected static boolean monetdbe_get_autocommit​(ByteBuffer db)
      Gets the current auto-commit value (either true or false).
      Parameters:
      db - C pointer to database
      Returns:
      true if auto-commit mode is on, false otherwise
    • monetdbe_prepare

      protected static String monetdbe_prepare​(ByteBuffer db, String sql, MonetPreparedStatement statement)
      Prepares a reusable statement with configurable parameters. The nParams (number of parameters), monetdbeTypes (array of types of the configurable parameters) and statementNative (C pointer to prepared statement for bind and execution) variables of the PreparedStatement object are set within this function.
      Parameters:
      db - C pointer to database
      sql - Statement to prepare
      statement - Parent PreparedStatement, needed for setting variables within function
      Returns:
      Error message
    • monetdbe_execute

      protected static String monetdbe_execute​(ByteBuffer stmt, MonetPreparedStatement statement, boolean largeUpdate, int maxrows)
      Executes prepared statement (which was previously prepared and had its parameters bound) and returns result set or update count, similarly to monetdbe_query function.
      Parameters:
      stmt - C pointer to prepared statement
      statement - Parent PreparedStatement, needed for setting result set/update count
      largeUpdate - If this function was called from an executeLarge method
      maxrows - Maximum amount of rows to be returned in case a result set is returned
      Returns:
      Error message
    • monetdbe_cleanup_statement

      protected static String monetdbe_cleanup_statement​(ByteBuffer db, ByteBuffer stmt)
      Cleans up and closes a previously prepared statement.
      Parameters:
      db - C pointer to database
      stmt - C pointer to prepared statement
      Returns:
      Error message
    • monetdbe_clear_bindings

      protected static String monetdbe_clear_bindings​(ByteBuffer db, ByteBuffer stmt)
    • monetdbe_bind_bool

      protected static String monetdbe_bind_bool​(ByteBuffer stmt, int param, boolean data)
      Binds boolean parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Boolean value to bind
      Returns:
      Error message
    • monetdbe_bind_byte

      protected static String monetdbe_bind_byte​(ByteBuffer stmt, int param, byte data)
      Binds byte parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Byte value to bind
      Returns:
      Error message
    • monetdbe_bind_short

      protected static String monetdbe_bind_short​(ByteBuffer stmt, int param, short data)
      Binds short parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Short value to bind
      Returns:
      Error message
    • monetdbe_bind_int

      protected static String monetdbe_bind_int​(ByteBuffer stmt, int param, int data)
      Binds integer parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Integer value to bind
      Returns:
      Error message
    • monetdbe_bind_long

      protected static String monetdbe_bind_long​(ByteBuffer stmt, int param, long data)
      Binds long parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Long value to bind
      Returns:
      Error message
    • monetdbe_bind_hugeint

      protected static String monetdbe_bind_hugeint​(ByteBuffer stmt, int param, BigInteger data)
      Binds big integer parameter to prepared statement. Not working currently.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Big integer value to bind
      Returns:
      Error message
    • monetdbe_bind_float

      protected static String monetdbe_bind_float​(ByteBuffer stmt, int param, float data)
      Binds float parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Float value to bind
      Returns:
      Error message
    • monetdbe_bind_double

      protected static String monetdbe_bind_double​(ByteBuffer stmt, int param, double data)
      Binds double parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Double value to bind
      Returns:
      Error message
    • monetdbe_bind_string

      protected static String monetdbe_bind_string​(ByteBuffer stmt, int param, String data)
      Binds string parameter to prepared statement.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - String value to bind
      Returns:
      Error message
    • monetdbe_bind_blob

      protected static String monetdbe_bind_blob​(ByteBuffer stmt, int param, byte[] data, long size)
      Binds blob parameter to prepared statement. Not working currently.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      data - Blob value to bind, as byte array
      size - Size of byte array
      Returns:
      Error message
    • monetdbe_bind_date

      protected static String monetdbe_bind_date​(ByteBuffer stmt, int param, int year, int month, int day)
      Binds date parameter to prepared statement. Not working currently.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      year - Date year
      month - Date month
      day - Date day
      Returns:
      Error message
    • monetdbe_bind_time

      protected static String monetdbe_bind_time​(ByteBuffer stmt, int param, int hours, int minutes, int seconds, int ms)
      Binds time parameter to prepared statement. Not working currently.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      hours - Time hours
      minutes - Time minutes
      seconds - Time seconds
      ms - Time milliseconds
      Returns:
      Error message
    • monetdbe_bind_timestamp

      protected static String monetdbe_bind_timestamp​(ByteBuffer stmt, int param, int year, int month, int day, int hours, int minutes, int seconds, int ms)
      Binds timestamp parameter to prepared statement. Not working currently.
      Parameters:
      stmt - C pointer to prepared statement
      param - Parameter number
      year - Timestamp year
      month - Timestamp month
      day - Timestamp day
      hours - Timestamp hours
      minutes - Timestamp minutes
      seconds - Timestamp seconds
      ms - Timestamp milliseconds
      Returns:
      Error message
    • monetdbe_bind_decimal

      protected static String monetdbe_bind_decimal​(ByteBuffer stmt, Object data, int type, int scale, int param)
      Binds decimal parameter to prepared statement. Not working currently.
      Parameters:
      stmt - C pointer to prepared statement
      data - Unscaled value
      type - Type of unscaled value
      scale - Scale of the decimal parameter
      param - Parameter number
      Returns:
      Error message
    • monetdbe_bind_null

      protected static String monetdbe_bind_null​(ByteBuffer db, int type, ByteBuffer stmt, int param)
      Binds a null value of any type to prepared statement. Not working for all types currently (datetime + decimal types).
      Parameters:
      db - C pointer to database
      type - Type of input parameter to set a null
      stmt - C pointer to prepared statement
      param - Parameter number
      Returns:
      Error message