Source Code Cross Referenced for TorqueSQLTask.java in  » Database-ORM » Torque » org » apache » torque » task » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Torque » org.apache.torque.task 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.torque.task;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.io.File;
023:        import java.io.FileInputStream;
024:        import java.io.FileOutputStream;
025:
026:        import java.util.Iterator;
027:        import java.util.Properties;
028:
029:        import org.apache.tools.ant.BuildException;
030:
031:        import org.apache.velocity.context.Context;
032:
033:        import org.apache.torque.engine.EngineException;
034:        import org.apache.torque.engine.database.transform.XmlToAppData;
035:        import org.apache.torque.engine.database.model.Database;
036:
037:        /**
038:         * An extended Texen task used for generating SQL source from
039:         * an XML schema describing a database structure.
040:         *
041:         * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
042:         * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
043:         * @version $Id: TorqueSQLTask.java 591762 2007-11-04 11:22:06Z tfischer $
044:         */
045:        public class TorqueSQLTask extends TorqueDataModelTask {
046:            // if the database is set than all generated sql files
047:            // will be placed in the specified database, the database
048:            // will not be taken from the data model schema file.
049:
050:            private String database;
051:            private String suffix = "";
052:
053:            private String idTableXMLFile = null;
054:
055:            /**
056:             * Sets the name of the database to generate sql for.
057:             *
058:             * @param database the name of the database to generate sql for.
059:             */
060:            public void setDatabase(String database) {
061:                this .database = database;
062:            }
063:
064:            /**
065:             * Returns the name of the database to generate sql for.
066:             *
067:             * @return the name of the database to generate sql for.
068:             */
069:            public String getDatabase() {
070:                return database;
071:            }
072:
073:            /**
074:             * Sets the suffix of the generated sql files.
075:             *
076:             * @param suffix the suffix of the generated sql files.
077:             */
078:            public void setSuffix(String suffix) {
079:                this .suffix = suffix;
080:            }
081:
082:            /**
083:             * Returns the suffix of the generated sql files.
084:             *
085:             * @return the suffix of the generated sql files.
086:             */
087:            public String getSuffix() {
088:                return suffix;
089:            }
090:
091:            /**
092:             * Set the path to the xml schema file that defines the id-table, used
093:             * by the idbroker method.
094:             *
095:             * @param idXmlFile xml schema file
096:             */
097:            public void setIdTableXMLFile(String idXmlFile) {
098:                idTableXMLFile = idXmlFile;
099:            }
100:
101:            /**
102:             * Gets the id-table xml schema file path.
103:             *
104:             * @return Path to file.
105:             */
106:            public String getIdTableXMLFile() {
107:                return idTableXMLFile;
108:            }
109:
110:            /**
111:             * create the sql -> database map.
112:             *
113:             * @throws Exception
114:             */
115:            private void createSqlDbMap() throws Exception {
116:                if (getSqlDbMap() == null) {
117:                    return;
118:                }
119:
120:                // Produce the sql -> database map
121:                Properties sqldbmap = new Properties();
122:
123:                // Check to see if the sqldbmap has already been created.
124:                File file = new File(getSqlDbMap());
125:
126:                if (file.exists()) {
127:                    FileInputStream fis = new FileInputStream(file);
128:                    sqldbmap.load(fis);
129:                    fis.close();
130:                }
131:
132:                Iterator i = getDataModelDbMap().keySet().iterator();
133:
134:                while (i.hasNext()) {
135:                    String dataModelName = (String) i.next();
136:                    String sqlFile = dataModelName + suffix + ".sql";
137:
138:                    String databaseName;
139:
140:                    if (getDatabase() == null) {
141:                        databaseName = (String) getDataModelDbMap().get(
142:                                dataModelName);
143:                    } else {
144:                        databaseName = getDatabase();
145:                    }
146:
147:                    sqldbmap.setProperty(sqlFile, databaseName);
148:                }
149:
150:                sqldbmap.store(new FileOutputStream(getSqlDbMap()),
151:                        "Sqlfile -> Database map");
152:            }
153:
154:            /**
155:             * Create the database model necessary for the IDBroker tables.
156:             * We use the model to generate the necessary SQL to create
157:             * these tables.  This method adds an AppData object containing
158:             * the model to the context under the name "idmodel".
159:             */
160:            public void loadIdBrokerModel() throws EngineException {
161:                // Transform the XML database schema into
162:                // data model object.
163:                XmlToAppData xmlParser = new XmlToAppData(getTargetDatabase(),
164:                        null);
165:                Database ad = xmlParser.parseFile(getIdTableXMLFile());
166:
167:                ad.setName("idmodel");
168:                context.put("idmodel", ad);
169:            }
170:
171:            /**
172:             * Place our target database and target platform
173:             * values into the context for use in the templates.
174:             *
175:             * @return the context
176:             * @throws Exception
177:             */
178:            public Context initControlContext() throws Exception {
179:                super .initControlContext();
180:                try {
181:                    createSqlDbMap();
182:
183:                    // If the load path for the id broker table xml schema is
184:                    // defined then load it.
185:                    String f = getIdTableXMLFile();
186:                    if (f != null && f.length() > 0) {
187:                        loadIdBrokerModel();
188:                    }
189:                } catch (EngineException ee) {
190:                    throw new BuildException(ee);
191:                }
192:
193:                return context;
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.