postgresql-jdbc.git / summary / log / commit / refs
commit ecf4a2ca9b2dcf8f233e89d33ec983c5f51bf97d
Author: Jeremy Whiting <jwhiting@redhat.com>
Date: Tue Dec 01 18:41:35 2015 +0000
Changed property loader to avoid using a default when property not already set. Allows the caller to detect when unset. Thus allowing connection Ctor to use programmatic log level value. Added test cases to check PGProperty method working properly.
org/postgresql/PGProperty.java | 15 ++++++++++++++-
org/postgresql/jdbc2/AbstractJdbc2Connection.java | 15 ++++++++++++---
org/postgresql/test/jdbc2/PGPropertyTest.java | 22 ++++++++++++++++++++++
3 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/org/postgresql/PGProperty.java b/org/postgresql/PGProperty.java
index 2191e5db..13f29ae9 100644
--- a/org/postgresql/PGProperty.java
+++ b/org/postgresql/PGProperty.java
@@ -463,7 +463,7 @@ public enum PGProperty
*/
public boolean isPresent(Properties properties)
{
- return get(properties) != null;
+ return getSetString(properties) != null;
}
/**
@@ -492,4 +492,17 @@ public enum PGProperty
}
return null;
}
+ /**
+ * Return the property if exists but avoiding the default. Allowing the caller
+ * to detect the lack of a property.
+ * @param properties properties bundle
+ * @return the value of a set property
+ */
+ public String getSetString(Properties properties)
+ {
+ Object o = properties.get(_name);
+ if (o instanceof String)
+ return (String) o;
+ return null;
+ }
}
diff --git a/org/postgresql/jdbc2/AbstractJdbc2Connection.java b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
index 17dde8e2..19c17084 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Connection.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Connection.java
@@ -8,7 +8,6 @@
package org.postgresql.jdbc2;
import java.io.IOException;
-import java.io.PrintWriter;
import java.sql.*;
import java.util.*;
@@ -122,12 +121,22 @@ public abstract class AbstractJdbc2Connection implements BaseConnection
{
this.creatingURL = url;
- // Read loglevel arg and set the loglevel based on this value;
+ // Read loglevel arg and set the loglevel based on this value
+ // otherwise use the programmatic or init logger level;
// In addition to setting the log level, enable output to
// standard out if no other printwriter is set
int logLevel = Driver.getLogLevel();
-
+ String connectionLogLevel = PGProperty.LOG_LEVEL.getSetString(info);
+ if (connectionLogLevel != null) {
+ try
+ {
+ logLevel = Integer.parseInt(connectionLogLevel);
+ } catch (NumberFormatException nfe)
+ {
+ // ignore
+ }
+ }
synchronized (AbstractJdbc2Connection.class) {
logger = new Logger(nextConnectionID++);
logger.setLogLevel(logLevel);
diff --git a/org/postgresql/test/jdbc2/PGPropertyTest.java b/org/postgresql/test/jdbc2/PGPropertyTest.java
index 37af49d7..e4d9638e 100644
--- a/org/postgresql/test/jdbc2/PGPropertyTest.java
+++ b/org/postgresql/test/jdbc2/PGPropertyTest.java
@@ -218,4 +218,26 @@ public class PGPropertyTest extends TestCase
parsedProperties = Driver.parseURL(TestUtil.getURL() + "&ssl=true" , null);
Assert.assertTrue("SSL property should be present", PGProperty.SSL.isPresent(parsedProperties));
}
+
+ /**
+ * Check whether the isPresent method really works.
+ */
+ public void testPresenceCheck()
+ {
+ Properties empty = new Properties();
+ Object value = PGProperty.LOG_LEVEL.get(empty);
+ assertNotNull(value);
+ Assert.assertFalse(PGProperty.LOG_LEVEL.isPresent(empty));
+ }
+
+ public void testNullValue()
+ {
+ Properties empty = new Properties();
+ assertNull(PGProperty.LOG_LEVEL.getSetString(empty));
+ assertNull(PGProperty.LOG_LEVEL.getSetString(empty));
+ Properties withLogging = new Properties();
+ withLogging.setProperty(PGProperty.LOG_LEVEL.getName(), "2");
+ assertNotNull(PGProperty.LOG_LEVEL.getSetString(withLogging));
+ }
+
}
[parent: e0a9b414eab3]