/external/apache-harmony/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk · Java · 117 lines · 66 code · 18 blank · 33 comment · 6 complexity · b6e7977f03525b60df48affbe698c760 MD5 · raw file

  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. package org.apache.harmony.sql.tests.java.sql;
  18. import java.sql.Connection;
  19. import java.sql.Driver;
  20. import java.sql.DriverManager;
  21. import java.sql.DriverPropertyInfo;
  22. import java.sql.SQLException;
  23. import java.util.Properties;
  24. /**
  25. * A simple implementation of a class implementing a JDBC Driver, for use in the
  26. * testing of the java.sql.DriverManager class
  27. *
  28. */
  29. public class TestHelper_Driver1 implements Driver {
  30. int majorVersion = 1;
  31. int minorVersion = 0;
  32. String baseURL = "jdbc:mikes1";
  33. String[] dataSources = { "data1", "data2", "data3" };
  34. static Driver theDriver;
  35. static {
  36. theDriver = new TestHelper_Driver1();
  37. try {
  38. DriverManager.registerDriver(theDriver);
  39. } catch (SQLException e) {
  40. System.out.println("Failed to register driver!");
  41. }
  42. } // end static block initializer
  43. protected TestHelper_Driver1() {
  44. super();
  45. } // end constructor TestHelper_Driver1()
  46. public boolean acceptsURL(String url) throws SQLException {
  47. // Check on the supplied String...
  48. if (url == null) {
  49. return false;
  50. }
  51. // Everything's fine if the quoted url starts with the base url for this
  52. // driver
  53. if (url.startsWith(baseURL)) {
  54. return true;
  55. }
  56. return false;
  57. } // end method acceptsURL
  58. static String validuser = "theuser";
  59. static String validpassword = "thepassword";
  60. static String userProperty = "user";
  61. static String passwordProperty = "password";
  62. public Connection connect(String url, Properties info) throws SQLException {
  63. // Does the URL have the right form?
  64. if (this.acceptsURL(url)) {
  65. // The datasource name is the remainder of the url after the ":"
  66. String datasource = url.substring(baseURL.length() + 1);
  67. for (String element : dataSources) {
  68. if (datasource.equals(element)) {
  69. /*
  70. * Check for user and password, except for datasource =
  71. * data1 which is set up not to require a user/password
  72. * combination
  73. */
  74. // It all checks out - so return a connection
  75. Connection connection = new TestHelper_Connection1();
  76. return connection;
  77. } // end if
  78. } // end for
  79. } // end if
  80. return null;
  81. } // end method connect(String, Properties)
  82. public int getMajorVersion() {
  83. return majorVersion;
  84. } // end method getMajorVersion()
  85. public int getMinorVersion() {
  86. return minorVersion;
  87. } // end method getMinorVersion()
  88. public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
  89. throws SQLException {
  90. DriverPropertyInfo[] theInfos = {
  91. new DriverPropertyInfo(userProperty, "*"),
  92. new DriverPropertyInfo(passwordProperty, "*"), };
  93. return theInfos;
  94. }
  95. public boolean jdbcCompliant() {
  96. // Basic version here returns false
  97. return false;
  98. }
  99. }