001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.sql.tests.java.sql;
019:
020: import java.sql.Connection;
021: import java.sql.Driver;
022: import java.sql.DriverManager;
023: import java.sql.DriverPropertyInfo;
024: import java.sql.SQLException;
025: import java.util.Properties;
026:
027: /**
028: * A simple implementation of a class implementing a JDBC Driver, for use in the
029: * testing of the java.sql.DriverManager class
030: *
031: */
032: public class TestHelper_Driver1 implements Driver {
033: int majorVersion = 1;
034:
035: int minorVersion = 0;
036:
037: String baseURL = "jdbc:mikes1";
038:
039: String[] dataSources = { "data1", "data2", "data3" };
040:
041: static Driver theDriver;
042: static {
043: theDriver = new TestHelper_Driver1();
044: try {
045: DriverManager.registerDriver(theDriver);
046: } catch (SQLException e) {
047: System.out.println("Failed to register driver!");
048: }
049: } // end static block initializer
050:
051: protected TestHelper_Driver1() {
052: super ();
053: } // end constructor TestHelper_Driver1()
054:
055: public boolean acceptsURL(String url) throws SQLException {
056: // Check on the supplied String...
057: if (url == null) {
058: return false;
059: }
060: // Everything's fine if the quoted url starts with the base url for this
061: // driver
062: if (url.startsWith(baseURL)) {
063: return true;
064: }
065: return false;
066: } // end method acceptsURL
067:
068: static String validuser = "theuser";
069:
070: static String validpassword = "thepassword";
071:
072: static String userProperty = "user";
073:
074: static String passwordProperty = "password";
075:
076: public Connection connect(String url, Properties info)
077: throws SQLException {
078: // Does the URL have the right form?
079: if (this .acceptsURL(url)) {
080: // The datasource name is the remainder of the url after the ":"
081: String datasource = url.substring(baseURL.length() + 1);
082: for (String element : dataSources) {
083: if (datasource.equals(element)) {
084: /*
085: * Check for user and password, except for datasource =
086: * data1 which is set up not to require a user/password
087: * combination
088: */
089: // It all checks out - so return a connection
090: Connection connection = new TestHelper_Connection1();
091: return connection;
092: } // end if
093: } // end for
094: } // end if
095: return null;
096: } // end method connect(String, Properties)
097:
098: public int getMajorVersion() {
099: return majorVersion;
100: } // end method getMajorVersion()
101:
102: public int getMinorVersion() {
103: return minorVersion;
104: } // end method getMinorVersion()
105:
106: public DriverPropertyInfo[] getPropertyInfo(String url,
107: Properties info) throws SQLException {
108: DriverPropertyInfo[] theInfos = {
109: new DriverPropertyInfo(userProperty, "*"),
110: new DriverPropertyInfo(passwordProperty, "*"), };
111: return theInfos;
112: }
113:
114: public boolean jdbcCompliant() {
115: // Basic version here returns false
116: return false;
117: }
118: }
|