Class AbstractDatabase

java.lang.Object
edu.ucsb.nceas.dbadapter.AbstractDatabase
Direct Known Subclasses:
OracleAdapter, PostgresqlAdapter, SqlserverAdapter

public abstract class AbstractDatabase extends Object
Java offers uniform database access through the use of JDBC. But many databases still use different SQL implementations and conventions. Thus this class offers extended programming interface that all subclasses should implement to gain access to different databases. To add a new database adapter class you must create a new class Adapter that extends edu.ucsb.nceas.dbadapter.AbstarctDatabase (where dbname is the name of the database or database driver you wish to add to your application). AbstarctDatabase is an abstract class, thus the subclasses need to implement the abstract methods.
  • Constructor Details

    • AbstractDatabase

      public AbstractDatabase()
  • Method Details

    • getUniqueID

      public abstract long getUniqueID(Connection conn, String tableName) throws SQLException
      Unique ID generator
      Parameters:
      conn - db connection in which the unique id was generated
      tableName - the table which unique id was generate
      Returns:
      return the generated unique id as a long type
      Throws:
      SQLException -
      any SQLException that can be thrown during the db operation
    • getDateTimeFunction

      public abstract String getDateTimeFunction()
      The function name that gets the current date and time from the database server
      Returns:
      return the current date and time function name
    • getIsNULLFunction

      public abstract String getIsNULLFunction()
      The function name that is used to return non-NULL value
      Returns:
      return the non-NULL function name
    • getStringDelimiter

      public abstract String getStringDelimiter()
      The character that the specific database implementation uses to indicate string literals in SQL. This will usually be a single qoute (').
      Returns:
      return the string delimiter
    • toDate

      public String toDate(String dateString, String format)
      MSSQL didn't support to_date function which to transfer a text string to date type. But Oracle and Postsql do.
    • getLeftJoinQuery

      public abstract String getLeftJoinQuery(String selectFields, String tableA, String tableB, String joinCriteria, String nonJoinCriteria)
      Syntax for doing a left join Add 'a.' in front of the fields for first table and 'b.' in front of the fields for the second table
      Parameters:
      selectFields - fields that you want to be selected
      tableA - first table in the join
      tableB - second table in the join
      joinCriteria - the criteria based on which the join will be made
      nonJoinCriteria - all other criterias
      Returns:
      return the string for teh select query
    • createObject

      public static Object createObject(String className) throws Exception
      Instantiate a class using the name of the class at runtime
      Parameters:
      className - the fully qualified name of the class to instantiate
      Throws:
      Exception
    • main

      public static void main(String[] args)
      the main routine used to test the dbadapter utility.
    • getReplicationDocumentListSQL

      public abstract String getReplicationDocumentListSQL()
      This method will return the sql command to get document list in xml_document in replication. Because it involes outer join, so this method is very flexible.
      Returns:
    • getPagedQuery

      public abstract String getPagedQuery(String queryWithOrderBy, Integer start, Integer count)
      for generating a query for paging
      Parameters:
      queryWithOrderBy - - the complete query with SELECT, FROM, WHERE and ORDER BY clauses
      start - the row number to start from
      count - the number of records from start to return
      Returns:
      query specific to the RDBMS in use