org.objectweb.jorm.mapper.rdb.adapter
Class PostgresAdapter

java.lang.Object
  extended by org.objectweb.jorm.mapper.rdb.adapter.BasicRdbAdapter
      extended by org.objectweb.jorm.mapper.rdb.adapter.PostgresAdapter
All Implemented Interfaces:
PreparedStatementAdapter, RdbAdapter, ResultsetAdapter, SequenceAdapter, TypeAdapter, ValueAsSQLStringAdapter

public class PostgresAdapter
extends BasicRdbAdapter

Author:
S. Chassande-Barrioz

Field Summary
private static java.lang.String POSTGRESCONCAT
           
 
Fields inherited from class org.objectweb.jorm.mapper.rdb.adapter.BasicRdbAdapter
logger, name
 
Fields inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.RdbAdapter
NOSIZE, RANGEATEND, RANGEATSTART, 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
 
Constructor Summary
PostgresAdapter()
           
 
Method Summary
 void escapeFunctionClose(java.lang.StringBuffer sb)
          Modifies the end of a function expression for the escape syntax.
 void escapeFunctionOpen(java.lang.StringBuffer sb)
          Postgres does not support the escape syntax
protected  boolean existRelation(java.sql.Connection connection, java.lang.String relName, java.lang.String[] relationTypes)
           
 boolean existSequence(java.sql.Connection connection, java.lang.String seqName)
          checks the sequence existence
 int fetchResultSetSize(java.sql.ResultSet rs)
          This calculates the size of a result set.
 java.lang.String getArrayElementAsSQLString(java.lang.Object elem, int elemTypeCode)
           
 java.lang.String getArrayValueAsSQLStringBegin()
           
 java.lang.String getArrayValueAsSQLStringEnd()
           
 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 getIndexedLocateExpression(java.lang.String instring, 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.
 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 getSqlType(int typeCode, boolean usedInPK, int size, int scale)
          This method returns the SQL type linked to the java type
 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 getValueAsSQLString(boolean value)
          This method returns a String value that represents a boolean value.
 java.lang.String getValueAsSQLString(java.lang.Object value, int typeCode)
          This method returns a String value that represents a value.
protected  void modifyQueryWithRange(java.lang.StringBuffer sb, boolean rangeStart, boolean rangeSize)
           
protected  void modifySelectClauseWithRange(java.lang.StringBuffer sb, boolean rangeStart, boolean rangeSize)
           
 boolean supportBatchPreparedStatement()
          Indicates if the driver supports the batch of PreparedStatement
 
Methods inherited from class org.objectweb.jorm.mapper.rdb.adapter.BasicRdbAdapter
appendClause, existTable, existView, getArray, getArrayToString, getArrayToStringBegin, getArrayToStringEnd, getArrayToStringSeparator, getArrayValueAsSQLString, getArrayValueAsSQLString, getArrayValueAsSQLStringSeparator, getBigDecimal, getBigInteger, getBoolean, getByte, getByteArray, getCACHEkeyWord, getChar, getCharArray, getCharArray, getColumnAliasExpr, getCreateSequence, getCreateSequence, getDate, getDate, getDouble, getFloat, getFromClause, getFromClause, getFromClause, getINCREMENTkeyWord, getInt, getLengthOperator, getLong, getManyNextValInSequence, getName, getNextValInSequence, getOboolean, getObyte, getOchar, getOdouble, getOfloat, getOint, getOlong, getOshort, getQuery, getQuery, getSerialized, getShort, getSqlTypeCode, getSqlTypeCode, getSTARTkeyWord, getString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, handleOrderBy, setArray, setBigDecimal, setBigInteger, setBoolean, setByte, setByteArray, setChar, setCharArray, setDate, setDouble, setFloat, setInt, setLogger, setLong, setNull, setOboolean, setObyte, setOchar, setOdouble, setOfloat, setOint, setOlong, setOshort, setSerialized, setShort, setString, supportArray, writeColumnAlias, writeTableAlias
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSTGRESCONCAT

private static final java.lang.String POSTGRESCONCAT
See Also:
Constant Field Values
Constructor Detail

PostgresAdapter

public PostgresAdapter()
Method Detail

supportBatchPreparedStatement

public boolean supportBatchPreparedStatement()
Description copied from interface: RdbAdapter
Indicates if the driver supports the batch of PreparedStatement

Specified by:
supportBatchPreparedStatement in interface RdbAdapter
Overrides:
supportBatchPreparedStatement in class BasicRdbAdapter

getSqlType

public java.lang.String getSqlType(int typeCode,
                                   boolean usedInPK,
                                   int size,
                                   int scale)
                            throws RdbAdapterException
Description copied from interface: TypeAdapter
This method returns the SQL type linked to the java type

Specified by:
getSqlType in interface TypeAdapter
Overrides:
getSqlType in class BasicRdbAdapter
Parameters:
typeCode - is the type code of the java type
usedInPK - indicates if the type has to be used into a Primary key
size - can indicates the expected size of the type. If it equals to NO_SIZE that means no size is expected. This parameter can be used for float, BigXXX numbers, String,...
scale - can indicates the expected scale of the type. If it equals to NO_SIZE that means no scale is expected.
Throws:
RdbAdapterException

getValueAsSQLString

public java.lang.String getValueAsSQLString(boolean value)
Description copied from interface: ValueAsSQLStringAdapter
This method returns a String value that represents a boolean value. This method can be used for the constant parameters of SQL queries.

Specified by:
getValueAsSQLString in interface ValueAsSQLStringAdapter
Overrides:
getValueAsSQLString in class BasicRdbAdapter

getValueAsSQLString

public java.lang.String getValueAsSQLString(java.lang.Object value,
                                            int typeCode)
Description copied from interface: ValueAsSQLStringAdapter
This method returns a String value that represents a value. This method can be used for the constant parameters of SQL queries.

Specified by:
getValueAsSQLString in interface ValueAsSQLStringAdapter
Overrides:
getValueAsSQLString in class BasicRdbAdapter
typeCode - is the java type of the value

escapeFunctionOpen

public void escapeFunctionOpen(java.lang.StringBuffer sb)
Postgres does not support the escape syntax

Specified by:
escapeFunctionOpen in interface RdbAdapter
Overrides:
escapeFunctionOpen in class BasicRdbAdapter
Parameters:
sb - the function expression to be escaped

escapeFunctionClose

public void escapeFunctionClose(java.lang.StringBuffer sb)
Description copied from interface: RdbAdapter
Modifies the end of a function expression for the escape syntax.

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

Specified by:
escapeFunctionClose in interface RdbAdapter
Overrides:
escapeFunctionClose in class BasicRdbAdapter
Parameters:
sb - the function expression to be escaped

getConcatExpression

public java.lang.String getConcatExpression(java.lang.String op1,
                                            java.lang.String op2)
Specified by:
getConcatExpression in interface RdbAdapter
Overrides:
getConcatExpression in class BasicRdbAdapter
Returns:
the use of the concat operator between two strings

getFirstLocateExpression

public java.lang.String getFirstLocateExpression(java.lang.String substring,
                                                 java.lang.String instring)
Description copied from interface: RdbAdapter
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).

