aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2001-06-29 17:23:33 +0000
committerBruce Momjian <bruce@momjian.us>2001-06-29 17:23:33 +0000
commitdb491a6d78a44c1cb39f8a00438344921159743a (patch)
treeffb4c6c33933703d86d1392b61b292589e10e65e /src
parent39381507b7eb086b03d10c0235a3af4158751476 (diff)
downloadpostgresql-db491a6d78a44c1cb39f8a00438344921159743a.tar.gz
postgresql-db491a6d78a44c1cb39f8a00438344921159743a.zip
SimpleDateFormat performance improvement, thread-safe.
Barry Lind
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
index 7b5babfb8d6..69898cc3c93 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java
@@ -65,14 +65,6 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
this.sql = sql;
this.connection = connection;
- // might just as well create it here, so we don't take the hit later
-
- SimpleDateFormat df = new SimpleDateFormat("''yyyy-MM-dd''");
- tl_df.set(df);
-
- df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- tl_tsdf.set(df);
-
for (i = 0; i < sql.length(); ++i)
{
int c = sql.charAt(i);
@@ -95,17 +87,6 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
templateStrings[i] = (String)v.elementAt(i);
}
- /**
- * New in 7.1 - overides Statement.close() to dispose of a few local objects
- */
- public void close() throws SQLException
- {
- // free the ThreadLocal caches
- tl_df.set(null);
- tl_tsdf.set(null);
- super.close();
- }
-
/**
* A Prepared SQL query is executed and its ResultSet is returned
*
@@ -343,6 +324,10 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
public void setDate(int parameterIndex, java.sql.Date x) throws SQLException
{
SimpleDateFormat df = (SimpleDateFormat) tl_df.get();
+ if(df==null) {
+ df = new SimpleDateFormat("''yyyy-MM-dd''");
+ tl_df.set(df);
+ }
set(parameterIndex, df.format(x));
@@ -382,6 +367,10 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
{
SimpleDateFormat df = (SimpleDateFormat) tl_tsdf.get();
+ if(df==null) {
+ df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ tl_tsdf.set(df);
+ }
df.setTimeZone(TimeZone.getTimeZone("GMT"));
// Use the shared StringBuffer