Source Code Cross Referenced for BlobDescriptor.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » fw » datasetviewer » cellcomponent » 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 Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
002:
003:        /*
004:         * Copyright (C) 2001-2003 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:
022:        import java.sql.Blob;
023:        import java.util.Arrays;
024:
025:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
026:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
027:
028:        /**
029:         * @author gwg
030:         *
031:         * This is the object that is actually stored in the ContentsTab table
032:         * for a BLOB field.
033:         * The data in a BLOB is handled differently than other data types.
034:         * When the row in the DB is read, what is returned is actually a
035:         * java.sql.Blob object that points to the data rather than the data itself.
036:         * Since BLOBs can be very large (and thus take a long time to read), we
037:         * provide the user the flexibility to read only part of the BLOB data, or
038:         * to not read any of it.  We use the user selected options in various operations
039:         * such as deciding if the field is editable or not.
040:         * These options are set in the Session Parameters,
041:         * and since those parameters can be changed after the data has been read, we
042:         * make a copy of the appropriate information here.
043:         */
044:        public class BlobDescriptor {
045:
046:            /**
047:             * The java.sql.Blob object that was read.
048:             */
049:            Blob _blob;
050:
051:            /**
052:             * The data read from the Blob.
053:             */
054:            byte[] _data = null;
055:
056:            /**
057:             * If <TT>_blobRead</TT> is <TT>true</TT> then at least some
058:             * of the data in the BLOB should have been read.  If <TT>false</TT>,
059:             * then we have not even tried to read the data.
060:             */
061:            private boolean _blobRead = false;
062:
063:            /**
064:             * If <TT>_wholeBlobRead</TT> is <TT>true</TT> then all of the
065:             * data in this BLOB has been read into _data..
066:             */
067:            private boolean _wholeBlobRead = false;
068:
069:            /**
070:             * If <TT>_wholeBlobRead</TT> is false, this is the size limit
071:             * set by the user for how much to read.
072:             */
073:            private int _userSetBlobLimit;
074:
075:            /** Internationalized strings for this class. */
076:            private static final StringManager s_stringMgr = StringManagerFactory
077:                    .getStringManager(BlobDescriptor.class);
078:
079:            public static interface i18n {
080:                String BLOB_LABEL = s_stringMgr
081:                        .getString("BlobDescriptor.blob");
082:            }
083:
084:            /**
085:             * Ctor
086:             */
087:            public BlobDescriptor(Blob blob, byte[] data, boolean blobRead,
088:                    boolean wholeBlobRead, int userSetBlobLimit) {
089:                _blob = blob;
090:                _data = data;
091:                _blobRead = blobRead;
092:                _wholeBlobRead = wholeBlobRead;
093:                _userSetBlobLimit = userSetBlobLimit;
094:            }
095:
096:            /**
097:             * Equals for Blobs means that the internal byte arrays are identical,
098:             * including their length.
099:             * We need to account for the fact that one or both of them may not
100:             * have actually had their data read.  If both have not had their data read,
101:             * then they are "equal", in a wierd kind of way.
102:             */
103:            public boolean equals(BlobDescriptor c) {
104:                if (c == null) {
105:                    // the other obj is null, so see if this non-null obj contains
106:                    // a null value, which is equivilent.
107:                    // Assume that if we have read some of the data and we still have
108:                    // _data == null, then the value in the DB is actually null.
109:                    if (_blobRead == true && _data == null)
110:                        return true;
111:                    else
112:                        return false;
113:                }
114:
115:                if (c.getBlobRead() == false) {
116:                    // the other obj has not read the data yet.
117:                    if (_blobRead == true)
118:                        return false; // we have read data, so that is not the same state
119:                    else
120:                        return true; //  odd-ball case: assume if neither has read data that they are equal
121:                }
122:
123:                // the other object has real data
124:                if (_blobRead == false)
125:                    return false; // this one does not, so they are not equal
126:
127:                // both have actual data, so compare the strings
128:                // Note that if one has read all of the data and the other has read only part
129:                // of the data that we will say that they are NOT equal.
130:                return Arrays.equals(c.getData(), _data);
131:            }
132:
133:            /**
134:             * toString means print the data string, unless the data has not been
135:             * read at all.
136:             */
137:            public String toString() {
138:                if (_blobRead) {
139:                    if (_data == null)
140:                        return null;
141:
142:                    // Convert the data into an ascii representation
143:                    // using the standard convention
144:                    Byte[] useValue = new Byte[_data.length];
145:                    for (int i = 0; i < _data.length; i++)
146:                        useValue[i] = Byte.valueOf(_data[i]);
147:                    String outString = BinaryDisplayConverter.convertToString(
148:                            useValue, BinaryDisplayConverter.HEX, false);
149:                    if (_wholeBlobRead || _userSetBlobLimit > _data.length)
150:                        return outString; // we have the whole contents of the BLOB
151:                    else
152:                        return outString + "..."; // tell user the data is truncated
153:                } else
154:                    return i18n.BLOB_LABEL;
155:            }
156:
157:            /* 
158:             * Getters and Setters
159:             */
160:
161:            public Blob getBlob() {
162:                return _blob;
163:            }
164:
165:            public void setBlob(Blob blob) {
166:                _blob = blob;
167:            }
168:
169:            public byte[] getData() {
170:                return _data;
171:            }
172:
173:            public void setData(byte[] data) {
174:                _data = data;
175:            }
176:
177:            public boolean getBlobRead() {
178:                return _blobRead;
179:            }
180:
181:            public void setBlobRead(boolean blobRead) {
182:                _blobRead = blobRead;
183:            }
184:
185:            public boolean getWholeBlobRead() {
186:                return _wholeBlobRead;
187:            }
188:
189:            public void setWholeBlobRead(boolean wholeBlobRead) {
190:                _wholeBlobRead = wholeBlobRead;
191:            }
192:
193:            public int getUserSetBlobLimit() {
194:                return _userSetBlobLimit;
195:            }
196:
197:            public void setUserSetBlobLimit(int userSetBlobLimit) {
198:                _userSetBlobLimit = userSetBlobLimit;
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.