KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > db > DB_PostgreSQL


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.db;
15
16 import java.sql.*;
17 import javax.sql.RowSet JavaDoc;
18
19 //import org.postgresql.*;
20

21 import org.compiere.dbPort.*;
22
23 /**
24  * PostgreSQL Database Port
25  *
26  * @author Jorg Janke
27  * @version $Id: DB_PostgreSQL.java,v 1.14 2003/09/27 01:22:18 jjanke Exp $
28  */

29 public class DB_PostgreSQL implements CompiereDatabase
30 {
31     /**
32      * PostgreSQL Database
33      */

34     public DB_PostgreSQL()
35     {
36         try
37         {
38             if (s_driver == null)
39                 s_driver = new org.postgresql.Driver();
40         }
41         catch (SQLException e)
42         {
43             System.err.println(e);
44         }
45     } // DB_PostgreSQL
46

47     /** Driver */
48     private org.postgresql.Driver s_driver = null;
49
50     /** Default Port */
51     public static final int DEFAULT_PORT = 5432;
52
53     /** Statement Converter */
54     private Convert m_convert = new Convert(Database.DB_POSTGRESQL, null);
55     /** Connection String */
56     private String JavaDoc m_connection;
57
58     /**
59      * Get Database Name
60      * @return database short name
61      */

62     public String JavaDoc getName()
63     {
64         return Database.DB_POSTGRESQL;
65     } // getName
66

67     /**
68      * Get Database Description
69      * @return database long name and version
70      */

71     public String JavaDoc getDescription()
72     {
73         return s_driver.toString();
74     } // getDescription
75

76     /**
77      * Get Standard JDBC Port
78      * @return standard port
79      */

80     public int getStandardPort()
81     {
82         return DEFAULT_PORT;
83     } // getStandardPort
84

85     /**
86      * Get Database Driver
87      * @return Driver
88      */

89     public java.sql.Driver JavaDoc getDriver()
90     {
91         return s_driver;
92     } // getDriver
93

94     /**
95      * Get Database Connection String.
96      * Requirements:
97      * - createdb -E UNICODE compiere
98      * @param connection Connection Descriptor
99      * @return connection String
100      */

101     public String JavaDoc getConnectionURL (CConnection connection)
102     {
103         // jdbc:postgresql://hostname:portnumber/databasename?encoding=UNICODE
104
StringBuffer JavaDoc sb = new StringBuffer JavaDoc("jdbc:postgresql:");
105         sb.append("//").append(connection.getDbHost())
106             .append(":").append(connection.getDbPort())
107             .append("/").append(connection.getDbName())
108             .append("?encoding=UNICODE");
109         m_connection = sb.toString();
110         return m_connection;
111     } // getConnectionString
112

113     /**
114      * Supports BLOB
115      * @return true if BLOB is supported
116      */

117     public boolean supportsBLOB()
118     {
119         return false;
120     } // supportsBLOB
121

122     /**
123      * String Representation
124      * @return info
125      */

126     public String JavaDoc toString()
127     {
128         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("DB_PostgreSQL[");
129         sb.append(m_connection)
130             .append("]");
131         return sb.toString();
132     } // toString
133

134     /*************************************************************************/
135
136     /**
137      * Convert an individual Oracle Style statements to target database statement syntax
138      *
139      * @param oraStatement
140      * @return converted Statement
141      * @throws Exception
142      */

143     public String JavaDoc convertStatement (String JavaDoc oraStatement)
144     {
145         String JavaDoc retValue[] = m_convert.convert(oraStatement);
146         if (retValue == null)
147             throw new IllegalArgumentException JavaDoc
148                 ("DB_PostgreSQL.convertStatement - Not Converted (" + oraStatement + ") - "
149                     + m_convert.getConversionError());
150         if (retValue.length != 1)
151             throw new IllegalArgumentException JavaDoc
152                 ("DB_PostgreSQL.convertStatement - Convert Command Number=" + retValue.length
153                     + " (" + oraStatement + ") - " + m_convert.getConversionError());
154         // Diagnostics (show changed, but not if AD_Error
155
if (!oraStatement.equals(retValue[0]) && retValue[0].indexOf("AD_Error") == -1)
156             System.out.println("PostgreSQL =>" + retValue[0] + "<= <" + oraStatement + ">");
157         //
158
return retValue[0];
159     } // convertStatement
160

161     /*************************************************************************/
162
163     /**
164      * Set the RowID
165      * @param pstmt
166      * @param pos
167      * @param rowID
168      * @throws SQLException
169      */

170     public void setRowID (PreparedStatement pstmt, int pos, Object JavaDoc rowID) throws SQLException
171     {
172         pstmt.setString (pos, (String JavaDoc)rowID);
173     } // setRowID
174

175     /**
176      * Get the RowID
177      * @param rs
178      * @param pos
179      * @return rowID
180      * @throws SQLException
181      */

182     public Object JavaDoc getRowID (java.sql.ResultSet JavaDoc rs, int pos) throws SQLException
183     {
184         return rs.getString (pos);
185     } // getRowID
186

187     /**
188      * Get RowSet
189      * @param rs ResultSet
190      * @return RowSet
191      * @throws SQLException
192      */

193     public RowSet JavaDoc getRowSet (java.sql.ResultSet JavaDoc rs) throws SQLException
194     {
195         throw new UnsupportedOperationException JavaDoc("PostgreSQL does not support RowSets");
196     } // getRowSet
197

198 } // DB_PostgreSQL
199
Popular Tags