Commit f37c1c48 authored by Bruce Momjian's avatar Bruce Momjian

Run pgjindent for Java folks.

parent b4295d05
......@@ -233,7 +233,7 @@ public class Unicode
catch (ClassNotFoundException cnfe)
{
log("Unable to load driver", cnfe);
return;
return ;
}
try
{
......
......@@ -6,7 +6,7 @@ import java.text.*;
/*
*
* $Id: basic.java,v 1.12 2002/07/23 03:59:54 barry Exp $
* $Id: basic.java,v 1.13 2002/09/06 21:23:05 momjian Exp $
*
* This example tests the basic components of the JDBC driver, and shows
* how even the simplest of queries can be implemented.
......@@ -137,6 +137,7 @@ public class basic
// result if you don't know what column number a value is in
System.out.println("performing another query");
rs = st.executeQuery("select * from basic where b>1");
if (rs != null)
......@@ -164,6 +165,7 @@ public class basic
// Now test maxrows by setting it to 3 rows
st.setMaxRows(3);
System.out.println("performing a query limited to " + st.getMaxRows());
rs = st.executeQuery("select a, b from basic");
......
......@@ -9,7 +9,7 @@ import org.omg.CosNaming.*;
*
* It has no GUI, just a text frontend to keep it simple.
*
* $Id: StockClient.java,v 1.5 2001/11/19 23:19:20 momjian Exp $
* $Id: StockClient.java,v 1.6 2002/09/06 21:23:05 momjian Exp $
*/
public class StockClient
{
......@@ -35,14 +35,14 @@ public class StockClient
if (nameServiceObj == null)
{
System.err.println("nameServiceObj == null");
return;
return ;
}
nameService = org.omg.CosNaming.NamingContextHelper.narrow(nameServiceObj);
if (nameService == null)
{
System.err.println("nameService == null");
return;
return ;
}
// Resolve the dispenser
......@@ -53,7 +53,7 @@ public class StockClient
if (dispenser == null)
{
System.err.println("dispenser == null");
return;
return ;
}
// Now run the front end.
......
......@@ -5,7 +5,7 @@ import org.omg.CosNaming.*;
/*
* This class implements the server side of the example.
*
* $Id: StockDispenserImpl.java,v 1.4 2001/11/19 23:19:20 momjian Exp $
* $Id: StockDispenserImpl.java,v 1.5 2002/09/06 21:23:05 momjian Exp $
*/
public class StockDispenserImpl extends stock._StockDispenserImplBase
{
......@@ -67,11 +67,11 @@ public class StockDispenserImpl extends stock._StockDispenserImplBase
{
stock[i].inUse = false;
System.out.println("Releasing slot " + i);
return;
return ;
}
}
System.out.println("Reserved object not a member of this dispenser");
return;
return ;
}
/*
......
......@@ -5,7 +5,7 @@ import org.omg.CosNaming.*;
/*
* This class implements the server side of the example.
*
* $Id: StockServer.java,v 1.4 2001/11/19 23:19:20 momjian Exp $
* $Id: StockServer.java,v 1.5 2002/09/06 21:23:05 momjian Exp $
*/
public class StockServer
{
......@@ -29,14 +29,14 @@ public class StockServer
if (nameServiceObj == null)
{
System.err.println("nameServiceObj = null");
return;
return ;
}
org.omg.CosNaming.NamingContext nameService = org.omg.CosNaming.NamingContextHelper.narrow(nameServiceObj);
if (nameService == null)
{
System.err.println("nameService = null");
return;
return ;
}
// bind the dispenser into the naming service
......
......@@ -82,7 +82,7 @@ public class psql
if (line.startsWith("\\"))
{
processSlashCommand(line);
return;
return ;
}
boolean type = st.execute(line);
......
......@@ -109,12 +109,14 @@ public class Driver implements java.sql.Driver
{
if ((props = parseURL(url, info)) == null)
{
if (Driver.logDebug) Driver.debug("Error in url" + url);
if (Driver.logDebug)
Driver.debug("Error in url" + url);
return null;
}
try
{
if (Driver.logDebug) Driver.debug("connect " + url);
if (Driver.logDebug)
Driver.debug("connect " + url);
@JDBCCONNECTCLASS@ con = (@JDBCCONNECTCLASS@)(Class.forName("@JDBCCONNECTCLASS@").newInstance());
con.openConnection (host(), port(), props, database(), url, this);
......@@ -122,7 +124,8 @@ public class Driver implements java.sql.Driver
}
catch (ClassNotFoundException ex)
{
if (Driver.logDebug) Driver.debug("error", ex);
if (Driver.logDebug)
Driver.debug("error", ex);
throw new PSQLException("postgresql.jvm.version", ex);
}
catch (PSQLException ex1)
......@@ -133,7 +136,8 @@ public class Driver implements java.sql.Driver
}
catch (Exception ex2)
{
if (Driver.logDebug) Driver.debug("error", ex2);
if (Driver.logDebug)
Driver.debug("error", ex2);
throw new PSQLException("postgresql.unusual", ex2);
}
}
......
......@@ -7,7 +7,7 @@ import org.postgresql.core.Encoding;
import org.postgresql.fastpath.Fastpath;
import org.postgresql.largeobject.LargeObjectManager;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGConnection.java,v 1.2 2002/09/02 03:07:36 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGConnection.java,v 1.3 2002/09/06 21:23:05 momjian Exp $
* This interface defines PostgreSQL extentions to the java.sql.Connection interface.
* Any java.sql.Connection object returned by the driver will also implement this
* interface
......
package org.postgresql;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGNotification.java,v 1.1 2002/09/02 03:07:36 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGNotification.java,v 1.2 2002/09/06 21:23:05 momjian Exp $
* This interface defines PostgreSQL extention for Notifications
*/
public interface PGNotification
......
......@@ -3,7 +3,7 @@ package org.postgresql;
import java.sql.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGStatement.java,v 1.4 2002/09/02 03:07:36 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/Attic/PGStatement.java,v 1.5 2002/09/06 21:23:05 momjian Exp $
* This interface defines PostgreSQL extentions to the java.sql.Statement interface.
* Any java.sql.Statement object returned by the driver will also implement this
* interface
......
......@@ -8,7 +8,7 @@ import org.postgresql.util.*;
/*
* Converts to and from the character encoding used by the backend.
*
* $Id: Encoding.java,v 1.5 2002/03/19 02:48:45 momjian Exp $
* $Id: Encoding.java,v 1.6 2002/09/06 21:23:05 momjian Exp $
*/
public class Encoding
......@@ -42,14 +42,14 @@ public class Encoding
encodings.put("EUC_KR", new String[] { "EUC_KR" });
encodings.put("JOHAB", new String[] { "Johab" });
encodings.put("EUC_TW", new String[] { "EUC_TW" });
encodings.put("SJIS", new String[] { "MS932","SJIS" });
encodings.put("BIG5", new String[] { "Big5","MS950","Cp950" });
encodings.put("GBK", new String[] { "GBK","MS936" });
encodings.put("UHC", new String[] { "MS949","Cp949","Cp949C" });
encodings.put("SJIS", new String[] { "MS932", "SJIS" });
encodings.put("BIG5", new String[] { "Big5", "MS950", "Cp950" });
encodings.put("GBK", new String[] { "GBK", "MS936" });
encodings.put("UHC", new String[] { "MS949", "Cp949", "Cp949C" });
encodings.put("TCVN", new String[] { "Cp1258" });
encodings.put("WIN1256", new String[] { "Cp1256" });
encodings.put("WIN1250", new String[] { "Cp1250" });
encodings.put("WIN874", new String[] { "MS874","Cp874" });
encodings.put("WIN874", new String[] { "MS874", "Cp874" });
encodings.put("WIN", new String[] { "Cp1251" });
encodings.put("ALT", new String[] { "Cp866" });
// We prefer KOI8-U, since it is a superset of KOI8-R.
......
package org.postgresql.core;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Notification.java,v 1.1 2002/09/02 03:07:36 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/core/Attic/Notification.java,v 1.2 2002/09/06 21:23:05 momjian Exp $
* This is the implementation of the PGNotification interface
*/
public class Notification implements org.postgresql.PGNotification
{
public Notification(String p_name, int p_pid) {
public Notification(String p_name, int p_pid)
{
m_name = p_name;
m_pid = p_pid;
}
......@@ -14,14 +15,16 @@ public class Notification implements org.postgresql.PGNotification
/*
* Returns name of this notification
*/
public String getName() {
public String getName()
{
return m_name;
}
/*
* Returns the process id of the backend process making this notification
*/
public int getPID() {
public int getPID()
{
return m_pid;
}
......
......@@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException;
* <p>The lifetime of a QueryExecutor object is from sending the query
* until the response has been received from the backend.
*
* $Id: QueryExecutor.java,v 1.15 2002/09/02 03:07:36 barry Exp $
* $Id: QueryExecutor.java,v 1.16 2002/09/06 21:23:05 momjian Exp $
*/
public class QueryExecutor
......@@ -137,7 +137,8 @@ public class QueryExecutor
try
{
pg_stream.SendChar('Q');
for (int i = 0 ; i < m_binds.length ; ++i) {
for (int i = 0 ; i < m_binds.length ; ++i)
{
if (m_binds[i] == null)
throw new PSQLException("postgresql.prep.param", new Integer(i + 1));
pg_stream.Send(connection.getEncoding().encode(m_sqlFrags[i]));
......
......@@ -6,7 +6,7 @@ import java.io.IOException;
/**
* Sent to the backend to initialize a newly created connection.
*
* $Id: StartupPacket.java,v 1.1 2002/03/21 02:40:03 davec Exp $
* $Id: StartupPacket.java,v 1.2 2002/09/06 21:23:05 momjian Exp $
*/
public class StartupPacket
......@@ -22,7 +22,8 @@ public class StartupPacket
private String user;
private String database;
public StartupPacket(int protocolMajor, int protocolMinor, String user, String database) {
public StartupPacket(int protocolMajor, int protocolMinor, String user, String database)
{
this.protocolMajor = protocolMajor;
this.protocolMinor = protocolMinor;
this.user = user;
......
......@@ -118,7 +118,8 @@ public class Fastpath
case 'V':
int l_nextChar = stream.ReceiveChar();
if (l_nextChar == 'G') {
if (l_nextChar == 'G')
{
int sz = stream.ReceiveIntegerR(4);
// Return an Integer if
if (resulttype)
......@@ -131,7 +132,9 @@ public class Fastpath
}
//There should be a trailing '0'
int l_endChar = stream.ReceiveChar();
} else {
}
else
{
//it must have been a '0', thus no results
}
break;
......@@ -174,7 +177,8 @@ public class Fastpath
*/
public Object fastpath(String name, boolean resulttype, FastpathArg[] args) throws SQLException
{
if (Driver.logDebug) Driver.debug("Fastpath: calling "+name);
if (Driver.logDebug)
Driver.debug("Fastpath: calling " + name);
return fastpath(getID(name), resulttype, args);
}
......
......@@ -14,7 +14,7 @@ import org.postgresql.largeobject.LargeObjectManager;
import org.postgresql.util.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.7 2002/09/02 03:07:36 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.8 2002/09/06 21:23:05 momjian Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
......@@ -130,23 +130,29 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
//Read loglevel arg and set the loglevel based on this value
//in addition to setting the log level enable output to
//standard out if no other printwriter is set
String l_logLevelProp = info.getProperty("loglevel","0");
String l_logLevelProp = info.getProperty("loglevel", "0");
int l_logLevel = 0;
try {
try
{
l_logLevel = Integer.parseInt(l_logLevelProp);
if (l_logLevel > org.postgresql.Driver.DEBUG || l_logLevel < org.postgresql.Driver.INFO) {
if (l_logLevel > org.postgresql.Driver.DEBUG || l_logLevel < org.postgresql.Driver.INFO)
{
l_logLevel = 0;
}
} catch (Exception l_e) {
}
catch (Exception l_e)
{
//invalid value for loglevel ignore
}
if (l_logLevel > 0) {
if (l_logLevel > 0)
{
org.postgresql.Driver.setLogLevel(l_logLevel);
enableDriverManagerLogging();
}
//Print out the driver version number
if (org.postgresql.Driver.logInfo) org.postgresql.Driver.info(org.postgresql.Driver.getVersion());
if (org.postgresql.Driver.logInfo)
org.postgresql.Driver.info(org.postgresql.Driver.getVersion());
// Now make the initial connection
try
......@@ -205,7 +211,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
rst[0] = (byte)pg_stream.ReceiveChar();
rst[1] = (byte)pg_stream.ReceiveChar();
salt = new String(rst, 0, 2);
if (org.postgresql.Driver.logDebug) org.postgresql.Driver.debug("Crypt salt=" + salt);
if (org.postgresql.Driver.logDebug)
org.postgresql.Driver.debug("Crypt salt=" + salt);
}
// Or get the md5 password salt if there is one
......@@ -217,7 +224,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
md5Salt[2] = (byte)pg_stream.ReceiveChar();
md5Salt[3] = (byte)pg_stream.ReceiveChar();
salt = new String(md5Salt, 0, 4);
if (org.postgresql.Driver.logDebug) org.postgresql.Driver.debug("MD5 salt=" + salt);
if (org.postgresql.Driver.logDebug)
org.postgresql.Driver.debug("MD5 salt=" + salt);
}
// now send the auth packet
......@@ -227,15 +235,18 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
break;
case AUTH_REQ_KRB4:
if (org.postgresql.Driver.logDebug) org.postgresql.Driver.debug("postgresql: KRB4");
if (org.postgresql.Driver.logDebug)
org.postgresql.Driver.debug("postgresql: KRB4");
throw new PSQLException("postgresql.con.kerb4");
case AUTH_REQ_KRB5:
if (org.postgresql.Driver.logDebug) org.postgresql.Driver.debug("postgresql: KRB5");
if (org.postgresql.Driver.logDebug)
org.postgresql.Driver.debug("postgresql: KRB5");
throw new PSQLException("postgresql.con.kerb5");
case AUTH_REQ_PASSWORD:
if (org.postgresql.Driver.logDebug) org.postgresql.Driver.debug("postgresql: PASSWORD");
if (org.postgresql.Driver.logDebug)
org.postgresql.Driver.debug("postgresql: PASSWORD");
pg_stream.SendInteger(5 + password.length(), 4);
pg_stream.Send(password.getBytes());
pg_stream.SendInteger(0, 1);
......@@ -243,7 +254,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
break;
case AUTH_REQ_CRYPT:
if (org.postgresql.Driver.logDebug) org.postgresql.Driver.debug("postgresql: CRYPT");
if (org.postgresql.Driver.logDebug)
org.postgresql.Driver.debug("postgresql: CRYPT");
String crypted = UnixCrypt.crypt(salt, password);
pg_stream.SendInteger(5 + crypted.length(), 4);
pg_stream.Send(crypted.getBytes());
......@@ -252,7 +264,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
break;
case AUTH_REQ_MD5:
if (org.postgresql.Driver.logDebug) org.postgresql.Driver.debug("postgresql: MD5");
if (org.postgresql.Driver.logDebug)
org.postgresql.Driver.debug("postgresql: MD5");
byte[] digest = MD5Digest.encode(PG_USER, password, md5Salt);
pg_stream.SendInteger(5 + digest.length, 4);
pg_stream.Send(digest);
......@@ -280,7 +293,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
// As of protocol version 2.0, we should now receive the cancellation key and the pid
int beresp;
do {
do
{
beresp = pg_stream.ReceiveChar();
switch (beresp)
{
......@@ -296,10 +310,12 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
default:
throw new PSQLException("postgresql.con.setup");
}
} while (beresp == 'N');
}
while (beresp == 'N');
// Expect ReadyForQuery packet
do {
do
{
beresp = pg_stream.ReceiveChar();
switch (beresp)
{
......@@ -313,7 +329,8 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
default:
throw new PSQLException("postgresql.con.setup");
}
} while (beresp == 'N');
}
while (beresp == 'N');
// "pg_encoding_to_char(1)" will return 'EUC_JP' for a backend compiled with multibyte,
// otherwise it's hardcoded to 'SQL_ASCII'.
// If the backend doesn't know about multibyte we can't assume anything about the encoding
......@@ -877,7 +894,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
public void setAutoCommit(boolean autoCommit) throws SQLException
{
if (this.autoCommit == autoCommit)
return;
return ;
if (autoCommit)
ExecSQL("end");
else
......@@ -920,7 +937,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
public void commit() throws SQLException
{
if (autoCommit)
return;
return ;
if (haveMinimumServerVersion("7.1"))
{
ExecSQL("commit;begin;" + getIsolationLevelSQL());
......@@ -944,7 +961,7 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
public void rollback() throws SQLException
{
if (autoCommit)
return;
return ;
if (haveMinimumServerVersion("7.1"))
{
ExecSQL("rollback; begin;" + getIsolationLevelSQL());
......@@ -1222,8 +1239,10 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
//Because the get/setLogStream methods are deprecated in JDBC2
//we use them for JDBC1 here and override this method in the jdbc2
//version of this class
protected void enableDriverManagerLogging() {
if (DriverManager.getLogStream() == null) {
protected void enableDriverManagerLogging()
{
if (DriverManager.getLogStream() == null)
{
DriverManager.setLogStream(System.out);
}
}
......@@ -1313,15 +1332,18 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
};
//Methods to support postgres notifications
public void addNotification(org.postgresql.PGNotification p_notification) {
public void addNotification(org.postgresql.PGNotification p_notification)
{
if (m_notifications == null)
m_notifications = new Vector();
m_notifications.addElement(p_notification);
}
public PGNotification[] getNotifications() {
public PGNotification[] getNotifications()
{
PGNotification[] l_return = null;
if (m_notifications != null) {
if (m_notifications != null)
{
l_return = new PGNotification[m_notifications.size()];
m_notifications.copyInto(l_return);
}
......
......@@ -13,7 +13,7 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.PGbytea;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.5 2002/09/02 03:07:36 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.6 2002/09/06 21:23:06 momjian Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2
* methods. The real ResultSet class (for jdbc1) is org.postgresql.jdbc1.Jdbc1ResultSet
......@@ -39,7 +39,7 @@ public abstract class AbstractJdbc1ResultSet
protected ResultSet next = null;
protected StringBuffer sbuf = null;
public byte[][] rowBuffer=null;
public byte[][] rowBuffer = null;
public AbstractJdbc1ResultSet(org.postgresql.PGConnection conn, Statement statement, Field[] fields, Vector tuples, String status, int updateCount, long insertOID, boolean binaryCursor)
......@@ -67,8 +67,8 @@ public abstract class AbstractJdbc1ResultSet
this_row = (byte [][])rows.elementAt(current_row);
rowBuffer=new byte[this_row.length][];
System.arraycopy(this_row,0,rowBuffer,0,this_row.length);
rowBuffer = new byte[this_row.length][];
System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
return true;
}
......@@ -230,12 +230,12 @@ public abstract class AbstractJdbc1ResultSet
public Time getTime(int columnIndex) throws SQLException
{
return toTime( getString(columnIndex), (java.sql.ResultSet)this, fields[columnIndex-1].getPGType() );
return toTime( getString(columnIndex), (java.sql.ResultSet)this, fields[columnIndex - 1].getPGType() );
}
public Timestamp getTimestamp(int columnIndex) throws SQLException
{
return toTimestamp( getString(columnIndex), (java.sql.ResultSet)this, fields[columnIndex-1].getPGType() );
return toTimestamp( getString(columnIndex), (java.sql.ResultSet)this, fields[columnIndex - 1].getPGType() );
}
public InputStream getAsciiStream(int columnIndex) throws SQLException
......@@ -423,7 +423,8 @@ public abstract class AbstractJdbc1ResultSet
warnings = null;
}
public void addWarnings(SQLWarning warnings) {
public void addWarnings(SQLWarning warnings)
{
if ( this.warnings != null )
this.warnings.setNextWarning(warnings);
else
......@@ -660,8 +661,10 @@ public abstract class AbstractJdbc1ResultSet
protected void checkResultSet( int column ) throws SQLException
{
if ( this_row == null ) throw new PSQLException("postgresql.res.nextrequired");
if ( column < 1 || column > fields.length ) throw new PSQLException("postgresql.res.colrange" );
if ( this_row == null )
throw new PSQLException("postgresql.res.nextrequired");
if ( column < 1 || column > fields.length )
throw new PSQLException("postgresql.res.colrange" );
}
//----------------- Formatting Methods -------------------
......@@ -789,23 +792,31 @@ public abstract class AbstractJdbc1ResultSet
return null; // SQL NULL
try
{
if (s.length() == 8) {
if (s.length() == 8)
{
//value is a time value
return java.sql.Time.valueOf(s);
} else if (s.indexOf(".") == 8) {
}
else if (s.indexOf(".") == 8)
{
//value is a time value with fractional seconds
java.sql.Time l_time = java.sql.Time.valueOf(s.substring(0,8));
java.sql.Time l_time = java.sql.Time.valueOf(s.substring(0, 8));
String l_strMillis = s.substring(9);
if (l_strMillis.length() > 3)
l_strMillis = l_strMillis.substring(0,3);
l_strMillis = l_strMillis.substring(0, 3);
int l_millis = Integer.parseInt(l_strMillis);
if (l_millis < 10) {
if (l_millis < 10)
{
l_millis = l_millis * 100;
} else if (l_millis < 100) {
}
else if (l_millis < 100)
{
l_millis = l_millis * 10;
}
return new java.sql.Time(l_time.getTime() + l_millis);
} else {
}
else
{
//value is a timestamp
return new java.sql.Time(toTimestamp(s, resultSet, pgDataType).getTime());
}
......@@ -847,12 +858,14 @@ public abstract class AbstractJdbc1ResultSet
synchronized (rs)
{
SimpleDateFormat df = null;
if ( org.postgresql.Driver.logDebug ) org.postgresql.Driver.debug("the data from the DB is "+s);
if ( org.postgresql.Driver.logDebug )
org.postgresql.Driver.debug("the data from the DB is " + s);
// If first time, create the buffer, otherwise clear it.
if (rs.sbuf == null)
rs.sbuf = new StringBuffer(32);
else {
else
{
rs.sbuf.setLength(0);
}
......@@ -880,7 +893,8 @@ public abstract class AbstractJdbc1ResultSet
if (i < 24)
rs.sbuf.append(c);
c = s.charAt(i++);
} while (i < slen && Character.isDigit(c));
}
while (i < slen && Character.isDigit(c));
// If there wasn't at least 3 digits we should add some zeros
// to make up the 3 digits we tell java to expect.
......@@ -913,10 +927,13 @@ public abstract class AbstractJdbc1ResultSet
{
// Just found fractional seconds but no timezone.
//If timestamptz then we use GMT, else local timezone
if (pgDataType.equals("timestamptz")) {
if (pgDataType.equals("timestamptz"))
{
rs.sbuf.append(" GMT");
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
} else {
}
else
{
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
}
......@@ -925,10 +942,13 @@ public abstract class AbstractJdbc1ResultSet
{
// No tz or fractional second info.
//If timestamptz then we use GMT, else local timezone
if (pgDataType.equals("timestamptz")) {
if (pgDataType.equals("timestamptz"))
{
rs.sbuf.append(" GMT");
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
} else {
}
else
{
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
}
......@@ -952,7 +972,8 @@ public abstract class AbstractJdbc1ResultSet
try
{
// All that's left is to parse the string and return the ts.
if ( org.postgresql.Driver.logDebug ) org.postgresql.Driver.debug( "" + df.parse(rs.sbuf.toString()).getTime() );
if ( org.postgresql.Driver.logDebug )
org.postgresql.Driver.debug( "" + df.parse(rs.sbuf.toString()).getTime() );
return new Timestamp(df.parse(rs.sbuf.toString()).getTime());
}
......
......@@ -6,7 +6,7 @@ import java.sql.*;
import org.postgresql.Field;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Connection.java,v 1.4 2002/07/26 05:29:35 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Connection.java,v 1.5 2002/09/06 21:23:06 momjian Exp $
* This class implements the java.sql.Connection interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1Connection
......
......@@ -5,7 +5,7 @@ import java.sql.*;
import java.util.Vector;
import org.postgresql.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1ResultSet.java,v 1.3 2002/07/26 05:29:35 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1ResultSet.java,v 1.4 2002/09/06 21:23:06 momjian Exp $
* This class implements the java.sql.ResultSet interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1ResultSet
......
......@@ -3,7 +3,7 @@ package org.postgresql.jdbc1;
import java.sql.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Statement.java,v 1.2 2002/07/24 22:08:40 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/Jdbc1Statement.java,v 1.3 2002/09/06 21:23:06 momjian Exp $
* This class implements the java.sql.Statement interface for JDBC1.
* However most of the implementation is really done in
* org.postgresql.jdbc1.AbstractJdbc1Statement
......
......@@ -6,7 +6,7 @@ import java.net.ConnectException;
import java.sql.*;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Connection.java,v 1.1 2002/07/23 03:59:55 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Connection.java,v 1.2 2002/09/06 21:23:06 momjian Exp $
* This class defines methods of the jdbc2 specification. This class extends
* org.postgresql.jdbc1.AbstractJdbc1Connection which provides the jdbc1
* methods. The real Connection class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Connection
......@@ -55,34 +55,44 @@ public abstract class AbstractJdbc2Connection extends org.postgresql.jdbc1.Abstr
public void cancelQuery() throws SQLException
{
org.postgresql.PG_Stream cancelStream = null;
try {
try
{
cancelStream = new org.postgresql.PG_Stream(PG_HOST, PG_PORT);
} catch (ConnectException cex) {
}
catch (ConnectException cex)
{
// Added by Peter Mount <peter@retep.org.uk>
// ConnectException is thrown when the connection cannot be made.
// we trap this an return a more meaningful message for the end user
throw new PSQLException ("postgresql.con.refused");
} catch (IOException e) {
throw new PSQLException ("postgresql.con.failed",e);
}
catch (IOException e)
{
throw new PSQLException ("postgresql.con.failed", e);
}
// Now we need to construct and send a cancel packet
try {
try
{
cancelStream.SendInteger(16, 4);
cancelStream.SendInteger(80877102, 4);
cancelStream.SendInteger(pid, 4);
cancelStream.SendInteger(ckey, 4);
cancelStream.flush();
}
catch(IOException e) {
throw new PSQLException("postgresql.con.failed",e);
catch (IOException e)
{
throw new PSQLException("postgresql.con.failed", e);
}
finally {
try {
if(cancelStream != null)
finally
{
try
{
if (cancelStream != null)
cancelStream.close();
}
catch(IOException e) {} // Ignore
catch (IOException e)
{} // Ignore
}
}
......@@ -111,8 +121,10 @@ public abstract class AbstractJdbc2Connection extends org.postgresql.jdbc1.Abstr
//Because the get/setLogStream methods are deprecated in JDBC2
//we use the get/setLogWriter methods here for JDBC2 by overriding
//the base version of this method
protected void enableDriverManagerLogging() {
if (DriverManager.getLogWriter() == null) {
protected void enableDriverManagerLogging()
{
if (DriverManager.getLogWriter() == null)
{
DriverManager.setLogWriter(new PrintWriter(System.out));
}
}
......
......@@ -513,40 +513,40 @@ public abstract class AbstractJdbc2ResultSetMetaData extends org.postgresql.jdbc
switch (sql_type)
{
case Types.BIT:
return("java.lang.Boolean");
return ("java.lang.Boolean");
case Types.SMALLINT:
return("java.lang.Short");
return ("java.lang.Short");
case Types.INTEGER:
return("java.lang.Integer");
return ("java.lang.Integer");
case Types.BIGINT:
return("java.lang.Long");
return ("java.lang.Long");
case Types.NUMERIC:
return("java.math.BigDecimal");
return ("java.math.BigDecimal");
case Types.REAL:
return("java.lang.Float");
return ("java.lang.Float");
case Types.DOUBLE:
return("java.lang.Double");
return ("java.lang.Double");
case Types.CHAR:
case Types.VARCHAR:
return("java.lang.String");
return ("java.lang.String");
case Types.DATE:
return("java.sql.Date");
return ("java.sql.Date");
case Types.TIME:
return("java.sql.Time");
return ("java.sql.Time");
case Types.TIMESTAMP:
return("java.sql.Timestamp");
return ("java.sql.Timestamp");
case Types.BINARY:
case Types.VARBINARY:
return("[B");
return ("[B");
case Types.ARRAY:
return("java.sql.Array");
return ("java.sql.Array");
default:
String type = field.getPGType();
if ("unknown".equals(type))
{
return("java.lang.String");
return ("java.lang.String");
}
return("java.lang.Object");
return ("java.lang.Object");
}
}
}
......
......@@ -8,7 +8,7 @@ import java.util.Vector;
import org.postgresql.largeobject.*;
import org.postgresql.util.PSQLException;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.5 2002/09/02 03:07:36 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2Statement.java,v 1.6 2002/09/06 21:23:06 momjian Exp $
* This class defines methods of the jdbc2 specification. This class extends
* org.postgresql.jdbc1.AbstractJdbc1Statement which provides the jdbc1
* methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2Statement
......@@ -183,12 +183,12 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
// is buffered internally anyhow, so there would be no performance
// boost gained, if anything it would be worse!
int bytesRemaining = (int)x.length();
int numRead = l_inStream.read(buf,0,Math.min(buf.length,bytesRemaining));
int numRead = l_inStream.read(buf, 0, Math.min(buf.length, bytesRemaining));
while (numRead != -1 && bytesRemaining > 0)
{
bytesRemaining -= numRead;
los.write(buf,0,numRead);
numRead = l_inStream.read(buf,0,Math.min(buf.length,bytesRemaining));
los.write(buf, 0, numRead);
numRead = l_inStream.read(buf, 0, Math.min(buf.length, bytesRemaining));
}
los.close();
}
......@@ -385,7 +385,8 @@ public abstract class AbstractJdbc2Statement extends org.postgresql.jdbc1.Abstra
//This is needed by AbstractJdbc2ResultSet to determine if the query is updateable or not
protected String[] getSqlFragments() {
protected String[] getSqlFragments()
{
return m_sqlFragments;
}
......
......@@ -6,7 +6,7 @@ import java.util.Vector;
import java.util.Hashtable;
import org.postgresql.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Connection.java,v 1.4 2002/07/26 05:29:35 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Connection.java,v 1.5 2002/09/06 21:23:06 momjian Exp $
* This class implements the java.sql.Connection interface for JDBC2.
* However most of the implementation is really done in
* org.postgresql.jdbc2.AbstractJdbc2Connection or one of it's parents
......@@ -33,7 +33,7 @@ public class Jdbc2Connection extends org.postgresql.jdbc2.AbstractJdbc2Connectio
public java.sql.CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
{
Jdbc2CallableStatement s = new org.postgresql.jdbc2.Jdbc2CallableStatement(this,sql);
Jdbc2CallableStatement s = new org.postgresql.jdbc2.Jdbc2CallableStatement(this, sql);
s.setResultSetType(resultSetType);
s.setResultSetConcurrency(resultSetConcurrency);
return s;
......
......@@ -5,7 +5,7 @@ import java.sql.*;
import java.util.Vector;
import org.postgresql.Field;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.4 2002/08/14 20:35:39 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2ResultSet.java,v 1.5 2002/09/06 21:23:06 momjian Exp $
* This class implements the java.sql.ResultSet interface for JDBC2.
* However most of the implementation is really done in
* org.postgresql.jdbc2.AbstractJdbc2ResultSet or one of it's parents
......@@ -23,11 +23,13 @@ public class Jdbc2ResultSet extends org.postgresql.jdbc2.AbstractJdbc2ResultSet
return new Jdbc2ResultSetMetaData(rows, fields);
}
public java.sql.Clob getClob(int i) throws SQLException {
public java.sql.Clob getClob(int i) throws SQLException
{
return new org.postgresql.jdbc2.Jdbc2Clob(connection, getInt(i));
}
public java.sql.Blob getBlob(int i) throws SQLException {
public java.sql.Blob getBlob(int i) throws SQLException
{
return new org.postgresql.jdbc2.Jdbc2Blob(connection, getInt(i));
}
......
......@@ -3,7 +3,7 @@ package org.postgresql.jdbc2;
import java.sql.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Statement.java,v 1.2 2002/07/24 22:08:43 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/Jdbc2Statement.java,v 1.3 2002/09/06 21:23:06 momjian Exp $
* This class implements the java.sql.Statement interface for JDBC2.
* However most of the implementation is really done in
* org.postgresql.jdbc2.AbstractJdbc2Statement or one of it's parents
......
......@@ -8,16 +8,20 @@ import java.sql.*;
* Base class for data sources and related classes.
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
public abstract class BaseDataSource implements Referenceable {
public abstract class BaseDataSource implements Referenceable
{
// Load the normal driver, since we'll use it to actually connect to the
// database. That way we don't have to maintain the connecting code in
// multiple places.
static {
try {
try
{
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
}
catch (ClassNotFoundException e)
{
System.err.println("PostgreSQL DataSource unable to load PostgreSQL JDBC Driver");
}
}
......@@ -42,7 +46,8 @@ public abstract class BaseDataSource implements Referenceable {
* @throws SQLException
* Occurs when the database connection cannot be established.
*/
public Connection getConnection() throws SQLException {
public Connection getConnection() throws SQLException
{
return getConnection(user, password);
}
......@@ -56,15 +61,21 @@ public abstract class BaseDataSource implements Referenceable {
* @throws SQLException
* Occurs when the database connection cannot be established.
*/
public Connection getConnection(String user, String password) throws SQLException {
try {
public Connection getConnection(String user, String password) throws SQLException
{
try
{
Connection con = DriverManager.getConnection(getUrl(), user, password);
if (logger != null) {
if (logger != null)
{
logger.println("Created a non-pooled connection for " + user + " at " + getUrl());
}
return con;
} catch (SQLException e) {
if (logger != null) {
}
catch (SQLException e)
{
if (logger != null)
{
logger.println("Failed to create a non-pooled connection for " + user + " at " + getUrl() + ": " + e);
}
throw e;
......@@ -75,7 +86,8 @@ public abstract class BaseDataSource implements Referenceable {
* This DataSource does not support a configurable login timeout.
* @return 0
*/
public int getLoginTimeout() throws SQLException {
public int getLoginTimeout() throws SQLException
{
return 0;
}
......@@ -83,27 +95,30 @@ public abstract class BaseDataSource implements Referenceable {
* This DataSource does not support a configurable login timeout. Any value
* provided here will be ignored.
*/
public void setLoginTimeout(int i) throws SQLException {
}
public void setLoginTimeout(int i) throws SQLException
{}
/**
* Gets the log writer used to log connections opened.
*/
public PrintWriter getLogWriter() throws SQLException {
public PrintWriter getLogWriter() throws SQLException
{
return logger;
}
/**
* The DataSource will note every connection opened to the provided log writer.
*/
public void setLogWriter(PrintWriter printWriter) throws SQLException {
public void setLogWriter(PrintWriter printWriter) throws SQLException
{
logger = printWriter;
}
/**
* Gets the name of the host the PostgreSQL database is running on.
*/
public String getServerName() {
public String getServerName()
{
return serverName;
}
......@@ -112,10 +127,14 @@ public abstract class BaseDataSource implements Referenceable {
* is changed, it will only affect future calls to getConnection. The default
* value is <tt>localhost</tt>.
*/
public void setServerName(String serverName) {
if(serverName == null || serverName.equals("")) {
public void setServerName(String serverName)
{
if (serverName == null || serverName.equals(""))
{
this.serverName = "localhost";
} else {
}
else
{
this.serverName = serverName;
}
}
......@@ -124,7 +143,8 @@ public abstract class BaseDataSource implements Referenceable {
* Gets the name of the PostgreSQL database, running on the server identified
* by the serverName property.
*/
public String getDatabaseName() {
public String getDatabaseName()
{
return databaseName;
}
......@@ -133,7 +153,8 @@ public abstract class BaseDataSource implements Referenceable {
* by the serverName property. If this is changed, it will only affect
* future calls to getConnection.
*/
public void setDatabaseName(String databaseName) {
public void setDatabaseName(String databaseName)
{
this.databaseName = databaseName;
}
......@@ -147,7 +168,8 @@ public abstract class BaseDataSource implements Referenceable {
* Gets the user to connect as by default. If this is not specified, you must
* use the getConnection method which takes a user and password as parameters.
*/
public String getUser() {
public String getUser()
{
return user;
}
......@@ -156,7 +178,8 @@ public abstract class BaseDataSource implements Referenceable {
* use the getConnection method which takes a user and password as parameters.
* If this is changed, it will only affect future calls to getConnection.
*/
public void setUser(String user) {
public void setUser(String user)
{
this.user = user;
}
......@@ -165,7 +188,8 @@ public abstract class BaseDataSource implements Referenceable {
* password is needed to log in, you must use the getConnection method which takes
* a user and password as parameters.
*/
public String getPassword() {
public String getPassword()
{
return password;
}
......@@ -175,7 +199,8 @@ public abstract class BaseDataSource implements Referenceable {
* a user and password as parameters. If this is changed, it will only affect
* future calls to getConnection.
*/
public void setPassword(String password) {
public void setPassword(String password)
{
this.password = password;
}
......@@ -185,7 +210,8 @@ public abstract class BaseDataSource implements Referenceable {
*
* @return The port, or 0 if the default port will be used.
*/
public int getPortNumber() {
public int getPortNumber()
{
return portNumber;
}
......@@ -194,28 +220,34 @@ public abstract class BaseDataSource implements Referenceable {
* connections. Be sure the -i flag is passed to postmaster when PostgreSQL
* is started. If this is not set, or set to 0, the default port will be used.
*/
public void setPortNumber(int portNumber) {
public void setPortNumber(int portNumber)
{
this.portNumber = portNumber;
}
/**
* Generates a DriverManager URL from the other properties supplied.
*/
private String getUrl() {
return "jdbc:postgresql://"+serverName+(portNumber == 0 ? "" : ":"+portNumber)+"/"+databaseName;
private String getUrl()
{
return "jdbc:postgresql://" + serverName + (portNumber == 0 ? "" : ":" + portNumber) + "/" + databaseName;
}
public Reference getReference() throws NamingException {
public Reference getReference() throws NamingException
{
Reference ref = new Reference(getClass().getName(), PGObjectFactory.class.getName(), null);
ref.add(new StringRefAddr("serverName", serverName));
if (portNumber != 0) {
if (portNumber != 0)
{
ref.add(new StringRefAddr("portNumber", Integer.toString(portNumber)));
}
ref.add(new StringRefAddr("databaseName", databaseName));
if (user != null) {
if (user != null)
{
ref.add(new StringRefAddr("user", user));
}
if (password != null) {
if (password != null)
{
ref.add(new StringRefAddr("password", password));
}
return ref;
......
......@@ -21,16 +21,18 @@ import java.io.Serializable;
* <p>This implementation supports JDK 1.3 and higher.</p>
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
public class ConnectionPool extends BaseDataSource implements Serializable, ConnectionPoolDataSource {
public class ConnectionPool extends BaseDataSource implements Serializable, ConnectionPoolDataSource
{
private boolean defaultAutoCommit = false;
/**
* Gets a description of this DataSource.
*/
public String getDescription() {
return "ConnectionPoolDataSource from "+org.postgresql.Driver.getVersion();
public String getDescription()
{
return "ConnectionPoolDataSource from " + org.postgresql.Driver.getVersion();
}
/**
......@@ -40,7 +42,8 @@ public class ConnectionPool extends BaseDataSource implements Serializable, Conn
* @throws java.sql.SQLException
* Occurs when the physical database connection cannot be established.
*/
public PooledConnection getPooledConnection() throws SQLException {
public PooledConnection getPooledConnection() throws SQLException
{
return new PooledConnectionImpl(getConnection(), defaultAutoCommit);
}
......@@ -51,7 +54,8 @@ public class ConnectionPool extends BaseDataSource implements Serializable, Conn
* @throws java.sql.SQLException
* Occurs when the physical database connection cannot be established.
*/
public PooledConnection getPooledConnection(String user, String password) throws SQLException {
public PooledConnection getPooledConnection(String user, String password) throws SQLException
{
return new PooledConnectionImpl(getConnection(user, password), defaultAutoCommit);
}
......@@ -60,7 +64,8 @@ public class ConnectionPool extends BaseDataSource implements Serializable, Conn
* turned on by default. The default value is <tt>false</tt>, so that
* autoCommit will be turned off by default.
*/
public boolean isDefaultAutoCommit() {
public boolean isDefaultAutoCommit()
{
return defaultAutoCommit;
}
......@@ -69,7 +74,8 @@ public class ConnectionPool extends BaseDataSource implements Serializable, Conn
* turned on by default. The default value is <tt>false</tt>, so that
* autoCommit will be turned off by default.
*/
public void setDefaultAutoCommit(boolean defaultAutoCommit) {
public void setDefaultAutoCommit(boolean defaultAutoCommit)
{
this.defaultAutoCommit = defaultAutoCommit;
}
......
......@@ -13,32 +13,43 @@ import java.util.Hashtable;
* consistent.
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
public class PGObjectFactory implements ObjectFactory {
public class PGObjectFactory implements ObjectFactory
{
/**
* Dereferences a PostgreSQL DataSource. Other types of references are
* ignored.
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable environment) throws Exception {
Hashtable environment) throws Exception
{
Reference ref = (Reference)obj;
if(ref.getClassName().equals(SimpleDataSource.class.getName())) {
if (ref.getClassName().equals(SimpleDataSource.class.getName()))
{
return loadSimpleDataSource(ref);
} else if (ref.getClassName().equals(ConnectionPool.class.getName())) {
}
else if (ref.getClassName().equals(ConnectionPool.class.getName()))
{
return loadConnectionPool(ref);
} else if (ref.getClassName().equals(PoolingDataSource.class.getName())) {
}
else if (ref.getClassName().equals(PoolingDataSource.class.getName()))
{
return loadPoolingDataSource(ref);
} else {
}
else
{
return null;
}
}
private Object loadPoolingDataSource(Reference ref) {
private Object loadPoolingDataSource(Reference ref)
{
// If DataSource exists, return it
String name = getProperty(ref, "dataSourceName");
PoolingDataSource pds = PoolingDataSource.getDataSource(name);
if(pds != null) {
if (pds != null)
{
return pds;
}
// Otherwise, create a new one
......@@ -46,31 +57,37 @@ public class PGObjectFactory implements ObjectFactory {
pds.setDataSourceName(name);
loadBaseDataSource(pds, ref);
String min = getProperty(ref, "initialConnections");
if (min != null) {
if (min != null)
{
pds.setInitialConnections(Integer.parseInt(min));
}
String max = getProperty(ref, "maxConnections");
if (max != null) {
if (max != null)
{
pds.setMaxConnections(Integer.parseInt(max));
}
return pds;
}
private Object loadSimpleDataSource(Reference ref) {
private Object loadSimpleDataSource(Reference ref)
{
SimpleDataSource ds = new SimpleDataSource();
return loadBaseDataSource(ds, ref);
}
private Object loadConnectionPool(Reference ref) {
private Object loadConnectionPool(Reference ref)
{
ConnectionPool cp = new ConnectionPool();
return loadBaseDataSource(cp, ref);
}
private Object loadBaseDataSource(BaseDataSource ds, Reference ref) {
private Object loadBaseDataSource(BaseDataSource ds, Reference ref)
{
ds.setDatabaseName(getProperty(ref, "databaseName"));
ds.setPassword(getProperty(ref, "password"));
String port = getProperty(ref, "portNumber");
if(port != null) {
if (port != null)
{
ds.setPortNumber(Integer.parseInt(port));
}
ds.setServerName(getProperty(ref, "serverName"));
......@@ -78,9 +95,11 @@ public class PGObjectFactory implements ObjectFactory {
return ds;
}
private String getProperty(Reference ref, String s) {
private String getProperty(Reference ref, String s)
{
RefAddr addr = ref.get(s);
if(addr == null) {
if (addr == null)
{
return null;
}
return (String)addr.getContent();
......
......@@ -13,9 +13,10 @@ import java.lang.reflect.*;
* @see ConnectionPool
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
public class PooledConnectionImpl implements PooledConnection {
public class PooledConnectionImpl implements PooledConnection
{
private List listeners = new LinkedList();
private Connection con;
private ConnectionHandler last;
......@@ -25,7 +26,8 @@ public class PooledConnectionImpl implements PooledConnection {
* Creates a new PooledConnection representing the specified physical
* connection.
*/
PooledConnectionImpl(Connection con, boolean autoCommit) {
PooledConnectionImpl(Connection con, boolean autoCommit)
{
this.con = con;
this.autoCommit = autoCommit;
}
......@@ -34,7 +36,8 @@ public class PooledConnectionImpl implements PooledConnection {
* Adds a listener for close or fatal error events on the connection
* handed out to a client.
*/
public void addConnectionEventListener(ConnectionEventListener connectionEventListener) {
public void addConnectionEventListener(ConnectionEventListener connectionEventListener)
{
listeners.add(connectionEventListener);
}
......@@ -42,7 +45,8 @@ public class PooledConnectionImpl implements PooledConnection {
* Removes a listener for close or fatal error events on the connection
* handed out to a client.
*/
public void removeConnectionEventListener(ConnectionEventListener connectionEventListener) {
public void removeConnectionEventListener(ConnectionEventListener connectionEventListener)
{
listeners.remove(connectionEventListener);
}
......@@ -51,16 +55,27 @@ public class PooledConnectionImpl implements PooledConnection {
* PooledConnection. If any client has a connection based on
* this PooledConnection, it is forcibly closed as well.
*/
public void close() throws SQLException {
if(last != null) {
public void close() throws SQLException
{
if (last != null)
{
last.close();
if(!con.getAutoCommit()) {
try {con.rollback();} catch (SQLException e) {}
if (!con.getAutoCommit())
{
try
{
con.rollback();
}
catch (SQLException e)
{}
}
try {
}
try
{
con.close();
} finally {
}
finally
{
con = null;
}
}
......@@ -76,15 +91,24 @@ public class PooledConnectionImpl implements PooledConnection {
* there is a previous handle active when this is called, the previous
* one is forcibly closed and its work rolled back.</p>
*/
public Connection getConnection() throws SQLException {
if(con == null) {
public Connection getConnection() throws SQLException
{
if (con == null)
{
throw new SQLException("This PooledConnection has already been closed!");
}
// Only one connection can be open at a time from this PooledConnection. See JDBC 2.0 Optional Package spec section 6.2.3
if(last != null) {
if (last != null)
{
last.close();
if(!con.getAutoCommit()) {
try {con.rollback();} catch(SQLException e) {}
if (!con.getAutoCommit())
{
try
{
con.rollback();
}
catch (SQLException e)
{}
}
con.clearWarnings();
}
......@@ -97,13 +121,16 @@ public class PooledConnectionImpl implements PooledConnection {
/**
* Used to fire a connection event to all listeners.
*/
void fireConnectionClosed() {
void fireConnectionClosed()
{
ConnectionEvent evt = null;
// Copy the listener list so the listener can remove itself during this method call
ConnectionEventListener[] local = (ConnectionEventListener[]) listeners.toArray(new ConnectionEventListener[listeners.size()]);
for (int i = 0; i < local.length; i++) {
for (int i = 0; i < local.length; i++)
{
ConnectionEventListener listener = local[i];
if (evt == null) {
if (evt == null)
{
evt = new ConnectionEvent(this);
}
listener.connectionClosed(evt);
......@@ -113,13 +140,16 @@ public class PooledConnectionImpl implements PooledConnection {
/**
* Used to fire a connection event to all listeners.
*/
void fireConnectionFatalError(SQLException e) {
void fireConnectionFatalError(SQLException e)
{
ConnectionEvent evt = null;
// Copy the listener list so the listener can remove itself during this method call
ConnectionEventListener[] local = (ConnectionEventListener[])listeners.toArray(new ConnectionEventListener[listeners.size()]);
for (int i=0; i<local.length; i++) {
for (int i = 0; i < local.length; i++)
{
ConnectionEventListener listener = local[i];
if (evt == null) {
if (evt == null)
{
evt = new ConnectionEvent(this, e);
}
listener.connectionErrorOccurred(evt);
......@@ -133,63 +163,90 @@ public class PooledConnectionImpl implements PooledConnection {
* requires JDK 1.3 or higher, though JDK 1.2 could be supported with a
* 3rd-party proxy package.
*/
private class ConnectionHandler implements InvocationHandler {
private class ConnectionHandler implements InvocationHandler
{
private Connection con;
private boolean automatic = false;
public ConnectionHandler(Connection con) {
public ConnectionHandler(Connection con)
{
this.con = con;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
throws Throwable
{
// From Object
if(method.getDeclaringClass().getName().equals("java.lang.Object")) {
if(method.getName().equals("toString")) {
return "Pooled connection wrapping physical connection "+con;
}
if(method.getName().equals("hashCode")) {
if (method.getDeclaringClass().getName().equals("java.lang.Object"))
{
if (method.getName().equals("toString"))
{
return "Pooled connection wrapping physical connection " + con;
}
if (method.getName().equals("hashCode"))
{
return new Integer(con.hashCode());
}
if(method.getName().equals("equals")) {
if(args[0] == null) {
if (method.getName().equals("equals"))
{
if (args[0] == null)
{
return Boolean.FALSE;
}
try {
try
{
return Proxy.isProxyClass(args[0].getClass()) && ((ConnectionHandler) Proxy.getInvocationHandler(args[0])).con == con ? Boolean.TRUE : Boolean.FALSE;
} catch(ClassCastException e) {
}
catch (ClassCastException e)
{
return Boolean.FALSE;
}
}
return method.invoke(con, args);
}
// All the rest is from the Connection interface
if(method.getName().equals("isClosed")) {
if (method.getName().equals("isClosed"))
{
return con == null ? Boolean.TRUE : Boolean.FALSE;
}
if(con == null) {
if (con == null)
{
throw new SQLException(automatic ? "Connection has been closed automatically because a new connection was opened for the same PooledConnection or the PooledConnection has been closed" : "Connection has been closed");
}
if(method.getName().equals("close")) {
if (method.getName().equals("close"))
{
SQLException ex = null;
if(!con.getAutoCommit()) {
try {con.rollback();} catch(SQLException e) {ex = e;}
if (!con.getAutoCommit())
{
try
{
con.rollback();
}
catch (SQLException e)
{
ex = e;
}
}
con.clearWarnings();
con = null;
last = null;
fireConnectionClosed();
if(ex != null) {
if (ex != null)
{
throw ex;
}
return null;
} else {
}
else
{
return method.invoke(con, args);
}
}
public void close() {
if(con != null) {
public void close()
{
if (con != null)
{
automatic = true;
}
con = null;
......
......@@ -10,13 +10,15 @@ import java.io.Serializable;
* are declared in the superclass.
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
public class SimpleDataSource extends BaseDataSource implements Serializable, DataSource {
public class SimpleDataSource extends BaseDataSource implements Serializable, DataSource
{
/**
* Gets a description of this DataSource.
*/
public String getDescription() {
return "Non-Pooling DataSource from "+org.postgresql.Driver.getVersion();
public String getDescription()
{
return "Non-Pooling DataSource from " + org.postgresql.Driver.getVersion();
}
}
......@@ -26,7 +26,8 @@ public abstract class AbstractJdbc3Blob extends org.postgresql.jdbc2.AbstractJdb
* @see #getBytes
* @since 1.4
*/
public int setBytes(long pos, byte[] bytes) throws SQLException {
public int setBytes(long pos, byte[] bytes) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -51,7 +52,8 @@ public abstract class AbstractJdbc3Blob extends org.postgresql.jdbc2.AbstractJdb
* @see #getBytes
* @since 1.4
*/
public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -69,7 +71,8 @@ public abstract class AbstractJdbc3Blob extends org.postgresql.jdbc2.AbstractJdb
* @see #getBinaryStream
* @since 1.4
*/
public java.io.OutputStream setBinaryStream(long pos) throws SQLException {
public java.io.OutputStream setBinaryStream(long pos) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -83,7 +86,8 @@ public abstract class AbstractJdbc3Blob extends org.postgresql.jdbc2.AbstractJdb
* <code>BLOB</code> value
* @since 1.4
*/
public void truncate(long len) throws SQLException {
public void truncate(long len) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......
......@@ -26,7 +26,8 @@ public abstract class AbstractJdbc3Clob extends org.postgresql.jdbc2.AbstractJdb
*
* @since 1.4
*/
public int setString(long pos, String str) throws SQLException {
public int setString(long pos, String str) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -48,7 +49,8 @@ public abstract class AbstractJdbc3Clob extends org.postgresql.jdbc2.AbstractJdb
*
* @since 1.4
*/
public int setString(long pos, String str, int offset, int len) throws SQLException {
public int setString(long pos, String str, int offset, int len) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -66,7 +68,8 @@ public abstract class AbstractJdbc3Clob extends org.postgresql.jdbc2.AbstractJdb
*
* @since 1.4
*/
public java.io.OutputStream setAsciiStream(long pos) throws SQLException {
public java.io.OutputStream setAsciiStream(long pos) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -85,7 +88,8 @@ public abstract class AbstractJdbc3Clob extends org.postgresql.jdbc2.AbstractJdb
*
* @since 1.4
*/
public java.io.Writer setCharacterStream(long pos) throws SQLException {
public java.io.Writer setCharacterStream(long pos) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -100,7 +104,8 @@ public abstract class AbstractJdbc3Clob extends org.postgresql.jdbc2.AbstractJdb
*
* @since 1.4
*/
public void truncate(long len) throws SQLException {
public void truncate(long len) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......
......@@ -2,7 +2,7 @@ package org.postgresql.jdbc3;
import java.sql.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Connection.java,v 1.1 2002/08/14 20:35:39 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/AbstractJdbc3Connection.java,v 1.2 2002/09/06 21:23:06 momjian Exp $
* This class defines methods of the jdbc3 specification. This class extends
* org.postgresql.jdbc2.AbstractJdbc2Connection which provides the jdbc2
* methods. The real Connection class (for jdbc3) is org.postgresql.jdbc3.Jdbc3Connection
......@@ -25,7 +25,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @see ResultSet
* @since 1.4
*/
public void setHoldability(int holdability) throws SQLException {
public void setHoldability(int holdability) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -41,7 +42,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @see ResultSet
* @since 1.4
*/
public int getHoldability() throws SQLException {
public int getHoldability() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -56,7 +58,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @see Savepoint
* @since 1.4
*/
public Savepoint setSavepoint() throws SQLException {
public Savepoint setSavepoint() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -72,7 +75,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @see Savepoint
* @since 1.4
*/
public Savepoint setSavepoint(String name) throws SQLException {
public Savepoint setSavepoint(String name) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -91,7 +95,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @see #rollback
* @since 1.4
*/
public void rollback(Savepoint savepoint) throws SQLException {
public void rollback(Savepoint savepoint) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -107,7 +112,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* savepoint in the current transaction
* @since 1.4
*/
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
public void releaseSavepoint(Savepoint savepoint) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -143,7 +149,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @since 1.4
*/
public Statement createStatement(int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
int resultSetHoldability) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -185,7 +192,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
*/
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -224,7 +232,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
*/
public CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
int resultSetHoldability) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -269,7 +278,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @since 1.4
*/
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException {
throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -314,7 +324,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @since 1.4
*/
public PreparedStatement prepareStatement(String sql, int columnIndexes[])
throws SQLException {
throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -359,7 +370,8 @@ public abstract class AbstractJdbc3Connection extends org.postgresql.jdbc2.Abstr
* @since 1.4
*/
public PreparedStatement prepareStatement(String sql, String columnNames[])
throws SQLException {
throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......
......@@ -20,7 +20,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public boolean supportsSavepoints() throws SQLException {
public boolean supportsSavepoints() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -33,7 +34,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public boolean supportsNamedParameters() throws SQLException {
public boolean supportsNamedParameters() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -48,7 +50,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a datanase access error occurs
* @since 1.4
*/
public boolean supportsMultipleOpenResults() throws SQLException {
public boolean supportsMultipleOpenResults() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -61,7 +64,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public boolean supportsGetGeneratedKeys() throws SQLException {
public boolean supportsGetGeneratedKeys() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -106,7 +110,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @since 1.4
*/
public ResultSet getSuperTypes(String catalog, String schemaPattern,
String typeNamePattern) throws SQLException {
String typeNamePattern) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -144,7 +149,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @since 1.4
*/
public ResultSet getSuperTables(String catalog, String schemaPattern,
String tableNamePattern) throws SQLException {
String tableNamePattern) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -220,7 +226,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
*/
public ResultSet getAttributes(String catalog, String schemaPattern,
String typeNamePattern, String attributeNamePattern)
throws SQLException {
throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -235,7 +242,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @see Connection
* @since 1.4
*/
public boolean supportsResultSetHoldability(int holdability) throws SQLException {
public boolean supportsResultSetHoldability(int holdability) throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -249,7 +257,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public int getResultSetHoldability() throws SQLException {
public int getResultSetHoldability() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -260,7 +269,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public int getDatabaseMajorVersion() throws SQLException {
public int getDatabaseMajorVersion() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -271,7 +281,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public int getDatabaseMinorVersion() throws SQLException {
public int getDatabaseMinorVersion() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -283,7 +294,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public int getJDBCMajorVersion() throws SQLException {
public int getJDBCMajorVersion() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -295,7 +307,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @exception SQLException if a database access error occurs
* @since 1.4
*/
public int getJDBCMinorVersion() throws SQLException {
public int getJDBCMinorVersion() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -308,7 +321,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @throws SQLException if a database access error occurs
* @since 1.4
*/
public int getSQLStateType() throws SQLException {
public int getSQLStateType() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -320,7 +334,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @throws SQLException if a database access error occurs
* @since 1.4
*/
public boolean locatorsUpdateCopy() throws SQLException {
public boolean locatorsUpdateCopy() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......@@ -332,7 +347,8 @@ public abstract class AbstractJdbc3DatabaseMetaData extends org.postgresql.jdbc2
* @throws SQLExcpetion if a database access error occurs
* @since 1.4
*/
public boolean supportsStatementPooling() throws SQLException {
public boolean supportsStatementPooling() throws SQLException
{
throw org.postgresql.Driver.notImplemented();
}
......
......@@ -3,7 +3,7 @@ package org.postgresql.jdbc3;
import java.sql.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Statement.java,v 1.1 2002/08/14 20:35:40 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc3/Attic/Jdbc3Statement.java,v 1.2 2002/09/06 21:23:06 momjian Exp $
* This class implements the java.sql.Statement interface for JDBC3.
* However most of the implementation is really done in
* org.postgresql.jdbc3.AbstractJdbc3Statement or one of it's parents
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment