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 aSQLDatabaseType
.
-
-
Field Summary
Fields Modifier and Type Field Description protected String
_driver
The driver of the database typeprotected I18nizableText
_driverNotFoundMessage
The driver not found messageprotected String
_id
The id of the database typeprotected I18nizableText
_label
The label of the database typeprotected String
_languageEscapeTableNameTemplate
The template to escape the table name.protected String
_languageLimitQueryTemplate
The template to limit the query to a limit/offset.protected String
_pluginName
The plugin's nameprotected String
_template
The url template for this database typeprotected String
_validationQuery
The SQL query to validate the connection is still alive
-
Constructor Summary
Constructors Constructor Description StaticSQLDatabaseType()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Configuration configuration)
InputStream
getBlob(ResultSet resultSet, int pos)
Get the InputStream to read a blobInputStream
getBlob(ResultSet resultSet, String columnName)
Get the InputStream to read a blobString
getDriver()
Get the driver of the database type.I18nizableText
getDriverNotFoundMessage()
Get the error message key when the specified driver was not foundString
getId()
Get the id of the database type.I18nizableText
getLabel()
Get the label of the database type.String
getTemplate()
Get the url template to use for this database typeString
getValidationQuery()
Get the query to validate a connectionString
languageEscapeTableName(String tableNameToEscape)
Some db systems requires the table names to be escapedString
languageLimitQuery(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 Detail
-
_label
protected I18nizableText _label
The label of the database type
-
_pluginName
protected String _pluginName
The plugin's name
-
_validationQuery
protected String _validationQuery
The SQL query to validate the connection is still alive
-
_driverNotFoundMessage
protected I18nizableText _driverNotFoundMessage
The driver not found message
-
_languageEscapeTableNameTemplate
protected String _languageEscapeTableNameTemplate
The template to escape the table name. Must contain {tableName}
-
_languageLimitQueryTemplate
protected String _languageLimitQueryTemplate
The template to limit the query to a limit/offset. Must contain {query} {limit} and {offset}
-
-
Constructor Detail
-
StaticSQLDatabaseType
public StaticSQLDatabaseType()
-
-
Method Detail
-
setPluginInfo
public void setPluginInfo(String pluginName, String featureName, String id)
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
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
getId
public String 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
public I18nizableText getLabel()
Description copied from interface:SQLDatabaseType
Get the label of the database type.- Specified by:
getLabel
in interfaceSQLDatabaseType
- Returns:
- the label
-
getDriver
public String 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
public String 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
public String 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
public I18nizableText 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
public String languageEscapeTableName(String tableNameToEscape)
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
public String languageLimitQuery(String queryToLimit, String limit, String offset)
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
public InputStream getBlob(ResultSet resultSet, String columnName) throws SQLException
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
public InputStream getBlob(ResultSet resultSet, int pos) throws SQLException
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
public void setBlob(PreparedStatement statement, int pos, byte[] bytes) 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 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
-
-