Source Code Cross Referenced for BlobTest.java in  » Database-ORM » db-ojb » org » apache » ojb » broker » 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 ORM » db ojb » org.apache.ojb.broker 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.ojb.broker;
002:
003:        /* Copyright 2002-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import org.apache.ojb.junit.PBTestCase;
019:        import org.apache.ojb.broker.platforms.PlatformHsqldbImpl;
020:        import org.apache.ojb.broker.platforms.PlatformPostgreSQLImpl;
021:
022:        import java.io.Serializable;
023:
024:        /**
025:         * This TestClass tests storing and retrieving Objects with BLOB/CLOB Attributes.
026:         * @version $Id: BlobTest.java,v 1.9.2.6 2005/12/21 22:31:23 tomdz Exp $
027:         */
028:        public class BlobTest extends PBTestCase {
029:            private static final String SKIP_MESSAGE = "# Skip "
030:                    + BlobTest.class.getName()
031:                    + ", DB does not support Blob/Clob #";
032:
033:            /**
034:             * Known issue (to be fixed, warn in setup)
035:             * or DB lack of features (will never be fixed)?
036:             */
037:            private boolean knownIssue;
038:            private boolean skipTest;
039:
040:            public BlobTest(String name) {
041:                super (name);
042:            }
043:
044:            public static void main(String[] args) {
045:                String[] arr = { BlobTest.class.getName() };
046:                junit.textui.TestRunner.main(arr);
047:            }
048:
049:            public void setUp() throws Exception {
050:                super .setUp();
051:
052:                String platformClass = getPlatformClass();
053:                /*
054:                hsqldb<1.7.2 does not support Blob/Clob, so we skip test for this DB
055:                 */
056:                knownIssue = false;
057:                if (platformClass.equals(PlatformHsqldbImpl.class.getName())) {
058:                    skipTest = true;
059:                } else if (platformClass.equals(PlatformPostgreSQLImpl.class
060:                        .getName())
061:                        && ojbSkipKnownIssueProblem("LOB handling is not yet implemented for PostgreSQL")) {
062:                    knownIssue = true;
063:                    skipTest = true;
064:                }
065:            }
066:
067:            public void testBlobInsertion() throws Exception {
068:                if (skipTest) {
069:                    if (!knownIssue) {
070:                        System.out.println(SKIP_MESSAGE);
071:                    }
072:                    return;
073:                }
074:
075:                int size = 5000;
076:
077:                ObjectWithBlob obj = new ObjectWithBlob();
078:
079:                byte[] barr = new byte[size];
080:                char[] carr = new char[size];
081:                for (int i = 0; i < size; i++) {
082:                    barr[i] = (byte) 'x';
083:                    carr[i] = 'y';
084:                }
085:
086:                // obj.setId(1); we use autoincrement
087:                obj.setBlob(barr);
088:                obj.setClob(new String(carr));
089:                broker.beginTransaction();
090:                broker.store(obj);
091:                broker.commitTransaction();
092:                broker.clearCache();
093:
094:                Identity oid = new Identity(obj, broker);
095:                ObjectWithBlob obj1 = (ObjectWithBlob) broker
096:                        .getObjectByIdentity(oid);
097:                assertNotNull("BLOB was not stored", obj1.getBlob());
098:                assertNotNull("CLOB was not stored", obj1.getClob());
099:                assertEquals(obj.getBlob().length, obj1.getBlob().length);
100:                assertEquals(obj.getClob().length(), obj1.getClob().length());
101:
102:            }
103:
104:            public void testReadNullBlob() {
105:                if (skipTest) {
106:                    if (!knownIssue) {
107:                        System.out.println(SKIP_MESSAGE);
108:                    }
109:                    return;
110:                }
111:
112:                ObjectWithBlob obj = new ObjectWithBlob();
113:
114:                // obj.setId(1); we use autoincrement
115:                obj.setBlob(null);
116:                obj.setClob(null);
117:                broker.beginTransaction();
118:                broker.store(obj);
119:                broker.commitTransaction();
120:                broker.clearCache();
121:
122:                Identity oid = new Identity(obj, broker);
123:                ObjectWithBlob obj1 = (ObjectWithBlob) broker
124:                        .getObjectByIdentity(oid);
125:
126:                assertEquals(null, obj1.getBlob());
127:                assertEquals(null, obj1.getClob());
128:            }
129:
130:            //*******************************************************
131:            // inner class - test class
132:            //*******************************************************
133:            public static class ObjectWithBlob implements  Serializable {
134:                private int id;
135:
136:                private byte[] blob;
137:
138:                private String clob;
139:
140:                /**
141:                 * Gets the blob.
142:                 * @return Returns a byte[]
143:                 */
144:                public byte[] getBlob() {
145:                    return blob;
146:                }
147:
148:                /**
149:                 * Sets the blob.
150:                 * @param blob The blob to set
151:                 */
152:                public void setBlob(byte[] blob) {
153:                    this .blob = blob;
154:                }
155:
156:                /**
157:                 * Gets the clob.
158:                 * @return Returns a char[]
159:                 */
160:                public String getClob() {
161:                    return clob;
162:                }
163:
164:                /**
165:                 * Sets the clob.
166:                 * @param clob The clob to set
167:                 */
168:                public void setClob(String clob) {
169:                    this .clob = clob;
170:                }
171:
172:                /**
173:                 * Gets the id.
174:                 * @return Returns a int
175:                 */
176:                public int getId() {
177:                    return id;
178:                }
179:
180:                /**
181:                 * Sets the id.
182:                 * @param id The id to set
183:                 */
184:                public void setId(int id) {
185:                    this.id = id;
186:                }
187:            }
188:
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.