aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDave Cramer <davec@fastcrypt.com>2002-03-21 02:40:03 +0000
committerDave Cramer <davec@fastcrypt.com>2002-03-21 02:40:03 +0000
commit00923229c2f076d241daf03dbc05e1458539c6d3 (patch)
treee537ad4c0e1e45d339d4c542d36f6cb88160ba8f /src
parentd96c29ab301ac22488cf8443e1da819826c47ac1 (diff)
downloadpostgresql-00923229c2f076d241daf03dbc05e1458539c6d3.tar.gz
postgresql-00923229c2f076d241daf03dbc05e1458539c6d3.zip
Part of Anders Bengtsson's patch to clean up Connection.java
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/jdbc/org/postgresql/core/StartupPacket.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java b/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java
new file mode 100644
index 00000000000..223f16ebd47
--- /dev/null
+++ b/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java
@@ -0,0 +1,43 @@
+package org.postgresql.core;
+
+import org.postgresql.PG_Stream;
+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 $
+ */
+
+public class StartupPacket
+{
+ private static final int SM_DATABASE = 64;
+ private static final int SM_USER = 32;
+ private static final int SM_OPTIONS = 64;
+ private static final int SM_UNUSED = 64;
+ private static final int SM_TTY = 64;
+
+ private int protocolMajor;
+ private int protocolMinor;
+ private String user;
+ private String database;
+
+ public StartupPacket(int protocolMajor, int protocolMinor, String user, String database) {
+ this.protocolMajor = protocolMajor;
+ this.protocolMinor = protocolMinor;
+ this.user = user;
+ this.database = database;
+ }
+
+ public void writeTo(PG_Stream stream) throws IOException
+ {
+ stream.SendInteger(4 + 4 + SM_DATABASE + SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY, 4);
+ stream.SendInteger(protocolMajor, 2);
+ stream.SendInteger(protocolMinor, 2);
+ stream.Send(database.getBytes(), SM_DATABASE);
+
+ // This last send includes the unused fields
+ stream.Send(user.getBytes(), SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY);
+ }
+}
+