org.objectweb.jorm.mapper.rdb.adapter

Class PostgresAdapter

Implemented Interfaces:
PreparedStatementAdapter, RdbAdapter, ResultsetAdapter, SequenceAdapter, TypeAdapter, ValueAsSQLStringAdapter

public class PostgresAdapter
extends BasicRdbAdapter

Author:
S. Chassande-Barrioz

Field Summary

private static String
POSTGRESCONCAT

Fields inherited from class org.objectweb.jorm.mapper.rdb.adapter.BasicRdbAdapter

CONCAT, INDEXEDLOCATE, accountForNanos, name

Fields inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.RdbAdapter

NOSIZE

Fields inherited from interface org.objectweb.jorm.mapper.rdb.adapter.api.TypeAdapter

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, TYPE_NAMES

Constructor Summary

PostgresAdapter()

Method Summary

void
escapeFunctionClose(StringBuffer sb)
Modifies the end of a function expression for the escape syntax.
void
escapeFunctionOpen(StringBuffer sb)
Postgres does not support the escape syntax
protected boolean
existRelation(Connection connection, String relName, String[] relationTypes)
boolean
existSequence(Connection connection, String seqName)
checks the sequence existence
int
fetchResultSetSize(ResultSet rs)
This calculates the size of a result set.
String
getConcatExpression(String op1, String op2)
String
getFirstLocateExpression(String substring, String instring)
Returns the expression for searching the position of the first occurrence of a substring in a string.
String
getIndexedLocateExpression(String instring, String substring, String fromIndex)
Returns the expression for searching the position of the first occurrence of a substring in a string starting from a given index.
String
getSqlType(int typeCode, boolean usedInPK, int size, int scale)
This method returns the SQL type linked to the java type
String
getSubqueryAlias()
In the case the subquery needs to be aliased (Postgres), returns a string to be appended to the subquery.
String
getValueAsSQLString(Object value, int typeCode)
This method returns a String value that represents a value.
String
getValueAsSQLString(boolean value)
This method returns a String value that represents a boolean value.
protected void
modifyWhereClauseWithRange(StringBuffer sb, String _where, int rangeStart, int rangeSize)
boolean
supportBatchPreparedStatement()
Indicates if the driver supports the batch of PreparedStatement

Methods inherited from class org.objectweb.jorm.mapper.rdb.adapter.BasicRdbAdapter

escapeFunctionClose, escapeFunctionOpen, existRelation, existSequence, existTable, existView, fetchResultSetSize, getBigDecimal, getBigInteger, getBoolean, getByte, getByteArray, getCACHEkeyWord, getChar, getCharArray, getCharArray, getCharArray, getColumnAliasExpr, getConcatExpression, getCreateSequence, getCreateSequence, getDate, getDate, getDouble, getFirstLocateExpression, getFloat, getFromClause, getFromClause, getINCREMENTkeyWord, getIndexedLocateExpression, getInt, getLengthOperator, getLong, getName, getNextValInSequence, getOboolean, getObyte, getOchar, getOdouble, getOfloat, getOint, getOlong, getOshort, getQuery, getSTARTkeyWord, getSerialized, getShort, getSqlType, getSqlTypeCode, getSqlTypeCode, getString, getSubqueryAlias, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getValueAsSQLString, getWhereClause, handleOrderBy, modifySelectClauseWithRange, modifyWhereClauseWithRange, setBigDecimal, setBigInteger, setBoolean, setByte, setByteArray, setChar, setCharArray, setDate, setDouble, setFloat, setInt, setLong, setNull, setOboolean, setObyte, setOchar, setOdouble, setOfloat, setOint, setOlong, setOshort, setSerialized, setShort, setString, sqldate2date, supportBatchPreparedStatement, time2date, timestamp2date, writeColumnAlias, writeTableAlias

Field Details

POSTGRESCONCAT

private static final String POSTGRESCONCAT

Constructor Details

PostgresAdapter

public PostgresAdapter()

Method Details

escapeFunctionClose

public void escapeFunctionClose(StringBuffer sb)
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 interface BasicRdbAdapter

Parameters:


escapeFunctionOpen

public void escapeFunctionOpen(StringBuffer sb)
Postgres does not support the escape syntax
Specified by:
escapeFunctionOpen in interface RdbAdapter
Overrides:
escapeFunctionOpen in interface BasicRdbAdapter


existRelation

protected boolean existRelation(Connection connection,
                                String relName,
                                String[] relationTypes)
            throws SQLException
Overrides:
existRelation in interface BasicRdbAdapter


existSequence

public boolean existSequence(Connection connection,
                             String seqName)
            throws SQLException
checks the sequence existence
Specified by:
existSequence in interface SequenceAdapter
Overrides:
existSequence in interface BasicRdbAdapter

Parameters:
connection - is the JDBC connection to use
seqName - is the sequence of the table

Returns:
true if the table exists, otherwise false.


fetchResultSetSize

public int fetchResultSetSize(ResultSet rs)
            throws 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 interface BasicRdbAdapter

Parameters:
rs - the result set which the size must be returned


getConcatExpression

public String getConcatExpression(String op1,
                                  String op2)
Specified by:
getConcatExpression in interface RdbAdapter
Overrides:
getConcatExpression in interface BasicRdbAdapter

Returns:
the use of the concat operator between two strings


getFirstLocateExpression

public String getFirstLocateExpression(String substring,
                                       String instring)
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 interface BasicRdbAdapter

Parameters:
substring - The substring searched
instring - The string in which to search the substring

Returns:
The corresponding relational expression.


getIndexedLocateExpression

public String getIndexedLocateExpression(String instring,
                                         String substring,
                                         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()

Specified by:
getIndexedLocateExpression in interface RdbAdapter
Overrides:
getIndexedLocateExpression in interface BasicRdbAdapter

Parameters:
substring - The substring searched
fromIndex - The index from which to start searching

Returns:
The corresponding relational expression.


getSqlType

public String getSqlType(int typeCode,
                         boolean usedInPK,
                         int size,
                         int scale)
            throws RdbAdapterException
This method returns the SQL type linked to the java type
Specified by:
getSqlType in interface TypeAdapter
Overrides:
getSqlType in interface 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.


getSubqueryAlias

public String getSubqueryAlias()
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 interface BasicRdbAdapter

Returns:
the String to be appended to the subquery


getValueAsSQLString

public String getValueAsSQLString(Object value,
                                  int typeCode)
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 interface BasicRdbAdapter

Parameters:
value -
typeCode - is the java type of the value


getValueAsSQLString

public String getValueAsSQLString(boolean value)
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 interface BasicRdbAdapter


modifyWhereClauseWithRange

protected void modifyWhereClauseWithRange(StringBuffer sb,
                                          String _where,
                                          int rangeStart,
                                          int rangeSize)
Overrides:
modifyWhereClauseWithRange in interface BasicRdbAdapter


supportBatchPreparedStatement

public boolean supportBatchPreparedStatement()
Indicates if the driver supports the batch of PreparedStatement
Specified by:
supportBatchPreparedStatement in interface RdbAdapter
Overrides:
supportBatchPreparedStatement in interface BasicRdbAdapter