org.objectweb.jorm.mapper.rdb.adapter.api
Interface RdbAdapter

All Superinterfaces:
PreparedStatementAdapter, ResultsetAdapter, SequenceAdapter, TypeAdapter, ValueAsSQLStringAdapter
All Known Subinterfaces:
RdbAdapter
All Known Implementing Classes:
BasicRdbAdapter

public interface RdbAdapter
extends TypeAdapter, ResultsetAdapter, PreparedStatementAdapter, ValueAsSQLStringAdapter, SequenceAdapter

This interface permits to adapte the use of a JDBC driver and the SQL type for the non conformance of a Database.

Author:
S.Chassande-Barrioz

Field Summary
static int NOSIZE
           
static int RANGEATEND
           
static int RANGEATSTART
           
static int RANGEUNSUPPORTED
           
 
Fields inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.TypeAdapter
TYPE_NAMES, TYPECODE_ARRAY, TYPECODE_BIGDECIMAL, TYPECODE_BIGINTEGER, TYPECODE_BOOLEAN, TYPECODE_BYTE, TYPECODE_BYTEARRAY, TYPECODE_CHAR, TYPECODE_CHARARRAY, TYPECODE_DATE, TYPECODE_DOUBLE, TYPECODE_FLOAT, TYPECODE_INT, TYPECODE_LONG, TYPECODE_OBJBOOLEAN, TYPECODE_OBJBYTE, TYPECODE_OBJCHAR, TYPECODE_OBJDOUBLE, TYPECODE_OBJFLOAT, TYPECODE_OBJINT, TYPECODE_OBJLONG, TYPECODE_OBJSHORT, TYPECODE_SERIALIZED, TYPECODE_SHORT, TYPECODE_STRING
 
Method Summary
 void escapeFunctionClose(java.lang.StringBuffer function)
          Modifies the end of a function expression for the escape syntax.
 void escapeFunctionOpen(java.lang.StringBuffer function)
          Modifies the start of a function expression for the escape syntax.
 boolean existTable(java.sql.Connection connection, java.lang.String tableName)
          checks the table existence
 boolean existView(java.sql.Connection connection, java.lang.String viewName)
          checks the view existence
 int fetchResultSetSize(java.sql.ResultSet rs)
          This method calculates the size of a result set window.
 java.lang.String getColumnAliasExpr(java.lang.String aliasName)
          Returns a column alias expression.
 java.lang.String getConcatExpression(java.lang.String op1, java.lang.String op2)
           
 java.lang.String getFirstLocateExpression(java.lang.String substring, java.lang.String instring)
          Returns the expression for searching the position of the first occurrence of a substring in a string.
 java.lang.String getFromClause(java.util.List jts)
          Builds a from clause from a list of JoinedTable objects.
 java.lang.String getIndexedLocateExpression(java.lang.String inputString, java.lang.String substring, java.lang.String fromIndex)
          Returns the expression for searching the position of the first occurrence of a substring in a string starting from a given index.
 java.lang.String getLengthOperator()
           
 java.lang.String getName()
           
 java.lang.String getQuery(java.lang.String selectClause, java.util.List jts, java.lang.String whereClause, boolean rangeFrom, boolean rangeSize)
          Builds a query with join and table alias.
 java.lang.String getQuery(java.lang.String selectClause, java.lang.String fromClause, java.lang.String whereClause, java.lang.String orderBy, java.lang.String groupBy, boolean rangeStart, boolean rangeSize)
          Builds a query with join and table alias.
 int getRangeParametersAtStart()
          Indicates whether parameters corresponding to range queries (range start and size) are positioned at the start or at the end of the SQL query.
 java.lang.String getSubqueryAlias()
          In the case the subquery needs to be aliased (Postgres), returns a string to be appended to the subquery.
 java.lang.String handleOrderBy(java.lang.String query)
           
 void setLogger(Logger logger)
          Sets the corresponding Monolog logger.
 boolean supportBatchPreparedStatement()
          Indicates if the driver supports the batch of PreparedStatement
 void writeColumnAlias(java.lang.String alias, java.lang.StringBuffer sb)
          Append a column alias to an SQL expression.
 void writeTableAlias(java.lang.String alias, java.lang.StringBuffer sb)
          Append a table alias to an SQL expression.
 
