Source Code Cross Referenced for ConstraintCheck.java in  » Database-DBMS » h2database » org » h2 » constraint » 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 DBMS » h2database » org.h2.constraint 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003:         * (http://h2database.com/html/license.html).
004:         * Initial Developer: H2 Group
005:         */
006:        package org.h2.constraint;
007:
008:        import java.sql.SQLException;
009:
010:        import org.h2.constant.ErrorCode;
011:        import org.h2.engine.Session;
012:        import org.h2.expression.Expression;
013:        import org.h2.index.Index;
014:        import org.h2.message.Message;
015:        import org.h2.result.LocalResult;
016:        import org.h2.result.Row;
017:        import org.h2.schema.Schema;
018:        import org.h2.table.Column;
019:        import org.h2.table.Table;
020:        import org.h2.table.TableFilter;
021:        import org.h2.util.StringUtils;
022:
023:        /**
024:         * A check constraint.
025:         */
026:        public class ConstraintCheck extends Constraint {
027:
028:            private TableFilter filter;
029:            private Expression expr;
030:
031:            public ConstraintCheck(Schema schema, int id, String name,
032:                    Table table) {
033:                super (schema, id, name, table);
034:            }
035:
036:            public String getConstraintType() {
037:                return Constraint.CHECK;
038:            }
039:
040:            public void setTableFilter(TableFilter filter) {
041:                this .filter = filter;
042:            }
043:
044:            public void setExpression(Expression expr) {
045:                this .expr = expr;
046:            }
047:
048:            public String getCreateSQLForCopy(Table table, String quotedName) {
049:                StringBuffer buff = new StringBuffer();
050:                buff.append("ALTER TABLE ");
051:                buff.append(table.getSQL());
052:                buff.append(" ADD CONSTRAINT ");
053:                buff.append(quotedName);
054:                if (comment != null) {
055:                    buff.append(" COMMENT ");
056:                    buff.append(StringUtils.quoteStringSQL(comment));
057:                }
058:                buff.append(" CHECK");
059:                buff.append(StringUtils.enclose(expr.getSQL()));
060:                buff.append(" NOCHECK");
061:                return buff.toString();
062:            }
063:
064:            public String getShortDescription() {
065:                StringBuffer buff = new StringBuffer();
066:                buff.append(getName());
067:                buff.append(": ");
068:                buff.append(expr.getSQL());
069:                return buff.toString();
070:            }
071:
072:            public String getCreateSQLWithoutIndexes() {
073:                return getCreateSQL();
074:            }
075:
076:            public String getCreateSQL() {
077:                return getCreateSQLForCopy(table, getSQL());
078:            }
079:
080:            public void removeChildrenAndResources(Session session)
081:                    throws SQLException {
082:                table.removeConstraint(this );
083:                database.removeMeta(session, getId());
084:                filter = null;
085:                expr = null;
086:                table = null;
087:                invalidate();
088:            }
089:
090:            public void checkRow(Session session, Table t, Row oldRow,
091:                    Row newRow) throws SQLException {
092:                if (newRow == null) {
093:                    return;
094:                }
095:                filter.set(newRow);
096:                // Both TRUE and NULL are ok
097:                if (Boolean.FALSE.equals(expr.getValue(session).getBoolean())) {
098:                    throw Message.getSQLException(
099:                            ErrorCode.CHECK_CONSTRAINT_VIOLATED_1,
100:                            getShortDescription());
101:                }
102:            }
103:
104:            public boolean usesIndex(Index index) {
105:                return false;
106:            }
107:
108:            public void setIndexOwner(Index index) {
109:                throw Message.getInternalError();
110:            }
111:
112:            public boolean containsColumn(Column col) {
113:                // TODO check constraints / containsColumn: this is cheating, maybe the
114:                // column is not referenced
115:                String s = col.getSQL();
116:                String sql = getCreateSQL();
117:                return sql.indexOf(s) >= 0;
118:            }
119:
120:            public Expression getExpression() {
121:                return expr;
122:            }
123:
124:            public boolean isBefore() {
125:                return true;
126:            }
127:
128:            public void checkExistingData(Session session) throws SQLException {
129:                if (session.getDatabase().isStarting()) {
130:                    // don't check at startup
131:                    return;
132:                }
133:                StringBuffer buff = new StringBuffer();
134:                buff.append("SELECT 1 FROM ");
135:                buff.append(filter.getTable().getSQL());
136:                buff.append(" WHERE NOT(");
137:                buff.append(expr.getSQL());
138:                buff.append(")");
139:                String sql = buff.toString();
140:                LocalResult r = session.prepare(sql).query(1);
141:                if (r.next()) {
142:                    throw Message.getSQLException(
143:                            ErrorCode.CHECK_CONSTRAINT_VIOLATED_1, getName());
144:                }
145:            }
146:
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.