Path: blob/master/test/jdk/java/sql/testng/util/StubDriverDA.java
41152 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package util;2324import java.io.File;25import java.io.IOException;26import java.sql.DriverAction;27import java.sql.DriverManager;28import java.sql.SQLException;29import java.util.logging.Level;30import java.util.logging.Logger;3132/**33* Simple java.sql.Driver stub class that registers the driver via a static34* block with a DriverAction Implementation35* @author ljanders36*/37public class StubDriverDA extends StubDriver {3839public static final String DriverActionCalled = "DriverActionCalled.txt";4041static DriverAction da;4243static {44try {45DriverManager.registerDriver(new StubDriverDA(), da);46} catch (SQLException ex) {47Logger.getLogger(StubDriverDA.class.getName()).log(Level.SEVERE, null, ex);48}49}5051public StubDriverDA() {52da = new DriverActionImpl(this);53}5455@Override56public boolean acceptsURL(String url) throws SQLException {57return url.matches("^jdbc:luckydog:.*");58}5960/**61* This method will write out a text file when called by the62* DriverActionImpl.release method when DriverManager.deregisterDriver63* is called. This is used by DriverManagerTests to validate that64* DriverAction.release was called65*/66protected void release() {67File file = new File(DriverActionCalled);68try {69file.createNewFile();70} catch (IOException ex) {71throw new RuntimeException(ex);72}73}74}757677