001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: *
019: */package org.apache.jetspeed.anttasks;
020:
021: import java.io.File;
022:
023: import org.apache.tools.ant.Project;
024: import org.apache.tools.ant.Target;
025: import org.apache.tools.ant.taskdefs.SQLExec;
026:
027: /**
028: * @author hajo
029: *
030: */
031: public class ExecuteJavaSQL {
032:
033: /**
034: * @param args
035: */
036: public static void main(String[] args) {
037: final class TEMPSQL extends SQLExec {
038: public TEMPSQL() {
039: setProject(new Project());
040: getProject().init();
041: super .setTaskType("sql");
042: super .setTaskName("sql");
043: super .target = new Target();
044: }
045: }
046:
047: boolean autocommit = true;
048: String driver = null;
049: String url = null;
050: String userid = null;
051: String password = null;
052: String source = null;
053: String onError = null;
054:
055: if (args == null)
056: throw new IllegalArgumentException(
057: "ExecuteSQL needs to know what to do - no arguments provided!!! ");
058:
059: // Parse all the command-line arguments
060: for (int n = 0; n < args.length; n++) {
061: String argument = args[n].toLowerCase().trim();
062:
063: if (argument.startsWith("driver=")) {
064: driver = args[n].substring("driver=".length());
065: } else if (argument.startsWith("url=")) {
066: url = args[n].substring("url=".length());
067: } else if (argument.startsWith("userid=")) {
068: userid = args[n].substring("userid=".length());
069: } else if (argument.startsWith("password=")) {
070: password = args[n].substring("password=".length());
071: } else if (argument.startsWith("src=")) {
072: source = args[n].substring("src=".length());
073: } else if (argument.startsWith("autocommit=")) {
074: String s = args[n].substring("src=".length());
075: try {
076: autocommit = Boolean.valueOf(s).booleanValue();
077: } catch (Exception e) {
078: e.printStackTrace();
079: }
080: } else if (argument.startsWith("onerror=")) {
081: onError = args[n].substring("onerror=".length());
082: } else {
083: throw new IllegalArgumentException("Unknown argument: "
084: + args[n]);
085: }
086: }
087: TEMPSQL sql = new TEMPSQL();
088:
089: sql.setAutocommit(autocommit);
090: sql.setDriver(driver);
091: sql.setUrl(url);
092: sql.setUserid(userid);
093: sql.setPassword(password);
094: File sqlFile = null;
095: try {
096: sqlFile = new File(source);
097: } catch (Exception e) {
098: throw new IllegalArgumentException("File parameter "
099: + source + " invalid : " + e.getLocalizedMessage());
100: }
101: sql.setSrc(sqlFile);
102: try {
103: SQLExec.OnError errorHandling = new SQLExec.OnError();
104: errorHandling.setValue(onError);
105: sql.setOnerror(errorHandling);
106: } catch (Exception e) {
107: throw new IllegalArgumentException(
108: "Error handling parameter " + onError
109: + " invalid : " + e.getLocalizedMessage());
110: }
111:
112: sql.execute();
113:
114: }
115: }
|