KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > dialect > PostgreSQLDialect


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: ferraro@users.sourceforge.net
20  */

21 package net.sf.hajdbc.dialect;
22
23 import java.sql.DatabaseMetaData JavaDoc;
24 import java.sql.ResultSetMetaData JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.sql.Types JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28
29 /**
30  * @author Paul Ferraro
31  * @since 1.1
32  */

33 public class PostgreSQLDialect extends DefaultDialect
34 {
35     /**
36      * Default implementation will not block INSERT statements.
37      * Requires explicit exclusive mode table lock.
38      * <p><em>From PostgreSQL documentation</em></p>
39      * Unlike traditional database systems which use locks for concurrency control, PostgreSQL maintains data consistency by using a multiversion model (Multiversion Concurrency Control, MVCC).
40      * This means that while querying a database each transaction sees a snapshot of data (a database version) as it was some time ago, regardless of the current state of the underlying data.
41      * This protects the transaction from viewing inconsistent data that could be caused by (other) concurrent transaction updates on the same data rows, providing transaction isolation for each database session. *
42      * @see net.sf.hajdbc.dialect.DefaultDialect#getLockTableSQL(java.sql.DatabaseMetaData, java.lang.String, java.lang.String)
43      */

44     @Override JavaDoc
45     public String JavaDoc getLockTableSQL(DatabaseMetaData JavaDoc metaData, String JavaDoc schema, String JavaDoc table) throws SQLException JavaDoc
46     {
47         return MessageFormat.format("LOCK TABLE {0} IN EXCLUSIVE MODE", this.qualifyTable(metaData, schema, table));
48     }
49
50     /**
51      * PostgreSQL uses the native type OID for BLOBs. However the driver interprets them as INTEGERs. OID columns should really be interpretted as BLOBs.
52      * @see net.sf.hajdbc.Dialect#getColumnType(java.sql.ResultSetMetaData, int)
53      */

54     @Override JavaDoc
55     public int getColumnType(ResultSetMetaData JavaDoc metaData, int column) throws SQLException JavaDoc
56     {
57         return metaData.getColumnTypeName(column).equals("oid") ? Types.BLOB : super.getColumnType(metaData, column);
58     }
59
60     /**
61      * @see net.sf.hajdbc.dialect.DefaultDialect#truncateTablePattern()
62      */

63     @Override JavaDoc
64     protected String JavaDoc truncateTablePattern()
65     {
66         return "TRUNCATE TABLE {0}";
67     }
68 }
69
Popular Tags