Package nl.cwi.monetdb.embedded.jdbc
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
-
Nested Class Summary
-
Field Summary
Fields inherited from class nl.cwi.monetdb.jdbc.MonetConnection
conn_props, hash, language, lastSetQueryTimeout, protocol
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
-
Constructor Summary
Constructors Constructor Description EmbeddedConnection(Properties props, String hash, String language, String directory)
EmbeddedConnection(Properties props, String hash, String language, String directory, Boolean silentFlag, Boolean sequentialFlag)
-
Method Summary
Modifier and Type Method Description void
closeUnderlyingConnection()
Closes the underlying connection implementation.List<String>
connect(String user, String pass)
Connects to the existing database on the JVM process.protected boolean
executeNextQueryBatch(nl.cwi.monetdb.jdbc.MonetStatement statement, List<String> batch, int[] counts, BatchUpdateException e)
Execute a batch query in an embedded connection.MonetDBEmbeddedConnection
getAsMonetDBEmbeddedConnection()
Makes a conversion of this connection as aMonetDBEmbeddedConnection
instance, making it possible to access theMonetDBEmbeddedConnection
API on a JDBC embedded connection, although that API doesn't follow the JDBC specification.int
getBlockSize()
Gets the underlying connection block size length.int
getDefFetchsize()
Gets the underlying connection default fetch size for DataBlock responses.String
getDirectory()
Gets the directory where the database is hosted.String
getJDBCURL()
Gets the underlying connection JDBC String URL.int
getSoTimeout()
In a embedded connection there is no timeout, so this methods always adds aSQLWarning
and returns -1.int
initialStringBuilderSize()
boolean
isRunningInMemory()
Is the connection running in memory?boolean
isSequentialFlag()
Is the sequential flag set?boolean
isSilentFlag()
Is the silent flag set?void
sendControlCommand(int commandID, int data)
Sends a control command to the server.void
setSoTimeout(int timeout)
In a embedded connection there is no timeout, so this methods always adds aSQLWarning
and the timeout parameter is ignored.Methods inherited from class nl.cwi.monetdb.jdbc.MonetConnection
abort, clearWarnings, close, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, finalize, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getLanguage, getMetaData, getNetworkTimeout, getProtocol, getSchema, getSeqCounter, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isEmbedded, isReadOnly, isValid, mapBlobAsVarBinary, mapClobAsVarChar, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setReadOnly, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.sql.Connection
beginRequest, endRequest, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid
-
Constructor Details
-
Method Details
-
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
Makes a conversion of this connection as aMonetDBEmbeddedConnection
instance, making it possible to access theMonetDBEmbeddedConnection
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.MCLExceptionConnects 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, aMCLException
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 classnl.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 directoryIOException
nl.cwi.monetdb.mcl.protocol.ProtocolException
-
getJDBCURL
Gets the underlying connection JDBC String URL.- Specified by:
getJDBCURL
in classnl.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 classnl.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 classnl.cwi.monetdb.jdbc.MonetConnection
- Returns:
- The integer max value
-
initialStringBuilderSize
public int initialStringBuilderSize()- Specified by:
initialStringBuilderSize
in classnl.cwi.monetdb.jdbc.MonetConnection
-
getSoTimeout
In a embedded connection there is no timeout, so this methods always adds aSQLWarning
and returns -1.- Specified by:
getSoTimeout
in classnl.cwi.monetdb.jdbc.MonetConnection
- Returns:
- -1
- Throws:
SocketException
-
setSoTimeout
In a embedded connection there is no timeout, so this methods always adds aSQLWarning
and the timeout parameter is ignored.- Specified by:
setSoTimeout
in classnl.cwi.monetdb.jdbc.MonetConnection
- Parameters:
timeout
- The specified timeout, in milliseconds (ignored)- Throws:
SocketException
-
closeUnderlyingConnection
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 classnl.cwi.monetdb.jdbc.MonetConnection
- Throws:
IOException
- if an error happens while closing the connection or the database
-
sendControlCommand
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 classnl.cwi.monetdb.jdbc.MonetConnection
- Parameters:
commandID
- the command identifier according toControlCommands
listingdata
- 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 SQLExceptionExecute a batch query in an embedded connection.- Specified by:
executeNextQueryBatch
in classnl.cwi.monetdb.jdbc.MonetConnection
- Parameters:
statement
- The original MonetStatement where the batch comes frombatch
- The list of queries to executecounts
- The return of the update statement of each input querye
- 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
-