|
||||||||
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 Map<String,String> |
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 String |
m_poolUrl
The pool URL to get connections from the JDBC driver manager, including DBCP's pool URL prefix. |
protected Map<String,String> |
m_queries
A map holding all SQL queries. |
protected static 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,
Connection con,
Statement stmnt,
ResultSet res)
Attempts to close the connection, statement and result set after a statement has been executed. |
byte[] |
getBytes(ResultSet res,
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. |
Connection |
getConnection(CmsDbContext dbc)
Returns a JDBC connection from the connection pool. |
static CmsSqlManager |
getInstance(String classname)
Creates a new instance of a SQL manager. |
PreparedStatement |
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. |
PreparedStatement |
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. |
PreparedStatement |
getPreparedStatement(Connection con,
String queryKey)
Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query. |
PreparedStatement |
getPreparedStatementForSql(Connection con,
String query)
Returns a PreparedStatement for a JDBC connection specified by the SQL query. |
void |
init(int driverType,
String poolUrl)
Initializes this SQL manager. |
protected void |
loadQueryProperties(String propertyFilename)
Loads a Java properties hash containing SQL queries. |
String |
readQuery(CmsProject project,
String queryKey)
Searches for the SQL query with the specified key and CmsProject. |
String |
readQuery(CmsUUID projectId,
String queryKey)
Searches for the SQL query with the specified key and project-ID. |
String |
readQuery(String queryKey)
Searches for the SQL query with the specified key. |
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 |
replaceQuerySearchPatterns()
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. |
String |
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String QUERY_PROJECT_SEARCH_PATTERN
protected Map<String,String> m_cachedQueries
protected int m_driverType
protected String m_poolUrl
protected Map<String,String> m_queries
Constructor Detail |
---|
public CmsSqlManager()
Method Detail |
---|
public static CmsSqlManager getInstance(String classname)
classname
- the classname of the SQL manager
protected static String replaceProjectPattern(CmsUUID projectId, String query)
projectId
- the ID of the current projectquery
- the SQL query
public void closeAll(CmsDbContext dbc, Connection con, Statement stmnt, ResultSet res)
dbc
- the current database contextcon
- the JDBC connectionstmnt
- the statementres
- the result setpublic byte[] getBytes(ResultSet res, String attributeName) throws 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
SQLException
- if a database access error occurspublic Connection getConnection(CmsDbContext dbc) throws SQLException
Use this method to get a connection for reading/writing project independent data.
dbc
- the current database context
SQLException
- if the project id is not supportedpublic PreparedStatement getPreparedStatement(Connection con, CmsProject project, String queryKey) throws SQLException
con
- the JDBC connectionproject
- the specified CmsProjectqueryKey
- the key of the SQL query
SQLException
- if a database access error occurspublic PreparedStatement getPreparedStatement(Connection con, CmsUUID projectId, String queryKey) throws SQLException
con
- the JDBC connectionprojectId
- the ID of the specified CmsProjectqueryKey
- the key of the SQL query
SQLException
- if a database access error occurspublic PreparedStatement getPreparedStatement(Connection con, String queryKey) throws SQLException
con
- the JDBC connectionqueryKey
- the key of the SQL query
SQLException
- if a database access error occurspublic PreparedStatement getPreparedStatementForSql(Connection con, String query) throws SQLException
con
- the JDBC connectionquery
- the SQL query
SQLException
- if a database access error occurspublic void init(int driverType, 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 String readQuery(CmsProject project, String queryKey)
project
- the specified CmsProjectqueryKey
- the key of the SQL query
public String readQuery(CmsUUID projectId, 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 String readQuery(String queryKey)
queryKey
- the SQL query key
public void setBytes(PreparedStatement statement, int pos, byte[] content) throws 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
SQLException
- if a database access error occurspublic String validateEmpty(String value)
" "
.
value
- the string to validate
protected void loadQueryProperties(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 |