Package org.compiere.db
Class DB_Oracle
- java.lang.Object
-
- org.compiere.db.DB_Oracle
-
- All Implemented Interfaces:
AdempiereDatabase
public class DB_Oracle extends Object implements AdempiereDatabase
Oracle Database Port- Version:
- $Id: DB_Oracle.java,v 1.7 2006/09/22 23:35:19 jjanke Exp $ --- Modifications: Refactoring. Replaced Oracle Cache Manager with C3P0 connection pooling framework for better and more efficient connnection handling
- Author:
- Jorg Janke, Ashley Ramdass (Posterita)
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CM_PORT
Default Connection Manager Portstatic int
DEFAULT_PORT
Default Portstatic String
DRIVER
Driver Class Name-
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_Oracle()
Oracle Database
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
addPagingSQL(String sql, int start, int end)
modify sql to return a subset of the query resultvoid
cleanup()
Clean upvoid
close()
CloseString
convertStatement(String oraStatement)
Convert an individual Oracle Style statements to target database statement syntax.boolean
createSequence(String name, int increment, int minvalue, int maxvalue, int start, String trxName)
boolean
forUpdate(PO po, int timeout)
Lock PO for updateString
getAlternativeSQL(int reExNo, String msg, String sql)
Check and generate an alternative SQLString
getBlobDataType()
Connection
getCachedConnection(CConnection connection, boolean autoCommit, int transactionIsolation)
Get Cached ConnectionString
getCatalog()
Get JDBC CatalogString
getCharacterDataType()
String
getClobDataType()
String[]
getCommands(int cmdType)
Get SQL Commands.String
getConnectionURL(String dbHost, int dbPort, String dbName, String userName)
Get Connection URL.String
getConnectionURL(String connectionURL, String userName)
Get Database Connection StringString
getConnectionURL(CConnection connection)
Get Database Connection String.String
getConstraintType(Connection conn, String tableName, String IXName)
Get constraint type associated with the indexConvert
getConvert()
DataSource
getDataSource(CConnection connection)
Create DataSourceString
getDataType(String columnName, int displayType, int precision, boolean defaultValue)
Deprecated.String
getDescription()
Get Database DescriptionDriver
getDriver()
Get and register Database DriverConnection
getDriverConnection(String dbUrl, String dbUid, String dbPwd)
Get Driver ConnectionConnection
getDriverConnection(CConnection connection)
Get Connection from DriverString
getName()
Get Database NameString
getNameOfUniqueConstraintError(Exception e)
int
getNextID(String name)
Return next sequence this Sequenceint
getNextID(String name, String trxName)
Return next sequence this SequenceString
getNumericDataType()
String
getSchema()
Get JDBC SchemaString
getSQLAdd(MTable table, MColumn column)
Get SQL Add commandString
getSQLDDL(MColumn column)
String
getSQLModify(MTable table, MColumn column, boolean setNullOption)
Get SQL Modify commandint
getStandardPort()
Get Standard JDBC PortString
getStatus()
Get StatusString
getSystemDatabase(String databaseName)
Get Name of System DatabaseString
getSystemUser()
Get Name of System UserString
getTimestampDataType()
String
getVarcharDataType()
String
getVarcharLengthSuffix()
String
intersectClauseForCSV(String columnName, String csv)
boolean
isPagingSupported()
Is the database have sql extension that return a subset of the query resultboolean
isQueryTimeout(SQLException ex)
boolean
isQueryTimeoutSupported()
boolean
isSupported(String sql)
Check if DBMS support the sql statementstatic void
main(String[] args)
TestingString
subsetClauseForCSV(String columnName, String csv)
boolean
supportsBLOB()
Supports BLOBString
TO_CHAR(String columnName, int displayType, String AD_Language)
Create SQL for formatted Date, NumberString
TO_DATE(Timestamp time, boolean dayOnly)
Create SQL TO Date String from TimestampString
TO_NUMBER(BigDecimal number, int displayType)
Return number as string for INSERT statements with correct precisionString
toString()
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, isNativeMode, quoteColumnName
-
-
-
-
Field Detail
-
DRIVER
public static final String DRIVER
Driver Class Name- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT
Default Port- See Also:
- Constant Field Values
-
DEFAULT_CM_PORT
public static final int DEFAULT_CM_PORT
Default Connection Manager Port- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public String getName()
Get Database Name- Specified by:
getName
in interfaceAdempiereDatabase
- Returns:
- database short name
-
getDescription
public String getDescription()
Get Database Description- Specified by:
getDescription
in interfaceAdempiereDatabase
- Returns:
- database long name and version
-
getStandardPort
public int getStandardPort()
Get Standard JDBC Port- Specified by:
getStandardPort
in interfaceAdempiereDatabase
- Returns:
- standard port
-
getDriver
public Driver getDriver() throws SQLException
Get and register Database Driver- Specified by:
getDriver
in interfaceAdempiereDatabase
- Returns:
- Driver
- Throws:
SQLException
-
getConnectionURL
public String getConnectionURL(CConnection connection)
Get Database Connection String.Timing: - CM with source_route not in address_list = 28.5 sec - CM with source_route in address_list = 58.0 sec - direct = 4.3-8 sec (no real difference if on other box) - bequeath = 3.4-8 sec
- Specified by:
getConnectionURL
in interfaceAdempiereDatabase
- Parameters:
connection
- Connection Descriptor- Returns:
- connection String
-
getConnectionURL
public String getConnectionURL(String dbHost, int dbPort, String dbName, String userName)
Get Connection URL. http://download-east.oracle.com/docs/cd/B14117_01/java.101/b10979/urls.htm#BEIDBFDF- Specified by:
getConnectionURL
in interfaceAdempiereDatabase
- Parameters:
dbHost
- db HostdbPort
- db PortdbName
- db NameuserName
- user name- Returns:
- connection
-
getConnectionURL
public String getConnectionURL(String connectionURL, String userName)
Get Database Connection String- Specified by:
getConnectionURL
in interfaceAdempiereDatabase
- Parameters:
connectionURL
- Connection URLuserName
- user name- Returns:
- connection String
-
getCatalog
public String getCatalog()
Get JDBC Catalog- Specified by:
getCatalog
in interfaceAdempiereDatabase
- Returns:
- null - not used
-
getSchema
public String getSchema()
Get JDBC Schema- Specified by:
getSchema
in interfaceAdempiereDatabase
- Returns:
- user name
-
supportsBLOB
public boolean supportsBLOB()
Supports BLOB- Specified by:
supportsBLOB
in interfaceAdempiereDatabase
- Returns:
- true if BLOB is supported
-
toString
public String toString()
String Representation- Specified by:
toString
in interfaceAdempiereDatabase
- Overrides:
toString
in classObject
- Returns:
- info
-
getStatus
public String getStatus()
Get Status- Specified by:
getStatus
in interfaceAdempiereDatabase
- Returns:
- status info
-
convertStatement
public String convertStatement(String oraStatement)
Convert an individual Oracle Style statements to target database statement syntax.- Specified by:
convertStatement
in interfaceAdempiereDatabase
- Parameters:
oraStatement
- oracle statement- Returns:
- converted Statement oracle statement
-
isSupported
public boolean isSupported(String sql)
Check if DBMS support the sql statement- Specified by:
isSupported
in interfaceAdempiereDatabase
- Returns:
- true: yes
-
getConstraintType
public String getConstraintType(Connection conn, String tableName, String IXName)
Get constraint type associated with the index- Specified by:
getConstraintType
in interfaceAdempiereDatabase
- Returns:
- String[0] = 0: do not know, 1: Primary Key 2: Foreign Key String[1] - String[n] = Constraint Name
-
getSystemUser
public String getSystemUser()
Get Name of System User- Specified by:
getSystemUser
in interfaceAdempiereDatabase
- Returns:
- system
-
getSystemDatabase
public String getSystemDatabase(String databaseName)
Get Name of System Database- Specified by:
getSystemDatabase
in 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_DATE
in 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_CHAR
in 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_NUMBER
in interfaceAdempiereDatabase
- Parameters:
number
- numberdisplayType
- display Type- Returns:
- number as string
-
getCommands
public String[] getCommands(int cmdType)
Get SQL Commands. The following variables are resolved:- Specified by:
getCommands
in interfaceAdempiereDatabase
- Parameters:
cmdType
- CMD_*- Returns:
- array of commands to be executed
-
getDataSource
public DataSource getDataSource(CConnection connection)
Create DataSource- Specified by:
getDataSource
in interfaceAdempiereDatabase
- Parameters:
connection
- connection- Returns:
- data dource
-
getCachedConnection
public Connection getCachedConnection(CConnection connection, boolean autoCommit, int transactionIsolation) throws Exception
Get Cached Connection- Specified by:
getCachedConnection
in interfaceAdempiereDatabase
- Parameters:
connection
- infoautoCommit
- true if autocommit connectiontransactionIsolation
- Connection transaction level- Returns:
- connection or null
- Throws:
Exception
-
getDriverConnection
public Connection getDriverConnection(CConnection connection) throws SQLException
Get Connection from Driver- Specified by:
getDriverConnection
in 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:
getDriverConnection
in interfaceAdempiereDatabase
- Parameters:
dbUrl
- URLdbUid
- userdbPwd
- password- Returns:
- connection
- Throws:
SQLException
-
close
public void close()
Close- Specified by:
close
in interfaceAdempiereDatabase
-
cleanup
public void cleanup()
Clean up
-
getDataType
public String getDataType(String columnName, int displayType, int precision, boolean defaultValue)
Deprecated.Get Data Type- Parameters:
columnName
-displayType
- display typeprecision
- precisiondefaultValue
- if true adds default value- Returns:
- data type
-
getAlternativeSQL
public String getAlternativeSQL(int reExNo, String msg, String sql)
Check and generate an alternative SQL- Specified by:
getAlternativeSQL
in interfaceAdempiereDatabase
- Returns:
- String, the alternative SQL, null if no alternative
-
main
public static void main(String[] args)
Testing- Parameters:
args
- ignored
-
getConvert
public Convert getConvert()
- Specified by:
getConvert
in interfaceAdempiereDatabase
-
getNextID
public int getNextID(String name)
Description copied from interface:AdempiereDatabase
Return next sequence this Sequence- Specified by:
getNextID
in interfaceAdempiereDatabase
- Parameters:
name
- Sequence
-
getNextID
public int getNextID(String name, String trxName)
Description copied from interface:AdempiereDatabase
Return next sequence this Sequence- Specified by:
getNextID
in interfaceAdempiereDatabase
- Parameters:
name
- SequencetrxName
- Transaction
-
createSequence
public boolean createSequence(String name, int increment, int minvalue, int maxvalue, int start, String trxName)
- Specified by:
createSequence
in interfaceAdempiereDatabase
-
isQueryTimeoutSupported
public boolean isQueryTimeoutSupported()
- Specified by:
isQueryTimeoutSupported
in interfaceAdempiereDatabase
- Returns:
- true if jdbc driver support statement timeout
-
addPagingSQL
public String addPagingSQL(String sql, int start, int end)
Description copied from interface:AdempiereDatabase
modify sql to return a subset of the query result- Specified by:
addPagingSQL
in interfaceAdempiereDatabase
- Returns:
-
isPagingSupported
public boolean isPagingSupported()
Description copied from interface:AdempiereDatabase
Is the database have sql extension that return a subset of the query result- Specified by:
isPagingSupported
in interfaceAdempiereDatabase
- Returns:
- boolean
-
forUpdate
public boolean forUpdate(PO po, int timeout)
Description copied from interface:AdempiereDatabase
Lock PO for update- Specified by:
forUpdate
in interfaceAdempiereDatabase
- Returns:
- true if lock is granted
-
getNameOfUniqueConstraintError
public String getNameOfUniqueConstraintError(Exception e)
- Specified by:
getNameOfUniqueConstraintError
in interfaceAdempiereDatabase
-
subsetClauseForCSV
public String subsetClauseForCSV(String columnName, String csv)
- Specified by:
subsetClauseForCSV
in interfaceAdempiereDatabase
csv
- comma separated value- Returns:
- subset sql clause
-
intersectClauseForCSV
public String intersectClauseForCSV(String columnName, String csv)
- Specified by:
intersectClauseForCSV
in interfaceAdempiereDatabase
csv
- comma separated value- Returns:
- subset sql clause
-
getNumericDataType
public String getNumericDataType()
- Specified by:
getNumericDataType
in interfaceAdempiereDatabase
- Returns:
- numeric data type name
-
getCharacterDataType
public String getCharacterDataType()
- Specified by:
getCharacterDataType
in interfaceAdempiereDatabase
- Returns:
- fixed lenght character data type name
-
getVarcharDataType
public String getVarcharDataType()
- Specified by:
getVarcharDataType
in interfaceAdempiereDatabase
- Returns:
- variable length character data type name
-
getVarcharLengthSuffix
public String getVarcharLengthSuffix()
- Specified by:
getVarcharLengthSuffix
in interfaceAdempiereDatabase
- Returns:
- variable length character data type suffix
-
getBlobDataType
public String getBlobDataType()
- Specified by:
getBlobDataType
in interfaceAdempiereDatabase
- Returns:
- binary large object data type name
-
getClobDataType
public String getClobDataType()
- Specified by:
getClobDataType
in interfaceAdempiereDatabase
- Returns:
- character large object data type name
-
getTimestampDataType
public String getTimestampDataType()
- Specified by:
getTimestampDataType
in interfaceAdempiereDatabase
- Returns:
- time stamp data type name
-
getSQLDDL
public String getSQLDDL(MColumn column)
- Specified by:
getSQLDDL
in interfaceAdempiereDatabase
- Returns:
- ddl sql for column
-
getSQLAdd
public String getSQLAdd(MTable table, MColumn column)
Get SQL Add command- Specified by:
getSQLAdd
in interfaceAdempiereDatabase
- Parameters:
table
- table- Returns:
- sql
-
getSQLModify
public String getSQLModify(MTable table, MColumn column, boolean setNullOption)
Get SQL Modify command- Specified by:
getSQLModify
in interfaceAdempiereDatabase
- Parameters:
table
- tablesetNullOption
- generate null / not null statement- Returns:
- sql separated by ;
-
isQueryTimeout
public boolean isQueryTimeout(SQLException ex)
- Specified by:
isQueryTimeout
in interfaceAdempiereDatabase
- Returns:
- true if ex is caused by query timeout
-
-