public class AceQLConnection extends org.kawanfw.driver.jdbc.abstracts.AbstractConnection implements Connection, Cloneable, Closeable
Connection implementation that enable to use a
virtual JDBC Connection that is mapped to a Server JDBC
Connection in order to access a remote SQL database through
HTTP.
This Connection implementation supports:
Blob/Clob updates with clean streaming behavior when
uploading.Blob/Clob reads with clean streaming behavior when
downloading.commit and rollback orders.
Supplementary specific methods that are not of instance of Connection are
also added.
After creating the AceQLConnection, just use it like a regular
Connection to execute your PreparedStatement and
Statement, and to navigate through your ResultSet.
All thrown exceptions are of type AceQLException. Use
Throwable.getCause() to get the original wrapped Exception.
The AceQL error_type value is available via the
AceQLException#getErrorCode() and the remote_stack value as a string
is available with AceQLException.getRemoteStackTrace()
Example:
The following dedicated// Define URL of the path to the AceQL Manager Servlet // We will use a secure SSL/TLS session. All uploads/downloads of SQL // commands & data will be encrypted. String url = "https://www.acme.org:9443/aceql"; // The login info for strong authentication on server side. // These are *not* the username/password of the remote JDBC Driver, // but are the auth info checked by remote server //DatabaseConfigurator.login(username, password)method. String database = "mydatabase"; String username = "MyUsername"; String password = "MyPassword"; // Attempts to establish a connection to the remote database: Connection connection = new AceQLConnection(serverUrl, database, username, password); // We can now use our remote JDBC Connection as a regular JDBC // Connection for our queries and updates: String sql = "SELECT CUSTOMER_ID, FNAME, LNAME FROM CUSTOMER " + "WHERE CUSTOMER_ID = ?"; PreparedStatement prepStatement = connection.prepareStatement(sql); prepStatement.setInt(1, 1); ResultSet rs = prepStatement.executeQuery(); while (rs.next()) { String customerId = rs.getString("customer_id"); String fname = rs.getString("fname"); String lname = rs.getString("lname"); System.out.println("customer_id: " + customerId); System.out.println("fname : " + fname); System.out.println("lname : " + lname); // Etc. }
AceQLConnection methods are specific to
the software and may be accessed with a cast:
setCancelled(AtomicBoolean)setGzipResult(boolean)setPrettyPrinting(boolean)setProgress(AtomicInteger)
All long Blobs update/reading that need to be run on a separated thread may
be followed in Swing using a JProgressBar,
ProgressMonitor or Android using a ProgressDialog
This is done by sharing two atomic variables that will be declared as fields:
AtomicInteger that represents the Blob/Clob transfer progress
between 0 and 100.AtomicBoolean that says if the end user has cancelled the
Blob/Clob transfer.
The atomic variables values will be shared by AceQL download/upload processes
and by the Progress Monitor used for the Progress Bar. The values are to be
initialized and passed to AceQLConnection before the JDBC actions
with the setters:
setProgress(AtomicInteger)
setCancelled(AtomicBoolean)
Example:
// Attempts to establish a connection to the remote database:
Connection connection = new AceQLConnection(url, username, password,
database);
// Pass the mutable & sharable progress and canceled to the
// underlying AceQLConnection.
// - progress value will be updated by the AceQLConnection and
// retrieved by progress monitors to increment the progress.
// - cancelled value will be updated to true if user cancels the
// task and AceQLConnection will interrupt the blob(s) transfer.
((AceQLConnection) connection).setProgress(progress);
((AceQLConnection) connection).setCancelled(cancelled);
// Execute JDBC statement
See the source code of
SqlProgressMonitorDemo.java that demonstrates the use of atomic
variables when inserting a Blob.TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE| Constructor and Description |
|---|
AceQLConnection(String serverUrl,
String database,
String username,
char[] password)
Login on the AceQL server and connect to a database
|
AceQLConnection(String serverUrl,
String database,
String username,
char[] password,
Proxy proxy,
PasswordAuthentication passwordAuthentication)
Login on the AceQL server and connect to a database
|
| Modifier and Type | Method and Description |
|---|---|
Connection |
clone() |
void |
close()
Releases this
Connection object's database and JDBC
resources immediately instead of waiting for them to be automatically
released. |
void |
commit()
Makes all changes made since the previous commit/rollback permanent and
releases any database locks currently held by this
Connection object. |
Statement |
createStatement()
Creates a
Statement object for sending SQL statements to the
database. |
boolean |
getAutoCommit()
Retrieves the current auto-commit mode for this
Connection
object. |
AtomicBoolean |
getCancelled()
Returns the cancelled value set by the progress indicator
|
String |
getClientVersion()
Returns the SDK current Version.
|
int |
getHoldability()
Retrieves the current holdability of
ResultSet objects
created using this Connection object. |
AtomicInteger |
getProgress()
Returns the sharable progress variable that will store Blob/Clob upload
or download progress between 0 and 100
|
String |
getServerVersion()
Returns the server product version
|
int |
getTransactionIsolation()
Retrieves this
Connection object's current transaction
isolation level. |
boolean |
isClosed()
Retrieves whether this
Connection object has been closed. |
boolean |
isReadOnly()
Retrieves whether this
Connection object is in read-only
mode. |
static boolean |
isTraceOn()
Says if trace is on
|
void |
logout() |
PreparedStatement |
prepareStatement(String sql)
Creates a
PreparedStatement object for sending parameterized
SQL statements to the database. |
void |
rollback()
Undoes all changes made in the current transaction and releases any
database locks currently held by this
Connection object. |
void |
setAutoCommit(boolean autoCommit)
Sets this connection's auto-commit mode to the given state.
|
void |
setCancelled(AtomicBoolean cancelled)
Sets the sharable canceled variable that will be used by the progress
indicator to notify this instance that the user has cancelled the current
Blob/Clob upload or download.
|
static void |
setConnectTimeout(int connectTimeout)
Sets the connect timeout.
|
void |
setGzipResult(boolean gzipResult)
Define if SQL result sets are returned compressed with the GZIP file
format before download.
|
void |
setHoldability(int holdability)
Changes the holdability of
ResultSet objects created using
this Connection object to the given holdability. |
void |
setPrettyPrinting(boolean prettyPrinting)
Says if JSON contents are to be pretty printed.
|
void |
setProgress(AtomicInteger progress)
Sets the sharable progress variable that will store Blob/Clob upload or
download progress between 0 and 100.
|
void |
setReadOnly(boolean readOnly)
Puts this connection in read-only mode as a hint to the driver to enable
database optimizations.
|
static void |
setReadTimeout(int readTimeout)
Sets the read timeout.
|
static void |
setTraceOn(boolean traceOn)
Sets the trace on/off
|
void |
setTransactionIsolation(int level)
Attempts to change the transaction isolation level for this
Connection object to the one given. |
abort, clearWarnings, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStruct, getCatalog, getClientInfo, getClientInfo, getMetaData, getNetworkTimeout, getSchema, getTypeMap, getWarnings, isValid, isWrapperFor, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setCatalog, setClientInfo, setClientInfo, setNetworkTimeout, setSavepoint, setSavepoint, setSchema, setTypeMap, unwrapequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitabort, clearWarnings, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStruct, getCatalog, getClientInfo, getClientInfo, getMetaData, getNetworkTimeout, getSchema, getTypeMap, getWarnings, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setCatalog, setClientInfo, setClientInfo, setNetworkTimeout, setSavepoint, setSavepoint, setSchema, setTypeMapisWrapperFor, unwrappublic AceQLConnection(String serverUrl, String database, String username, char[] password) throws SQLException
serverUrl - the URL of the AceQL server. Example:
http://localhost:9090/aceqldatabase - the server database to connect to.username - the loginpassword - the passwordSQLException - if any I/O error occurspublic AceQLConnection(String serverUrl, String database, String username, char[] password, Proxy proxy, PasswordAuthentication passwordAuthentication) throws SQLException
serverUrl - the URL of the AceQL server. Example:
http://localhost:9090/aceqldatabase - the server database to connect to.username - the loginpassword - the passwordproxy - the proxy to use. null if none.passwordAuthentication - the username and password holder to use for authenticated
proxy. Null if no proxy or if proxy does not require
authentication.SQLException - if any I/O error occurspublic static void setConnectTimeout(int connectTimeout)
connectTimeout - Sets a specified timeout value, in milliseconds, to be used
when opening a communications link to the remote server. If
the timeout expires before the connection can be established,
a java.net.SocketTimeoutException is raised. A timeout of zero
is interpreted as an infinite timeout. See
URLConnection.setConnectTimeout(int)public static void setReadTimeout(int readTimeout)
readTimeout - an int that specifies the read timeout value, in
milliseconds, to be used when an http connection is
established to the remote server. See
URLConnection.setReadTimeout(int)public void close()
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object's database and JDBC
resources immediately instead of waiting for them to be automatically
released.
Calling the method close on a Connection object
that is already closed is a no-op.
Note: A Connection object is automatically closed
when it is garbage collected. Certain fatal errors also close a
Connection object.
close in interface Closeableclose in interface AutoCloseableclose in interface Connectionclose in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionpublic void logout()
public void commit()
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object. This method should be used only when
auto-commit mode has been disabled.commit in interface Connectioncommit in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionSQLException - if a database access error occurs or this
Connection object is in auto-commit modeAbstractConnection.setAutoCommit(boolean)public void rollback()
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object.
This method should be used only when auto-commit mode has been disabled.rollback in interface Connectionrollback in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionSQLException - if a database access error occurs or this
Connection object is in auto-commit modeAbstractConnection.setAutoCommit(boolean)public void setTransactionIsolation(int level)
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object to the one given. The constants defined in
the interface Connection are the possible transaction
isolation levels.
Note: If this method is called during a transaction, the result is implementation-defined.
setTransactionIsolation in interface ConnectionsetTransactionIsolation in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionlevel - one of the following Connection constants:
Connection.TRANSACTION_READ_UNCOMMITTED,
Connection.TRANSACTION_READ_COMMITTED,
Connection.TRANSACTION_REPEATABLE_READ, or
Connection.TRANSACTION_SERIALIZABLE. (Note that
Connection.TRANSACTION_NONE cannot be used
because it specifies that transactions are not supported.)SQLException - if a database access error occurs or the given parameter
is not one of the Connection constantsDatabaseMetaData.supportsTransactionIsolationLevel(int),
AbstractConnection.getTransactionIsolation()public void setHoldability(int holdability)
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionResultSet objects created using
this Connection object to the given holdability.setHoldability in interface ConnectionsetHoldability in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionholdability - a ResultSet holdability constant; one of
ResultSet.HOLD_CURSORS_OVER_COMMIT or
ResultSet.CLOSE_CURSORS_AT_COMMITSQLException - if a database access occurs, the given parameter is not a
ResultSet constant indicating holdability, or
the given holdability is not supportedAbstractConnection.getHoldability(),
ResultSetpublic void setAutoCommit(boolean autoCommit)
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectioncommit or the method rollback
. By default, new connections are in auto-commit mode.
The commit occurs when the statement completes or the next execute
occurs, whichever comes first. In the case of statements returning a
ResultSet object, the statement completes when the last row
of the ResultSet object has been retrieved or the
ResultSet object has been closed. In advanced cases, a
single statement may return multiple results as well as output parameter
values. In these cases, the commit occurs when all results and output
parameter values have been retrieved.
NOTE: If this method is called during a transaction, the transaction is committed.
setAutoCommit in interface ConnectionsetAutoCommit in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionautoCommit - true to enable auto-commit mode;
false to disable itSQLException - if a database access error occursAbstractConnection.getAutoCommit()public boolean getAutoCommit()
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection
object.getAutoCommit in interface ConnectiongetAutoCommit in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object's
auto-commit modeSQLException - if a database access error occursAbstractConnection.setAutoCommit(boolean)public void setReadOnly(boolean readOnly)
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionNote: This method cannot be called during a transaction.
setReadOnly in interface ConnectionsetReadOnly in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionreadOnly - true enables read-only mode; false
disables itSQLException - if a database access error occurs or this method is called
during a transactionpublic boolean isReadOnly()
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object is in read-only
mode.isReadOnly in interface ConnectionisReadOnly in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectiontrue if this Connection object is
read-only; false otherwiseSQLException - if a database access error occurspublic int getHoldability()
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionResultSet objects
created using this Connection object.getHoldability in interface ConnectiongetHoldability in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionResultSet.HOLD_CURSORS_OVER_COMMIT or
ResultSet.CLOSE_CURSORS_AT_COMMITSQLException - if a database access occursAbstractConnection.setHoldability(int),
ResultSetpublic int getTransactionIsolation()
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object's current transaction
isolation level.getTransactionIsolation in interface ConnectiongetTransactionIsolation in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection.TRANSACTION_READ_UNCOMMITTED,
Connection.TRANSACTION_READ_COMMITTED,
Connection.TRANSACTION_REPEATABLE_READ,
Connection.TRANSACTION_SERIALIZABLE, or
Connection.TRANSACTION_NONE.SQLException - if a database access error occursAbstractConnection.setTransactionIsolation(int)public Statement createStatement() throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionStatement object for sending SQL statements to the
database. SQL statements without parameters are normally executed using
Statement objects. If the same SQL statement is executed
many times, it may be more efficient to use a
PreparedStatement object.
Result sets created using the returned Statement object will
by default be type TYPE_FORWARD_ONLY and have a concurrency
level of CONCUR_READ_ONLY.
createStatement in interface ConnectioncreateStatement in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionStatement objectSQLException - if a database access error occurspublic PreparedStatement prepareStatement(String sql) throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionPreparedStatement object for sending parameterized
SQL statements to the database.
A SQL statement with or without IN parameters can be pre-compiled and
stored in a PreparedStatement object. This object can then
be used to efficiently execute this statement multiple times.
Note: This method is optimized for handling parametric SQL
statements that benefit from precompilation. If the driver supports
precompilation, the method prepareStatement will send the
statement to the database for precompilation. Some drivers may not
support precompilation. In this case, the statement may not be sent to
the database until the PreparedStatement object is executed.
This has no direct effect on users; however, it does affect which methods
throw certain SQLException objects.
Result sets created using the returned PreparedStatement
object will by default be type TYPE_FORWARD_ONLY and have a
concurrency level of CONCUR_READ_ONLY.
prepareStatement in interface ConnectionprepareStatement in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectionsql - an SQL statement that may contain one or more '?' IN parameter
placeholdersPreparedStatement object containing
the pre-compiled SQL statementSQLException - if a database access error occurspublic Connection clone()
public String getClientVersion()
public String getServerVersion() throws AceQLException
AceQLException - if any Exception occurspublic static boolean isTraceOn()
public static void setTraceOn(boolean traceOn)
traceOn - if true, trace will be onpublic void setPrettyPrinting(boolean prettyPrinting)
prettyPrinting - if true, JSON contents are to be pretty printedpublic void setGzipResult(boolean gzipResult)
gzipResult - if true, sets are compressed before downloadpublic AtomicBoolean getCancelled()
public void setCancelled(AtomicBoolean cancelled)
cancelled - the Sharable canceled variable that will be used by the
progress indicator to notify this instance that the end user
has cancelled the current Blob/Clob upload or downloadpublic AtomicInteger getProgress()
public void setProgress(AtomicInteger progress)
progress - the sharable progress variablepublic boolean isClosed()
throws SQLException
org.kawanfw.driver.jdbc.abstracts.AbstractConnectionConnection object has been closed. A
connection is closed if the method close has been called on
it or if certain fatal errors have occurred. This method is guaranteed to
return true only when it is called after the method
Connection.close has been called.
This method generally cannot be called to determine whether a connection to a database is valid or invalid. A typical client can determine that a connection is invalid by catching any exceptions that might be thrown when an operation is attempted.
isClosed in interface ConnectionisClosed in class org.kawanfw.driver.jdbc.abstracts.AbstractConnectiontrue if this Connection object is
closed; false if it is still openSQLException - if a database access error occurs
DB2 - Informix - Ingres - MySQL - Oracle Database - PostgreSQL - SQL Server - Sybase - Teradata
Copyright © 2017 KawanSoft SAS