Interface AdempiereDatabase

All Known Implementing Classes:
DB_Oracle, DB_PostgreSQL

public interface AdempiereDatabase
Interface for database adapter
Version:
$Id: AdempiereDatabase.java,v 1.5 2006/09/22 23:35:19 jjanke Exp $
Author:
Jorg Janke
  • Field Details

    • LOCK_TIME_OUT

      static final int LOCK_TIME_OUT
      default lock timeout, 60 seconds
      See Also:
    • MAX_OBJECT_NAME_LENGTH

      static final int MAX_OBJECT_NAME_LENGTH
      See Also:
    • CMD_CREATE_USER

      static final int CMD_CREATE_USER
      Create User commands
      See Also:
    • CMD_CREATE_DATABASE

      static final int CMD_CREATE_DATABASE
      Create Database/Schema Commands
      See Also:
    • CMD_DROP_DATABASE

      static final int CMD_DROP_DATABASE
      Drop Database/Schema Commands
      See Also:
  • Method Details

    • getName

      String getName()
      Get Database Name
      Returns:
      database short name
    • getDescription

      String getDescription()
      Get Database Description
      Returns:
      database long name and version
    • getDriver

      Driver getDriver() throws SQLException
      Get and register Database Driver
      Returns:
      Driver
      Throws:
      SQLException
    • getStandardPort

      int getStandardPort()
      Get Standard JDBC Port
      Returns:
      standard port
    • getConnectionURL

      String getConnectionURL(CConnection connection)
      Get Database Connection String
      Parameters:
      connection - Connection Descriptor
      Returns:
      connection String
    • getConnectionURL

      String getConnectionURL(String dbHost, int dbPort, String dbName, String userName)
      Get Connection URL
      Parameters:
      dbHost - db Host
      dbPort - db Port
      dbName - db Name
      userName - user name
      Returns:
      url
    • getConnectionURL

      String getConnectionURL(String connectionURL, String userName)
      Get Database Connection URL
      Parameters:
      connectionURL - Connection URL
      userName - user name
      Returns:
      connection URL
    • getCatalog

      String getCatalog()
      Get JDBC Catalog
      Returns:
      catalog
    • getSchema

      String getSchema()
      Get JDBC Schema
      Returns:
      schema
    • supportsBLOB

      boolean supportsBLOB()
      Supports BLOB
      Returns:
      true if BLOB is supported
    • toString

      String toString()
      String Representation
      Overrides:
      toString in class Object
      Returns:
      info
    • convertStatement

      String convertStatement(String oraStatement)
      Convert an individual Oracle syntax statements to target database statement syntax
      Parameters:
      oraStatement - oracle statement
      Returns:
      converted Statement
    • isSupported

      boolean isSupported(String sql)
      Check if DBMS support the sql statement
      Parameters:
      sql - SQL statement
      Returns:
      true: yes
    • getConstraintType

      String getConstraintType(Connection conn, String tableName, String IXName)
      Get constraint type associated with the index
      Parameters:
      conn - connection
      tableName - table name
      IXName - Index name
      Returns:
      String[0] = 0: do not know, 1: Primary Key 2: Foreign Key String[1] - String[n] = Constraint Name
    • getAlternativeSQL

      String getAlternativeSQL(int reExNo, String msg, String sql)
      Check and generate an alternative SQL
      Parameters:
      reExNo - number of re-execution
      msg - previous execution error message
      sql - previous executed SQL
      Returns:
      String, the alternative SQL, null if no alternative
    • getSystemUser

      String getSystemUser()
      Get Name of System User
      Returns:
      e.g. sa, system
    • getSystemDatabase

      String getSystemDatabase(String databaseName)
      Get Name of System Database
      Parameters:
      databaseName - database Name
      Returns:
      e.g. master or database Name
    • TO_DATE

      String TO_DATE(Timestamp time, boolean dayOnly)
      Create SQL TO Date statement for Timestamp
      Parameters:
      time - Date to be converted
      dayOnly - true if time should be set to 00:00:00
      Returns:
      to date function
    • TO_CHAR

      String TO_CHAR(String columnName, int displayType, String AD_Language)
      Create SQL for formatted Date, Number
      Parameters:
      columnName - the column name in the SQL
      displayType - Display Type
      AD_Language - 6 character language setting (from Env.LANG_*)
      Returns:
      TRIM(TO_CHAR(columnName,'999G999G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')) or TRIM(TO_CHAR(columnName,'TM9')) depending on DisplayType and Language
      See Also:
    • TO_NUMBER

      String TO_NUMBER(BigDecimal number, int displayType)
      Return number as string for INSERT statements with correct precision
      Parameters:
      number - number
      displayType - display Type
      Returns:
      number as string
    • TO_JSON

      String TO_JSON(String value)
      Return string as JSON object for INSERT statements
      Parameters:
      value -
      Returns:
      value as JSON
    • getJSONCast

      String getJSONCast()
      Returns:
      string with right casting for JSON inserts
    • getNextID

      int getNextID(String Name, String trxName)
      Get next sequence number in this Sequence
      Parameters:
      Name - Sequence name
      trxName - Transaction name
    • getNextID

      int getNextID(String Name)
      Get next sequence number in this Sequence
      Parameters:
      Name - Sequence name
    • createSequence

      boolean createSequence(String name, int increment, int minvalue, int maxvalue, int start, String trxName)
      Create Native Sequence
      Parameters:
      name - Sequence Name
      increment -
      minvalue -
      maxvalue -
      start -
      trxName -
    • getCommands

      String[] getCommands(int cmdType)
      Get SQL Commands.
              The following variables are resolved:
      Parameters:
      cmdType - CMD_CREATE_USER, CMD_CREATE_DATABASE or CMD_DROP_DATABASE
      Returns:
      array of commands to be executed
    • getCachedConnection

      Connection getCachedConnection(CConnection connection, boolean autoCommit, int transactionIsolation) throws Exception
      Get Cached Connection on Server
      Parameters:
      connection - info
      autoCommit - true if autocommit connection
      transactionIsolation - transaction isolation level
      Returns:
      connection or null
      Throws:
      Exception
    • getDriverConnection

      Connection getDriverConnection(CConnection connection) throws SQLException
      Get Connection from Driver
      Parameters:
      connection - info
      Returns:
      connection or null
      Throws:
      SQLException
    • getDriverConnection

      Connection getDriverConnection(String dbUrl, String dbUid, String dbPwd) throws SQLException
      Get Driver Connection
      Parameters:
      dbUrl - URL
      dbUid - user
      dbPwd - password
      Returns:
      connection
      Throws:
      SQLException
    • getDataSource

      DataSource getDataSource(CConnection connection)
      Create DataSource
      Parameters:
      connection - connection
      Returns:
      data source
    • getStatus

      String getStatus()
      Get Status
      Returns:
      status info or null if no local datasource available
    • close

      void close()
      Close
    • getConvert

      Convert getConvert()
      Get Convert implementation for this DB adapter
      Returns:
      Convert instance
    • isQueryTimeoutSupported

      boolean isQueryTimeoutSupported()
      Returns:
      true if jdbc driver support statement timeout
    • isPagingSupported

      boolean isPagingSupported()
      Is the database have sql extension that return a subset of the query result
      Returns:
      true if DB support paging SQL
    • addPagingSQL

      String addPagingSQL(String sql, int start, int end)
      modify sql to return a subset of the query result. use 1 base index for start and end parameter
      Parameters:
      sql -
      start -
      end -
      Returns:
      SQL with added paging clause
    • forUpdate

      boolean forUpdate(PO po, int timeout)
      Lock PO for update
      Parameters:
      po -
      timeout -
      Returns:
      true if lock is granted
    • getNameOfUniqueConstraintError

      String getNameOfUniqueConstraintError(Exception e)
      Parameters:
      e -
      Returns:
      unique constraint name
    • getForeignKeyConstraint

      String getForeignKeyConstraint(Exception e)

      The "child record found error" contains the foreign key constraint name after the second occurrence of the opening double quote: ["].

      Example:

      ERROR: update or delete on table "m_product_category" violates foreign key constraint "mprodcategory_mdiscountsbreak" on table "m_discountschemabreak" Detail: Key (m_product_category_id)=(50000) is still referenced from table "m_discountschemabreak".

      Parameters:
      e -
      Returns:
      constraint name
    • subsetClauseForCSV

      String subsetClauseForCSV(String columnName, String csv)
      Parameters:
      columnName -
      csv - comma separated value
      Returns:
      subset sql clause
    • intersectClauseForCSV

      String intersectClauseForCSV(String columnName, String csv)
      Parameters:
      columnName -
      csv - comma separated value
      Returns:
      intersect sql clause
    • intersectClauseForCSV

      String intersectClauseForCSV(String columnName, String csv, boolean isNotClause)
      Parameters:
      columnName -
      csv - comma separated value
      isNotClause -
      Returns:
      intersect sql clause
    • quoteColumnName

      default String quoteColumnName(String columnName)
      Quote column name if necessary (usually to avoid conflict with reserved keywords)
      Parameters:
      columnName -
      Returns:
      columnName or quoted columnName
    • isNativeMode

      default boolean isNativeMode()
      Returns:
      true if using native dialect, false if using oracle dialect
    • getNumericDataType

      String getNumericDataType()
      Returns:
      numeric data type name
    • getCharacterDataType

      String getCharacterDataType()
      Returns:
      fixed length character data type name
    • getVarcharDataType

      String getVarcharDataType()
      Returns:
      variable length character data type name
    • getVarcharLengthSuffix

      default String getVarcharLengthSuffix()
      Returns:
      variable length character data type suffix
    • getBlobDataType

      String getBlobDataType()
      Returns:
      binary large object data type name
    • getClobDataType

      String getClobDataType()
      Returns:
      character large object data type name
    • getJsonDataType

      String getJsonDataType()
      Returns:
      json object data type name
    • getTimestampDataType

      String getTimestampDataType()
      Returns:
      time stamp data type name
    • getTimestampWithTimezoneDataType

      String getTimestampWithTimezoneDataType()
      Returns:
      timestamp with time zone type name
    • getSQLCreate

      default String getSQLCreate(MTable table)
      Get create table SQL statement
      Parameters:
      table -
      Returns:
      create table DDL
    • TO_Blob

      String TO_Blob(byte[] blob)
      Convert blob to hex encoded string and return SQL function that will convert the hex encoded string back to blob
      Parameters:
      blob -
      Returns:
      SQL statement
    • getSQLDDL

      String getSQLDDL(MColumn column)
      Parameters:
      column -
      Returns:
      DDL SQL statement for column
    • getSQLAdd

      String getSQLAdd(MTable table, MColumn column)
      Parameters:
      table -
      column -
      Returns:
      add column SQL statement
    • getSQLModify

      String getSQLModify(MTable table, MColumn column, boolean setNullOption)
      Parameters:
      table -
      column -
      setNullOption -
      Returns:
      alter column SQL statement
    • isQueryTimeout

      default boolean isQueryTimeout(SQLException ex)
      Parameters:
      ex -
      Returns:
      true if ex is caused by query timeout
    • getTablePartitionService

      default ITablePartitionService getTablePartitionService()
      Get DB specific table partition support
      Returns:
      ITablePartitionService instance