|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.db.CmsSqlManager
org.opencms.db.generic.CmsSqlManager
public class CmsSqlManager
Generic (ANSI-SQL) implementation of the SQL manager.
Field Summary | |
---|---|
protected java.util.Map |
m_cachedQueries
A map to cache queries with replaced search patterns. |
protected int |
m_driverType
The type ID of the driver (vfs, user, project or history) from where this SQL manager is referenced. |
protected java.lang.String |
m_poolUrl
The pool URL to get connections from the JDBC driver manager, including DBCP's pool URL prefix. |
protected java.util.Map |
m_queries
A map holding all SQL queries. |
protected static java.lang.String |
QUERY_PROJECT_SEARCH_PATTERN
A pattern being replaced in SQL queries to generate SQL queries to access online/offline tables. |
Constructor Summary | |
---|---|
CmsSqlManager()
Creates a new, empty SQL manager. |
Method Summary | |
---|---|
void |
closeAll(CmsDbContext dbc,
java.sql.Connection con,
java.sql.Statement stmnt,
java.sql.ResultSet res)
Attempts to close the connection, statement and result set after a statement has been executed. |
byte[] |
getBytes(java.sql.ResultSet res,
java.lang.String attributeName)
Retrieves the value of the designated column in the current row of this ResultSet object as a byte array in the Java programming language. |
java.sql.Connection |
getConnection(CmsDbContext dbc)
Returns a JDBC connection from the connection pool. |
static CmsSqlManager |
getInstance(java.lang.String classname)
Creates a new instance of a SQL manager. |
java.sql.PreparedStatement |
getPreparedStatement(java.sql.Connection con,
CmsProject project,
java.lang.String queryKey)
Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query and the CmsProject. |
java.sql.PreparedStatement |
getPreparedStatement(java.sql.Connection con,
CmsUUID projectId,
java.lang.String queryKey)
Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query and the project-ID. |
java.sql.PreparedStatement |
getPreparedStatement(java.sql.Connection con,
java.lang.String queryKey)
Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query. |
java.sql.PreparedStatement |
getPreparedStatementForSql(java.sql.Connection con,
java.lang.String query)
Returns a PreparedStatement for a JDBC connection specified by the SQL query. |
void |
init(int driverType,
java.lang.String poolUrl)
Initializes this SQL manager. |
protected void |
loadQueryProperties(java.lang.String propertyFilename)
Loads a Java properties hash containing SQL queries. |
java.lang.String |
readQuery(CmsProject project,
java.lang.String queryKey)
Searches for the SQL query with the specified key and CmsProject. |
java.lang.String |
readQuery(CmsUUID projectId,
java.lang.String queryKey)
Searches for the SQL query with the specified key and project-ID. |
java.lang.String |
readQuery(java.lang.String queryKey)
Searches for the SQL query with the specified key. |
protected static java.lang.String |
replaceProjectPattern(CmsUUID projectId,
java.lang.String query)
Replaces the project search pattern in SQL queries by the pattern _ONLINE_ or _OFFLINE_ depending on the specified project ID. |
protected void |
replaceQuerySearchPatterns()
Replaces patterns ${XXX} by another property value, if XXX is a property key with a value. |
void |
setBytes(java.sql.PreparedStatement statement,
int pos,
byte[] content)
Sets the designated parameter to the given Java array of bytes. |
java.lang.String |
validateEmpty(java.lang.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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String QUERY_PROJECT_SEARCH_PATTERN
protected java.util.Map m_cachedQueries
protected int m_driverType
protected java.lang.String m_poolUrl
protected java.util.Map m_queries
Constructor Detail |
---|
public CmsSqlManager()
Method Detail |
---|
public static CmsSqlManager getInstance(java.lang.String classname)
classname
- the classname of the SQL manager
protected static java.lang.String replaceProjectPattern(CmsUUID projectId, java.lang.String query)
projectId
- the ID of the current projectquery
- the SQL query
public void closeAll(CmsDbContext dbc, java.sql.Connection con, java.sql.Statement stmnt, java.sql.ResultSet res)
dbc
- the current database contextcon
- the JDBC connectionstmnt
- the statementres
- the result setpublic byte[] getBytes(java.sql.ResultSet res, java.lang.String attributeName) throws java.sql.SQLException
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.
res
- the result setattributeName
- the name of the table attribute
java.sql.SQLException
- if a database access error occurspublic java.sql.Connection getConnection(CmsDbContext dbc) throws java.sql.SQLException
Use this method to get a connection for reading/writing project independent data.
dbc
- the current database context
java.sql.SQLException
- if the project id is not supportedpublic java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con, CmsProject project, java.lang.String queryKey) throws java.sql.SQLException
con
- the JDBC connectionproject
- the specified CmsProjectqueryKey
- the key of the SQL query
java.sql.SQLException
- if a database access error occurspublic java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con, CmsUUID projectId, java.lang.String queryKey) throws java.sql.SQLException
con
- the JDBC connectionprojectId
- the ID of the specified CmsProjectqueryKey
- the key of the SQL query
java.sql.SQLException
- if a database access error occurspublic java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con, java.lang.String queryKey) throws java.sql.SQLException
con
- the JDBC connectionqueryKey
- the key of the SQL query
java.sql.SQLException
- if a database access error occurspublic java.sql.PreparedStatement getPreparedStatementForSql(java.sql.Connection con, java.lang.String query) throws java.sql.SQLException
con
- the JDBC connectionquery
- the SQL query
java.sql.SQLException
- if a database access error occurspublic void init(int driverType, java.lang.String poolUrl)
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 managerpublic java.lang.String readQuery(CmsProject project, java.lang.String queryKey)
project
- the specified CmsProjectqueryKey
- the key of the SQL query
public java.lang.String readQuery(CmsUUID projectId, java.lang.String queryKey)
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!
projectId
- the ID of the specified CmsProjectqueryKey
- the key of the SQL query
public java.lang.String readQuery(java.lang.String queryKey)
queryKey
- the SQL query key
public void setBytes(java.sql.PreparedStatement statement, int pos, byte[] content) throws java.sql.SQLException
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.
statement
- the PreparedStatement where the content is setpos
- the first parameter is 1, the second is 2, ...content
- the parameter value
java.sql.SQLException
- if a database access error occurspublic java.lang.String validateEmpty(java.lang.String value)
" "
.
value
- the string to validate
protected void loadQueryProperties(java.lang.String propertyFilename)
propertyFilename
- the package/filename of the properties hashprotected void replaceQuerySearchPatterns()
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |