Package org.compiere.db
Class DB_PostgreSQL
- java.lang.Object
-
- org.compiere.db.DB_PostgreSQL
-
- All Implemented Interfaces:
AdempiereDatabase
public class DB_PostgreSQL extends Object implements AdempiereDatabase
PostgreSQL Database Port- Version:
- $Id: DB_PostgreSQL.java,v 1.23 2005/03/11 20:29:01 jjanke Exp $ --- Modifications: removed static references to database connection and instead always get a new connection from database pool manager which manages all connections set rw/ro properties for the connection accordingly.
- Author:
- , Jorg Janke, Victor Perez, Ashley Ramdass (Posterita)
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_PORTDefault Portstatic StringDRIVERDriver class-
Fields inherited from interface org.compiere.db.AdempiereDatabase
CMD_CREATE_DATABASE, CMD_CREATE_USER, CMD_DROP_DATABASE, LOCK_TIME_OUT
-
-
Constructor Summary
Constructors Constructor Description DB_PostgreSQL()PostgreSQL Database
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringaddPagingSQL(String sql, int start, int end)Implemented using the limit and offset feature. use 1 base index for start and end parametervoidclose()CloseStringconvertStatement(String oraStatement)Convert an individual Oracle Style statements to target database statement syntaxConnectionPoolDataSourcecreatePoolDataSource(CConnection connection)Create Pooled DataSource (Server)booleancreateSequence(String name, int increment, int minvalue, int maxvalue, int start, String trxName)static voiddumpLocks(Connection conn)Dump table lock info to console for current transactionbooleanforUpdate(PO po, int timeout)Lock PO for updateStringgetAlternativeSQL(int reExNo, String msg, String sql)Check and generate an alternative SQLStringgetBlobDataType()ConnectiongetCachedConnection(CConnection connection, boolean autoCommit, int transactionIsolation)Get Cached ConnectionStringgetCatalog()Get JDBC CatalogStringgetCharacterDataType()StringgetClobDataType()String[]getCommands(int cmdType)Get SQL CommandsStringgetConnectionURL(String dbHost, int dbPort, String dbName, String userName)Get Connection URLStringgetConnectionURL(String connectionURL, String userName)Get Database Connection StringStringgetConnectionURL(CConnection connection)Get Database Connection String.StringgetConstraintType(Connection conn, String tableName, String IXName)Get constraint type associated with the indexConvertgetConvert()DataSourcegetDataSource(CConnection connection)Create DataSource (Client)StringgetDescription()Get Database DescriptionDrivergetDriver()Get and register Database DriverConnectiongetDriverConnection(String dbUrl, String dbUid, String dbPwd)Get Driver ConnectionConnectiongetDriverConnection(CConnection connection)Get Connection from DriverStringgetName()Get Database NameStringgetNameOfUniqueConstraintError(Exception e)intgetNextID(String name)Return next sequence this SequenceintgetNextID(String name, String trxName)Return next sequence this SequenceStringgetNumericDataType()RowSetgetRowSet(ResultSet rs)Get RowSetStringgetSchema()Get JDBC SchemaStringgetSQLAdd(MTable table, MColumn column)Get SQL Add commandStringgetSQLDDL(MColumn column)StringgetSQLModify(MTable table, MColumn column, boolean setNullOption)Get SQL Modify commandintgetStandardPort()Get Standard JDBC PortStringgetStatus()Get StatusStringgetSystemDatabase(String databaseName)Get Name of System DatabaseStringgetSystemUser()Get Name of System UserStringgetTimestampDataType()StringgetVarcharDataType()StringintersectClauseForCSV(String columnName, String csv)booleanisNativeMode()booleanisPagingSupported()Is the database have sql extension that return a subset of the query resultbooleanisQueryTimeout(SQLException ex)booleanisQueryTimeoutSupported()Postgresql jdbc driver doesn't support setQueryTimeout, query/statement timeout is implemented using the "SET LOCAL statement_timeout TO" statement.booleanisSupported(String sql)Check if DBMS support the sql statementstatic booleanisUseNativeDialect()static StringmarkNativeKeyword(String keyword)StringquoteColumnName(String columnName)Quote column name if necessary (usually to avoid conflict with reserved keywords)static StringremoveNativeKeyworkMarker(String statement)StringsubsetClauseForCSV(String columnName, String csv)booleansupportsBLOB()Supports BLOBStringTO_CHAR(String columnName, int displayType, String AD_Language)Create SQL for formatted Date, NumberStringTO_DATE(Timestamp time, boolean dayOnly)Create SQL TO Date String from TimestampStringTO_NUMBER(BigDecimal number, int displayType)Return number as string for INSERT statements with correct precisionStringtoString()String Representation-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.compiere.db.AdempiereDatabase
getSQLCreate, getVarcharLengthSuffix
-
-
-
-
Field Detail
-
DRIVER
public static final String DRIVER
Driver class- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT
Default Port- See Also:
- Constant Field Values
-
-
Method Detail
-
getConvert
public Convert getConvert()
- Specified by:
getConvertin interfaceAdempiereDatabase
-
getName
public String getName()
Get Database Name- Specified by:
getNamein interfaceAdempiereDatabase- Returns:
- database short name
-
getDescription
public String getDescription()
Get Database Description- Specified by:
getDescriptionin interfaceAdempiereDatabase- Returns:
- database long name and version
-
getStandardPort
public int getStandardPort()
Get Standard JDBC Port- Specified by:
getStandardPortin interfaceAdempiereDatabase- Returns:
- standard port
-
getDriver
public Driver getDriver() throws SQLException
Get and register Database Driver- Specified by:
getDriverin interfaceAdempiereDatabase- Returns:
- Driver
- Throws:
SQLException
-
getConnectionURL
public String getConnectionURL(CConnection connection)
Get Database Connection String. Requirements: - createdb -E UNICODE compiere- Specified by:
getConnectionURLin interfaceAdempiereDatabase- Parameters:
connection- Connection Descriptor- Returns:
- connection String
-
getConnectionURL
public String getConnectionURL(String dbHost, int dbPort, String dbName, String userName)
Get Connection URL- Specified by:
getConnectionURLin interfaceAdempiereDatabase- Parameters:
dbHost- db HostdbPort- db PortdbName- sb NameuserName- user name- Returns:
- connection url
-
getConnectionURL
public String getConnectionURL(String connectionURL, String userName)
Get Database Connection String- Specified by:
getConnectionURLin interfaceAdempiereDatabase- Parameters:
connectionURL- Connection URLuserName- user name- Returns:
- connection String
-
getCatalog
public String getCatalog()
Get JDBC Catalog- Specified by:
getCatalogin interfaceAdempiereDatabase- Returns:
- catalog (database name)
-
getSchema
public String getSchema()
Get JDBC Schema- Specified by:
getSchemain interfaceAdempiereDatabase- Returns:
- schema (dbo)
-
supportsBLOB
public boolean supportsBLOB()
Supports BLOB- Specified by:
supportsBLOBin interfaceAdempiereDatabase- Returns:
- true if BLOB is supported
-
toString
public String toString()
String Representation- Specified by:
toStringin interfaceAdempiereDatabase- Overrides:
toStringin classObject- Returns:
- info
-
getStatus
public String getStatus()
Get Status- Specified by:
getStatusin interfaceAdempiereDatabase- Returns:
- status info
-
convertStatement
public String convertStatement(String oraStatement)
Convert an individual Oracle Style statements to target database statement syntax- Specified by:
convertStatementin interfaceAdempiereDatabase- Parameters:
oraStatement-- Returns:
- converted Statement
- Throws:
Exception
-
getSystemUser
public String getSystemUser()
Get Name of System User- Specified by:
getSystemUserin interfaceAdempiereDatabase- Returns:
- e.g. sa, system
-
getSystemDatabase
public String getSystemDatabase(String databaseName)
Get Name of System Database- Specified by:
getSystemDatabasein interfaceAdempiereDatabase- Parameters:
databaseName- database Name- Returns:
- e.g. master or database Name
-
TO_DATE
public String TO_DATE(Timestamp time, boolean dayOnly)
Create SQL TO Date String from Timestamp- Specified by:
TO_DATEin interfaceAdempiereDatabase- Parameters:
time- Date to be converteddayOnly- true if time set to 00:00:00- Returns:
- TO_DATE('2001-01-30 18:10:20',''YYYY-MM-DD HH24:MI:SS') or TO_DATE('2001-01-30',''YYYY-MM-DD')
-
TO_CHAR
public String TO_CHAR(String columnName, int displayType, String AD_Language)
Create SQL for formatted Date, Number- Specified by:
TO_CHARin interfaceAdempiereDatabase- Parameters:
columnName- the column name in the SQLdisplayType- Display TypeAD_Language- 6 character language setting (from Env.LANG_*)- Returns:
- TRIM(TO_CHAR(columnName,'999G999G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')) or TRIM(TO_CHAR(columnName,'TM9')) depending on DisplayType and Language
- See Also:
DisplayType,Env
-
TO_NUMBER
public String TO_NUMBER(BigDecimal number, int displayType)
Return number as string for INSERT statements with correct precision- Specified by:
TO_NUMBERin interfaceAdempiereDatabase- Parameters:
number- numberdisplayType- display Type- Returns:
- number as string
-
getCommands
public String[] getCommands(int cmdType)
Get SQL Commands- Specified by:
getCommandsin interfaceAdempiereDatabase- Parameters:
cmdType- CMD_*- Returns:
- array of commands to be executed
-
getRowSet
public RowSet getRowSet(ResultSet rs) throws SQLException
Get RowSet- Parameters:
rs- ResultSet- Returns:
- RowSet
- Throws:
SQLException
-
getCachedConnection
public Connection getCachedConnection(CConnection connection, boolean autoCommit, int transactionIsolation) throws Exception
Get Cached Connection- Specified by:
getCachedConnectionin interfaceAdempiereDatabase- Parameters:
connection- connectionautoCommit- auto committransactionIsolation- trx isolation- Returns:
- Connection
- Throws:
Exception
-
getDataSource
public DataSource getDataSource(CConnection connection)
Create DataSource (Client)- Specified by:
getDataSourcein interfaceAdempiereDatabase- Parameters:
connection- connection- Returns:
- data dource
-
createPoolDataSource
public ConnectionPoolDataSource createPoolDataSource(CConnection connection)
Create Pooled DataSource (Server)- Parameters:
connection- connection- Returns:
- data source
-
getDriverConnection
public Connection getDriverConnection(CConnection connection) throws SQLException
Get Connection from Driver- Specified by:
getDriverConnectionin interfaceAdempiereDatabase- Parameters:
connection- info- Returns:
- connection or null
- Throws:
SQLException
-
getDriverConnection
public Connection getDriverConnection(String dbUrl, String dbUid, String dbPwd) throws SQLException
Get Driver Connection- Specified by:
getDriverConnectionin interfaceAdempiereDatabase- Parameters:
dbUrl- URLdbUid- userdbPwd- password- Returns:
- connection
- Throws:
SQLException
-
close
public void close()
Close- Specified by:
closein interfaceAdempiereDatabase
-
getAlternativeSQL
public String getAlternativeSQL(int reExNo, String msg, String sql)
Check and generate an alternative SQL- Specified by:
getAlternativeSQLin interfaceAdempiereDatabase- Returns:
- String, the alternative SQL, null if no alternative
-
getConstraintType
public String getConstraintType(Connection conn, String tableName, String IXName)
Get constraint type associated with the index- Specified by:
getConstraintTypein interfaceAdempiereDatabase- Returns:
- String[0] = 0: do not know, 1: Primary Key 2: Foreign Key String[1] - String[n] = Constraint Name
-
isSupported
public boolean isSupported(String sql)
Check if DBMS support the sql statement- Specified by:
isSupportedin interfaceAdempiereDatabase- Returns:
- true: yes
-
dumpLocks
public static void dumpLocks(Connection conn)
Dump table lock info to console for current transaction- Parameters:
conn-
-
getNextID
public int getNextID(String name)
Description copied from interface:AdempiereDatabaseReturn next sequence this Sequence- Specified by:
getNextIDin interfaceAdempiereDatabase- Parameters:
name- Sequence
-
getNextID
public int getNextID(String name, String trxName)
Description copied from interface:AdempiereDatabaseReturn next sequence this Sequence- Specified by:
getNextIDin interfaceAdempiereDatabase- Parameters:
name- SequencetrxName- Transaction
-
createSequence
public boolean createSequence(String name, int increment, int minvalue, int maxvalue, int start, String trxName)
- Specified by:
createSequencein interfaceAdempiereDatabase
-
isQueryTimeoutSupported
public boolean isQueryTimeoutSupported()
Postgresql jdbc driver doesn't support setQueryTimeout, query/statement timeout is implemented using the "SET LOCAL statement_timeout TO" statement.- Specified by:
isQueryTimeoutSupportedin interfaceAdempiereDatabase- Returns:
- true
-
addPagingSQL
public String addPagingSQL(String sql, int start, int end)
Implemented using the limit and offset feature. use 1 base index for start and end parameter- Specified by:
addPagingSQLin interfaceAdempiereDatabase- Parameters:
sql-start-end-- Returns:
-
isPagingSupported
public boolean isPagingSupported()
Description copied from interface:AdempiereDatabaseIs the database have sql extension that return a subset of the query result- Specified by:
isPagingSupportedin interfaceAdempiereDatabase- Returns:
- boolean
-
forUpdate
public boolean forUpdate(PO po, int timeout)
Description copied from interface:AdempiereDatabaseLock PO for update- Specified by:
forUpdatein interfaceAdempiereDatabase- Returns:
- true if lock is granted
-
getNameOfUniqueConstraintError
public String getNameOfUniqueConstraintError(Exception e)
- Specified by:
getNameOfUniqueConstraintErrorin interfaceAdempiereDatabase
-
subsetClauseForCSV
public String subsetClauseForCSV(String columnName, String csv)
- Specified by:
subsetClauseForCSVin interfaceAdempiereDatabasecsv- comma separated value- Returns:
- subset sql clause
-
quoteColumnName
public String quoteColumnName(String columnName)
Description copied from interface:AdempiereDatabaseQuote column name if necessary (usually to avoid conflict with reserved keywords)- Specified by:
quoteColumnNamein interfaceAdempiereDatabase- Returns:
- columnName or quoted columnName
-
intersectClauseForCSV
public String intersectClauseForCSV(String columnName, String csv)
- Specified by:
intersectClauseForCSVin interfaceAdempiereDatabasecsv- comma separated value- Returns:
- subset sql clause
-
isNativeMode
public boolean isNativeMode()
- Specified by:
isNativeModein interfaceAdempiereDatabase- Returns:
- true if using native dialect, false if using oracle dialect
-
isUseNativeDialect
public static final boolean isUseNativeDialect()
- Returns:
- true if it is using native dialect
-
markNativeKeyword
public static final String markNativeKeyword(String keyword)
- Parameters:
keyword-- Returns:
- if not using native dialect, return native_marker + keyword
-
removeNativeKeyworkMarker
public static final String removeNativeKeyworkMarker(String statement)
- Parameters:
statement-- Returns:
- statement after the removal of native keyword marker
-
getNumericDataType
public String getNumericDataType()
- Specified by:
getNumericDataTypein interfaceAdempiereDatabase- Returns:
- numeric data type name
-
getCharacterDataType
public String getCharacterDataType()
- Specified by:
getCharacterDataTypein interfaceAdempiereDatabase- Returns:
- fixed lenght character data type name
-
getVarcharDataType
public String getVarcharDataType()
- Specified by:
getVarcharDataTypein interfaceAdempiereDatabase- Returns:
- variable length character data type name
-
getBlobDataType
public String getBlobDataType()
- Specified by:
getBlobDataTypein interfaceAdempiereDatabase- Returns:
- binary large object data type name
-
getClobDataType
public String getClobDataType()
- Specified by:
getClobDataTypein interfaceAdempiereDatabase- Returns:
- character large object data type name
-
getTimestampDataType
public String getTimestampDataType()
- Specified by:
getTimestampDataTypein interfaceAdempiereDatabase- Returns:
- time stamp data type name
-
getSQLDDL
public String getSQLDDL(MColumn column)
- Specified by:
getSQLDDLin interfaceAdempiereDatabase- Returns:
- ddl sql for column
-
getSQLAdd
public String getSQLAdd(MTable table, MColumn column)
Get SQL Add command- Specified by:
getSQLAddin interfaceAdempiereDatabase- Parameters:
table- table- Returns:
- sql
-
getSQLModify
public String getSQLModify(MTable table, MColumn column, boolean setNullOption)
Get SQL Modify command- Specified by:
getSQLModifyin interfaceAdempiereDatabase- Parameters:
table- tablesetNullOption- generate null / not null statement- Returns:
- sql separated by ;
-
isQueryTimeout
public boolean isQueryTimeout(SQLException ex)
- Specified by:
isQueryTimeoutin interfaceAdempiereDatabase- Returns:
- true if ex is caused by query timeout
-
-