Package org.kawanfw.sql.api.server
Class DefaultDatabaseConfigurator
java.lang.Object
org.kawanfw.sql.api.server.DefaultDatabaseConfigurator
- All Implemented Interfaces:
DatabaseConfigurator
public class DefaultDatabaseConfigurator extends Object implements DatabaseConfigurator
Default implementation of server side configuration for AceQL.
The two fully functional and secured methods are:
getConnection(String)
that extractsConnections
from a Tomcat JDBC Connection Pool.close(Connection)
that simplify closes theConnection
and thus releases it into the pool.
- Author:
- Nicolas de Pomereu
-
Constructor Summary
Constructors Constructor Description DefaultDatabaseConfigurator()
-
Method Summary
Modifier and Type Method Description void
close(Connection connection)
Closes the connection acquired byDatabaseConfigurator.getConnection(String)
with a call toConnection.close()
.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)
Returns aConnection
from Tomcat JDBC Connection Pool.
theConnection
is extracted from theDataSource
created by the embedded Tomcat JDBC Pool.org.slf4j.Logger
getLogger()
Creates a static default Logback/sl4fj Logger for main AceQL activity.static Map<String,String>
getLoggerElements()
Returns the Logger elements (for debug purpose)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.
-
Constructor Details
-
DefaultDatabaseConfigurator
public DefaultDatabaseConfigurator()
-
-
Method Details
-
getConnection
Returns aConnection
from Tomcat JDBC Connection Pool.
theConnection
is extracted from theDataSource
created by the embedded Tomcat JDBC Pool. The JDBC parameters used to create theDataSource
are defined in the properties file passed at start-up of AceQL.- Specified by:
getConnection
in interfaceDatabaseConfigurator
- Parameters:
database
- the database name to extract theConnection
for.- Returns:
- the
Connection
extracted from Tomcat JDBC Connection Pool. - Throws:
SQLException
- if a database access error occurs
-
close
Closes the connection acquired byDatabaseConfigurator.getConnection(String)
with a call toConnection.close()
.
Note that Exceptions are trapped to avoid client failure. Stack trace is printed on standard error stream.- Specified by:
close
in interfaceDatabaseConfigurator
- Parameters:
connection
- a connection to the data source- Throws:
SQLException
- if a SQLException occurs
-
getMaxRows
Description copied from interface:DatabaseConfigurator
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.- Specified by:
getMaxRows
in interfaceDatabaseConfigurator
- Parameters:
username
- the client username to check the max rows for.database
- the database name as defined in the JDBC URL field- Returns:
- the value of the property
defaultDatabaseConfigurator.maxRows
defined in theaceql-server.properties
file at server startup. If the property does not exist, returns 0. - Throws:
IOException
- if an IOException occursSQLException
- if a SQLException occurs
-
getMaxBlobLength
Description copied from interface:DatabaseConfigurator
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.- Specified by:
getMaxBlobLength
in interfaceDatabaseConfigurator
- Parameters:
username
- the client usernamedatabase
- the database name as defined in the JDBC URL field- Returns:
- the value of the property
defaultDatabaseConfigurator.maxBlobLength
defined in theaceql-server.properties
file at server startup. If the property does not exist, it defaults to 2GB in order to avoid DOS attacks aimed to saturate the server's disk space - Throws:
IOException
- if an IOException occursSQLException
- if a SQLException occurs
-
getBlobsDirectory
Description copied from interface:DatabaseConfigurator
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:getBlobsDirectory(String)
.- Specified by:
getBlobsDirectory
in interfaceDatabaseConfigurator
- Parameters:
username
- the client username- Returns:
user.home/.aceql-server-root/username
. (user.home
is the one of the servlet container).- Throws:
IOException
- if an IOException occursSQLException
- if a SQLException occurs
-
getLogger
Creates a static default Logback/sl4fj Logger for main AceQL activity. Logger has default characteristics:- Name:
DefaultLoggerCreator
- Log directory:
user.home/.kawansoft/log
- File name pattern:
"aceql_%d.log.%i"
(example of file created:aceql_2024-07-01.log.1
.) - Pattern of each line of log:
"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"}
- Maximum File Size: 300Mb
- Total Size Cap: 30Gb
DefaultLoggerCreator.properties
file inuser.home/.kawansoft/conf
.
See the DefaultLoggerCreator.properties format.
- Specified by:
getLogger
in interfaceDatabaseConfigurator
- Returns:
- the
Logger
that will be used by AceQL logging; - Throws:
IOException
- if an IOException occurs
- Name:
-
getLoggerElements
Returns the Logger elements (for debug purpose)- Returns:
- the lOGGER_ELEMENTS
-