Methods inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.TypeAdapter
getSqlType, getSqlTypeCode, getSqlTypeCode, supportArray
 
Methods inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.ResultsetAdapter
getArray, getBigDecimal, getBigInteger, getBoolean, getByte, getByteArray, getChar, getCharArray, getDate, getDate, getDouble, getFloat, getInt, getLong, getOboolean, getObyte, getOchar, getOdouble, getOfloat, getOint, getOlong, getOshort, getSerialized, getShort, getString
 
Methods inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.PreparedStatementAdapter
getArrayToString, setArray, setBigDecimal, setBigInteger, setBoolean, setByte, setByteArray, setChar, setCharArray, setDate, setDouble, setFloat, setInt, setLong, setNull, setOboolean, setObyte, setOchar, setOdouble, setOfloat, setOint, setOlong, setOshort, setSerialized, setShort, setString
 
Methods inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.ValueAsSQLStringAdapter
getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString
 
Methods inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.SequenceAdapter
existSequence, getCreateSequence, getCreateSequence, getManyNextValInSequence, getNextValInSequence
 

Field Detail

RANGEATSTART

public static final int RANGEATSTART
See Also:
Constant Field Values

RANGEATEND

public static final int RANGEATEND
See Also:
Constant Field Values

RANGEUNSUPPORTED

public static final int RANGEUNSUPPORTED
See Also:
Constant Field Values

NOSIZE

public static final int NOSIZE
See Also:
Constant Field Values
Method Detail

getName

public java.lang.String getName()
Returns:
The name of the RdbAdapter. This name is used in the factory to register the RdbAdapter instance. In addition it is supposes that the adapter is a part of the class name of the rdb adapter in respect to the following pattern: org.objectweb.jorm.mapper.rdb.XxxxAdapter where Xxxx is the adapter name with the upper first letter.

supportBatchPreparedStatement

public boolean supportBatchPreparedStatement()
Indicates if the driver supports the batch of PreparedStatement


fetchResultSetSize

public int fetchResultSetSize(java.sql.ResultSet rs)
                       throws java.sql.SQLException
This method calculates the size of a result set window. If this feature is not supported by a database or its jdbc driver, this method returns -1.

Parameters:
rs - the result set which the size must be returned
Throws:
java.sql.SQLException

escapeFunctionOpen

public void escapeFunctionOpen(java.lang.StringBuffer function)
Modifies the start of a function expression for the escape syntax.

The JDBC standard syntax is "fn{function}".

Parameters:
function - the function expression to be escaped

escapeFunctionClose

public void escapeFunctionClose(java.lang.StringBuffer function)
Modifies the end of a function expression for the escape syntax.

The JDBC standard syntax is "fn{function}".

Parameters:
function - the function expression to be escaped

getConcatExpression

public java.lang.String getConcatExpression(java.lang.String op1,
                                            java.lang.String op2)
Returns:
the use of the concat operator between two strings

getFirstLocateExpression

public java.lang.String getFirstLocateExpression(java.lang.String substring,
                                                 java.lang.String instring)
                                          throws RdbAdapterException
Returns the expression for searching the position of the first occurrence of a substring in a string.

Three main syntaxes are found: position(substr in str), locate(substr, srt) and instr(str, substr).

Parameters:
substring - The substring searched
instring - The string in which to search the substring
Returns:
The corresponding relational expression.
Throws:
RdbAdapterException

getIndexedLocateExpression

public java.lang.String getIndexedLocateExpression(java.lang.String inputString,
                                                   java.lang.String substring,
                                                   java.lang.String fromIndex)
                                            throws RdbAdapterException
Returns the expression for searching the position of the first occurrence of a substring in a string starting from a given index.

Two main syntaxes are found: instr() and locate()

Parameters:
inputString - The string in which to search the substring
substring - The substring searched
fromIndex - The index from which to start searching
Returns:
The corresponding relational expression.
Throws:
RdbAdapterException

getLengthOperator

public java.lang.String getLengthOperator()
                                   throws RdbAdapterException
Returns:
the name of the length operator
Throws:
RdbAdapterException

getQuery

public java.lang.String getQuery(java.lang.String selectClause,
                                 java.util.List jts,
                                 java.lang.String whereClause,
                                 boolean rangeFrom,
                                 boolean rangeSize)
