OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / org / apache / harmony / sql / tests / java / sql / TestHelper_Driver1.java
1 /*
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.apache.harmony.sql.tests.java.sql;
19
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;
26
27 /**
28  * A simple implementation of a class implementing a JDBC Driver, for use in the
29  * testing of the java.sql.DriverManager class
30  *
31  */
32 public class TestHelper_Driver1 implements Driver {
33     int majorVersion = 1;
34
35     int minorVersion = 0;
36
37     String baseURL = "jdbc:mikes1";
38
39     String[] dataSources = { "data1", "data2", "data3" };
40
41     static Driver theDriver;
42     static {
43         theDriver = new TestHelper_Driver1();
44         try {
45             DriverManager.registerDriver(theDriver);
46         } catch (SQLException e) {
47             System.out.println("Failed to register driver!");
48         }
49     } // end static block initializer
50
51     protected TestHelper_Driver1() {
52         super();
53     } // end constructor TestHelper_Driver1()
54
55     public boolean acceptsURL(String url) throws SQLException {
56         // Check on the supplied String...
57         if (url == null) {
58             return false;
59         }
60         // Everything's fine if the quoted url starts with the base url for this
61         // driver
62         if (url.startsWith(baseURL)) {
63             return true;
64         }
65         return false;
66     } // end method acceptsURL
67
68     static String validuser = "theuser";
69
70     static String validpassword = "thepassword";
71
72     static String userProperty = "user";
73
74     static String passwordProperty = "password";
75
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)) {
83                     /*
84                      * Check for user and password, except for datasource =
85                      * data1 which is set up not to require a user/password
86                      * combination
87                      */
88                     // It all checks out - so return a connection
89                     Connection connection = new TestHelper_Connection1();
90                     return connection;
91                 } // end if
92             } // end for
93         } // end if
94         return null;
95     } // end method connect(String, Properties)
96
97     public int getMajorVersion() {
98         return majorVersion;
99     } // end method getMajorVersion()
100
101     public int getMinorVersion() {
102         return minorVersion;
103     } // end method getMinorVersion()
104
105     public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
106             throws SQLException {
107         DriverPropertyInfo[] theInfos = {
108                 new DriverPropertyInfo(userProperty, "*"),
109                 new DriverPropertyInfo(passwordProperty, "*"), };
110         return theInfos;
111     }
112
113     public boolean jdbcCompliant() {
114         // Basic version here returns false
115         return false;
116     }
117 }