Package org.opencms.db.generic
Class CmsSqlManager
java.lang.Object
org.opencms.db.CmsSqlManager
org.opencms.db.generic.CmsSqlManager
- Direct Known Subclasses:
CmsSqlManager
,CmsSqlManager
,CmsSqlManager
,CmsSqlManager
,CmsSqlManager
,CmsSqlManager
,CmsSqlManager
Generic (ANSI-SQL) implementation of the SQL manager.
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionprotected ConcurrentHashMap<String,
String> A map to cache queries with replaced search patterns.protected int
The type ID of the driver (vfs, user, project or history) from where this SQL manager is referenced.protected String
The pool URL to get connections from the JDBC driver manager, including DBCP's pool URL prefix.A map holding all SQL queries.protected static final String
A pattern being replaced in SQL queries to generate SQL queries to access online/offline tables. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
closeAll
(CmsDbContext dbc, Connection con, Statement stmnt, ResultSet res) Attempts to close the connection, statement and result set after a statement has been executed.byte[]
Retrieves the value of the designated column in the current row of this ResultSet object as a byte array in the Java programming language.Returns a JDBC connection from the connection pool.static CmsSqlManager
getInstance
(String classname) Creates a new instance of a SQL manager.getPreparedStatement
(Connection con, String queryKey) Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query.getPreparedStatement
(Connection con, CmsProject project, String queryKey) Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query and the CmsProject.getPreparedStatement
(Connection con, CmsUUID projectId, String queryKey) Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query and the project-ID.getPreparedStatementForSql
(Connection con, String query) Returns a PreparedStatement for a JDBC connection specified by the SQL query.void
Initializes this SQL manager.protected void
loadQueryProperties
(String propertyFilename) Loads a Java properties hash containing SQL queries.Searches for the SQL query with the specified key.readQuery
(CmsProject project, String queryKey) Searches for the SQL query with the specified key and CmsProject.Searches for the SQL query with the specified key and project-ID.protected static String
replaceProjectPattern
(CmsUUID projectId, String query) Replaces the project search pattern in SQL queries by the pattern _ONLINE_ or _OFFLINE_ depending on the specified project ID.protected void
Replaces patterns ${XXX} by another property value, if XXX is a property key with a value.void
setBytes
(PreparedStatement statement, int pos, byte[] content) Sets the designated parameter to the given Java array of bytes.validateEmpty
(String value) Replaces null or empty Strings with a String with one space character" "
.Methods inherited from class org.opencms.db.CmsSqlManager
getActiveConnections, getConnection, getConnectionByUrl, getDbPoolUrls, getDefaultDbPoolName, getIdleConnections
-
Field Details
-
QUERY_PROJECT_SEARCH_PATTERN
A pattern being replaced in SQL queries to generate SQL queries to access online/offline tables.- See Also:
-
m_cachedQueries
A map to cache queries with replaced search patterns. -
m_driverType
The type ID of the driver (vfs, user, project or history) from where this SQL manager is referenced. -
m_poolUrl
The pool URL to get connections from the JDBC driver manager, including DBCP's pool URL prefix. -
m_queries
A map holding all SQL queries.
-
-
Constructor Details
-
CmsSqlManager
public CmsSqlManager()Creates a new, empty SQL manager.
-
-
Method Details
-
getInstance
Creates a new instance of a SQL manager.- Parameters:
classname
- the classname of the SQL manager- Returns:
- a new instance of the SQL manager
-
replaceProjectPattern
Replaces the project search pattern in SQL queries by the pattern _ONLINE_ or _OFFLINE_ depending on the specified project ID.- Parameters:
projectId
- the ID of the current projectquery
- the SQL query- Returns:
- String the SQL query with the table key search pattern replaced
-
closeAll
Attempts to close the connection, statement and result set after a statement has been executed.- Parameters:
dbc
- the current database contextcon
- the JDBC connectionstmnt
- the statementres
- the result set
-
getBytes
Retrieves the value of the designated column in the current row of this ResultSet object as a byte array in the Java programming language.The bytes represent the raw values returned by the driver. Overwrite this method if another database server requires a different handling of byte attributes in tables.
- Parameters:
res
- the result setattributeName
- the name of the table attribute- Returns:
- byte[] the column value; if the value is SQL NULL, the value returned is null
- Throws:
SQLException
- if a database access error occurs
-
getConnection
Returns a JDBC connection from the connection pool.Use this method to get a connection for reading/writing project independent data.
- Parameters:
dbc
- the current database context- Returns:
- a JDBC connection
- Throws:
SQLException
- if the project id is not supported
-
getPreparedStatement
public PreparedStatement getPreparedStatement(Connection con, CmsProject project, String queryKey) throws SQLException Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query and the CmsProject.- Parameters:
con
- the JDBC connectionproject
- the specified CmsProjectqueryKey
- the key of the SQL query- Returns:
- PreparedStatement a new PreparedStatement containing the pre-compiled SQL statement
- Throws:
SQLException
- if a database access error occurs
-
getPreparedStatement
public PreparedStatement getPreparedStatement(Connection con, CmsUUID projectId, String queryKey) throws SQLException Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query and the project-ID.- Parameters:
con
- the JDBC connectionprojectId
- the ID of the specified CmsProjectqueryKey
- the key of the SQL query- Returns:
- PreparedStatement a new PreparedStatement containing the pre-compiled SQL statement
- Throws:
SQLException
- if a database access error occurs
-
getPreparedStatement
Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query.- Parameters:
con
- the JDBC connectionqueryKey
- the key of the SQL query- Returns:
- PreparedStatement a new PreparedStatement containing the pre-compiled SQL statement
- Throws:
SQLException
- if a database access error occurs
-
getPreparedStatementForSql
public PreparedStatement getPreparedStatementForSql(Connection con, String query) throws SQLException Returns a PreparedStatement for a JDBC connection specified by the SQL query.- Parameters:
con
- the JDBC connectionquery
- the SQL query- Returns:
- PreparedStatement a new PreparedStatement containing the pre-compiled SQL statement
- Throws:
SQLException
- if a database access error occurs
-
init
Initializes this SQL manager.- Parameters:
driverType
- the type ID of the driver (vfs,user,project or history) from where this SQL manager is referencedpoolUrl
- the pool URL to get connections from the JDBC driver manager
-
readQuery
Searches for the SQL query with the specified key and CmsProject.- Parameters:
project
- the specified CmsProjectqueryKey
- the key of the SQL query- Returns:
- the the SQL query in this property list with the specified key
-
readQuery
Searches for the SQL query with the specified key and project-ID.For projectIds ≠ 0, the pattern
QUERY_PROJECT_SEARCH_PATTERN
in table names of queries is replaced with "_ONLINE_" or "_OFFLINE_" to choose the right database tables for SQL queries that are project dependent!- Parameters:
projectId
- the ID of the specified CmsProjectqueryKey
- the key of the SQL query- Returns:
- the the SQL query in this property list with the specified key
-
readQuery
Searches for the SQL query with the specified key.- Parameters:
queryKey
- the SQL query key- Returns:
- the the SQL query in this property list with the specified key
-
setBytes
Sets the designated parameter to the given Java array of bytes.The driver converts this to an SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARY values) when it sends it to the database.
- Parameters:
statement
- the PreparedStatement where the content is setpos
- the first parameter is 1, the second is 2, ...content
- the parameter value- Throws:
SQLException
- if a database access error occurs
-
validateEmpty
Replaces null or empty Strings with a String with one space character" "
.- Parameters:
value
- the string to validate- Returns:
- the validate string or a String with one space character if the validated string is null or empty
-
loadQueryProperties
Loads a Java properties hash containing SQL queries.- Parameters:
propertyFilename
- the package/filename of the properties hash
-
replaceQuerySearchPatterns
Replaces patterns ${XXX} by another property value, if XXX is a property key with a value.
-