Skip to content

Commit

Permalink
Merge pull request pgjdbc#38 from davecramer/master
Browse files Browse the repository at this point in the history
logging did not work properly when using a datasource, also many properties were not copied to the datasource
  • Loading branch information
Dave Cramer committed Feb 7, 2013
2 parents e9ac5f8 + e16ba69 commit f6544e2
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions org/postgresql/ds/common/BaseDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public abstract class BaseDataSource implements Referenceable

// Standard properties, defined in the JDBC 2.0 Optional Package spec
private String serverName = "localhost";
private String databaseName;
private String databaseName = "";
private String user;
private String password;
private int portNumber = 0;
private int prepareThreshold = 5;
private int unknownLength = Integer.MAX_VALUE;
private boolean binaryTransfer = true;
private String binaryTransferEnable = "";
private String binaryTransferDisable = "";
private String binaryTransferEnable;
private String binaryTransferDisable;
private int loginTimeout = 0; // in seconds
private int socketTimeout = 0; // in seconds
private int receiveBufferSize = -1; // off (-1), not in use
Expand All @@ -63,6 +63,7 @@ public abstract class BaseDataSource implements Referenceable
private int logLevel = 0;
private int protocolVersion = 0;
private String applicationName;
private boolean logLevelSet = false;

/**
* Gets a connection to the PostgreSQL database. The database is identified by the
Expand Down Expand Up @@ -184,6 +185,7 @@ public int getLogLevel()
public void setLogLevel(int logLevel)
{
this.logLevel = logLevel;
logLevelSet = true;
}

public int getProtocolVersion()
Expand Down Expand Up @@ -294,6 +296,14 @@ public void setPrepareThreshold(int count)
this.prepareThreshold = count;
}

/**
* Gets the write buffer size of TCP/IP socket.
*/
public int getReceiveBufferSize()
{
return receiveBufferSize;
}

/**
* Sets the write buffer size of TCP/IP socket.
*/
Expand All @@ -302,6 +312,14 @@ public void setReceiveBufferSize(int nbytes)
this.receiveBufferSize = nbytes;
}

/**
* Gets the send buffer size of TCP/IP socket.
*/
public int getSendBufferSize()
{
return sendBufferSize;
}

/**
* Sets the send buffer size of TCP/IP socket.
*/
Expand Down Expand Up @@ -486,7 +504,9 @@ private String getUrl()
sb.append("&socketTimeout=").append(socketTimeout);
sb.append("&prepareThreshold=").append(prepareThreshold);
sb.append("&unknownLength=").append(unknownLength);
sb.append("&loglevel=").append(logLevel);
if (logLevelSet) {
sb.append("&loglevel=").append(logLevel);
}
if (protocolVersion != 0) {
sb.append("&protocolVersion=").append(protocolVersion);
}
Expand All @@ -510,10 +530,14 @@ private String getUrl()
sb.append("&ApplicationName=");
sb.append(applicationName);
}
if (binaryTransfer) {
sb.append("&binaryTransfer=true");
sb.append("&binaryTransfer=").append(binaryTransfer);
if (binaryTransferEnable != null) {
sb.append("&binaryTransferEnable=").append(binaryTransferEnable);
}

if (binaryTransferDisable != null) {
sb.append("&binaryTransferDisable=").append(binaryTransferDisable);
}

return sb.toString();
}

Expand Down Expand Up @@ -548,11 +572,22 @@ public Reference getReference() throws NamingException
ref.add(new StringRefAddr("prepareThreshold", Integer.toString(prepareThreshold)));
ref.add(new StringRefAddr("unknownLength", Integer.toString(unknownLength)));
ref.add(new StringRefAddr("binaryTransfer", Boolean.toString(binaryTransfer)));
if (binaryTransferEnable != null)
{
ref.add(new StringRefAddr("binaryTransferEnable", binaryTransferEnable));
}
if (binaryTransferDisable != null)
{
ref.add(new StringRefAddr("binaryTransferDisable", binaryTransferDisable));
}
ref.add(new StringRefAddr("loginTimeout", Integer.toString(loginTimeout)));
ref.add(new StringRefAddr("socketTimeout", Integer.toString(socketTimeout)));

ref.add(new StringRefAddr("ssl", Boolean.toString(ssl)));
ref.add(new StringRefAddr("sslfactory", sslfactory));
if(sslfactory !=null)
{
ref.add(new StringRefAddr("sslfactory", sslfactory));
}

ref.add(new StringRefAddr("receiveBufferSize", Integer.toString(receiveBufferSize)));
ref.add(new StringRefAddr("sendBufferSize", Integer.toString(sendBufferSize)));
Expand All @@ -562,9 +597,15 @@ public Reference getReference() throws NamingException
ref.add(new StringRefAddr("compatible", compatible));
}

ref.add(new StringRefAddr("logLevel", Integer.toString(logLevel)));
if(logLevelSet)
{
ref.add(new StringRefAddr("logLevel", Integer.toString(logLevel)));
}
ref.add(new StringRefAddr("protocolVersion", Integer.toString(protocolVersion)));
ref.add(new StringRefAddr("ApplicationName", applicationName));
if(applicationName != null)
{
ref.add(new StringRefAddr("ApplicationName", applicationName));
}

return ref;
}
Expand Down Expand Up @@ -592,6 +633,7 @@ protected void writeBaseObject(ObjectOutputStream out) throws IOException
out.writeBoolean(binaryTransfer);
out.writeObject(binaryTransferEnable);
out.writeObject(binaryTransferDisable);
out.writeBoolean(logLevelSet);
}

protected void readBaseObject(ObjectInputStream in) throws IOException, ClassNotFoundException
Expand All @@ -617,6 +659,7 @@ protected void readBaseObject(ObjectInputStream in) throws IOException, ClassNot
binaryTransfer = in.readBoolean();
binaryTransferEnable = (String)in.readObject();
binaryTransferDisable = (String)in.readObject();
logLevelSet = in.readBoolean();
}

public void initializeFrom(BaseDataSource source) throws IOException, ClassNotFoundException {
Expand Down

0 comments on commit f6544e2

Please sign in to comment.