2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.harmony.sql.tests.java.sql;
20 import java.sql.Connection;
21 import java.sql.Driver;
22 import java.sql.DriverManager;
23 import java.sql.DriverPropertyInfo;
24 import java.sql.SQLException;
25 import java.util.Properties;
28 * A simple implementation of a class implementing a JDBC Driver, for use in the
29 * testing of the java.sql.DriverManager class
32 public class TestHelper_Driver1 implements Driver {
37 String baseURL = "jdbc:mikes1";
39 String[] dataSources = { "data1", "data2", "data3" };
41 static Driver theDriver;
43 theDriver = new TestHelper_Driver1();
45 DriverManager.registerDriver(theDriver);
46 } catch (SQLException e) {
47 System.out.println("Failed to register driver!");
49 } // end static block initializer
51 protected TestHelper_Driver1() {
53 } // end constructor TestHelper_Driver1()
55 public boolean acceptsURL(String url) throws SQLException {
56 // Check on the supplied String...
60 // Everything's fine if the quoted url starts with the base url for this
62 if (url.startsWith(baseURL)) {
66 } // end method acceptsURL
68 static String validuser = "theuser";
70 static String validpassword = "thepassword";
72 static String userProperty = "user";
74 static String passwordProperty = "password";
76 public Connection connect(String url, Properties info) throws SQLException {
77 // Does the URL have the right form?
78 if (this.acceptsURL(url)) {
79 // The datasource name is the remainder of the url after the ":"
80 String datasource = url.substring(baseURL.length() + 1);
81 for (String element : dataSources) {
82 if (datasource.equals(element)) {
84 * Check for user and password, except for datasource =
85 * data1 which is set up not to require a user/password
88 // It all checks out - so return a connection
89 Connection connection = new TestHelper_Connection1();
95 } // end method connect(String, Properties)
97 public int getMajorVersion() {
99 } // end method getMajorVersion()
101 public int getMinorVersion() {
103 } // end method getMinorVersion()
105 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
106 throws SQLException {
107 DriverPropertyInfo[] theInfos = {
108 new DriverPropertyInfo(userProperty, "*"),
109 new DriverPropertyInfo(passwordProperty, "*"), };
113 public boolean jdbcCompliant() {
114 // Basic version here returns false