Source Code Cross Referenced for BLOBDataModelSetup.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbcapi » 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.derbyTesting.functionTests.tests.jdbcapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *
003:         * Derby - Class BLOBDataModelSetup
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,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
017:         * either express or implied. See the License for the specific
018:         * language governing permissions and limitations under the License.
019:         */package org.apache.derbyTesting.functionTests.tests.jdbcapi;
020:
021:        import org.apache.derbyTesting.functionTests.util.TestInputStream;
022:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
023:        import org.apache.derbyTesting.junit.BaseJDBCTestSetup;
024:
025:        import junit.extensions.TestSetup;
026:        import junit.framework.Test;
027:        import java.sql.Connection;
028:        import java.sql.PreparedStatement;
029:        import java.sql.SQLException;
030:        import java.sql.Statement;
031:        import java.io.InputStream;
032:
033:        /**
034:         * Sets up a data model with very large BLOBs.
035:         * The table created will have three fields: 
036:         *  1. a value field (val), which is the value for every byte in the BLOB.
037:         *  2. a length (length) field which is the actual size of the BLOB
038:         *  3. the data field (data), which is the actual BLOB data.
039:         *
040:         * @author Andreas Korneliussen
041:         */
042:        final public class BLOBDataModelSetup extends BaseJDBCTestSetup {
043:
044:            /** 
045:             * Constructor
046:             * @param test test object being decorated by this TestSetup
047:             */
048:            public BLOBDataModelSetup(Test test) {
049:                super (test);
050:            }
051:
052:            /**
053:             * The setup creates a Connection to the database, and creates a table
054:             * with blob columns.
055:             * @exception Exception any exception will cause test to fail with error.
056:             */
057:            protected final void setUp() throws Exception {
058:                Connection con = getConnection();
059:                con.setAutoCommit(false);
060:
061:                // Create table:
062:                final Statement statement = con.createStatement();
063:                statement.executeUpdate("CREATE TABLE " + tableName + " ("
064:                        + " val INTEGER," + " length INTEGER, "
065:                        + " data BLOB(2G) NOT NULL)");
066:                statement.close();
067:                // Insert some data:
068:                final PreparedStatement preparedStatement = con
069:                        .prepareStatement("INSERT INTO " + tableName
070:                                + "(val, length, data) VALUES (?,?, ?)");
071:
072:                // Insert 10 records with size of 1MB
073:                for (int i = 0; i < regularBlobs; i++) {
074:                    final int val = i;
075:                    final InputStream stream = new TestInputStream(size, val);
076:                    preparedStatement.setInt(1, val);
077:                    preparedStatement.setInt(2, size);
078:                    preparedStatement.setBinaryStream(3, stream, size);
079:                    preparedStatement.executeUpdate();
080:                }
081:
082:                // Insert 1 record with size of 64 MB
083:                BaseJDBCTestCase.println("Insert BLOB with size = " + bigSize);
084:                preparedStatement.setInt(1, bigVal);
085:                preparedStatement.setInt(2, bigSize);
086:                final InputStream stream = new TestInputStream(bigSize, bigVal);
087:                preparedStatement.setBinaryStream(3, stream, bigSize);
088:
089:                BaseJDBCTestCase.println("Execute update");
090:                preparedStatement.executeUpdate();
091:                preparedStatement.close();
092:
093:                BaseJDBCTestCase.println("Commit");
094:                con.commit();
095:            }
096:
097:            /**
098:             * Teardown test.
099:             * Rollback connection and close it.
100:             * @exception Exceptions causes the test to fail with error
101:             */
102:            protected final void tearDown() throws Exception {
103:                try {
104:                    Connection con = getConnection();
105:                    Statement statement = con.createStatement();
106:                    statement.execute("DROP TABLE " + tableName);
107:                    statement.close();
108:                    con.commit();
109:                } catch (SQLException e) {
110:                    BaseJDBCTestCase.printStackTrace(e);
111:                }
112:
113:                super .tearDown();
114:            }
115:
116:            /**
117:             * Return table name 
118:             * @return table name
119:             */
120:            public static final String getBlobTableName() {
121:                return tableName;
122:            }
123:
124:            /** Size of regular Blobs (currently 1MB) */
125:            final static int size = 1024 * 1024;
126:
127:            /** Number of regular Blobs */
128:            final static int regularBlobs = 10;
129:
130:            /** Size of big record (currently 64 MB) */
131:            final static int bigSize = 64 * 1024 * 1024;
132:
133:            /** Val for big  record */
134:            final static int bigVal = regularBlobs + 1;
135:
136:            /** Name of table */
137:            private static final String tableName = "TESTBLOBTABLE";
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.