Class DerbyDictionary

All Implemented Interfaces:
JoinSyntaxes, Configurable, IdentifierConfiguration, ConnectionDecorator, LoggingConnectionDecorator.SQLWarningHandler

public class DerbyDictionary extends AbstractDB2Dictionary
Dictionary for Apache Derby (formerly Cloudscape).
  • Field Details

    • shutdownOnClose

      public boolean shutdownOnClose
      If true, we will shutdown the embedded database when closing the DataSource.
  • Constructor Details

    • DerbyDictionary

      public DerbyDictionary()
  • Method Details

    • getExtractDateTimeFieldFunction

      public String getExtractDateTimeFieldFunction(DateTimeExtractField extField)
      Derby has no EXTRACT, but a function per field. QUARTER is derived from the month, and WEEK, the ISO-8601 week, is computed arithmetically from the year, month and day.
      Overrides:
      getExtractDateTimeFieldFunction in class DBDictionary
    • connectedConfiguration

      public void connectedConfiguration(Connection conn) throws SQLException
      Description copied from class: DBDictionary
      This method is called when the dictionary first sees any connection. It is used to initialize dictionary metadata if needed. If you override this method, be sure to call super.connectedConfiguration.
      Overrides:
      connectedConfiguration in class DBDictionary
      Throws:
      SQLException
    • getCreateSequenceSQL

      public String[] getCreateSequenceSQL(Sequence seq)
      Derby creates a sequence of type INTEGER unless told otherwise, which runs out at 2^31 - 1. Use BIGINT, as the values are read as longs anyway. Derby accepts the sequence elements in any order, so the clause is appended.
      Overrides:
      getCreateSequenceSQL in class DBDictionary
    • getSequenceIncrement

      public Long getSequenceIncrement(Connection conn, Sequence seq) throws SQLException
      Reads the increment of the sequence from SYS.SYSSEQUENCES. Without a schema the sequence is looked up in the current schema, where Derby resolves an unqualified name.
      Overrides:
      getSequenceIncrement in class DBDictionary
      Returns:
      null if this dictionary cannot read the increment of a sequence (the default), a value below 1 if the sequence was not found, the increment otherwise
      Throws:
      SQLException
    • getDropSequenceSQL

      public String[] getDropSequenceSQL(Sequence seq)
      Derby requires the RESTRICT keyword on DROP SEQUENCE.
      Overrides:
      getDropSequenceSQL in class DBDictionary
    • getSequencesSQL

      protected String getSequencesSQL(String schemaName, String sequenceName)
      Derby lists sequences in SYS.SYSSEQUENCES. Without a schema the query is restricted to the current schema, as an unqualified sequence lives there; the SYS schema holds the internal sequences of identity columns, which never belong to the application.
      Overrides:
      getSequencesSQL in class DBDictionary
    • getSequencesSQL

      protected String getSequencesSQL(DBIdentifier schemaName, DBIdentifier sequenceName)
      Overrides:
      getSequencesSQL in class DBDictionary
    • appendSelectRange

      protected void appendSelectRange(SQLBuffer buf, long start, long end, boolean subselect)
      Appends a range to the given buffer.
      A range query is never appended to a subselct clause.
      If this dictionary supports offset and limit on queries then the syntax is
      [ OFFSET {start} ROWS ]
      [ FETCH NEXT {end-start} ROWS ONLY ]
      
      Otherwise, the offset is not used and the syntax is
      [ FETCH FIRST {end} ROWS ONLY ]
      
      Overrides:
      appendSelectRange in class DBDictionary
      Parameters:
      buf - the SQL buffer to be appended
      start - starting offset. 0 means offset is not used.
      end - number of rows to be fetched. Long.MAX_VALUE means no limit.
      subselect - flags if the buffer represents a SQL Subquery clause
    • getStringCastTypeName

      public String getStringCastTypeName()
      Derby rejects a VARCHAR without a length, so give the cast written for CAST(... AS STRING) the same length as the other VARCHAR casts of this dictionary.
      Overrides:
      getStringCastTypeName in class DBDictionary
    • appendLength

      protected void appendLength(SQLBuffer buf, int type)
      Derby rejects a VARCHAR without a length, so give the casts written for DBDictionary.requiresCastForComparisons and DBDictionary.requiresCastForMathFunctions the same length as the other VARCHAR casts of this dictionary.
      Overrides:
      appendLength in class DBDictionary
    • left

      public void left(SQLBuffer buf, FilterValue str, FilterValue length)
      Derby has no LEFT function, so render it with SUBSTR. SUBSTR fails when the length goes past the end of the string, where LEFT returns the whole string, so that case is handled separately.
      Overrides:
      left in class DBDictionary
    • right

      public void right(SQLBuffer buf, FilterValue str, FilterValue length)
      Derby has no RIGHT function, so render it with SUBSTR. SUBSTR fails when the start goes before the beginning of the string, where RIGHT returns the whole string, so that case is handled separately.
      Overrides:
      right in class DBDictionary
    • closeDataSource

      public void closeDataSource(DataSource dataSource)
      Description copied from class: DBDictionary
      Closes the specified DataSource and releases any resources associated with it.
      Overrides:
      closeDataSource in class DBDictionary
      Parameters:
      dataSource - the DataSource to close
    • isFatalException

      public boolean isFatalException(int subtype, SQLException ex)
      Description copied from class: DBDictionary
      Determine if the given SQL Exception is fatal or recoverable (such as a timeout). This implementation always returns true (i.e. all exceptions are fatal). The current dictionary implementation can overwrite this method to mark certain exception conditions as recoverable error.
      Overrides:
      isFatalException in class DBDictionary
      Parameters:
      subtype - A constant indicating the category of error as defined in StoreException.
      ex - original SQL Exception as raised by the database driver.
      Returns:
      false if the error is fatal.
    • applyRange

      public int applyRange(Select select, int count)
      Applies range calculation on the actual number of rows selected by a COUNT(*) query. A range query may use either only the limit or both offset and limit based on database dictionary support and accordingly the number of rows in the result set needs to be modified.
      Overrides:
      applyRange in class DBDictionary
      Parameters:
      select -
      count -
      Returns:
    • getPreferredType

      public int getPreferredType(int type)
      Derby doesn't support SQL-2003 'WITH TIMEZONE' nor the respective JDBC types.
      Overrides:
      getPreferredType in class DBDictionary