de.unidu.is.sql
Class SQLFormatterImplementation

java.lang.Object
  extended byde.unidu.is.sql.SQLFormatterImplementation
All Implemented Interfaces:
SQLFormatter

public class SQLFormatterImplementation
extends java.lang.Object
implements SQLFormatter

The default implementation of a formatter for SQL statements.

A formatter converts an abstract SQL statement into an SQL string suitable for a specific database. This allows for bridging the subtle differences in the SQL syntax of the different relational database management systems.

This implemenation uses a configuration file, located in the directory conf/db relatively to the CLASSPATH. The name is the part of the JDBC URI between the first and the second colon.

Since:
2003-10-08
Version:
$Revision: 1.9 $, $Date: 2005/03/18 22:01:19 $
Author:
Henrik Nottelmann

Field Summary
protected  StreamPropertyMap config
          Property map for formatting SQL statements.
protected  DB db
          The DB parameters.
 
Constructor Summary
protected SQLFormatterImplementation(DB db)
          Creates a new formatter.
 
Method Summary
 void addIndex(java.lang.String tableName, java.lang.String indexName, java.lang.String[] cols, boolean[] textCols)
          Adds an index to the specified table.
 void clear(java.lang.String tableName)
          Clear the specified tables, which means deletes all rows.
 void close(java.sql.ResultSet rs)
          Closes the specified ResultSet.
 void create(java.lang.String tableName, java.lang.String[] cols, java.lang.String[] types)
          Creates a table.
 DB getDB()
          Returns the DB parameters.
 java.lang.String getSelect(SQL sql)
          Returns a concrete select statement for this DB, obtained from the specified abstract SQL select statement.
 void perform(SQL sql, java.lang.String resultTableName)
          Transforms the specified abstract SQL insert statement into a concrete SQL statement for this DB, and performs it.
 java.sql.ResultSet performQuery(SQL sql)
          Transforms the specified abstract SQL select statement into a concrete SQL statement for this DB, performs it, and returns a corresponding ResultSet.
 void remove(java.lang.String tableName)
          Removes the specified table.
 void setDB(DB db)
          Sets the DB parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db

protected DB db
The DB parameters.


config

protected StreamPropertyMap config
Property map for formatting SQL statements.

Constructor Detail

SQLFormatterImplementation

protected SQLFormatterImplementation(DB db)
Creates a new formatter.

Parameters:
db - DB parameters
Method Detail

create

public void create(java.lang.String tableName,
                   java.lang.String[] cols,
                   java.lang.String[] types)
Creates a table.

Specified by:
create in interface SQLFormatter
Parameters:
tableName - name of the table
cols - names of the columns
types - types of the columns, can be subject to substitution

clear

public void clear(java.lang.String tableName)
Clear the specified tables, which means deletes all rows.

Specified by:
clear in interface SQLFormatter
Parameters:
tableName - name of the table

perform

public void perform(SQL sql,
                    java.lang.String resultTableName)
Transforms the specified abstract SQL insert statement into a concrete SQL statement for this DB, and performs it.

Specified by:
perform in interface SQLFormatter
Parameters:
sql - abstract SQL statement
resultTableName - name of the result table (if null, the insert name from the SQL statement will be used)

performQuery

public java.sql.ResultSet performQuery(SQL sql)
                                throws java.sql.SQLException
Transforms the specified abstract SQL select statement into a concrete SQL statement for this DB, performs it, and returns a corresponding ResultSet.

Specified by:
performQuery in interface SQLFormatter
Parameters:
sql - abstract SQL statement
Returns:
result set
Throws:
java.sql.SQLException

close

public void close(java.sql.ResultSet rs)
Closes the specified ResultSet.

Specified by:
close in interface SQLFormatter
Parameters:
rs - result set

getSelect

public java.lang.String getSelect(SQL sql)
Returns a concrete select statement for this DB, obtained from the specified abstract SQL select statement.

Specified by:
getSelect in interface SQLFormatter
Parameters:
sql - abstract SQL statement
Returns:
concrete select statement for this DB

remove

public void remove(java.lang.String tableName)
Removes the specified table.

Specified by:
remove in interface SQLFormatter
Parameters:
tableName - name of the table to remove

addIndex

public void addIndex(java.lang.String tableName,
                     java.lang.String indexName,
                     java.lang.String[] cols,
                     boolean[] textCols)
Adds an index to the specified table.

Specified by:
addIndex in interface SQLFormatter
Parameters:
tableName - name of the table
indexName - name of the new index
cols - imvolved columns
textCols - flag indicating that the column is a text column

getDB

public DB getDB()
Returns the DB parameters.

Specified by:
getDB in interface SQLFormatter
Returns:
DB parameters

setDB

public void setDB(DB db)
Sets the DB parameters.

Specified by:
setDB in interface SQLFormatter
Parameters:
db - DB parameters