Source Code Cross Referenced for Sql92Dialect.java in  » Content-Management-System » riotfamily » org » riotfamily » revolt » dialect » 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 » Content Management System » riotfamily » org.riotfamily.revolt.dialect 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ***** BEGIN LICENSE BLOCK *****
002:         * Version: MPL 1.1
003:         * The contents of this file are subject to the Mozilla Public License Version
004:         * 1.1 (the "License"); you may not use this file except in compliance with
005:         * the License. You may obtain a copy of the License at
006:         * http://www.mozilla.org/MPL/
007:         * 
008:         * Software distributed under the License is distributed on an "AS IS" basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010:         * for the specific language governing rights and limitations under the
011:         * License.
012:         * 
013:         * The Original Code is Riot.
014:         * 
015:         * The Initial Developer of the Original Code is
016:         * Neteye GmbH.
017:         * Portions created by the Initial Developer are Copyright (C) 2006
018:         * the Initial Developer. All Rights Reserved.
019:         * 
020:         * Contributor(s):
021:         *   Felix Gnass [fgnass at neteye dot de]
022:         * 
023:         * ***** END LICENSE BLOCK ***** */
024:        package org.riotfamily.revolt.dialect;
025:
026:        import java.util.Collection;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.Map;
030:
031:        import org.riotfamily.revolt.Script;
032:        import org.riotfamily.revolt.definition.Column;
033:        import org.riotfamily.revolt.definition.ForeignKey;
034:        import org.riotfamily.revolt.definition.Identifier;
035:        import org.riotfamily.revolt.definition.Index;
036:        import org.riotfamily.revolt.definition.RecordEntry;
037:        import org.riotfamily.revolt.definition.Table;
038:        import org.riotfamily.revolt.definition.UniqueConstraint;
039:
040:        /**
041:         * @author Felix Gnass [fgnass at neteye dot de]
042:         * 
043:         */
044:        public abstract class Sql92Dialect extends AbstractDialect {
045:            private static final Map actions = new HashMap();
046:
047:            static {
048:                actions.put(ForeignKey.NO_ACTION_HANDLER, "NO ACTION");
049:                actions.put(ForeignKey.CASCADE_HANDLER, "CASCADE");
050:                actions.put(ForeignKey.SET_NULL_HANDLER, "SET NULL");
051:                actions.put(ForeignKey.SET_DEFAULT_HANDLER, "SET DEFAULT");
052:            }
053:
054:            private String getDeleteAction(ForeignKey foreignKey) {
055:                return (String) actions.get(foreignKey.getDeleteAction());
056:            }
057:
058:            private String getUpdateAction(ForeignKey foreignKey) {
059:                return (String) actions.get(foreignKey.getUpdateAction());
060:            }
061:
062:            public Sql92Dialect() {
063:            }
064:
065:            public Script createTable(Table table) {
066:
067:                Script sql = new Script("CREATE TABLE").append(quote(table))
068:                        .append('(');
069:
070:                Iterator it = table.getColumns().iterator();
071:                while (it.hasNext()) {
072:                    Column column = (Column) it.next();
073:                    addColumnDefinition(sql, column);
074:                    if (it.hasNext()) {
075:                        sql.append(',');
076:                    }
077:                }
078:                if (!(table.getPrimaryKeys().isEmpty())) {
079:                    sql.append(',').append("PRIMARY KEY");
080:                    addColumnNames(sql, table.getPrimaryKeys());
081:                }
082:
083:                sql.append(')');
084:
085:                return sql;
086:            }
087:
088:            public Script renameTable(String name, String renameTo) {
089:                throw new OperationNotSupportedException(
090:                        "Tables can't be renamed in SQL 92");
091:            }
092:
093:            public Script dropTable(String name) {
094:                return new Script("DROP TABLE").append(quote(name));
095:            }
096:
097:            public Script addColumn(String table, Column column) {
098:                Script sql = alterTable(table).append("ADD COLUMN");
099:                addColumnDefinition(sql, column);
100:                return sql;
101:            }
102:
103:            public Script renameColumn(String table, String name,
104:                    String renameTo) {
105:                throw new OperationNotSupportedException(
106:                        "Columns can't be renamed in SQL 92");
107:            }
108:
109:            public Script modifyColumn(String table, Column column) {
110:                throw new OperationNotSupportedException(
111:                        "Columns can't be modified in SQL 92");
112:            }
113:
114:            public Script dropColumn(String table, String name) {
115:
116:                return alterTable(table).append("DROP COLUMN").append(
117:                        quote(name));
118:            }
119:
120:            public Script addIndex(String table, Index index) {
121:                throw new OperationNotSupportedException(
122:                        "SQL 92 does not support indices");
123:            }
124:
125:            public Script dropIndex(String table, String name) {
126:                throw new OperationNotSupportedException(
127:                        "SQL 92 does not support indices");
128:            }
129:
130:            public Script addUniqueConstraint(String table,
131:                    UniqueConstraint constraint) {
132:                Script sql = alterTable(table).append("ADD CONSTRAINT").append(
133:                        constraint.getName()).append("UNIQUE");
134:
135:                addColumnNames(sql, constraint.getColumns());
136:                return sql;
137:            }
138:
139:            public Script dropUniqueConstraint(String table, String name) {
140:                return dropConstraint(table, name);
141:            }
142:
143:            public Script addForeignKey(String table, ForeignKey fk) {
144:                Script sql = alterTable(table).append("ADD CONSTRAINT").append(
145:                        fk.getName()).append("FOREIGN KEY");
146:
147:                addColumnNames(sql, fk.getLocalColumns());
148:                sql.append("REFERENCES").append(fk.getForeignTable());
149:                addColumnNames(sql, fk.getForeignColumns());
150:                if (fk.hasUpdateAction()) {
151:                    sql.append("ON UPDATE").append(getUpdateAction(fk));
152:                }
153:                if (fk.hasDeleteAction()) {
154:                    sql.append("ON DELETE").append(getDeleteAction(fk));
155:                }
156:                return sql;
157:            }
158:
159:            public Script dropForeignKey(String table, String name) {
160:                return dropConstraint(table, name);
161:            }
162:
163:            public Script insert(String table, Collection data) {
164:                Script sql = new Script("INSERT INTO").append(quote(table));
165:
166:                addColumnNames(sql, data);
167:                sql.append("VALUES").append('(');
168:                Iterator it = data.iterator();
169:                while (it.hasNext()) {
170:                    RecordEntry entry = (RecordEntry) it.next();
171:                    sql.append(convertQuotes(entry.getValue()));
172:                    if (it.hasNext()) {
173:                        sql.append(',');
174:                    }
175:                }
176:                sql.append(')');
177:                return sql;
178:            }
179:
180:            protected Script alterTable(String name) {
181:                return new Script("ALTER TABLE").append(quote(name));
182:            }
183:
184:            protected Script dropConstraint(String table, String name) {
185:                return alterTable(table).append("DROP CONSTRAINT").append(name);
186:            }
187:
188:            protected void addColumnDefinition(Script sql, Column column) {
189:                sql.append(quote(column)).append(getColumnType(column));
190:
191:                if (column.isDefaultValueSet()) {
192:                    sql.append("DEFAULT").append(
193:                            convertQuotes(column.getDefaultValue()));
194:                }
195:                if (column.isNotNullSet()) {
196:                    if (column.isNotNull()) {
197:                        sql.append("NOT");
198:                    }
199:                    sql.append("NULL");
200:                }
201:            }
202:
203:            protected void addColumnNames(Script sql, Collection columns) {
204:                sql.append('(');
205:                Iterator it = columns.iterator();
206:                while (it.hasNext()) {
207:                    sql.append(quote((Identifier) it.next()));
208:                    if (it.hasNext()) {
209:                        sql.append(',');
210:                    }
211:                }
212:                sql.append(')');
213:            }
214:
215:            protected String getIdentifierQuote() {
216:                return "\"";
217:            }
218:
219:            protected String quote(String id) {
220:                return quote(new Identifier(id));
221:            }
222:
223:            protected String quote(Identifier id) {
224:                if (id.isQuoted()) {
225:                    return getIdentifierQuote() + id.getName()
226:                            + getIdentifierQuote();
227:                }
228:                return id.getName();
229:            }
230:
231:            protected String convertQuotes(String value) {
232:                return value;
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.