de.unidu.is.pdatalog
Class PDatalogSQLFormatter

java.lang.Object
  extended byde.unidu.is.pdatalog.PDatalogSQLFormatter
All Implemented Interfaces:
SQLFormatter

public class PDatalogSQLFormatter
extends java.lang.Object
implements SQLFormatter

An formatter for pDatalog++ into SQL statements.

Since:
2003-10-08
Version:
$Revision: 1.6 $, $Date: 2005/02/28 22:27:55 $
Author:
Henrik Nottelmann

Field Summary
protected  SQLFormatter formatter
          The formatter to be used.
 
Constructor Summary
PDatalogSQLFormatter(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(Relation relation)
          Clear the specified relation, which means deletes all facts for that relation.
 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(int arity, java.lang.String relationName)
          Creates a relation table.
 void create(Relation relation)
          Creates a relation table.
 void create(java.lang.String tableName, java.lang.String[] cols, java.lang.String[] types)
          Creates a table.
 void dump(int arity, java.lang.String relationName)
          Dumps the content of the specified relation to STDOUT.
 void dump(int arity, java.lang.String relationName, java.io.PrintStream out)
          Dumps the content of the specified relation to the specified stream.
 void dump(Relation relation)
          Dumps the content of the specified relation to STDOUT.
 void dump(Relation relation, java.io.PrintStream out)
          Dumps the content of the specified relation to the specified stream.
 boolean equals(java.lang.Object obj)
           
 DB getDB()
          Returns the underlying DB object.
 java.lang.String getSelect(SQL sql)
          Returns a concrete select statement for this DB, obtained from the specified abstract SQL select statement.
 int hashCode()
           
 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 specified DB object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

formatter

protected SQLFormatter formatter
The formatter to be used.

Constructor Detail

PDatalogSQLFormatter

public PDatalogSQLFormatter(DB db)
Creates a new formatter.

Parameters:
db - DB parameters
Method Detail

create

public void create(Relation relation)
Creates a relation table.

Parameters:
relation - relation for which a table will be created

create

public void create(int arity,
                   java.lang.String relationName)
Creates a relation table.

Parameters:
arity - arity of the relation (number of arguments)
relationName - name of the relation

clear

public void clear(Relation relation)
Clear the specified relation, which means deletes all facts for that relation.

Parameters:
relation - relation to be cleared

dump

public void dump(Relation relation)
Dumps the content of the specified relation to STDOUT.

Parameters:
relation - relation to be dumped

dump

public void dump(int arity,
                 java.lang.String relationName)
Dumps the content of the specified relation to STDOUT.

Parameters:
arity - arity of the relation to be dumped
relationName - name of the relation to be dumped

dump

public void dump(Relation relation,
                 java.io.PrintStream out)
Dumps the content of the specified relation to the specified stream.

Parameters:
relation - relation to be dumped
out - stream to which the relation will be dumped

dump

public void dump(int arity,
                 java.lang.String relationName,
                 java.io.PrintStream out)
Dumps the content of the specified relation to the specified stream.

Parameters:
arity - arity of the relation to be dumped
relationName - name of the relation to be dumped
out - stream to which the relation will be dumped

clear

public void clear(java.lang.String tableName)
Description copied from interface: SQLFormatter
Clear the specified tables, which means deletes all rows.

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

close

public void close(java.sql.ResultSet rs)
Description copied from interface: SQLFormatter
Closes the specified ResultSet.

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

create

public void create(java.lang.String tableName,
                   java.lang.String[] cols,
                   java.lang.String[] types)
Description copied from interface: SQLFormatter
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

equals

public boolean equals(java.lang.Object obj)

getDB

public DB getDB()
Returns the underlying DB object.

Specified by:
getDB in interface SQLFormatter
Returns:
underlying DB object

getSelect

public java.lang.String getSelect(SQL sql)
Description copied from interface: SQLFormatter
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

hashCode

public int hashCode()

perform

public void perform(SQL sql,
                    java.lang.String resultTableName)
Description copied from interface: SQLFormatter
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
Description copied from interface: SQLFormatter
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

remove

public void remove(java.lang.String tableName)
Description copied from interface: SQLFormatter
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

setDB

public void setDB(DB db)
Sets the specified DB object.

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

toString

public java.lang.String toString()