Package org.monetdb.monetdbe
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 Summary
Constructors Constructor Description MonetNative() -
Method Summary
Modifier and Type Method Description protected static Stringmonetdbe_bind_blob(ByteBuffer stmt, int param, byte[] data, long size)Binds blob parameter to prepared statement.protected static Stringmonetdbe_bind_bool(ByteBuffer stmt, int param, boolean data)Binds boolean parameter to prepared statement.protected static Stringmonetdbe_bind_byte(ByteBuffer stmt, int param, byte data)Binds byte parameter to prepared statement.protected static Stringmonetdbe_bind_date(ByteBuffer stmt, int param, int year, int month, int day)Binds date parameter to prepared statement.protected static Stringmonetdbe_bind_decimal(ByteBuffer stmt, Object data, int type, int scale, int param)Binds decimal parameter to prepared statement.protected static Stringmonetdbe_bind_double(ByteBuffer stmt, int param, double data)Binds double parameter to prepared statement.protected static Stringmonetdbe_bind_float(ByteBuffer stmt, int param, float data)Binds float parameter to prepared statement.protected static Stringmonetdbe_bind_hugeint(ByteBuffer stmt, int param, BigInteger data)Binds big integer parameter to prepared statement.protected static Stringmonetdbe_bind_int(ByteBuffer stmt, int param, int data)Binds integer parameter to prepared statement.protected static Stringmonetdbe_bind_long(ByteBuffer stmt, int param, long data)Binds long parameter to prepared statement.protected static Stringmonetdbe_bind_null(ByteBuffer db, int type, ByteBuffer stmt, int param)Binds a null value of any type to prepared statement.protected static Stringmonetdbe_bind_short(ByteBuffer stmt, int param, short data)Binds short parameter to prepared statement.protected static Stringmonetdbe_bind_string(ByteBuffer stmt, int param, String data)Binds string parameter to prepared statement.protected static Stringmonetdbe_bind_time(ByteBuffer stmt, int param, int hours, int minutes, int seconds, int ms)Binds time parameter to prepared statement.protected static Stringmonetdbe_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.protected static Stringmonetdbe_cleanup_statement(ByteBuffer db, ByteBuffer stmt)Cleans up and closes a previously prepared statement.protected static Stringmonetdbe_clear_bindings(ByteBuffer db, ByteBuffer stmt)protected static Stringmonetdbe_close(ByteBuffer db)Close the database connection.protected static Stringmonetdbe_error(ByteBuffer db)Returns latest error message from the database.protected static Stringmonetdbe_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.protected static booleanmonetdbe_get_autocommit(ByteBuffer db)Gets the current auto-commit value (either true or false).protected static Stringmonetdbe_open(String dbdir, MonetConnection conn)Open connection to memory or local directory database with default options.protected static Stringmonetdbe_open(String dbdir, MonetConnection conn, int sessiontimeout, int querytimeout, int memorylimit, int nr_threads)Open connection to memory or local directory database.protected static Stringmonetdbe_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.protected static Stringmonetdbe_prepare(ByteBuffer db, String sql, MonetPreparedStatement statement)Prepares a reusable statement with configurable parameters.protected static Stringmonetdbe_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.protected static Stringmonetdbe_result_cleanup(ByteBuffer db, ByteBuffer nativeResult)Cleans up and closes a result set.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.protected static Stringmonetdbe_set_autocommit(ByteBuffer db, int value)Sets auto-commit mode.
-
Constructor Details
-
MonetNative
public MonetNative()
-
-
Method Details
-
monetdbe_open
Open connection to memory or local directory database with default options.- Parameters:
dbdir- Directory for database, NULL for memory DBsconn- 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 DBsconn- Parent Connection, needed for setting the created connectionsessiontimeout- Option for monetdbe_open() library functionquerytimeout- Option for monetdbe_open() library functionmemorylimit- Option for monetdbe_open() library functionnr_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 DBsconn- Parent Connection, needed for setting the created connectionsessiontimeout- Option for monetdbe_open() library functionquerytimeout- Option for monetdbe_open() library functionmemorylimit- Option for monetdbe_open() library functionnr_threads- Option for monetdbe_open() library functionhost- Remote host to connect toport- Remote port to connect todatabase- Remote databaseuser- Username in the remote databasepassword- Password in the remote database- Returns:
- Error message
-
monetdbe_close
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 databasesql- Query to executestatement- Parent Statement, needed for setting result set/update countlargeUpdate- If this function was called from an executeLarge methodmaxrows- 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 resultnrows- Number of rows in resultncols- Number of columns in result- Returns:
- Java object representation of result columns
-
monetdbe_result_cleanup
Cleans up and closes a result set.- Parameters:
db- C pointer to databasenativeResult- C pointer to result- Returns:
- Error message
-
monetdbe_error
Returns latest error message from the database.- Parameters:
db- C pointer to database- Returns:
- Latest error message
-
monetdbe_set_autocommit
Sets auto-commit mode.- Parameters:
db- C pointer to databasevalue- true or false- Returns:
- Error message
-
monetdbe_get_autocommit
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 databasesql- Statement to preparestatement- 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 statementstatement- Parent PreparedStatement, needed for setting result set/update countlargeUpdate- If this function was called from an executeLarge methodmaxrows- Maximum amount of rows to be returned in case a result set is returned- Returns:
- Error message
-
monetdbe_cleanup_statement
Cleans up and closes a previously prepared statement.- Parameters:
db- C pointer to databasestmt- C pointer to prepared statement- Returns:
- Error message
-
monetdbe_clear_bindings
-
monetdbe_bind_bool
Binds boolean parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Boolean value to bind- Returns:
- Error message
-
monetdbe_bind_byte
Binds byte parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Byte value to bind- Returns:
- Error message
-
monetdbe_bind_short
Binds short parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Short value to bind- Returns:
- Error message
-
monetdbe_bind_int
Binds integer parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Integer value to bind- Returns:
- Error message
-
monetdbe_bind_long
Binds long parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Long value to bind- Returns:
- Error message
-
monetdbe_bind_hugeint
Binds big integer parameter to prepared statement. Not working currently.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Big integer value to bind- Returns:
- Error message
-
monetdbe_bind_float
Binds float parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Float value to bind- Returns:
- Error message
-
monetdbe_bind_double
Binds double parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Double value to bind- Returns:
- Error message
-
monetdbe_bind_string
Binds string parameter to prepared statement.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- String value to bind- Returns:
- Error message
-
monetdbe_bind_blob
Binds blob parameter to prepared statement. Not working currently.- Parameters:
stmt- C pointer to prepared statementparam- Parameter numberdata- Blob value to bind, as byte arraysize- 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 statementparam- Parameter numberyear- Date yearmonth- Date monthday- 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 statementparam- Parameter numberhours- Time hoursminutes- Time minutesseconds- Time secondsms- 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 statementparam- Parameter numberyear- Timestamp yearmonth- Timestamp monthday- Timestamp dayhours- Timestamp hoursminutes- Timestamp minutesseconds- Timestamp secondsms- 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 statementdata- Unscaled valuetype- Type of unscaled valuescale- Scale of the decimal parameterparam- Parameter number- Returns:
- Error message
-
monetdbe_bind_null
Binds a null value of any type to prepared statement. Not working for all types currently (datetime + decimal types).- Parameters:
db- C pointer to databasetype- Type of input parameter to set a nullstmt- C pointer to prepared statementparam- Parameter number- Returns:
- Error message
-