Source Code Cross Referenced for TimestampTypeCompiler.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » sql » compile » 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 » db derby 10.2 » org.apache.derby.impl.sql.compile 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.sql.compile.TimestampTypeCompiler
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           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, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:
022:        package org.apache.derby.impl.sql.compile;
023:
024:        import org.apache.derby.iapi.services.loader.ClassFactory;
025:
026:        import org.apache.derby.iapi.error.StandardException;
027:
028:        import org.apache.derby.iapi.types.DataTypeDescriptor;
029:        import org.apache.derby.iapi.types.DateTimeDataValue;
030:        import org.apache.derby.iapi.types.DataValueFactory;
031:        import org.apache.derby.iapi.types.TypeId;
032:
033:        import org.apache.derby.iapi.sql.compile.TypeCompiler;
034:
035:        import org.apache.derby.iapi.services.sanity.SanityManager;
036:
037:        import java.sql.Types;
038:        import org.apache.derby.iapi.reference.ClassName;
039:
040:        public class TimestampTypeCompiler extends BaseTypeCompiler {
041:            /* TypeCompiler methods */
042:
043:            /**
044:             * Timestamps are comparable to timestamps and to comparable
045:             * user types.
046:             *
047:             * @param otherType the type of the instance to compare with this type.
048:             * @param forEquals True if this is an = or <> comparison, false
049:             *					otherwise.
050:             * @param cf		A ClassFactory
051:             * @return true if otherType is comparable to this type, else false.
052:             */
053:            public boolean comparable(TypeId otherType, boolean forEquals,
054:                    ClassFactory cf) {
055:                return comparable(getTypeId(), otherType, forEquals, cf);
056:            }
057:
058:            boolean comparable(TypeId leftType, TypeId otherType,
059:                    boolean forEquals, ClassFactory cf) {
060:
061:                int otherJDBCTypeId = otherType.getJDBCTypeId();
062:
063:                // Long types cannot be compared
064:                if (otherType.isLongConcatableTypeId())
065:                    return false;
066:
067:                TypeCompiler otherTC = getTypeCompiler(otherType);
068:                if (otherJDBCTypeId == Types.TIMESTAMP
069:                        || otherType.isStringTypeId())
070:                    return true;
071:
072:                /* User types know the rules for what can be compared to them */
073:                if (otherType.userType()) {
074:                    return otherTC.comparable(getTypeId(), forEquals, cf);
075:                }
076:
077:                return false;
078:            }
079:
080:            /**
081:             * User types are convertible to other user types only if
082:             * (for now) they are the same type and are being used to
083:             * implement some JDBC type.  This is sufficient for
084:             * date/time types; it may be generalized later for e.g.
085:             * comparison of any user type with one of its subtypes.
086:             *
087:             * @see TypeCompiler#convertible 
088:             *
089:             */
090:            public boolean convertible(TypeId otherType,
091:                    boolean forDataTypeFunction) {
092:                if (otherType.isStringTypeId()
093:                        && (!otherType.isLongConcatableTypeId())) {
094:                    return true;
095:                }
096:
097:                int otherJDBCTypeId = otherType.getJDBCTypeId();
098:
099:                /*
100:                 ** At this point, we have only date/time.  If
101:                 ** same type, convert always ok.
102:                 */
103:                if (otherJDBCTypeId == Types.TIMESTAMP) {
104:                    return true;
105:                }
106:
107:                /*
108:                 ** Otherwise, we can convert timestamp to
109:                 ** date or time only.
110:                 */
111:                return ((otherJDBCTypeId == Types.DATE) || (otherJDBCTypeId == Types.TIME));
112:            }
113:
114:            /**
115:             * Tell whether this type (timestamp) is compatible with the given type.
116:             *
117:             * @param otherType     The TypeId of the other type.
118:             */
119:            public boolean compatible(TypeId otherType) {
120:                if (otherType.isStringTypeId()
121:                        && (!otherType.isLongConcatableTypeId())) {
122:                    return true;
123:                }
124:
125:                /*
126:                 ** Both are timestamp datatypes and hence compatible.
127:                 */
128:                return (getStoredFormatIdFromTypeId() == otherType
129:                        .getTypeFormatId());
130:            }
131:
132:            /**
133:             * User types are storable into other user types that they
134:             * are assignable to. The other type must be a subclass of
135:             * this type, or implement this type as one of its interfaces.
136:             *
137:             * Built-in types are also storable into user types when the built-in
138:             * type's corresponding Java type is assignable to the user type.
139:             *
140:             * @param otherType the type of the instance to store into this type.
141:             * @param cf		A ClassFactory
142:             * @return true if otherType is storable into this type, else false.
143:             */
144:            public boolean storable(TypeId otherType, ClassFactory cf) {
145:                int otherJDBCTypeId = otherType.getJDBCTypeId();
146:
147:                if (otherJDBCTypeId == Types.TIMESTAMP
148:                        || (otherJDBCTypeId == Types.CHAR)
149:                        || (otherJDBCTypeId == Types.VARCHAR)) {
150:                    return true;
151:                }
152:
153:                return cf.getClassInspector().assignableTo(
154:                        otherType.getCorrespondingJavaTypeName(),
155:                        "java.sql.Timestamp");
156:            }
157:
158:            /** @see TypeCompiler#interfaceName */
159:            public String interfaceName() {
160:                return ClassName.DateTimeDataValue;
161:            }
162:
163:            /**
164:             * @see TypeCompiler#getCorrespondingPrimitiveTypeName
165:             */
166:
167:            public String getCorrespondingPrimitiveTypeName() {
168:                return "java.sql.Timestamp";
169:            }
170:
171:            /**
172:             * @see TypeCompiler#getCastToCharWidth
173:             */
174:            public int getCastToCharWidth(DataTypeDescriptor dts) {
175:                return 26; // DATE TIME.milliseconds (extra few for good measure)
176:            }
177:
178:            public double estimatedMemoryUsage(DataTypeDescriptor dtd) {
179:                return 12.0;
180:            }
181:
182:            protected String nullMethodName() {
183:                return "getNullTimestamp";
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.