db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From banda...@apache.org
Subject svn commit: r165178 [26/26] - in /incubator/derby/code/trunk: ./ java/client/ java/client/org/ java/client/org/apache/ java/client/org/apache/derby/ java/client/org/apache/derby/client/ java/client/org/apache/derby/client/am/ java/client/org/apache/derby/client/net/ java/client/org/apache/derby/client/resources/ java/client/org/apache/derby/jdbc/ tools/ant/properties/
Date Thu, 28 Apr 2005 19:05:45 GMT
Added: incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java (added)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java Thu Apr
28 12:05:42 2005
@@ -0,0 +1,297 @@
+/*
+
+   Derby - Class org.apache.derby.jdbc.ClientDriver
+
+   Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+package org.apache.derby.jdbc;
+
+import org.apache.derby.client.resources.ResourceKeys;
+import org.apache.derby.client.am.ResourceUtilities;
+import org.apache.derby.client.am.Utils;
+import org.apache.derby.client.am.Configuration;
+import org.apache.derby.client.am.SqlException;
+import org.apache.derby.client.am.Version;
+
+
+public class ClientDriver implements java.sql.Driver
+{
+  private transient int traceFileSuffixIndex_ = 0;
+
+  private final static int DERBY_REMOTE_PROTOCOL = 1;
+
+  static private SqlException exceptionsOnLoadDriver__ = null;
+  // Keep track of the registere driver so that we can deregister it if we're a stored proc.
+  static private ClientDriver registeredDriver__ = null;
+
+  static {
+    // This may possibly hit the race-condition bug of java 1.1.
+    // The Configuration static clause should execute before the following line does.
+    if (Configuration.exceptionsOnLoadResources != null) {
+      exceptionsOnLoadDriver__ =
+        Utils.accumulateSQLException (Configuration.exceptionsOnLoadResources,
+                                      exceptionsOnLoadDriver__);
+    }
+    try {
+      registeredDriver__ = new ClientDriver();
+      java.sql.DriverManager.registerDriver (registeredDriver__);
+    }
+    catch (java.sql.SQLException e) {
+      // A null log writer is passed, because jdbc 1 sql exceptions are automatically traced
+      exceptionsOnLoadDriver__ =
+        new SqlException (null, "Error occurred while trying to register Dnc driver with
JDBC 1 Driver Manager");
+      exceptionsOnLoadDriver__.setNextException (e);
+    }
+  }
+
+  public ClientDriver() {}
+
+  public java.sql.Connection connect (String url,
+                                      java.util.Properties properties) throws java.sql.SQLException
+  {
+    if (exceptionsOnLoadDriver__ != null) throw exceptionsOnLoadDriver__;
+
+    if (properties == null) properties = new java.util.Properties();
+
+    java.util.StringTokenizer urlTokenizer =
+      new java.util.StringTokenizer (url, "/:= \t\n\r\f", true);
+
+    int protocol = tokenizeProtocol (url, urlTokenizer);
+    if (protocol == 0) return null; // unrecognized database URL prefix.
+
+    String slashOrNull = null;
+    if (protocol == DERBY_REMOTE_PROTOCOL) {
+      try {
+        slashOrNull = urlTokenizer.nextToken (":/");
+      }
+      catch (java.util.NoSuchElementException e) {
+        // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+        throw new SqlException (null, e, "Invalid database url syntax: " + url);
+      }
+    }
+      String server = tokenizeServerName (urlTokenizer, url);    // "/server"
+      int port = tokenizeOptionalPortNumber (urlTokenizer, url); // "[:port]/"
+      if (port == 0)
+          port = ClientDataSource.propertyDefault_portNumber;
+
+	  // longDatabase is the databaseName and attributes.  This will be 
+	  // sent to network server as the databaseName
+      String database = tokenizeDatabase (urlTokenizer, url); // "database"
+	 java.util.Properties  augmentedProperties = tokenizeURLProperties (url, properties);
+
+	 
+      int traceLevel;
+      try {
+        traceLevel = ClientDataSource.getTraceLevel (augmentedProperties);
+      }
+      catch (java.lang.NumberFormatException e) {
+        // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+        throw new SqlException (null, e, "trouble reading traceLevel connection property");
+      }
+
+      // Jdbc 1 connections will write driver trace info on a
+      // driver-wide basis using the jdbc 1 driver manager log writer.
+      // This log writer may be narrowed to the connection-level
+      // This log writer will be passed to the agent constructor.
+      org.apache.derby.client.am.LogWriter dncLogWriter =
+        ClientDataSource.computeDncLogWriterForNewConnection (
+          java.sql.DriverManager.getLogWriter(),
+          ClientDataSource.getTraceDirectory (augmentedProperties),
+          ClientDataSource.getTraceFile (augmentedProperties),
+          ClientDataSource.getTraceFileAppend (augmentedProperties),
+          traceLevel,
+          "_driver",
+          traceFileSuffixIndex_++);
+
+      org.apache.derby.client.net.NetConnection conn =
+        new org.apache.derby.client.net.NetConnection (
+          (org.apache.derby.client.net.NetLogWriter) dncLogWriter,
+          java.sql.DriverManager.getLoginTimeout(),
+          server,
+          port,
+          database,
+          augmentedProperties);
+      return conn;
+  }
+
+  public boolean acceptsURL (String url) throws java.sql.SQLException
+  {
+    java.util.StringTokenizer urlTokenizer = new java.util.StringTokenizer (url, "/:=; \t\n\r\f",
true);
+    int protocol = tokenizeProtocol (url, urlTokenizer);
+    return protocol != 0;
+  }
+
+  public java.sql.DriverPropertyInfo[] getPropertyInfo (String url,
+                                                        java.util.Properties properties)
throws java.sql.SQLException
+  {
+    java.sql.DriverPropertyInfo driverPropertyInfo[] = new java.sql.DriverPropertyInfo[2];
+
+    // If there are no properties set already,
+    // then create a dummy properties just to make the calls go thru.
+    if (properties == null)
+      properties = new java.util.Properties ();
+
+    driverPropertyInfo[0] =
+      new java.sql.DriverPropertyInfo (ClientDataSource.propertyKey_user,
+                                       properties.getProperty (ClientDataSource.propertyKey_user,ClientDataSource.propertyDefault_user));
+
+    driverPropertyInfo[1] =
+      new java.sql.DriverPropertyInfo (ClientDataSource.propertyKey_password,
+                                       properties.getProperty (ClientDataSource.propertyKey_password));
+
+    driverPropertyInfo[0].description =
+      ResourceUtilities.getResource (ResourceKeys.propertyDescription__user);
+    driverPropertyInfo[1].description =
+      ResourceUtilities.getResource (ResourceKeys.propertyDescription__password);
+
+    driverPropertyInfo[0].required = true;
+    driverPropertyInfo[1].required = false; // depending on the security mechanism
+
+    return driverPropertyInfo;
+  }
+
+  public int getMajorVersion()
+  {
+    return Version.getMajorVersion();
+  }
+
+  public int getMinorVersion()
+  {
+    return Version.getMinorVersion();
+  }
+
+  public boolean jdbcCompliant()
+  {
+    return Configuration.jdbcCompliant;
+  }
+
+  // ----------------helper methods---------------------------------------------
+
+  // Tokenize one of the following:
+  //  "jdbc:derby:"
+  // and return 0 if the protcol is unrecognized
+  // return DERBY_PROTOCOL for "jdbc:derby"
+  private static int tokenizeProtocol (String url, java.util.StringTokenizer urlTokenizer)
throws SqlException
+  {
+    // Is this condition necessary, StringTokenizer constructor may do this for us
+    if (url == null) return 0;
+
+    if (urlTokenizer == null) return 0;
+
+    try {
+      String jdbc = urlTokenizer.nextToken (":");
+      if (!jdbc.equals ("jdbc")) return 0;
+      if (!urlTokenizer.nextToken (":").equals (":"))
+        return 0; // Skip over the first colon in jdbc:derby:
+      String dbname = urlTokenizer.nextToken (":");
+      int protocol = 0;
+      if (dbname.equals("derby") && (url.indexOf("derby://") != -1)){
+		  // For Derby AS need to check for // since jdbc:derby: is also the
+		  // embedded prefix
+		protocol = DERBY_REMOTE_PROTOCOL;
+      }
+      else
+         return 0;
+
+      if (!urlTokenizer.nextToken (":").equals (":") )
+        return 0; // Skip over the second colon in jdbc:derby:
+
+      return protocol;
+    }
+    catch (java.util.NoSuchElementException e) {
+      return 0;
+    }
+  }
+
+  // tokenize "/server" from URL jdbc:derby://server:port/
+  // returns server name
+  private static String tokenizeServerName (java.util.StringTokenizer urlTokenizer,
+                                                   String url) throws SqlException
+  {
+    try {
+      if (!urlTokenizer.nextToken("/").equals ("/"))
+        // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+        throw new SqlException (null, "Invalid database url syntax: " + url);
+      return urlTokenizer.nextToken ("/:");
+    }
+    catch (java.util.NoSuchElementException e) {
+      // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+      throw new SqlException (null, e, "Invalid database url syntax: " + url);
+    }
+  }
+
+  // tokenize "[:portNumber]/" from URL jdbc:derby://server[:port]/
+  // returns the portNumber or zero if portNumber is not specified.
+  private static int tokenizeOptionalPortNumber (java.util.StringTokenizer urlTokenizer,
+                                                   String url) throws SqlException
+  {
+    try {
+      String firstToken = urlTokenizer.nextToken(":/");
+      if (firstToken.equals (":")) {
+        String port = urlTokenizer.nextToken ("/");
+        if (!urlTokenizer.nextToken ("/").equals ("/")) {
+          // A null log writer is passed, because jdbc 1 sqlexceptions are automatically
traced
+          throw new SqlException (null, "Invalid database url syntax: " + url);
+        }
+        return Integer.parseInt (port);
+      }
+      else if (firstToken.equals ("/")) {
+        return 0;
+      }
+      else {
+        // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+        throw new SqlException (null, "Invalid database url syntax: " + url);
+      }
+    }
+    catch (java.util.NoSuchElementException e) {
+      // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+      throw new SqlException (null, e, "Invalid database url syntax: " + url);
+    }
+  }
+
+  //return database name and attributes
+  private static String tokenizeDatabase (java.util.StringTokenizer urlTokenizer,
+                                          String url) throws SqlException
+  {
+    try {
+      String databaseName = urlTokenizer.nextToken (" \t\n\r\f");
+      return databaseName;
+    }
+    catch (java.util.NoSuchElementException e) {
+      // A null log writer is passed, because jdbc 1 sqlexceptions are automatically traced
+      throw new SqlException (null, e, "Invalid database url syntax: " + url);
+    }
+  }
+
+  private static java.util.Properties tokenizeURLProperties (String url,
+                                               java.util.Properties properties)
+	  throws SqlException
+	{
+		String attributeString = null;
+		int attributeIndex = -1;
+		
+		if ((url != null) && 
+			((attributeIndex = url.indexOf(";")) != -1))
+			attributeString = url.substring(attributeIndex);
+		return ClientDataSource.tokenizeAttributes(attributeString, properties);
+	}
+ 
+
+}
+
+
+

Propchange: incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java?rev=165178&view=auto
==============================================================================
--- incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java (added)
+++ incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java Thu
Apr 28 12:05:42 2005
@@ -0,0 +1,63 @@
+/*
+
+   Derby - Class org.apache.derby.jdbc.ClientXADataSource
+
+   Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+package org.apache.derby.jdbc;
+
+import javax.sql.*;
+import org.apache.derby.client.ClientXAConnection;
+
+
+public class ClientXADataSource extends ClientDataSource implements XADataSource,
+                                                                  java.io.Serializable,
+                                                                  javax.naming.Referenceable
+{
+  public static final String className__ = "org.apache.derby.jdbc.ClientXADataSource";
+
+  // following serialVersionUID was generated by the JDK's serialver program
+  // verify it everytime that ClientXADataSource is modified
+  static final long serialVersionUID = 7057075094707674880L;
+
+  private String password = null;
+  synchronized public void setPassword (String password) { this.password = password; }
+  public final static String propertyKey_password = "password";
+
+  public ClientXADataSource()
+  {
+    this.setResultSetHoldability( org.apache.derby.client.ClientBaseDataSource.CLOSE_CURSORS_AT_COMMIT
);
+  }
+
+  public XAConnection getXAConnection() throws java.sql.SQLException
+  {
+
+    return getXAConnection(this.user, this.password);
+  }
+
+  public XAConnection getXAConnection (String user, String password) throws java.sql.SQLException
+  {
+    org.apache.derby.client.am.LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection
("_xads");
+
+
+    ClientXAConnection xaConn_ = new ClientXAConnection( this,
+          (org.apache.derby.client.net.NetLogWriter) dncLogWriter,
+          user,
+          password);
+    return xaConn_;
+  }
+}

Propchange: incubator/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/derby/code/trunk/tools/ant/properties/dirs.properties
URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/tools/ant/properties/dirs.properties?rev=165178&r1=165177&r2=165178&view=diff
==============================================================================
--- incubator/derby/code/trunk/tools/ant/properties/dirs.properties (original)
+++ incubator/derby/code/trunk/tools/ant/properties/dirs.properties Thu Apr 28 12:05:42 2005
@@ -34,6 +34,7 @@
 
 derby.engine.src.dir=${derbysrc.dir}/engine
 derby.drda.src.dir=${derbysrc.dir}/drda
+derby.client.src.dir=${derbysrc.dir}/client
 derby.tools.src.dir=${derbysrc.dir}/tools
 derby.build.src.dir=${derbysrc.dir}/build
 derby.demo.src.dir=${derbysrc.dir}/demo
@@ -42,6 +43,7 @@
 
 derby.engine.dir=${derby.engine.src.dir}/${derby.dir}
 derby.drda.dir=${derby.drda.src.dir}/${derby.dir}
+derby.client.dir=${derby.client.src.dir}/{derby.dir}
 derby.tools.dir=${derby.tools.src.dir}/${derby.dir}
 derby.build.dir=${derby.build.src.dir}/org/apache/derbyBuild
 derby.locales.dir=${derby.engine.dir}/loc



Mime
View raw message