1   package org.apache.velocity.test.sql;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import java.io.PrintWriter;
23  import java.sql.Connection;
24  import java.sql.DriverManager;
25  import java.sql.SQLException;
26  
27  import javax.sql.DataSource;
28  
29  import org.hsqldb.jdbcDriver;
30  
31  public class HsqlDataSource implements DataSource {
32  
33      private final String url;
34  
35      private PrintWriter logWriter = null;
36  
37      private int loginTimeout = 0;
38  
39      public HsqlDataSource(final String url) throws Exception {
40  	this.url = url;
41  	Class.forName(jdbcDriver.class.getName());
42      }
43  
44      public Connection getConnection() throws SQLException {
45  	return DriverManager.getConnection(url, "sa", "");
46      }
47  
48      public Connection getConnection(final String username, final String password)
49  	    throws SQLException {
50  	return DriverManager.getConnection(url, username, password);
51      }
52  
53      public PrintWriter getLogWriter() throws SQLException {
54  	return logWriter;
55      }
56  
57      public int getLoginTimeout() throws SQLException {
58  	return loginTimeout;
59      }
60  
61      public void setLogWriter(final PrintWriter logWriter) throws SQLException {
62  	this.logWriter = logWriter;
63      }
64  
65      public void setLoginTimeout(final int loginTimeout) throws SQLException {
66  	this.loginTimeout = loginTimeout;
67      }
68  
69      public boolean isWrapperFor(final Class iface) throws SQLException {
70  	return false;
71      }
72  
73      public Object unwrap(final Class iface) throws SQLException {
74  	throw new SQLException("Not implemented");
75      }
76  
77  }