Update of /cvsroot/compiere/dbPort/src/org/compiere/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11331/src/org/compiere/db Modified Files: DB_Oracle.java Database.java CConnection.java CompiereDatabase.java DB_Sybase.java Added Files: DB_DB2.java DB_PostgreSQL.java.txt Log Message: --- NEW FILE: DB_DB2.java --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial * Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke * are Copyright (C) 1999-2005 Jorg Janke. * All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.db; import java.math.*; import java.sql.*; import java.util.logging.*; import javax.sql.*; import org.compiere.util.*; import com.ibm.db2.jcc.*; /** * DB2 Database Driver * * @author Jorg Janke * @version $Id: DB_DB2.java,v 1.1 2005/12/31 06:33:21 jjanke Exp $ */ public class DB_DB2 implements CompiereDatabase { public DB_DB2() { } /** Static Driver */ private static DB2Driver s_driver = null; /** Driver Class Name */ public static final String DRIVER = "com.ibm.db2.jcc.DB2Driver"; /* Type 2 Driver */ public static final String DRIVER2 = "COM.ibm.db2.jdbc.app.DB2Driver"; /** Default Port 446 */ public static final int DEFAULT_PORT = 446; /** Default Port 50000 */ public static final int DEFAULT_PORT_0 = 50000; /** Cached User Name */ private String m_userName = null; /** Connection String */ private String m_connectionURL; private DB2SimpleDataSource m_ds = null; /** Logger */ private static CLogger log = CLogger.getCLogger (DB_DB2.class); /** * Get Database Name * @return database short name */ public String getName() { return Database.DB_DB2; } // getName /** * Get Database Description * @return database long name and version */ public String getDescription() { try { if (s_driver == null) getDriver(); } catch (Exception e) { } if (s_driver != null) return s_driver.toString(); return "No Driver"; } // getDescription /** * Get Standard JDBC Port * @return standard port */ public int getStandardPort() { return DEFAULT_PORT_0; } // getStandardPort /** * Get and register Database Driver * @return Driver */ public Driver getDriver() throws SQLException { if (s_driver == null) { s_driver = new DB2Driver(); DriverManager.registerDriver (s_driver); DriverManager.setLoginTimeout (Database.CONNECTION_TIMEOUT); } return s_driver; } // getDriver /** * Get Database Connection String. * <pre> * Timing: * </pre> * @param connection Connection Descriptor * @return connection String */ public String getConnectionURL (CConnection connection) { StringBuffer sb = null; // connection//server:port/database sb = new StringBuffer ("jdbc:db2:"); // Cloudscape = jdbc:db2j:net: sb.append("//") .append(connection.getDbHost()) .append(":").append(connection.getDbPort()) .append("/").append(connection.getDbName()); m_connectionURL = sb.toString(); // log.config(m_connectionURL); // m_userName = connection.getDbUid(); return m_connectionURL; } // getConnectionURL /** * Get Connection URL. * @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) { m_userName = userName; return "jdbc:db2://" + dbHost + ":" + dbPort + "/" + dbName; } // getConnectionURL /** * Get JDBC Catalog * @return null - not used */ public String getCatalog() { return null; } // getCatalog /** * Get JDBC Schema * @return user name */ public String getSchema() { if (m_userName != null) return m_userName.toUpperCase(); log.severe("User Name not set (yet) - call getConnectionURL first"); return null; } // getSchema /** * Supports BLOB * @return true if BLOB is supported */ public boolean supportsBLOB() { return true; } // supportsBLOB /** * String Representation * @return info */ public String toString() { StringBuffer sb = new StringBuffer("DB_DB2["); sb.append(m_connectionURL); sb.append("]"); return sb.toString(); } // toString /** * Get Status * @return status info */ public String getStatus() { StringBuffer sb = new StringBuffer(); return sb.toString(); } // getStatus /************************************************************************** * Convert an individual Oracle Style statements to target database statement syntax. * @param oraStatement oracle statement * @return converted Statement oracle statement */ public String convertStatement (String oraStatement) { return oraStatement; } // convertStatement /** * Get Name of System User * @return system */ public String getSystemUser() { return "db2adm"; } // getSystemUser /** * Get Name of System Database * @param databaseName database Name * @return e.g. master or database Name */ public String getSystemDatabase(String databaseName) { return databaseName; } // getSystemDatabase /** * Create SQL TO Date String from Timestamp * * @param time Date to be converted * @param dayOnly true if time set to 00:00:00 * * @return TO_DATE('1999-12-31 23:59:59', 'YYYY-MM-DD HH24:MI:SS') * or TIMESTAMP('2000-01-10-00.00.00.000000') */ public String TO_DATE (Timestamp time, boolean dayOnly) { if (time == null) { if (dayOnly) return "trunc(CURRENT TIMESTAMP)"; return "CURRENT TIMESTAMP"; } // TIMESTAMP('2000-01-10-00.00.00.000000') StringBuffer dateString = new StringBuffer("TIMESTAMP('"); // YYYY-MM-DD HH24:MI:SS.mmmm JDBC Timestamp format String myDate = time.toString(); if (dayOnly) { dateString.append(myDate.substring(0,10)); dateString.append("-00.00.00.000000')"); } else { myDate = myDate.replace('-', ' '); myDate = myDate.replace(':', '.'); dateString.append(myDate); dateString.append("00')"); } return dateString.toString(); } // TO_DATE /** * 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_*) * * @return TRIM(TO_CHAR(columnName,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')) * 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) { return columnName; /** StringBuffer retValue = new StringBuffer("TRIM(TO_CHAR("); retValue.append(columnName); // Numbers if (DisplayType.isNumeric(displayType)) { if (displayType == DisplayType.Amount) retValue.append(",'9G999G990D00'"); else retValue.append(",'TM9'"); // 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()) .append("'"); } retValue.append("))"); // return retValue.toString(); **/ } // TO_CHAR /** * Return number as string for INSERT statements with correct precision * @param number number * @param displayType display Type * @return number as string */ public String TO_NUMBER (BigDecimal number, int displayType) { if (number == null) return "NULL"; return number.toString(); } // TO_NUMBER /** * 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) { if (CMD_CREATE_USER == cmdType) return new String[] { }; // if (CMD_CREATE_DATABASE == cmdType) return new String[] { }; // if (CMD_DROP_DATABASE == cmdType) return new String[] { }; // return null; } // getCommands /** * Create DataSource * @param connection connection * @return data dource */ public DataSource getDataSource(CConnection connection) { if (m_ds == null) { m_ds = new DB2SimpleDataSource(); m_ds.setServerName(connection.getDbHost()); m_ds.setPortNumber(connection.getDbPort()); m_ds.setDatabaseName(connection.getDbName()); m_ds.setDescription("Compiere DataSource"); m_ds.setUser(connection.getDbUid()); m_ds.setPassword(connection.getDbPwd()); m_ds.setLoginTimeout(5); // seconds // m_ds.setUseCachedCursor(true); } return m_ds; } // getDataSource /** * Get Cached Connection * @param connection info * @param autoCommit true if autocommit connection * @param transactionIsolation Connection transaction level * @return connection or null */ public Connection getCachedConnection (CConnection connection, boolean autoCommit, int transactionIsolation) throws Exception { Connection conn = getDataSource(connection).getConnection(); conn.setAutoCommit(autoCommit); conn.setTransactionIsolation(transactionIsolation); return conn; } // getCachedConnection /** * Get Connection from Driver * @param connection info * @return connection or null */ public Connection getDriverConnection (CConnection connection) throws SQLException { getDriver(); return DriverManager.getConnection (getConnectionURL (connection), connection.getDbUid(), connection.getDbPwd()); } // getDriverConnection /** * Get Driver Connection * @param dbUrl URL * @param dbUid user * @param dbPwd password * @return connection * @throws SQLException */ public Connection getDriverConnection (String dbUrl, String dbUid, String dbPwd) throws SQLException { getDriver(); return DriverManager.getConnection (dbUrl, dbUid, dbPwd); } // getDriverConnection /** * Close */ public void close() { log.config(toString()); m_ds = null; } // close /** * Clean up */ public void cleanup() { log.config(""); } // cleanup /** * Get Data Type * @param displayType display type * @param precision precision * @param defaultValue if true adds default value * @return data type */ public String getDataType (int displayType, int precision, boolean defaultValue) { String retValue = null; switch (displayType) { // IDs case DisplayType.Account: case DisplayType.Assignment: case DisplayType.Color: case DisplayType.ID: case DisplayType.Location: case DisplayType.Locator: case DisplayType.PAttribute: case DisplayType.Search: case DisplayType.Table: case DisplayType.TableDir: retValue = "INTEGER"; break; // Dynamic Precision case DisplayType.Amount: retValue = "DECIMAL(18,2)"; if (defaultValue) retValue += " DEFAULT 0"; break; case DisplayType.Binary: case DisplayType.Image: retValue = "BLOB"; break; case DisplayType.Button: retValue = "CHAR(1)"; break; // Number Dynamic Precision case DisplayType.CostPrice: retValue = "DECIMAL(22,6)"; if (defaultValue) retValue += " DEFAULT 0"; break; // Date case DisplayType.Date: case DisplayType.DateTime: case DisplayType.Time: retValue = "Timestamp"; if (defaultValue) retValue += " DEFAULT 0"; break; // Number(10) case DisplayType.Integer: retValue = "NUMBER(10)"; break; case DisplayType.List: retValue = "CHAR(" + precision + ")"; break; // NVARCHAR case DisplayType.Memo: case DisplayType.String: case DisplayType.Text: retValue = "NVARCHAR(" + precision + ")"; break; case DisplayType.TextLong: retValue = "CLOB"; break; // Dyn Prec case DisplayType.Quantity: retValue = "NUMBER"; break; case DisplayType.YesNo: retValue = "CHAR(1)"; break; default: log.severe("Unknown: " + displayType); break; } return retValue; } // getDataType /************************************************************************** * Testing * @param args ignored */ public static void main (String[] args) { /** Compiere.startupEnvironment(true); CConnection cc = CConnection.get(); DB_Oracle db = (DB_Oracle)cc.getDatabase(); db.cleanup(); try { Connection conn = ; // System.out.println("Driver=" + db.getDriverConnection(cc)); DataSource ds = db.getDataSource(cc); System.out.println("DS=" + ds.getConnection()); conn = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED); System.out.println("Cached=" + conn); System.out.println(db); ////////////////////////// System.out.println("JAVA classpath: [\n" + System.getProperty("java.class.path") + "\n]"); DatabaseMetaData dmd = conn.getMetaData(); System.out.println("DriverVersion: ["+ dmd.getDriverVersion()+"]"); System.out.println("DriverMajorVersion: ["+ dmd.getDriverMajorVersion()+"]"); System.out.println("DriverMinorVersion: ["+ dmd.getDriverMinorVersion()+"]"); System.out.println("DriverName: ["+ dmd.getDriverName()+"]"); System.out.println("ProductName: ["+ dmd.getDatabaseProductName() +"]"); System.out.println("ProductVersion: [\n"+ dmd.getDatabaseProductVersion()+"\n]"); ////////////////////////// } catch (Exception e1) { e1.printStackTrace(); } db.cleanup(); System.out.println("--------------------------------------------------"); try { Connection conn1 = db.getCachedConnection(cc, false, Connection.TRANSACTION_READ_COMMITTED); Connection conn2 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED); Connection conn3 = db.getCachedConnection(cc, false, Connection.TRANSACTION_READ_COMMITTED); System.out.println("3 -> " + db); conn1.close(); conn2.close(); conn1 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED); conn2 = db.getCachedConnection(cc, true, Connection.TRANSACTION_READ_COMMITTED); System.out.println("3 -> " + db); conn1.close(); conn2.close(); conn3.close(); System.out.println("0 -> " + db); } catch (Exception e1) { e1.printStackTrace(); } db.cleanup(); // System.exit(0); System.out.println("--------------------------------------------------"); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.getConnectionRO()); System.out.println(DB.getConnectionRW()); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED)); System.out.println(db); try { System.out.println("-- Sleeping --"); Thread.sleep(60000); System.out.println(db); db.close(); db.cleanup(); System.out.println(db); } catch (InterruptedException e) { } /** **/ /** **/ // Connection option 1 try { DB2Driver driver = new DB2Driver(); DriverManager.registerDriver(driver); Connection con = DriverManager.getConnection("jdbc:db2://dev1:50000/sample", "db2admin", "db2admin"); // "compiere", "compiere"); // "db2inst1", "daDm7rfr"); System.out.println("Connection Catalog = " + con.getCatalog()); // DatabaseMetaData md = con.getMetaData(); System.out.println(md.getDatabaseProductName() + " - " + md.getDatabaseProductVersion()); // System.out.println(md.getDatabaseMajorVersion() + " - " + md.getDatabaseMinorVersion()); System.out.println(md.getDriverName() + " - " + md.getDriverVersion()); // System.out.println(md.getDriverMajorVersion() + " - " + md.getDriverMinorVersion()); System.out.println("URL=" + md.getURL()); System.out.println("User=" + md.getUserName()); // System.out.println(md.getNumericFunctions()); System.out.println(md.getStringFunctions()); System.out.println(md.getTimeDateFunctions()); System.out.println(md.getSystemFunctions()); // System.out.println("Catalogs - " + md.getCatalogTerm()); ResultSet rs = md.getCatalogs(); while (rs.next()) System.out.println("- " + rs.getString(1)); // System.out.println("Schemas - " + md.getSchemaTerm()); rs = md.getSchemas(); while (rs.next()) System.out.println("- " + rs.getString(1)); String sql = "SELECT GRANTOR,GRANTEE,DBADMAUTH FROM SYSCAT.DBAUTH"; PreparedStatement pstmt = null; try { pstmt = con.prepareStatement (sql); rs = pstmt.executeQuery (); while (rs.next ()) { String GRANTOR = rs.getString(1); String GRANTEE = rs.getString(2); String DBADMAUTH = rs.getString(3); System.out.println(GRANTOR + " -> " + GRANTEE + " = " + DBADMAUTH); } rs.close (); pstmt.close (); pstmt = null; } catch (Exception e) { log.log (Level.SEVERE, sql, e); } try { if (pstmt != null) pstmt.close (); pstmt = null; } catch (Exception e) { pstmt = null; } System.out.println("SysCat Table"); rs = md.getTables(null, "SYSCAT", null, new String[] {"TABLE", "VIEW"}); while (rs.next()) System.out.println("- User=" + rs.getString(2) + " | Table=" + rs.getString(3) + " | Type=" + rs.getString(4) + " | " + rs.getString(5)); // System.out.println("Column"); rs = md.getColumns(null, "SYSCAT", "DBAUTH", null); while (rs.next()) System.out.println("- Tab=" + rs.getString(3) + " | Col=" + rs.getString(4) + " | Type=" + rs.getString(5) + ", " + rs.getString(6) + " | Size=" + rs.getString(7) + " | " + rs.getString(8) + " | Digits=" + rs.getString(9) + " | Radix=" + rs.getString(10) + " | Null=" + rs.getString(11) + " | Rem=" + rs.getString(12) + " | Def=" + rs.getString(13) + " | " + rs.getString(14) + " | " + rs.getString(15) + " | " + rs.getString(16) + " | Ord=" + rs.getString(17) + " | Null=" + rs.getString(18) ); con.close(); } catch (SQLException ex) { ex.printStackTrace(); } /** **/ } // main } // DB_DB2 --- NEW FILE: DB_PostgreSQL.java.txt --- /****************************************************************************** * The contents of this file are subject to the Compiere License Version 1.1 * ("License"); You may not use this file except in compliance with the License * You may obtain a copy of the License at http://www.compiere.org/license.html * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial * Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke * are Copyright (C) 1999-2005 Jorg Janke. * All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved. * Contributor(s): ______________________________________. *****************************************************************************/ package org.compiere.db; import java.math.*; import java.sql.*; import javax.sql.*; import org.compiere.dbPort.*; import org.compiere.util.*; /** * PostgreSQL Database Port * * @author Jorg Janke * @version $Id: DB_PostgreSQL.java.txt,v 1.1 2005/12/31 06:33:21 jjanke Exp $ */ public class DB_PostgreSQL implements CompiereDatabase { /** * PostgreSQL Database */ public DB_PostgreSQL() { } // DB_PostgreSQL /** Driver */ private org.postgresql.Driver s_driver = null; /** Default Port */ public static final int DEFAULT_PORT = 5432; /** Statement Converter */ private Convert m_convert = new Convert(Database.DB_POSTGRESQL); /** Connection String */ private String m_connection; /** Cached Database Name */ private String m_dbName = null; /** * Get Database Name * @return database short name */ public String getName() { return Database.DB_POSTGRESQL; } // getName /** * Get Database Description * @return database long name and version */ public String getDescription() { return s_driver.toString(); } // getDescription /** * Get Standard JDBC Port * @return standard port */ public int getStandardPort() { return DEFAULT_PORT; } // getStandardPort /** * Get and register Database Driver * @return Driver */ public java.sql.Driver getDriver() throws SQLException { if (s_driver == null) { s_driver = new org.postgresql.Driver(); DriverManager.registerDriver (s_driver); DriverManager.setLoginTimeout (Database.CONNECTION_TIMEOUT); } return s_driver; } // getDriver /** * Get Database Connection String. * Requirements: * - createdb -E UNICODE compiere * @param connection Connection Descriptor * @return connection String */ public String getConnectionURL (CConnection connection) { // jdbc:postgresql://hostname:portnumber/databasename?encoding=UNICODE StringBuffer sb = new StringBuffer("jdbc:postgresql:"); sb.append("//").append(connection.getDbHost()) .append(":").append(connection.getDbPort()) .append("/").append(connection.getDbName()) .append("?encoding=UNICODE"); m_connection = sb.toString(); return m_connection; } // getConnectionString /** * Get Connection URL * @param dbHost db Host * @param dbPort db Port * @param dbName sb Name * @param userName user name * @return connection url */ public String getConnectionURL (String dbHost, int dbPort, String dbName, String userName) { return "jdbc:postgresql://" + dbHost + ":" + dbPort + "/" + dbName; } // getConnectionURL /** * Get JDBC Catalog * @return catalog (database name) */ public String getCatalog() { if (m_dbName != null) return m_dbName; // log.severe("Database Name not set (yet) - call getConnectionURL first"); return null; } // getCatalog /** * Get JDBC Schema * @return schema (dbo) */ public String getSchema() { return null; } // getSchema /** * Supports BLOB * @return true if BLOB is supported */ public boolean supportsBLOB() { return false; } // supportsBLOB /** * String Representation * @return info */ public String toString() { StringBuffer sb = new StringBuffer("DB_PostgreSQL["); sb.append(m_connection) .append("]"); return sb.toString(); } // toString /** * Get Status * @return status info */ public String getStatus() { return ""; } // getStatus /************************************************************************** * Convert an individual Oracle Style statements to target database statement syntax * * @param oraStatement * @return converted Statement */ public String convertStatement (String oraStatement) { String retValue[] = m_convert.convert(oraStatement); if (retValue == null) throw new IllegalArgumentException ("DB_PostgreSQL.convertStatement - Not Converted (" + oraStatement + ") - " + m_convert.getConversionError()); if (retValue.length != 1) throw new IllegalArgumentException ("DB_PostgreSQL.convertStatement - Convert Command Number=" + retValue.length + " (" + oraStatement + ") - " + m_convert.getConversionError()); // Diagnostics (show changed, but not if AD_Error if (!oraStatement.equals(retValue[0]) && retValue[0].indexOf("AD_Error") == -1) System.out.println("PostgreSQL =>" + retValue[0] + "<= <" + oraStatement + ">"); // return retValue[0]; } // convertStatement /** * Get Name of System User * @return e.g. sa, system */ public String getSystemUser() { return "sa"; } // getSystemUser /** * Get Name of System Database * @param databaseName database Name * @return e.g. master or database Name */ public String getSystemDatabase(String databaseName) { return "master"; } // getSystemDatabase /** * Create SQL TO Date String from Timestamp * * @param time Date to be converted * @param dayOnly true if time set to 00:00:00 * @return date function */ public String TO_DATE (Timestamp time, boolean dayOnly) { return ""; } // TO_DATE /** * 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_*) * * @return TRIM(TO_CHAR(columnName,'9G999G990D00','NLS_NUMERIC_CHARACTERS='',.''')) * 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) { return ""; } // TO_CHAR /** * Return number as string for INSERT statements with correct precision * @param number number * @param displayType display Type * @return number as string */ public String TO_NUMBER (BigDecimal number, int displayType) { if (number == null) return "NULL"; BigDecimal result = number; int scale = DisplayType.getDefaultPrecision(displayType); if (scale > number.scale()) { try { result = number.setScale(scale, BigDecimal.ROUND_HALF_UP); } catch (Exception e) { // log.severe("Number=" + number + ", Scale=" + " - " + e.getMessage()); } } return result.toString(); } // TO_NUMBER /** * Get SQL Commands * @param cmdType CMD_* * @return array of commands to be executed */ public String[] getCommands (int cmdType) { if (CMD_CREATE_USER == cmdType) return new String[] { }; // if (CMD_CREATE_DATABASE == cmdType) return new String[] { }; // if (CMD_DROP_DATABASE == cmdType) return new String[] { }; // return null; } // getCommands /************************************************************************** * Get RowSet * @param rs ResultSet * @return RowSet * @throws SQLException */ public RowSet getRowSet (java.sql.ResultSet rs) throws SQLException { throw new UnsupportedOperationException("PostgreSQL does not support RowSets"); } // getRowSet /** * Get Cached Connection on Server * @param connection info * @param autoCommit true if autocommit connection * @param transactionIsolation Connection transaction level * @return connection or null */ public Connection getCachedConnection (CConnection connection, boolean autoCommit, int transactionIsolation) { throw new UnsupportedOperationException("Not supported/implemented"); } /** * Create DataSource (Client) * @param connection connection * @return data dource */ public DataSource getDataSource(CConnection connection) { throw new UnsupportedOperationException("Not supported/implemented"); } /** * Create Pooled DataSource (Server) * @param connection connection * @return data dource */ public ConnectionPoolDataSource createPoolDataSource(CConnection connection) { throw new UnsupportedOperationException("Not supported/implemented"); } /** * Get Connection from Driver * @param connection info * @return connection or null */ public Connection getDriverConnection (CConnection connection) throws SQLException { getDriver(); return DriverManager.getConnection (getConnectionURL (connection), connection.getDbUid(), connection.getDbPwd()); } // getDriverConnection /** * Get Driver Connection * @param dbUrl URL * @param dbUid user * @param dbPwd password * @return connection * @throws SQLException */ public Connection getDriverConnection (String dbUrl, String dbUid, String dbPwd) throws SQLException { getDriver(); return DriverManager.getConnection (dbUrl, dbUid, dbPwd); } // getDriverConnection /** * Close */ public void close() { } // close } // DB_PostgreSQL Index: DB_Oracle.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/db/DB_Oracle.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** DB_Oracle.java 16 Sep 2005 03:54:02 -0000 1.44 --- DB_Oracle.java 31 Dec 2005 06:33:21 -0000 1.45 *************** *** 722,725 **** --- 722,821 ---- + /** + * Get Data Type + * @param displayType display type + * @param precision precision + * @param defaultValue if true adds default value + * @return data type + */ + public String getDataType (int displayType, int precision, + boolean defaultValue) + { + String retValue = null; + switch (displayType) + { + // IDs + case DisplayType.Account: + case DisplayType.Assignment: + case DisplayType.Color: + case DisplayType.ID: + case DisplayType.Location: + case DisplayType.Locator: + case DisplayType.PAttribute: + case DisplayType.Search: + case DisplayType.Table: + case DisplayType.TableDir: + retValue = "NUMBER(10)"; + break; + + // Dynamic Precision + case DisplayType.Amount: + retValue = "NUMBER"; + if (defaultValue) + retValue += " DEFAULT 0"; + break; + + case DisplayType.Binary: + case DisplayType.Image: + retValue = "BLOB"; + break; + + case DisplayType.Button: + retValue = "CHAR(1)"; + break; + + // Number Dynamic Precision + case DisplayType.CostPrice: + retValue = "NUMBER"; + if (defaultValue) + retValue += " DEFAULT 0"; + break; + + // Date + case DisplayType.Date: + case DisplayType.DateTime: + case DisplayType.Time: + retValue = "DATE"; + if (defaultValue) + retValue += " DEFAULT SYSDATE"; + break; + + // Number(10) + case DisplayType.Integer: + retValue = "NUMBER(10)"; + break; + + case DisplayType.List: + retValue = "CHAR(" + precision + ")"; + break; + + // NVARCHAR + case DisplayType.Memo: + case DisplayType.String: + case DisplayType.Text: + retValue = "NVARCHAR(" + precision + ")"; + break; + + case DisplayType.TextLong: + retValue = "CLOB"; + break; + + // Dyn Prec + case DisplayType.Quantity: + retValue = "NUMBER"; + break; + + case DisplayType.YesNo: + retValue = "CHAR(1)"; + break; + + default: + log.severe("Unknown: " + displayType); + break; + } + return retValue; + } // getDataType + + /************************************************************************** Index: Database.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/db/Database.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Database.java 11 Mar 2005 20:29:01 -0000 1.13 --- Database.java 31 Dec 2005 06:33:21 -0000 1.14 *************** *** 32,41 **** /** IBM DB/2 ID */ public static String DB_DB2 = "DB2"; ! /** MySQL ID */ ! public static String DB_MYSQL = "MySQL"; /** Supported Databases */ public static String[] DB_NAMES = new String[] { ! DB_ORACLE, DB_SYBASE // ,DB_POSTGRESQL }; --- 32,43 ---- /** IBM DB/2 ID */ public static String DB_DB2 = "DB2"; ! /** Derby ID */ ! public static String DB_DERBY = "Derby"; /** Supported Databases */ public static String[] DB_NAMES = new String[] { ! DB_ORACLE ! ,DB_DB2 ! ,DB_SYBASE // ,DB_POSTGRESQL }; *************** *** 43,47 **** /** Database Classes */ protected static Class[] DB_CLASSES = new Class[] { ! DB_Oracle.class, DB_Sybase.class // ,DB_PostgreSQL.class }; --- 45,51 ---- /** Database Classes */ protected static Class[] DB_CLASSES = new Class[] { ! DB_Oracle.class ! ,DB_DB2.class ! ,DB_Sybase.class // ,DB_PostgreSQL.class }; Index: CConnection.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/db/CConnection.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** CConnection.java 13 Dec 2005 00:16:10 -0000 1.71 --- CConnection.java 31 Dec 2005 06:33:21 -0000 1.72 *************** *** 195,208 **** private boolean m_okApps = false; ! /** Info */ private String[] m_info = new String[2]; ! /** Server Version */ private String m_version = null; ! /** DataSource */ private DataSource m_ds = null; /** Server Session */ private Server m_server = null; --- 195,210 ---- private boolean m_okApps = false; ! /** Info */ private String[] m_info = new String[2]; ! /** Server Version */ private String m_version = null; ! /** DataSource */ private DataSource m_ds = null; /** Server Session */ private Server m_server = null; + /** DB Info */ + private String m_dbInfo = null; *************** *** 790,798 **** } ! // PostgreSQL ! if (isPostgreSQL ()) { ! if (getDbPort () != DB_PostgreSQL.DEFAULT_PORT) ! setDbPort (DB_PostgreSQL.DEFAULT_PORT); } else if (isSybase()) --- 792,800 ---- } ! // DB2 ! if (isDB2()) { ! if (getDbPort () != DB_DB2.DEFAULT_PORT) ! setDbPort (DB_DB2.DEFAULT_PORT); } else if (isSybase()) *************** *** 832,842 **** /** ! * Is PostgreSQL DB ! * @return true if PostgreSQL */ ! public boolean isPostgreSQL () { ! return Database.DB_POSTGRESQL.equals (m_type); ! } // isPostgreSQL /** --- 834,862 ---- /** ! * Is IBM DB/2 ! * @return true if DB/2 */ ! public boolean isDB2 () { ! return Database.DB_DB2.equals (m_type); ! } // isDB2 ! ! /** ! * Is Apache Derby ! * @return true if Derby ! */ ! public boolean isDerby () ! { ! return Database.DB_DERBY.equals (m_type); ! } // isDerby ! ! /** ! * Is Microsoft SQL Server ! * @return true if Derby ! */ ! public boolean isMSSQLServer() ! { ! return Database.DB_MSSQLServer.equals (m_type); ! } // isMSSQLServer /** *************** *** 986,990 **** + " - " + dbmd.getDriverVersion ()); if (isDataSource()) ! sb.append(" - via DataSource"); conn.close (); } --- 1006,1010 ---- + " - " + dbmd.getDriverVersion ()); if (isDataSource()) ! sb.append(" - via DS"); conn.close (); } *************** *** 995,1000 **** conn = null; return sb.toString (); ! } // toString /** * String representation. --- 1015,1056 ---- conn = null; return sb.toString (); ! } // toStringDetail ! ! /** ! * Get DB Version Info ! * @return info ! */ ! public String getDBInfo() ! { ! if (m_dbInfo != null) ! return m_dbInfo; ! StringBuffer sb = new StringBuffer (); ! Connection conn = getConnection (true, ! Connection.TRANSACTION_READ_COMMITTED); ! if (conn != null) ! { ! try ! { ! DatabaseMetaData dbmd = conn.getMetaData (); ! sb.append(dbmd.getDatabaseProductName()) ! .append(",").append(dbmd.getDatabaseProductVersion()); ! sb.append(";").append(dbmd.getDriverName()) ! .append(",").append(dbmd.getDriverVersion()); ! if (isDataSource()) ! sb.append(";DS"); ! conn.close (); ! m_dbInfo = sb.toString (); ! } ! catch (Exception e) ! { ! log.log(Level.SEVERE, "", e); ! sb.append(e.getLocalizedMessage()); ! } ! } ! conn = null; ! return sb.toString(); ! } // toStringDetail + /** * String representation. Index: CompiereDatabase.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/db/CompiereDatabase.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** CompiereDatabase.java 16 Sep 2005 03:54:02 -0000 1.25 --- CompiereDatabase.java 31 Dec 2005 06:33:21 -0000 1.26 *************** *** 218,221 **** --- 218,229 ---- public void close(); + /** + * Get Data Type + * @param DisplayType display type + * @return data type + */ + // public String getDataType (int displayType, int precision, + // boolean defaultValue) + } // CompiereDatabase Index: DB_Sybase.java =================================================================== RCS file: /cvsroot/compiere/dbPort/src/org/compiere/db/DB_Sybase.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DB_Sybase.java 11 Mar 2005 20:29:01 -0000 1.9 --- DB_Sybase.java 31 Dec 2005 06:33:21 -0000 1.10 *************** *** 104,111 **** if (s_driver == null) { ! if (JTDS) s_driver = new net.sourceforge.jtds.jdbc.Driver(); ! else ! s_driver = new com.sybase.jdbc3.jdbc.SybDriver(); DriverManager.registerDriver (s_driver); DriverManager.setLoginTimeout (Database.CONNECTION_TIMEOUT); --- 104,111 ---- if (s_driver == null) { ! // if (JTDS) s_driver = new net.sourceforge.jtds.jdbc.Driver(); ! // else ! // s_driver = new com.sybase.jdbc3.jdbc.SybDriver(); DriverManager.registerDriver (s_driver); DriverManager.setLoginTimeout (Database.CONNECTION_TIMEOUT); *************** *** 466,470 **** return m_ds; ! if (JTDS) { net.sourceforge.jtds.jdbcx.JtdsDataSource ds = new net.sourceforge.jtds.jdbcx.JtdsDataSource(); --- 466,470 ---- return m_ds; ! // if (JTDS) { net.sourceforge.jtds.jdbcx.JtdsDataSource ds = new net.sourceforge.jtds.jdbcx.JtdsDataSource(); *************** *** 479,482 **** --- 479,483 ---- m_ds = ds; } + /** else { *************** *** 491,494 **** --- 492,496 ---- m_ds = ds; } + **/ // m_ds.setLoginTimeout(10); // |