| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TorqueSQLTransformTask |
|
| 1.4;1.4 |
| 1 | package org.apache.torque.task; | |
| 2 | ||
| 3 | /* | |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE | |
| 5 | * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file | |
| 6 | * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | |
| 7 | * License. You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| 12 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| 13 | * specific language governing permissions and limitations under the License. | |
| 14 | */ | |
| 15 | ||
| 16 | import java.io.BufferedWriter; | |
| 17 | import java.io.FileWriter; | |
| 18 | ||
| 19 | import org.apache.tools.ant.BuildException; | |
| 20 | import org.apache.tools.ant.Project; | |
| 21 | import org.apache.tools.ant.Task; | |
| 22 | ||
| 23 | import org.apache.torque.engine.database.model.Database; | |
| 24 | import org.apache.torque.engine.database.transform.SQLToAppData; | |
| 25 | ||
| 26 | /** | |
| 27 | * An ant task for creating an xml schema from an sql schema | |
| 28 | * | |
| 29 | * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a> | |
| 30 | * @author <a href="mailto:jvanzyl@zenplex.com">Jason van Zyl</a> | |
| 31 | * @version $Id: TorqueSQLTransformTask.java,v 1.1 2007-10-21 07:57:26 abyrne Exp $ | |
| 32 | */ | |
| 33 | 0 | public class TorqueSQLTransformTask extends Task { |
| 34 | /** SQL input file. */ | |
| 35 | private String inputFile; | |
| 36 | ||
| 37 | /** XML descriptor output file. */ | |
| 38 | private String outputFile; | |
| 39 | ||
| 40 | /** | |
| 41 | * Get the current input file | |
| 42 | * | |
| 43 | * @return the input file | |
| 44 | */ | |
| 45 | public String getInputFile() { | |
| 46 | 0 | return inputFile; |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Set the sql input file. This file must exist | |
| 51 | * | |
| 52 | * @param v | |
| 53 | * the input file | |
| 54 | */ | |
| 55 | public void setInputFile(String v) { | |
| 56 | 0 | inputFile = v; |
| 57 | 0 | } |
| 58 | ||
| 59 | /** | |
| 60 | * Get the current output file. | |
| 61 | * | |
| 62 | * @return the output file | |
| 63 | */ | |
| 64 | public String getOutputFile() { | |
| 65 | 0 | return outputFile; |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Set the current output file. If the file does not exist it will be created. If the file exists all it's contents | |
| 70 | * will be replaced. | |
| 71 | * | |
| 72 | * @param v | |
| 73 | * the output file | |
| 74 | */ | |
| 75 | public void setOutputFile(String v) { | |
| 76 | 0 | outputFile = v; |
| 77 | 0 | } |
| 78 | ||
| 79 | /** | |
| 80 | * Execute the task. | |
| 81 | * | |
| 82 | * @throws BuildException | |
| 83 | * Any exceptions caught during procssing will be rethrown wrapped into a BuildException | |
| 84 | */ | |
| 85 | public void execute() throws BuildException { | |
| 86 | try { | |
| 87 | 0 | log("Parsing SQL Schema", Project.MSG_INFO); |
| 88 | ||
| 89 | 0 | SQLToAppData sqlParser = new SQLToAppData(inputFile); |
| 90 | 0 | Database app = sqlParser.execute(); |
| 91 | ||
| 92 | 0 | log("Preparing to write xml schema", Project.MSG_INFO); |
| 93 | 0 | FileWriter fr = new FileWriter(outputFile); |
| 94 | 0 | BufferedWriter br = new BufferedWriter(fr); |
| 95 | ||
| 96 | 0 | br.write(app.toString()); |
| 97 | ||
| 98 | 0 | log("Writing xml schema", Project.MSG_INFO); |
| 99 | ||
| 100 | 0 | br.flush(); |
| 101 | 0 | br.close(); |
| 102 | 0 | } catch (Exception e) { |
| 103 | 0 | throw new BuildException(e); |
| 104 | 0 | } |
| 105 | 0 | } |
| 106 | } |