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 * $Id: InternalDataSource.java 464373 2006-10-16 04:21:54Z rahul $ 18 */ 19 20 package org.apache.shale.examples.sqlbrowser; 21 22 import java.sql.Connection; 23 import java.sql.SQLException; 24 import org.apache.derby.jdbc.EmbeddedDataSource; 25 26 /*** 27 * <p>Trivial implementation of <code>DataSource</code> that wraps a data source 28 * provided by Derby, and provides a shutdown hook.</p> 29 */ 30 public class InternalDataSource extends EmbeddedDataSource { 31 32 33 // ------------------------------------------------------------ Constructors 34 35 36 /*** 37 * <p>Construct a connection pool for the specified URL.</p> 38 */ 39 public InternalDataSource(String url) throws SQLException { 40 41 // Instantiate and configure a Derby EmbeddedDataSource 42 setDatabaseName(url); 43 setCreateDatabase("create"); 44 45 } 46 47 48 // ---------------------------------------------------------- Public Methods 49 50 51 /*** 52 * <p>Cause the embedded Derby database to be shut down.</p> 53 */ 54 public void shutdown() throws SQLException { 55 56 setShutdownDatabase("shutdown"); 57 Connection conn = null; 58 try { 59 conn = getConnection(); 60 } catch (SQLException e) { 61 ; // Ignore errors here; we just wanted to trigger the shutdown 62 } finally { 63 try { 64 if (conn != null) { 65 conn.close(); 66 } 67 } catch (SQLException e) { 68 ; 69 } 70 } 71 72 } 73 74 75 }