001 /******************************************************************************
002 * Copyright (C) MActor Developers. All rights reserved. *
003 * ---------------------------------------------------------------------------*
004 * This file is part of MActor. *
005 * *
006 * MActor is free software; you can redistribute it and/or modify *
007 * it under the terms of the GNU General Public License as published by *
008 * the Free Software Foundation; either version 2 of the License, or *
009 * (at your option) any later version. *
010 * *
011 * MActor is distributed in the hope that it will be useful, *
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
014 * GNU General Public License for more details. *
015 * *
016 * You should have received a copy of the GNU General Public License *
017 * along with MActor; if not, write to the Free Software *
018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
019 ******************************************************************************/
020 package org.mactor.framework.data.jdbc;
021
022 import org.mactor.framework.ConfigException;
023 import org.mactor.framework.MactorException;
024 import org.mactor.framework.spec.GlobalConfig;
025 import org.mactor.framework.spec.GlobalConfig.Group;
026
027 public class SqlCommandUtil {
028 private JdbcUtil db;
029 private String sqlExpression;
030 public SqlCommandUtil(String command, GlobalConfig globalConfig) throws MactorException {
031 int start = command.indexOf(":");
032 if (start <= 0 || start > command.length() - 4) {
033 throw new ConfigException("Invalid sql command syntax 'sql:" + command
034 + "'. Correct syntax is: 'sql:<name of sql global config group>:<sql expession> | <sql script file ending with .sql>' ");
035 }
036 String groupName = command.substring(0, start);
037 this.sqlExpression = command.substring(start + 1, command.length());
038 Group config = globalConfig.getRequieredGroup(groupName);
039 this.db = new JdbcUtil(config.getValue("driver"), config.getRequieredValue("url"), config.getRequieredValue("username"), config.getRequieredValue("password"));
040 }
041 public JdbcUtil getDb() {
042 return db;
043 }
044 public String getSqlExpression() {
045 return sqlExpression;
046 }
047 }