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, protocolFields 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 voidcloseUnderlyingConnection()Closes the underlying connection implementation.List<String>connect(String user, String pass)Connects to the existing database on the JVM process.protected booleanexecuteNextQueryBatch(nl.cwi.monetdb.jdbc.MonetStatement statement, List<String> batch, int[] counts, BatchUpdateException e)Execute a batch query in an embedded connection.MonetDBEmbeddedConnectiongetAsMonetDBEmbeddedConnection()Makes a conversion of this connection as aMonetDBEmbeddedConnectioninstance, making it possible to access theMonetDBEmbeddedConnectionAPI on a JDBC embedded connection, although that API doesn't follow the JDBC specification.intgetBlockSize()Gets the underlying connection block size length.intgetDefFetchsize()Gets the underlying connection default fetch size for DataBlock responses.StringgetDirectory()Gets the directory where the database is hosted.StringgetJDBCURL()Gets the underlying connection JDBC String URL.intgetSoTimeout()In a embedded connection there is no timeout, so this methods always adds aSQLWarningand returns -1.intinitialStringBuilderSize()booleanisRunningInMemory()Is the connection running in memory?booleanisSequentialFlag()Is the sequential flag set?booleanisSilentFlag()Is the silent flag set?voidsendControlCommand(int commandID, int data)Sends a control command to the server.voidsetSoTimeout(int timeout)In a embedded connection there is no timeout, so this methods always adds aSQLWarningand 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, toStringMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 aMonetDBEmbeddedConnectioninstance, making it possible to access theMonetDBEmbeddedConnectionAPI on a JDBC embedded connection, although that API doesn't follow the JDBC specification.- Returns:
- This connection as a
MonetDBEmbeddedConnectioninstance
-
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, aMCLExceptionwill 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:
connectin 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 directoryIOExceptionnl.cwi.monetdb.mcl.protocol.ProtocolException
-
getJDBCURL
Gets the underlying connection JDBC String URL.- Specified by:
getJDBCURLin 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:
getBlockSizein 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:
getDefFetchsizein classnl.cwi.monetdb.jdbc.MonetConnection- Returns:
- The integer max value
-
initialStringBuilderSize
public int initialStringBuilderSize()- Specified by:
initialStringBuilderSizein classnl.cwi.monetdb.jdbc.MonetConnection
-
getSoTimeout
In a embedded connection there is no timeout, so this methods always adds aSQLWarningand returns -1.- Specified by:
getSoTimeoutin classnl.cwi.monetdb.jdbc.MonetConnection- Returns:
- -1
- Throws:
SocketException
-
setSoTimeout
In a embedded connection there is no timeout, so this methods always adds aSQLWarningand the timeout parameter is ignored.- Specified by:
setSoTimeoutin 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:
closeUnderlyingConnectionin 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:
sendControlCommandin classnl.cwi.monetdb.jdbc.MonetConnection- Parameters:
commandID- the command identifier according toControlCommandslistingdata- 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:
executeNextQueryBatchin 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
-