01: /*
02: * hgcommons 7
03: * Hammurapi Group Common Library
04: * Copyright (C) 2003 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21: * e-Mail: support@hammurapi.biz
22: */
23: package biz.hammurapi.sql.hypersonic;
24:
25: import java.io.IOException;
26: import java.sql.SQLException;
27:
28: import org.w3c.dom.Element;
29: import org.w3c.dom.Node;
30:
31: import biz.hammurapi.CarryOverException;
32: import biz.hammurapi.config.ConfigurationException;
33: import biz.hammurapi.config.Context;
34: import biz.hammurapi.sql.SQLProcessor;
35: import biz.hammurapi.sql.Transaction;
36:
37: public class HypersonicStandaloneDataSourceComponent extends
38: HypersonicDataSourceComponent {
39:
40: private HypersonicStandaloneDataSource master;
41:
42: public HypersonicStandaloneDataSourceComponent() {
43: super ();
44: }
45:
46: public Object getMaster() {
47: if (master == null) {
48: throw new IllegalStateException("Not yet started");
49: }
50: return master;
51: }
52:
53: private String location;
54:
55: public void configure(Node configNode, Context context)
56: throws ConfigurationException {
57: super .configure(configNode, context);
58: location = ((Element) configNode).getAttribute("location");
59: }
60:
61: public void start() throws ConfigurationException {
62: try {
63: master = new HypersonicStandaloneDataSource(location,
64: new Transaction() {
65:
66: public boolean execute(SQLProcessor processor)
67: throws SQLException {
68: try {
69: processor.executeScript(getReader());
70: } catch (IOException e) {
71: throw new CarryOverException(e);
72: }
73: return true;
74: }
75:
76: });
77: } catch (ClassNotFoundException e) {
78: throw new ConfigurationException("Driver class not found",
79: e);
80: } catch (SQLException e) {
81: throw new ConfigurationException(
82: "Could not initialize database: " + e, e);
83: } catch (CarryOverException e) {
84: throw new ConfigurationException(
85: "Could not initialize databse: " + e.getCause(), e
86: .getCause());
87: }
88: }
89:
90: public void stop() throws ConfigurationException {
91: if (master != null) {
92: master.shutdown();
93: }
94: }
95: }
|