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