Package org.kawanfw.sql.api.server
Interface DatabaseConfigurator
- All Known Implementing Classes:
DefaultDatabaseConfigurator
public interface DatabaseConfigurator
Interface that defines the database configurations for AceQL HTTP.
The implemented methods will be called by AceQL when a client program, referred by a user username, asks for a JDBC operation from the Client side.
A concrete implementation should be developed on the server side in order to:
- Define how to extract a JDBC Connection from a Connection Pool.
- Define the directories where the Blobs/Clobs are located for upload and download.
- Define some Java code to execute before/after a
Connection.close()
. - Define the maximum number of rows that may be returned to the client.
- Define the maximum length allowed for a Blob upload.
- Define the
Logger
to use to trap server Exceptions.
- Author:
- Nicolas de Pomereu
-
Method Summary
Modifier and Type Method Description void
close(Connection connection)
Allows to define how to close the Connection acquired withgetConnection(String)
and return it to the pool.File
getBlobsDirectory(String username)
Allows to define the directory into which Blobs/Clobs are uploaded by client side, and from which Blobs/Clobs are downloaded by client side.Connection
getConnection(String database)
Attempts to establish a connection with an underlying data source.org.slf4j.Logger
getLogger()
Returns the SLF4JLogger
that will be used by AceQL for logging: All Exceptions thrown by server side will be logged. Exceptions thrown are flattened when logged for compatible usage with tools like Logstash. It is not necessary nor recommended to implement this method; do it only if you want take control of the logging to modify the default characteristics ofDefaultDatabaseConfigurator.getLogger()
.long
getMaxBlobLength(String username, String database)
Allows to define the maximum length authorized for of a Blob to be uploaded.int
getMaxRows(String username, String database)
Allows to define the maximum rows per request to be returned to the client.
-
Method Details
-
getConnection
Attempts to establish a connection with an underlying data source.
- Parameters:
database
- the database name to get the connection from- Returns:
- a
Connection
to the data source - Throws:
SQLException
- if a database access error occurs
-
close
Allows to define how to close the Connection acquired withgetConnection(String)
and return it to the pool.
Most connection pool implementations just require to callConnection.close()
to release the connection, but it is sometimes necessary for applications to add some operation before/after the close. This method allows you to add specific code before or after the close.
It is not required to implement this method, because the default implementationDefaultDatabaseConfigurator.close(Connection)
closes the connection with an explicit call toConnection.close()
.
If you implement this method, you *must* close the connection.- Parameters:
connection
- a connection to the data source- Throws:
SQLException
- if a SQLException occurs
-
getMaxRows
Allows to define the maximum rows per request to be returned to the client. If this limit is exceeded, the excess rows are silently dropped.- Parameters:
username
- the client username to check the max rows for.database
- the database name as defined in the JDBC URL field- Returns:
- the maximum rows per request to be returned to the client; zero means there is no limit
- Throws:
IOException
- if an IOException occursSQLException
- if a SQLException occurs
-
getMaxBlobLength
Allows to define the maximum length authorized for of a Blob to be uploaded. If this limit is exceeded, anIOException
is thrown This allows to prevent from DOS attacks that would saturate the AceQL server. 0 means there is no limit.- Parameters:
username
- the client usernamedatabase
- the database name as defined in the JDBC URL field- Returns:
- the maximum Blob length for upload, 0 means there is no limit
- Throws:
IOException
- if an IOException occursSQLException
- if a SQLException occurs
-
getBlobsDirectory
Allows to define the directory into which Blobs/Clobs are uploaded by client side, and from which Blobs/Clobs are downloaded by client side.
See default implementation in:DefaultDatabaseConfigurator.getBlobsDirectory(String)
.- Parameters:
username
- the client username- Returns:
- the Blob/Clob upload and download directory for this username
- Throws:
IOException
- if an IOException occursSQLException
- if a SQLException occurs
-
getLogger
Returns the SLF4JLogger
that will be used by AceQL for logging:- All Exceptions thrown by server side will be logged.
- Exceptions thrown are flattened when logged for compatible usage with tools like Logstash.
DefaultDatabaseConfigurator.getLogger()
.- Returns:
- the
Logger
that will be used by AceQL logging; - Throws:
IOException
- if an IOException occurs
-