Package edu.ucsb.nceas.dbadapter
Class AbstractDatabase
java.lang.Object
edu.ucsb.nceas.dbadapter.AbstractDatabase
- Direct Known Subclasses:
OracleAdapter
,PostgresqlAdapter
,SqlserverAdapter
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
createObject
(String className) Instantiate a class using the name of the class at runtimeabstract String
The function name that gets the current date and time from the database serverabstract String
The function name that is used to return non-NULL valueabstract 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 tableabstract String
getPagedQuery
(String queryWithOrderBy, Integer start, Integer count) for generating a query for pagingabstract String
This method will return the sql command to get document list in xml_document in replication.abstract String
The character that the specific database implementation uses to indicate string literals in SQL.abstract long
getUniqueID
(Connection conn, String tableName) Unique ID generatorstatic void
the main routine used to test the dbadapter utility.MSSQL didn't support to_date function which to transfer a text string to date type.
-
Constructor Details
-
AbstractDatabase
public AbstractDatabase()
-
-
Method Details
-
getUniqueID
Unique ID generator- Parameters:
conn
- db connection in which the unique id was generatedtableName
- 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
The function name that gets the current date and time from the database server- Returns:
- return the current date and time function name
-
getIsNULLFunction
The function name that is used to return non-NULL value- Returns:
- return the non-NULL function name
-
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
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 selectedtableA
- first table in the jointableB
- second table in the joinjoinCriteria
- the criteria based on which the join will be madenonJoinCriteria
- all other criterias- Returns:
- return the string for teh select query
-
createObject
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
the main routine used to test the dbadapter utility. -
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
for generating a query for paging- Parameters:
queryWithOrderBy
- - the complete query with SELECT, FROM, WHERE and ORDER BY clausesstart
- the row number to start fromcount
- the number of records from start to return- Returns:
- query specific to the RDBMS in use
-