Specified by:
getFirstLocateExpression in interface RdbAdapter
Overrides:
getFirstLocateExpression in class BasicRdbAdapter
Parameters:
substring - The substring searched
instring - The string in which to search the substring
Returns:
The corresponding relational expression.

getIndexedLocateExpression

public java.lang.String getIndexedLocateExpression(java.lang.String instring,
                                                   java.lang.String substring,
                                                   java.lang.String fromIndex)
                                            throws RdbAdapterException
Description copied from interface: RdbAdapter
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()

Specified by:
getIndexedLocateExpression in interface RdbAdapter
Overrides:
getIndexedLocateExpression in class BasicRdbAdapter
Parameters:
instring - 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

fetchResultSetSize

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

Specified by:
fetchResultSetSize in interface RdbAdapter
Overrides:
fetchResultSetSize in class BasicRdbAdapter
Parameters:
rs - the result set which the size must be returned
Throws:
java.sql.SQLException

existSequence

public boolean existSequence(java.sql.Connection connection,
                             java.lang.String seqName)
                      throws java.sql.SQLException
Description copied from interface: SequenceAdapter
checks the sequence existence

Specified by:
existSequence in interface SequenceAdapter
Overrides:
existSequence in class BasicRdbAdapter
Parameters:
connection - is the JDBC connection to use
seqName - is the sequence of the table
Returns:
true if the table exists, otherwise false.
Throws:
java.sql.SQLException

existRelation

protected boolean existRelation(java.sql.Connection connection,
                                java.lang.String relName,
                                java.lang.String[] relationTypes)
                         throws java.sql.SQLException
Overrides:
existRelation in class BasicRdbAdapter
Throws:
java.sql.SQLException

getSubqueryAlias

public java.lang.String getSubqueryAlias()
Description copied from interface: RdbAdapter
In the case the subquery needs to be aliased (Postgres), returns a string to be appended to the subquery.

Specified by:
getSubqueryAlias in interface RdbAdapter
Overrides:
getSubqueryAlias in class BasicRdbAdapter
Returns:
the String to be appended to the subquery

modifySelectClauseWithRange

protected void modifySelectClauseWithRange(java.lang.StringBuffer sb,
                                           boolean rangeStart,
                                           boolean rangeSize)
Overrides:
modifySelectClauseWithRange in class BasicRdbAdapter

modifyQueryWithRange

protected void modifyQueryWithRange(java.lang.StringBuffer sb,
                                    boolean rangeStart,
                                    boolean rangeSize)
Overrides:
modifyQueryWithRange in class BasicRdbAdapter

getRangeParametersAtStart

public int getRangeParametersAtStart()
Description copied from interface: RdbAdapter
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.

Specified by:
getRangeParametersAtStart in interface RdbAdapter
Overrides:
getRangeParametersAtStart in class BasicRdbAdapter
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.

getArrayValueAsSQLStringBegin

public java.lang.String getArrayValueAsSQLStringBegin()
Overrides:
getArrayValueAsSQLStringBegin in class BasicRdbAdapter

getArrayValueAsSQLStringEnd

public java.lang.String getArrayValueAsSQLStringEnd()
Overrides:
getArrayValueAsSQLStringEnd in class BasicRdbAdapter

getArrayElementAsSQLString

public java.lang.String getArrayElementAsSQLString(java.lang.Object elem,
                                                   int elemTypeCode)
Overrides:
getArrayElementAsSQLString in class BasicRdbAdapter