1   /********************************************************************************
2    * Copyright (c) 2005 Chris Rose and AIMedia All rights reserved.
3    * TestingDataSource and the accompanying materials are made available under the
4    * terms of the Common Public License v1.0 which accompanies this distribution,
5    * and is available at http://www.eclipse.org/legal/cpl-v10.html Contributors:
6    * Chris Rose
7    ******************************************************************************/
8   package ca.spaz.cron.datasource.sql;
9   
10  import org.apache.log4j.Logger;
11  
12  import java.sql.SQLException;
13  
14  /***
15   * TODO describe
16   * 
17   * @author Chris Rose
18   */
19  public class TestingDataSource extends SQLDatasource {
20     /***
21      * Logger for this class
22      */
23     private static final Logger logger = Logger
24           .getLogger(TestingDataSource.class);
25  
26     public void initialize() {
27        super.initialize();
28     }
29  
30     public void close() {
31        try {
32           if (!conn.isClosed()) {
33              if (conn.getMetaData().getURL().startsWith("jdbc:hsqldb:file") ||
34                    conn.getMetaData().getURL().startsWith("jdbc:hsqldb:mem")) {
35                 conn.createStatement().execute("SHUTDOWN");
36                 logger.info("[" + getId() + "] - Shutdown called");
37              }
38              conn.close();
39              logger.info("[" + getId() + "] - closed");
40           }
41        } catch (SQLException e) {
42           logger.error("[" + getId() + "] - close()", e);
43           registerError(e);
44        }
45     }
46  
47     /***
48      * @param name
49      * @param id
50      * @param conn
51      * @param allowLocal
52      */
53     public TestingDataSource(boolean allowLocal) {
54        super("Testing Database", "test_rw", ConnectionManager.getInstance(
55              "test_rw").getConnection(), allowLocal);
56     }
57  
58  }