01: /******************************************************************************
02: * Copyright (C) Lars Ivar Almli. All rights reserved. *
03: * ---------------------------------------------------------------------------*
04: * This file is part of MActor. *
05: * *
06: * MActor is free software; you can redistribute it and/or modify *
07: * it under the terms of the GNU General Public License as published by *
08: * the Free Software Foundation; either version 2 of the License, or *
09: * (at your option) any later version. *
10: * *
11: * MActor 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 *
14: * GNU General Public License for more details. *
15: * *
16: * You should have received a copy of the GNU General Public License *
17: * along with MActor; if not, write to the Free Software *
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19: ******************************************************************************/package org.mactor.framework.commandexecutors.sql;
20:
21: import org.mactor.framework.ConfigException;
22: import org.mactor.framework.MactorException;
23: import org.mactor.framework.spec.GlobalConfig;
24: import org.mactor.framework.spec.GlobalConfig.Group;
25:
26: public class SqlCommandUtil {
27: private JdbcUtil db;
28: private String sqlExpression;
29:
30: public SqlCommandUtil(String command, GlobalConfig globalConfig)
31: throws MactorException {
32: int start = command.indexOf(":");
33: if (start <= 0 || start > command.length() - 4) {
34: throw new ConfigException(
35: "Invalid sql command syntax 'sql:"
36: + command
37: + "'. Correct syntax is: command=sql:<name of sql global config group>:<sql expession | sql script file ending with '.sql'> ");
38: }
39: String groupName = command.substring(0, start);
40: this .sqlExpression = command.substring(start + 1, command
41: .length());
42: Group config = globalConfig.getRequieredGroup(groupName);
43: this .db = new JdbcUtil(config.getValue("driver"), config
44: .getRequieredValue("url"), config
45: .getRequieredValue("username"), config
46: .getRequieredValue("password"));
47: }
48:
49: public JdbcUtil getDb() {
50: return db;
51: }
52:
53: public String getSqlExpression() {
54: return sqlExpression;
55: }
56: }
|