Class CmsSqlManager

java.lang.Object
org.opencms.db.CmsSqlManager
org.opencms.db.generic.CmsSqlManager
Direct Known Subclasses:
CmsSqlManager, CmsSqlManager, CmsSqlManager, CmsSqlManager, CmsSqlManager, CmsSqlManager, CmsSqlManager

public class CmsSqlManager extends CmsSqlManager
Generic (ANSI-SQL) implementation of the SQL manager.

Since:
6.0.0
  • Field Details

  • Constructor Details

    • CmsSqlManager

      public CmsSqlManager()
      Creates a new, empty SQL manager.

  • Method Details

    • getInstance

      public static CmsSqlManager getInstance(String classname)
      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

      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.

      Parameters:
      projectId - the ID of the current project
      query - the SQL query
      Returns:
      String the SQL query with the table key search pattern replaced
    • closeAll

      public 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.

      Parameters:
      dbc - the current database context
      con - the JDBC connection
      stmnt - the statement
      res - the result set
    • getBytes

      public byte[] getBytes(ResultSet res, String attributeName) throws SQLException
      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 set
      attributeName - 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

      Returns a PreparedStatement for a JDBC connection specified by the key of a SQL query and the CmsProject.

      Parameters:
      con - the JDBC connection
      project - the specified CmsProject
      queryKey - 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 connection
      projectId - the ID of the specified CmsProject
      queryKey - 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 connection
      queryKey - 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

      Returns a PreparedStatement for a JDBC connection specified by the SQL query.

      Parameters:
      con - the JDBC connection
      query - the SQL query
      Returns:
      PreparedStatement a new PreparedStatement containing the pre-compiled SQL statement
      Throws:
      SQLException - if a database access error occurs
    • init

      public void init(int driverType, String poolUrl)
      Initializes this SQL manager.

      Parameters:
      driverType - the type ID of the driver (vfs,user,project or history) from where this SQL manager is referenced
      poolUrl - the pool URL to get connections from the JDBC driver manager
    • readQuery

      public String readQuery(CmsProject project, String queryKey)
      Searches for the SQL query with the specified key and CmsProject.

      Parameters:
      project - the specified CmsProject
      queryKey - the key of the SQL query
      Returns:
      the the SQL query in this property list with the specified key
    • readQuery

      public String readQuery(CmsUUID projectId, String queryKey)
      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 CmsProject
      queryKey - the key of the SQL query
      Returns:
      the the SQL query in this property list with the specified key
    • readQuery

      public String readQuery(String queryKey)
      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

      public void setBytes(PreparedStatement statement, int pos, byte[] content) throws SQLException
      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 set
      pos - the first parameter is 1, the second is 2, ...
      content - the parameter value
      Throws:
      SQLException - if a database access error occurs
    • validateEmpty

      public String validateEmpty(String value)
      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

      protected void loadQueryProperties(String propertyFilename)
      Loads a Java properties hash containing SQL queries.

      Parameters:
      propertyFilename - the package/filename of the properties hash
    • replaceQuerySearchPatterns

      protected void replaceQuerySearchPatterns()
      Replaces patterns ${XXX} by another property value, if XXX is a property key with a value.