Class StaticSQLDatabaseType
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.core.impl.datasource.StaticSQLDatabaseType
- All Implemented Interfaces:
SQLDatabaseType
,LogEnabled
,PluginAware
,Configurable
- Direct Known Subclasses:
DerbySQLDatabaseType
,PostgreSQLDatabaseType
public class StaticSQLDatabaseType
extends AbstractLogEnabled
implements Configurable, SQLDatabaseType, PluginAware
Default implementation for a
SQLDatabaseType
.-
Field Summary
Modifier and TypeFieldDescriptionprotected String
The driver of the database typeprotected I18nizableText
The driver not found messageprotected String
The id of the database typeprotected I18nizableText
The label of the database typeprotected String
The template to escape the table name.protected String
The template to limit the query to a limit/offset.protected String
The plugin's nameprotected String
The url template for this database typeprotected String
The SQL query to validate the connection is still alive -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(Configuration configuration) Get the InputStream to read a blobGet the InputStream to read a blobGet the driver of the database type.Get the error message key when the specified driver was not foundgetId()
Get the id of the database type.getLabel()
Get the label of the database type.Get the url template to use for this database typeGet the query to validate a connectionlanguageEscapeTableName
(String tableNameToEscape) Some db systems requires the table names to be escapedlanguageLimitQuery
(String queryToLimit, String limit, String offset) Add a limit/offset element to the given queryvoid
setBlob
(PreparedStatement statement, int pos, byte[] bytes) Set an array of bytes (UTF-8 encoded) into a blob, if you want to pass a String, you can useSQLDatabaseType.setBlob(PreparedStatement, int, String)
void
setBlob
(PreparedStatement statement, int pos, InputStream is, long length) Set an array of bytes (UTF-8 encoded) into a blob, if you want to pass a String, you can useSQLDatabaseType.setBlob(PreparedStatement, int, String)
void
setBlob
(PreparedStatement statement, int pos, String blob) Set an String into a blobvoid
setPluginInfo
(String pluginName, String featureName, String id) Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
_id
The id of the database type -
_label
The label of the database type -
_driver
The driver of the database type -
_template
The url template for this database type -
_pluginName
The plugin's name -
_validationQuery
The SQL query to validate the connection is still alive -
_driverNotFoundMessage
The driver not found message -
_languageEscapeTableNameTemplate
The template to escape the table name. Must contain {tableName} -
_languageLimitQueryTemplate
The template to limit the query to a limit/offset. Must contain {query} {limit} and {offset}
-
-
Constructor Details
-
StaticSQLDatabaseType
public StaticSQLDatabaseType()
-
-
Method Details
-
setPluginInfo
Description copied from interface:PluginAware
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.- Specified by:
setPluginInfo
in interfacePluginAware
- Parameters:
pluginName
- Unique identifier for the plugin hosting the extensionfeatureName
- Unique feature identifier (unique for a given pluginName)id
- Unique identifier of this component
-
configure
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
getId
Description copied from interface:SQLDatabaseType
Get the id of the database type.- Specified by:
getId
in interfaceSQLDatabaseType
- Returns:
- the id. Can not be null.
-
getLabel
Description copied from interface:SQLDatabaseType
Get the label of the database type.- Specified by:
getLabel
in interfaceSQLDatabaseType
- Returns:
- the label
-
getDriver
Description copied from interface:SQLDatabaseType
Get the driver of the database type.- Specified by:
getDriver
in interfaceSQLDatabaseType
- Returns:
- the driver. Can not be null.
-
getTemplate
Description copied from interface:SQLDatabaseType
Get the url template to use for this database type- Specified by:
getTemplate
in interfaceSQLDatabaseType
- Returns:
- the url template
-
getValidationQuery
Description copied from interface:SQLDatabaseType
Get the query to validate a connection- Specified by:
getValidationQuery
in interfaceSQLDatabaseType
- Returns:
- A SQL query to ensure that a connection is still alive
-
getDriverNotFoundMessage
Description copied from interface:SQLDatabaseType
Get the error message key when the specified driver was not found- Specified by:
getDriverNotFoundMessage
in interfaceSQLDatabaseType
- Returns:
- the error message
-
languageEscapeTableName
Description copied from interface:SQLDatabaseType
Some db systems requires the table names to be escaped- Specified by:
languageEscapeTableName
in interfaceSQLDatabaseType
- Parameters:
tableNameToEscape
- The non-null table name- Returns:
- The escaped table name or at least the table name if no escape is required
-
languageLimitQuery
Description copied from interface:SQLDatabaseType
Add a limit/offset element to the given query- Specified by:
languageLimitQuery
in interfaceSQLDatabaseType
- Parameters:
queryToLimit
- The sql query that will be amendedlimit
- The max number of the results to returnoffset
- The initial offset of the results to return- Returns:
- The initial query amended to handle the limit and offset.
-
getBlob
Description copied from interface:SQLDatabaseType
Get the InputStream to read a blob- Specified by:
getBlob
in interfaceSQLDatabaseType
- Parameters:
resultSet
- the result set containing the blob.columnName
- column- Returns:
- an InputStream to read the blob or null if the column is null
- Throws:
SQLException
- if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
-
getBlob
Description copied from interface:SQLDatabaseType
Get the InputStream to read a blob- Specified by:
getBlob
in interfaceSQLDatabaseType
- Parameters:
resultSet
- the result set containing the blob.pos
- column position- Returns:
- an InputStream to read the blob
- Throws:
SQLException
- if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
-
setBlob
public void setBlob(PreparedStatement statement, int pos, String blob) throws SQLException, UnsupportedEncodingException Description copied from interface:SQLDatabaseType
Set an String into a blob- Specified by:
setBlob
in interfaceSQLDatabaseType
- Parameters:
statement
- The satement where the blob will be setpos
- position in the statementblob
- String representing the blob. Can be null- Throws:
SQLException
- if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result setUnsupportedEncodingException
- if UTF-8 is not supported
-
setBlob
Description copied from interface:SQLDatabaseType
Set an array of bytes (UTF-8 encoded) into a blob, if you want to pass a String, you can useSQLDatabaseType.setBlob(PreparedStatement, int, String)
- Specified by:
setBlob
in interfaceSQLDatabaseType
- Parameters:
statement
- The satement where the blob will be setpos
- position in the statementbytes
- byte[] representing the blob, in UTF-8. Can be null- Throws:
SQLException
- if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
-
setBlob
public void setBlob(PreparedStatement statement, int pos, InputStream is, long length) throws SQLException Description copied from interface:SQLDatabaseType
Set an array of bytes (UTF-8 encoded) into a blob, if you want to pass a String, you can useSQLDatabaseType.setBlob(PreparedStatement, int, String)
- Specified by:
setBlob
in interfaceSQLDatabaseType
- Parameters:
statement
- The satement where the blob will be setpos
- position in the statementis
- inputStream to put in the blob. Can be nulllength
- length of the stream- Throws:
SQLException
- if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set
-