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


001:        /*
002:
003:           Derby - Class org.apache.derby.iapi.types.SQLVarbit
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.iapi.types;
023:
024:        import org.apache.derby.iapi.types.DataTypeDescriptor;
025:        import org.apache.derby.iapi.types.DataValueDescriptor;
026:        import org.apache.derby.iapi.types.TypeId;
027:        import org.apache.derby.iapi.types.BitDataValue;
028:        import org.apache.derby.iapi.types.DataValueDescriptor;
029:        import org.apache.derby.iapi.reference.SQLState;
030:        import org.apache.derby.iapi.reference.Limits;
031:        import org.apache.derby.iapi.error.StandardException;
032:
033:        import org.apache.derby.iapi.types.Orderable;
034:
035:        import org.apache.derby.iapi.services.io.FormatIdUtil;
036:        import org.apache.derby.iapi.services.io.StoredFormatIds;
037:
038:        import org.apache.derby.iapi.services.sanity.SanityManager;
039:
040:        import org.apache.derby.iapi.types.BooleanDataValue;
041:        import org.apache.derby.iapi.types.StringDataValue;
042:        import org.apache.derby.iapi.types.NumberDataValue;
043:
044:        import org.apache.derby.iapi.services.io.FormatableBitSet;
045:        import org.apache.derby.iapi.util.StringUtil;
046:
047:        import java.io.ObjectOutput;
048:        import java.io.ObjectInput;
049:        import java.io.IOException;
050:
051:        /**
052:         * SQLVarbit represents the SQL type VARCHAR FOR BIT DATA
053:         * It is an extension of SQLBit and is virtually indistinguishable
054:         * other than normalization.
055:         */
056:        public class SQLVarbit extends SQLBit {
057:
058:            public String getTypeName() {
059:                return TypeId.VARBIT_NAME;
060:            }
061:
062:            /**
063:             * Return max memory usage for a SQL Varbit
064:             */
065:            int getMaxMemoryUsage() {
066:                return Limits.DB2_VARCHAR_MAXWIDTH;
067:            }
068:
069:            /**
070:             * @see DataValueDescriptor#getNewNull
071:             */
072:            public DataValueDescriptor getNewNull() {
073:                return new SQLVarbit();
074:            }
075:
076:            /**
077:            	Return my format identifier.
078:
079:            	@see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
080:             */
081:            public int getTypeFormatId() {
082:                return StoredFormatIds.SQL_VARBIT_ID;
083:            }
084:
085:            /**
086:             * Normalization method - this method may be called when putting
087:             * a value into a SQLBit, for example, when inserting into a SQLBit
088:             * column.  See NormalizeResultSet in execution.
089:             *
090:             * @param desiredType	The type to normalize the source column to
091:             * @param source		The value to normalize
092:             *
093:             * @exception StandardException				Thrown for null into
094:             *											non-nullable column, and for
095:             *											truncation error
096:             */
097:
098:            public void normalize(DataTypeDescriptor desiredType,
099:                    DataValueDescriptor source) throws StandardException {
100:                int desiredWidth = desiredType.getMaximumWidth();
101:
102:                byte[] sourceData = source.getBytes();
103:                setValue(sourceData);
104:                if (sourceData.length > desiredWidth)
105:                    setWidth(desiredWidth, 0, true);
106:            }
107:
108:            /**
109:             * Set the width of the to the desired value.  Used
110:             * when CASTing.  Ideally we'd recycle normalize(), but
111:             * the behavior is different (we issue a warning instead
112:             * of an error, and we aren't interested in nullability).
113:             *
114:             * @param desiredWidth	the desired length	
115:             * @param desiredScale	the desired scale (ignored)	
116:             * @param errorOnTrunc	throw error on truncation
117:             *
118:             * @exception StandardException		Thrown on non-zero truncation
119:             *		if errorOnTrunc is true	
120:             */
121:            public void setWidth(int desiredWidth, int desiredScale, // Ignored 
122:                    boolean errorOnTrunc) throws StandardException {
123:                /*
124:                 ** If the input is NULL, nothing to do.
125:                 */
126:                if (getValue() == null) {
127:                    return;
128:                }
129:
130:                int sourceWidth = dataValue.length;
131:
132:                if (sourceWidth > desiredWidth) {
133:                    if (errorOnTrunc) {
134:                        // error if truncating non pad characters.
135:                        for (int i = desiredWidth; i < dataValue.length; i++) {
136:
137:                            if (dataValue[i] != SQLBinary.PAD)
138:                                throw StandardException.newException(
139:                                        SQLState.LANG_STRING_TRUNCATION,
140:                                        getTypeName(),
141:                                        StringUtil.formatForPrint(this 
142:                                                .toString()), String
143:                                                .valueOf(desiredWidth));
144:                        }
145:                    }
146:                    //else
147:                    //{
148:                    // RESOLVE: when we have warnings, issue a warning if
149:                    // truncation of non-zero bits will occur
150:                    //}
151:
152:                    /*
153:                     ** Truncate to the desired width.
154:                     */
155:                    byte[] shrunkData = new byte[desiredWidth];
156:                    System.arraycopy(dataValue, 0, shrunkData, 0, desiredWidth);
157:                    dataValue = shrunkData;
158:
159:                }
160:            }
161:
162:            /*
163:             * Column interface
164:             */
165:
166:            /*
167:             * class interface
168:             */
169:
170:            /*
171:             * constructors
172:             */
173:            public SQLVarbit() {
174:            }
175:
176:            public SQLVarbit(byte[] val) {
177:                super (val);
178:            }
179:
180:            /*
181:             * DataValueDescriptor interface
182:             */
183:
184:            /** @see DataValueDescriptor#typePrecedence */
185:            public int typePrecedence() {
186:                return TypeId.VARBIT_PRECEDENCE;
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.