Builds a query with join and table alias. The implementation must use writeTableAlias(String StringBuffer) method.

Parameters:
selectClause - is a string representation of the select clause
jts - is the tables with their join
whereClause - is a string representation of the where clause
rangeFrom - is the rank of the first row to be returned in case of a range limit, starting at 0
rangeSize - is the number of rows to be returned in case of a range limit. The convention is that Integer.MAX_VALUE means no range limit.

getQuery

public java.lang.String getQuery(java.lang.String selectClause,
                                 java.lang.String fromClause,
                                 java.lang.String whereClause,
                                 java.lang.String orderBy,
                                 java.lang.String groupBy,
                                 boolean rangeStart,
                                 boolean rangeSize)
Builds a query with join and table alias. The implementation must use writeTableAlias(String StringBuffer) method.

Parameters:
selectClause - is a string representation of the select clause
whereClause - is a string representation of the where clause
orderBy - is a string representation of the order by clause
groupBy - is a string representation of the group by clause
rangeStart - is the rank of the first row to be returned in case of a range limit, starting at 0
rangeSize - is the number of rows to be returned in case of a range limit. The convention is that Integer.MAX_VALUE means no range limit.

getFromClause

public java.lang.String getFromClause(java.util.List jts)
Builds a from clause from a list of JoinedTable objects.


writeTableAlias

public void writeTableAlias(java.lang.String alias,
                            java.lang.StringBuffer sb)
Append a table alias to an SQL expression. To be used when constructing the string expression of a from clause. For example, most database recognize the syntax 'select ... from R as ALIAS_FOR_R, S as ALIAS_FOR_S ... ' whereas Orabcle accepts the following syntax : 'select ... from R ALIAS_FOR_R, S ALIAS_FOR_S ... '

Parameters:
alias - The table alias
sb - The StringBuffer into which to write the alias.

writeColumnAlias

public void writeColumnAlias(java.lang.String alias,
                             java.lang.StringBuffer sb)
Append a column alias to an SQL expression. To be used when constructing the string expression of a select clause. For example, most database recognize the syntax 'select A as ALIAS_FOR_A, B as ALIAS_FOR_B ... ' whereas Orabcle accepts the following syntax : 'select A "ALIAS_FOR_A", B "ALIAS_FOR_B" '

Parameters:
alias - the column alias
sb - The StringBuffer into which to write the alias.

getColumnAliasExpr

public java.lang.String getColumnAliasExpr(java.lang.String aliasName)
Returns a column alias expression. To be used when constructing the string expression of a select clause. For example, most database recognize the syntax 'select A as ALIAS_FOR_A, B as ALIAS_FOR_B ... ' whereas Orabcle accepts the following syntax : 'select A "ALIAS_FOR_A", B "ALIAS_FOR_B" '

Parameters:
aliasName - the column alias

handleOrderBy

public java.lang.String handleOrderBy(java.lang.String query)

existTable

public boolean existTable(java.sql.Connection connection,
                          java.lang.String tableName)
                   throws java.sql.SQLException
checks the table existence

Parameters:
connection - is the JDBC connection to use
tableName - is the name of the table
Returns:
true if the table exists, otherwise false.
Throws:
java.sql.SQLException

existView

public boolean existView(java.sql.Connection connection,
                         java.lang.String viewName)
                  throws java.sql.SQLException
checks the view existence

Parameters:
connection - is the JDBC connection to use
viewName - is the name of the view
Returns:
true if the view exists, otherwise false.
Throws:
java.sql.SQLException

getSubqueryAlias

public java.lang.String getSubqueryAlias()
In the case the subquery needs to be aliased (Postgres), returns a string to be appended to the subquery.

Returns:
the String to be appended to the subquery

getRangeParametersAtStart

public int getRangeParametersAtStart()
Indicates whether parameters corresponding to range queries (range start and size) are positioned at the start or at the end of the SQL query.

Indeed, depending on the database, the SQL syntax may vary, and the parameters can either be put at the front or at the end.

Returns:
RANGEATSTART if the parameters are at the start, RANGEATEND if they are at the end, RANGEUNSUPPORTED if range queries are not supported by the adapter.

setLogger

public void setLogger(Logger logger)
Sets the corresponding Monolog logger.

Parameters:
logger - the Monolog logger attached to the RdbAdapter