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


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.functionTests.tests.lang.WISCInsert
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.derbyTesting.functionTests.tests.lang;
023:
024:        import java.sql.*;
025:
026:        /**
027:         * This class is a VTI for loading data into the Wisconsin benchmark schema.
028:         * See The Benchmark Handbook, Second Edition (edited by Jim Gray).
029:         */
030:        public class WISCInsert {
031:
032:            private static final char[] chars = { 'A', 'B', 'C', 'D', 'E', 'F',
033:                    'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
034:                    'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
035:
036:            int numrows;
037:            int prime;
038:            int generator;
039:            int rowsReturned = 0;
040:
041:            int unique1;
042:            int unique2;
043:            int two;
044:            int four;
045:            int ten;
046:            int twenty;
047:            int onePercent;
048:            int tenPercent;
049:            int twentyPercent;
050:            int fiftyPercent;
051:            int unique3;
052:            int evenOnePercent;
053:            int oddOnePercent;
054:            String stringu1;
055:            String stringu2;
056:            String string4;
057:
058:            int seed;
059:            static final String[] cyclicStrings = {
060:                    "AAAAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
061:                    "HHHHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
062:                    "OOOOxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
063:                    "VVVVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" };
064:
065:            boolean closed = false;
066:
067:            public WISCInsert() {
068:            }
069:
070:            public int doWISCInsert(int numrows, String tableName,
071:                    Connection conn) throws SQLException {
072:                this .numrows = numrows;
073:
074:                /* Choose prime and generator values for the desired table size */
075:                if (numrows <= 1000) {
076:                    generator = 279;
077:                    prime = 1009;
078:                } else if (numrows <= 10000) {
079:                    generator = 2969;
080:                    prime = 10007;
081:                } else if (numrows <= 100000) {
082:                    generator = 21395;
083:                    prime = 100003;
084:                } else if (numrows <= 1000000) {
085:                    generator = 2107;
086:                    prime = 1000003;
087:                } else if (numrows <= 10000000) {
088:                    generator = 211;
089:                    prime = 10000019;
090:                } else if (numrows <= 100000000) {
091:                    generator = 21;
092:                    prime = 100000007;
093:                } else {
094:                    throw new SQLException(
095:                            "Too many rows - maximum is 100000000, " + numrows
096:                                    + " requested.");
097:                }
098:
099:                seed = generator;
100:
101:                String insertString = "insert into "
102:                        + tableName
103:                        + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
104:                PreparedStatement ps = conn.prepareStatement(insertString);
105:
106:                // loop the insert statement
107:                for (int i = 0; i < numrows; i++) {
108:                    next();
109:                    ps.setInt(1, unique1);
110:                    ps.setInt(2, unique2);
111:                    ps.setInt(3, two);
112:                    ps.setInt(4, four);
113:                    ps.setInt(5, ten);
114:                    ps.setInt(6, twenty);
115:                    ps.setInt(7, onePercent);
116:                    ps.setInt(8, tenPercent);
117:                    ps.setInt(9, twentyPercent);
118:                    ps.setInt(10, fiftyPercent);
119:                    ps.setInt(11, unique3);
120:                    ps.setInt(12, evenOnePercent);
121:                    ps.setInt(13, oddOnePercent);
122:                    ps.setString(14, stringu1);
123:                    ps.setString(15, stringu2);
124:                    ps.setString(16, string4);
125:                    ps.executeUpdate();
126:                    // commit every once in a while?
127:                }
128:                return numrows;
129:            }
130:
131:            public boolean next() throws SQLException {
132:                if (rowsReturned >= numrows)
133:                    return false;
134:
135:                seed = rand(seed, numrows);
136:
137:                unique1 = seed - 1;
138:                unique2 = rowsReturned;
139:                two = unique1 % 2;
140:                four = unique1 % 4;
141:                ten = unique1 % 10;
142:                twenty = unique1 % 20;
143:                onePercent = unique1 % 100;
144:                tenPercent = unique1 % 10;
145:                twentyPercent = unique1 % 5;
146:                fiftyPercent = unique1 % 2;
147:                unique3 = unique1;
148:                evenOnePercent = onePercent * 2;
149:                oddOnePercent = evenOnePercent + 1;
150:                stringu1 = uniqueString(unique1);
151:                stringu2 = uniqueString(unique2);
152:                string4 = cyclicStrings[rowsReturned % cyclicStrings.length];
153:
154:                rowsReturned++;
155:
156:                return true;
157:            }
158:
159:            private int rand(int seed, int limit) {
160:                do {
161:                    seed = (generator * seed) % prime;
162:                } while (seed > limit);
163:
164:                return seed;
165:            }
166:
167:            private String uniqueString(int unique) {
168:                int i;
169:                int rem;
170:                char[] retval = new char[52];
171:
172:                // First set result string to
173:                // "AAAAAAA                                             "
174:                for (i = 0; i < 7; i++) {
175:                    retval[i] = 'A';
176:                }
177:                for (i = 7; i < retval.length; i++) {
178:                    retval[i] = 'x';
179:                }
180:
181:                // Convert unique value from right to left into an alphabetic string
182:                i = 6;
183:                while (unique > 0) {
184:                    rem = unique % 26;
185:                    retval[i] = chars[rem];
186:                    unique /= 26;
187:                    i--;
188:                }
189:
190:                return new String(retval);
191:            }
192:
193:            public String getShortTestDescription() {
194:                StringBuffer st = new StringBuffer(
195:                        "insert values into wisconsin benchmark schema.");
196:                st
197:                        .append("See The Benchmark Handbook, Second Edition (edited by Jim Gray).");
198:                return st.toString();
199:            }
200:
201:            public String getLongTestDescription() {
202:                StringBuffer st = new StringBuffer(
203:                        getShortTestDescription()
204:                                + "\n Called from performance.wisc.WiscLoad. This is not actually a test itself. Based on a scale value by which to multiply the number of rows, the values are generated. This class is based on the vti org.apache.derbyTesting.functionTests.tests.lang.Wisc, however, this will work with any database, not just Cloudscape.");
205:                return st.toString();
206:
207:            }
208:
209:            public boolean isCloudscapeSpecificTest() {
210:                return false;
211:            }
212:
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.