Fyracle dump and bug fixes
This commit is contained in:
parent
cca70607ff
commit
a309e926b8
|
@ -564,26 +564,42 @@ public final class Find extends CDialog
|
|||
m_query = new MQuery(m_tableName);
|
||||
if (hasValue && !valueField.getText().equals("%") && valueField.getText().length() != 0)
|
||||
{
|
||||
String value = valueField.getText().toUpperCase();
|
||||
//@TODO Fyracle bug with upper
|
||||
String value;
|
||||
if(DB.isFyracle()){
|
||||
value = valueField.getText();
|
||||
}else{
|
||||
value = valueField.getText().toUpperCase();
|
||||
}
|
||||
if (!value.endsWith("%"))
|
||||
value += "%";
|
||||
m_query.addRestriction("UPPER(Value)", MQuery.LIKE, value, valueLabel.getText(), value);
|
||||
m_query.addRestriction((DB.isFyracle()?"Value":"UPPER(Value)"), MQuery.LIKE, value, valueLabel.getText(), value);
|
||||
}
|
||||
//
|
||||
if (hasDocNo && !docNoField.getText().equals("%") && docNoField.getText().length() != 0)
|
||||
{
|
||||
String value = docNoField.getText().toUpperCase();
|
||||
String value;
|
||||
if(DB.isFyracle()){
|
||||
value = docNoField.getText();
|
||||
}else{
|
||||
value = docNoField.getText().toUpperCase();
|
||||
}
|
||||
if (!value.endsWith("%"))
|
||||
value += "%";
|
||||
m_query.addRestriction("UPPER(DocumentNo)", MQuery.LIKE, value, docNoLabel.getText(), value);
|
||||
m_query.addRestriction((DB.isFyracle()?"DocumentNo":"UPPER(DocumentNo)"), MQuery.LIKE, value, docNoLabel.getText(), value);
|
||||
}
|
||||
//
|
||||
if ((hasName) && !nameField.getText().equals("%") && nameField.getText().length() != 0)
|
||||
{
|
||||
String value = nameField.getText().toUpperCase();
|
||||
String value;
|
||||
if(DB.isFyracle()){
|
||||
value = nameField.getText();
|
||||
}else{
|
||||
value = nameField.getText().toUpperCase();
|
||||
}
|
||||
if (!value.endsWith("%"))
|
||||
value += "%";
|
||||
m_query.addRestriction("UPPER(Name)", MQuery.LIKE, value, nameLabel.getText(), value);
|
||||
m_query.addRestriction((DB.isFyracle()?"Name":"UPPER(Name)"), MQuery.LIKE, value, nameLabel.getText(), value);
|
||||
}
|
||||
//
|
||||
if (hasDescription && !descriptionField.getText().equals("%") && descriptionField.getText().length() != 0)
|
||||
|
|
|
@ -13,12 +13,16 @@
|
|||
*****************************************************************************/
|
||||
package org.compiere.db;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
@ -28,6 +32,8 @@ import org.compiere.dbPort.Convert_Oracle;
|
|||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Language;
|
||||
import org.firebirdsql.jdbc.FBConnection;
|
||||
import org.firebirdsql.pool.DriverConnectionPoolDataSource;
|
||||
import org.firebirdsql.pool.FBWrappingDataSource;
|
||||
|
||||
/**
|
||||
|
@ -53,20 +59,19 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
/** Default Port */
|
||||
public static final int DEFAULT_PORT = 3050;
|
||||
|
||||
|
||||
/** Connection String */
|
||||
private String m_connection;
|
||||
|
||||
private FBWrappingDataSource m_ds;
|
||||
|
||||
private static CLogger log = CLogger.getCLogger (DB_Fyracle.class);
|
||||
private static CLogger log = CLogger.getCLogger(DB_Fyracle.class);
|
||||
|
||||
private Convert m_convert = new Convert_Oracle();
|
||||
|
||||
private String m_userName;
|
||||
|
||||
private String m_connectionURL;
|
||||
|
||||
|
||||
/**
|
||||
* Get Database Name
|
||||
*
|
||||
|
@ -122,22 +127,25 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
m_userName = connection.getDbUid();
|
||||
return m_connection;
|
||||
} // getConnectionString
|
||||
|
||||
/**
|
||||
* Get Connection URL.
|
||||
* http://download-east.oracle.com/docs/cd/B14117_01/java.101/b10979/urls.htm#BEIDBFDF
|
||||
* @param dbHost db Host
|
||||
* @param dbPort db Port
|
||||
* @param dbName db Name
|
||||
* @param userName user name
|
||||
*
|
||||
* @param dbHost
|
||||
* db Host
|
||||
* @param dbPort
|
||||
* db Port
|
||||
* @param dbName
|
||||
* db Name
|
||||
* @param userName
|
||||
* user name
|
||||
* @return connection
|
||||
*/
|
||||
public String getConnectionURL (String dbHost, int dbPort, String dbName,
|
||||
String userName)
|
||||
{
|
||||
public String getConnectionURL(String dbHost, int dbPort, String dbName,
|
||||
String userName) {
|
||||
StringBuffer sb = new StringBuffer("jdbc:firebirdsql:oracle:");
|
||||
sb.append(dbHost).append("/").append(
|
||||
dbPort).append(":").append(
|
||||
dbName);
|
||||
sb.append(dbHost).append("/").append(dbPort).append(":").append(dbName);
|
||||
m_connection = sb.toString();
|
||||
m_userName = userName;
|
||||
return m_connection;
|
||||
|
@ -204,7 +212,6 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
return rs.getString(pos);
|
||||
} // getRowID
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
@ -216,7 +223,9 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
if (m_ds == null)
|
||||
getDataSource(connection);
|
||||
Connection conn = null;
|
||||
conn = m_ds.getConnection();
|
||||
// @TODO FYRACLE PooledConnection ignore setAutoCommit
|
||||
// conn = m_ds.getConnection();
|
||||
conn = getDriverConnection(connection);
|
||||
if (conn != null) {
|
||||
if (conn.getTransactionIsolation() != transactionIsolation)
|
||||
conn.setTransactionIsolation(transactionIsolation);
|
||||
|
@ -227,40 +236,48 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get JDBC Schema
|
||||
*
|
||||
* @return user name
|
||||
*/
|
||||
public String getSchema()
|
||||
{
|
||||
public String getSchema() {
|
||||
if (m_userName != null)
|
||||
return m_userName.toUpperCase();
|
||||
log.severe("User Name not set (yet) - call getConnectionURL first");
|
||||
return null;
|
||||
} // getSchema
|
||||
|
||||
/**
|
||||
* Get Driver Connection
|
||||
* @param dbUrl URL
|
||||
* @param dbUid user
|
||||
* @param dbPwd password
|
||||
*
|
||||
* @param dbUrl
|
||||
* URL
|
||||
* @param dbUid
|
||||
* user
|
||||
* @param dbPwd
|
||||
* password
|
||||
* @return connection
|
||||
* @throws SQLException
|
||||
*/
|
||||
public Connection getDriverConnection (String dbUrl, String dbUid, String dbPwd)
|
||||
throws SQLException
|
||||
{
|
||||
public Connection getDriverConnection(String dbUrl, String dbUid,
|
||||
String dbPwd) throws SQLException {
|
||||
getDriver();
|
||||
return DriverManager.getConnection (dbUrl, dbUid, dbPwd);
|
||||
return DriverManager.getConnection(dbUrl, dbUid, dbPwd);
|
||||
} // getDriverConnection
|
||||
|
||||
/**
|
||||
* Get Connection from Driver
|
||||
* @param connection info
|
||||
*
|
||||
* @param connection
|
||||
* info
|
||||
* @return connection or null
|
||||
*/
|
||||
public Connection getDriverConnection (CConnection connection) throws SQLException
|
||||
{
|
||||
public Connection getDriverConnection(CConnection connection)
|
||||
throws SQLException {
|
||||
getDriver();
|
||||
return DriverManager.getConnection (getConnectionURL (connection),
|
||||
return DriverManager.getConnection(getConnectionURL(connection),
|
||||
connection.getDbUid(), connection.getDbPwd());
|
||||
} // getDriverConnection
|
||||
|
||||
|
@ -274,9 +291,9 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
return m_ds;
|
||||
try {
|
||||
m_ds = new FBWrappingDataSource();
|
||||
StringBuffer db = new StringBuffer().append(connection.getDbHost()).append("/").append(
|
||||
connection.getDbPort()).append(":").append(
|
||||
connection.getDbName());
|
||||
StringBuffer db = new StringBuffer().append(connection.getDbHost())
|
||||
.append("/").append(connection.getDbPort()).append(":")
|
||||
.append(connection.getDbName());
|
||||
|
||||
m_ds.setDatabase(db.toString());
|
||||
m_ds.setUserName(connection.getDbUid());
|
||||
|
@ -287,13 +304,14 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
|
||||
m_ds.setLoginTimeout(10);
|
||||
m_ds.setMaxStatements(MAX_STATEMENTS);
|
||||
|
||||
m_ds.setLoginTimeout(10);
|
||||
m_ds.setMaxStatements(MAX_STATEMENTS);
|
||||
|
||||
return m_ds;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, toString(), e);
|
||||
//throw new RuntimeException(e);
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
|
||||
|
@ -315,7 +333,7 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
* @see org.compiere.db.CompiereDatabase#close()
|
||||
*/
|
||||
public void close() {
|
||||
m_ds=null;
|
||||
m_ds = null;
|
||||
}
|
||||
|
||||
public static void main(String[] a) {
|
||||
|
@ -335,69 +353,81 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
m_ds.setType("ORACLE_MODE");
|
||||
Connection c = null;
|
||||
c = m_ds.getConnection();
|
||||
c.createStatement().executeQuery("SELECT * FROM ad_CLIENT WHERE created>TO_DATE('2001-01-01')");
|
||||
c
|
||||
.createStatement()
|
||||
.executeQuery(
|
||||
"SELECT * FROM ad_CLIENT WHERE created>TO_DATE('2001-01-01')");
|
||||
|
||||
new DB_Fyracle().getDriver();
|
||||
c = DriverManager.getConnection ("jdbc:firebirdsql:oracle:localhost/3050:c:/devspace/apps/fyracle/data/compiere.fdb", "SYSDBA", "masterkey");
|
||||
c = DriverManager
|
||||
.getConnection(
|
||||
"jdbc:firebirdsql:oracle:localhost/3050:c:/devspace/apps/fyracle/data/compiere.fdb",
|
||||
"SYSDBA", "masterkey");
|
||||
|
||||
|
||||
c.createStatement().executeQuery("SELECT * FROM ad_CLIENT WHERE created>TO_DATE('2001-01-01')");
|
||||
c
|
||||
.createStatement()
|
||||
.executeQuery(
|
||||
"SELECT * FROM ad_CLIENT WHERE created>TO_DATE('2001-01-01')");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get JDBC Catalog
|
||||
*
|
||||
* @return null - not used
|
||||
*/
|
||||
public String getCatalog()
|
||||
{
|
||||
public String getCatalog() {
|
||||
return null;
|
||||
} // getCatalog
|
||||
|
||||
/**
|
||||
* Get SQL Commands.
|
||||
* The following variables are resolved:
|
||||
* @SystemPassword@, @CompiereUser@, @CompierePassword@
|
||||
* @SystemPassword@, @DatabaseName@, @DatabaseDevice@
|
||||
* @param cmdType CMD_*
|
||||
* Get SQL Commands. The following variables are resolved:
|
||||
*
|
||||
* @SystemPassword@,
|
||||
* @CompiereUser@,
|
||||
* @CompierePassword@
|
||||
* @SystemPassword@,
|
||||
* @DatabaseName@,
|
||||
* @DatabaseDevice@
|
||||
* @param cmdType
|
||||
* CMD_*
|
||||
* @return array of commands to be executed
|
||||
*/
|
||||
public String[] getCommands (int cmdType)
|
||||
{
|
||||
public String[] getCommands(int cmdType) {
|
||||
if (CMD_CREATE_USER == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
return new String[] {
|
||||
|
||||
};
|
||||
//
|
||||
if (CMD_CREATE_DATABASE == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
return new String[] {
|
||||
|
||||
};
|
||||
//
|
||||
if (CMD_DROP_DATABASE == cmdType)
|
||||
return new String[]
|
||||
{
|
||||
return new String[] {
|
||||
|
||||
};
|
||||
//
|
||||
return null;
|
||||
} // getCommands
|
||||
|
||||
/**
|
||||
* Create SQL TO Date String from Timestamp
|
||||
*
|
||||
* @param time Date to be converted
|
||||
* @param dayOnly true if time set to 00:00:00
|
||||
* @param time
|
||||
* Date to be converted
|
||||
* @param dayOnly
|
||||
* true if time set to 00:00:00
|
||||
*
|
||||
* @return TO_DATE('2001-01-30 18:10:20',''YYYY-MM-DD HH24:MI:SS')
|
||||
* or TO_DATE('2001-01-30',''YYYY-MM-DD')
|
||||
* @return TO_DATE('2001-01-30 18:10:20',''YYYY-MM-DD HH24:MI:SS') or
|
||||
* TO_DATE('2001-01-30',''YYYY-MM-DD')
|
||||
*/
|
||||
public String TO_DATE (Timestamp time, boolean dayOnly)
|
||||
{
|
||||
if (time == null)
|
||||
{
|
||||
public String TO_DATE(Timestamp time, boolean dayOnly) {
|
||||
if (time == null) {
|
||||
if (dayOnly)
|
||||
return "TRUNC(SysDate)";
|
||||
return "SysDate";
|
||||
|
@ -406,14 +436,13 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
StringBuffer dateString = new StringBuffer("TO_DATE('");
|
||||
// YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format
|
||||
String myDate = time.toString();
|
||||
if (dayOnly)
|
||||
{
|
||||
dateString.append(myDate.substring(0,10));
|
||||
if (dayOnly) {
|
||||
dateString.append(myDate.substring(0, 10));
|
||||
dateString.append("','YYYY-MM-DD')");
|
||||
}
|
||||
else
|
||||
{
|
||||
dateString.append(myDate.substring(0, myDate.indexOf("."))); // cut off miliseconds
|
||||
} else {
|
||||
dateString.append(myDate.substring(0, myDate.indexOf("."))); // cut
|
||||
// off
|
||||
// miliseconds
|
||||
dateString.append("','YYYY-MM-DD HH24:MI:SS')");
|
||||
}
|
||||
return dateString.toString();
|
||||
|
@ -422,24 +451,26 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
/**
|
||||
* Create SQL for formatted Date, Number
|
||||
*
|
||||
* @param columnName the column name in the SQL
|
||||
* @param displayType Display Type
|
||||
* @param AD_Language 6 character language setting (from Env.LANG_*)
|
||||
* @param columnName
|
||||
* the column name in the SQL
|
||||
* @param displayType
|
||||
* Display Type
|
||||
* @param AD_Language
|
||||
* 6 character language setting (from Env.LANG_*)
|
||||
*
|
||||
* @return TRIM(TO_CHAR(columnName,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.'''))
|
||||
* or TRIM(TO_CHAR(columnName,'TM9')) depending on DisplayType and Language
|
||||
* or TRIM(TO_CHAR(columnName,'TM9')) depending on DisplayType and
|
||||
* Language
|
||||
* @see org.compiere.util.DisplayType
|
||||
* @see org.compiere.util.Env
|
||||
*
|
||||
* */
|
||||
public String TO_CHAR (String columnName, int displayType, String AD_Language)
|
||||
{
|
||||
*/
|
||||
public String TO_CHAR(String columnName, int displayType, String AD_Language) {
|
||||
StringBuffer retValue = new StringBuffer("TRIM(TO_CHAR(");
|
||||
retValue.append(columnName);
|
||||
|
||||
// Numbers
|
||||
if (DisplayType.isNumeric(displayType))
|
||||
{
|
||||
if (DisplayType.isNumeric(displayType)) {
|
||||
if (displayType == DisplayType.Amount)
|
||||
retValue.append(",'9G999G990D00'");
|
||||
else
|
||||
|
@ -447,11 +478,9 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
// TO_CHAR(GrandTotal,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')
|
||||
if (!Language.isDecimalPoint(AD_Language)) // reversed
|
||||
retValue.append(",'NLS_NUMERIC_CHARACTERS='',.'''");
|
||||
}
|
||||
else if (DisplayType.isDate(displayType))
|
||||
{
|
||||
retValue.append(",'")
|
||||
.append(Language.getLanguage(AD_Language).getDBdatePattern())
|
||||
} else if (DisplayType.isDate(displayType)) {
|
||||
retValue.append(",'").append(
|
||||
Language.getLanguage(AD_Language).getDBdatePattern())
|
||||
.append("'");
|
||||
}
|
||||
retValue.append("))");
|
||||
|
@ -461,12 +490,14 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
|
||||
/**
|
||||
* Return number as string for INSERT statements with correct precision
|
||||
* @param number number
|
||||
* @param displayType display Type
|
||||
*
|
||||
* @param number
|
||||
* number
|
||||
* @param displayType
|
||||
* display Type
|
||||
* @return number as string
|
||||
*/
|
||||
public String TO_NUMBER (BigDecimal number, int displayType)
|
||||
{
|
||||
public String TO_NUMBER(BigDecimal number, int displayType) {
|
||||
if (number == null)
|
||||
return "NULL";
|
||||
return number.toString();
|
||||
|
@ -474,20 +505,21 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
|
||||
/**
|
||||
* Get Name of System User
|
||||
*
|
||||
* @return system
|
||||
*/
|
||||
public String getSystemUser()
|
||||
{
|
||||
public String getSystemUser() {
|
||||
return "sysdba";
|
||||
} // getSystemUser
|
||||
|
||||
/**
|
||||
* Get Name of System Database
|
||||
* @param databaseName database Name
|
||||
*
|
||||
* @param databaseName
|
||||
* database Name
|
||||
* @return e.g. master or database Name
|
||||
*/
|
||||
public String getSystemDatabase(String databaseName)
|
||||
{
|
||||
public String getSystemDatabase(String databaseName) {
|
||||
return databaseName;
|
||||
} // getSystemDatabase
|
||||
|
||||
|
@ -501,11 +533,12 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
return m_connectionURL;
|
||||
}
|
||||
|
||||
public String getConstraintType(Connection conn, String tableName, String IXName) {
|
||||
if (IXName == null || IXName.length()==0)
|
||||
public String getConstraintType(Connection conn, String tableName,
|
||||
String IXName) {
|
||||
if (IXName == null || IXName.length() == 0)
|
||||
return "0";
|
||||
if (IXName.endsWith("_KEY"))
|
||||
return "1"+IXName;
|
||||
return "1" + IXName;
|
||||
else
|
||||
return "0";
|
||||
}
|
||||
|
@ -518,5 +551,77 @@ public class DB_Fyracle implements AdempiereDatabase {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // DB_Firebird
|
||||
|
||||
class DataSourceImpl implements DataSource {
|
||||
DriverConnectionPoolDataSource impl;
|
||||
|
||||
public DataSourceImpl() {
|
||||
impl = new DriverConnectionPoolDataSource();
|
||||
impl.setPooling(true);
|
||||
impl.setStatementPooling(true);
|
||||
impl.setDriverClassName("org.firebirdsql.jdbc.FBDriver");
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
return impl.getPooledConnection("SYSDBA", "masterkey").getConnection();
|
||||
}
|
||||
|
||||
public void setJdbcUrl(String url) throws SQLException {
|
||||
impl.setJdbcUrl(url);
|
||||
}
|
||||
|
||||
public Connection getConnection(String username, String password)
|
||||
throws SQLException {
|
||||
return impl.getPooledConnection(username, password).getConnection();
|
||||
}
|
||||
|
||||
public PrintWriter getLogWriter() throws SQLException {
|
||||
return impl.getLogWriter();
|
||||
}
|
||||
|
||||
public int getLoginTimeout() throws SQLException {
|
||||
return impl.getLoginTimeout();
|
||||
}
|
||||
|
||||
public void setLogWriter(PrintWriter out) throws SQLException {
|
||||
impl.setLogWriter(out);
|
||||
}
|
||||
|
||||
public void setLoginTimeout(int seconds) throws SQLException {
|
||||
impl.setLoginTimeout(seconds);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
return impl.equals(obj);
|
||||
}
|
||||
|
||||
public void setMaxConnections(int arg0) {
|
||||
impl.setMaxConnections(arg0);
|
||||
}
|
||||
|
||||
public void setMaxIdleTime(int arg0) {
|
||||
impl.setMaxIdleTime(arg0);
|
||||
}
|
||||
|
||||
public void setMaxPoolSize(int arg0) {
|
||||
impl.setMaxPoolSize(arg0);
|
||||
}
|
||||
|
||||
public void setMaxStatements(int arg0) {
|
||||
impl.setMaxStatements(arg0);
|
||||
}
|
||||
|
||||
public void setProperty(String arg0, String arg1) {
|
||||
impl.setProperty(arg0, arg1);
|
||||
}
|
||||
|
||||
public void setTransactionIsolationLevel(int arg0) {
|
||||
impl.setTransactionIsolationLevel(arg0);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return impl.toString();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue