Source Code Cross Referenced for TestAxionBTreeDelete.java in  » Database-DBMS » axion » org » axiondb » functional » 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 » axion » org.axiondb.functional 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TestAxionBTreeDelete.java,v 1.2 2005/05/02 22:32:02 ahimanikya Exp $
003:         * =======================================================================
004:         * Copyright (c) 2005 Axion Development Team.  All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above
011:         *    copyright notice, this list of conditions and the following
012:         *    disclaimer.
013:         *
014:         * 2. Redistributions in binary form must reproduce the above copyright
015:         *    notice, this list of conditions and the following disclaimer in
016:         *    the documentation and/or other materials provided with the
017:         *    distribution.
018:         *
019:         * 3. The names "Tigris", "Axion", nor the names of its contributors may
020:         *    not be used to endorse or promote products derived from this
021:         *    software without specific prior written permission.
022:         *
023:         * 4. Products derived from this software may not be called "Axion", nor
024:         *    may "Tigris" or "Axion" appear in their names without specific prior
025:         *    written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030:         * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031:         * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037:         * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038:         * =======================================================================
039:         */
040:
041:        package org.axiondb.functional;
042:
043:        import java.io.File;
044:        import java.sql.ResultSet;
045:        import java.sql.Statement;
046:
047:        import junit.framework.Test;
048:        import junit.framework.TestSuite;
049:
050:        /**
051:         * @version $Revision: 1.2 $ $Date: 2005/05/02 22:32:02 $
052:         * @author Charles Ye
053:         * @author Ahimanikya Satapathy
054:         */
055:        public class TestAxionBTreeDelete extends AbstractFunctionalTest {
056:
057:            //------------------------------------------------------------ Conventional
058:
059:            public TestAxionBTreeDelete(String testName) {
060:                super (testName);
061:            }
062:
063:            public static Test suite() {
064:                return new TestSuite(TestAxionBTreeDelete.class);
065:            }
066:
067:            //--------------------------------------------------------------- Lifecycle
068:
069:            public void setUp() throws Exception {
070:                super .setUp();
071:            }
072:
073:            public void tearDown() throws Exception {
074:                super .tearDown();
075:            }
076:
077:            protected String getConnectString() {
078:                // disk table
079:                // return "jdbc:axiondb:diskdb:testdb";
080:                // memory table
081:                return "jdbc:axiondb:memdb";
082:            }
083:
084:            protected File getDatabaseDirectory() {
085:                return new File(new File("."), "testdb");
086:            }
087:
088:            //------------------------------------------------------------------- Tests
089:            public void test001_IntBTree() throws Exception {
090:
091:                _stmt
092:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
093:                _stmt.execute("create btree index id_index on x(id)");
094:
095:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
096:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
097:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
098:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
099:
100:                _stmt.executeUpdate("delete from x where name='Amy1'");
101:
102:                ResultSet rset = _stmt
103:                        .executeQuery("select id, xid, name from x where id = 1");
104:
105:                while (rset.next()) {
106:                    assertTrue(!"Amy1".equals(rset.getString(3)));
107:                }
108:                assertTrue(!rset.next());
109:            }
110:
111:            public void test002_IntBTree() throws Exception {
112:
113:                _stmt
114:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
115:                _stmt.execute("create unique btree index id_index on x(id)");
116:
117:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
118:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
119:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
120:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
121:
122:                _stmt.execute("delete from x where name='Amy1'");
123:
124:                ResultSet rset = _stmt
125:                        .executeQuery("select id, xid, name from x where id = 1");
126:
127:                while (rset.next()) {
128:                    assertTrue(!"Amy1".equals(rset.getString(3)));
129:                }
130:                assertTrue(!rset.next());
131:            }
132:
133:            public void test003_IntBTree() throws Exception {
134:                _stmt
135:                        .execute("create table x ( id integer, xid varchar(10), name varchar(10) )");
136:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
137:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
138:                _stmt.execute("create unique btree index id_index on x(id)");
139:
140:                _stmt.executeUpdate("delete from x where id <= 1");
141:
142:                ResultSet rset = _stmt
143:                        .executeQuery("select id, xid, name from x");
144:
145:                for (int i = 1; i <= 1; i++) {
146:                    assertTrue(rset.next());
147:                    assertEquals(2, rset.getInt(1));
148:                    assertEquals("Mike" + i, rset.getString(3));
149:                }
150:                assertTrue(!rset.next());
151:            }
152:
153:            public void test004_IntBTree() throws Exception {
154:                _stmt
155:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
156:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
157:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
158:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
159:                _stmt.execute("insert into x values ( 1, 'Amy4', 'Amy4' )");
160:                _stmt.execute("insert into x values ( 1, 'Amy5', 'Amy5' )");
161:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
162:                _stmt.execute("insert into x values ( 2, 'Mike2', 'Mike2' )");
163:                _stmt.execute("insert into x values ( 2, 'Mike3', 'Mike3' )");
164:                _stmt.execute("insert into x values ( 2, 'Mike4', 'Mike4' )");
165:                _stmt.execute("insert into x values ( 2, 'Mike5', 'Mike5' )");
166:                _stmt.execute("create btree index id_index on x(id)");
167:
168:                ResultSet rset = _stmt
169:                        .executeQuery("select id, xid, name from x");
170:                assertNotNull(rset);
171:                for (int i = 1; i <= 5; i++) {
172:                    assertTrue(rset.next());
173:                    assertEquals(1, rset.getInt(1));
174:                    assertEquals("Amy" + i, rset.getString(3));
175:                }
176:
177:                for (int i = 1; i <= 5; i++) {
178:                    assertTrue(rset.next());
179:                    assertEquals(2, rset.getInt(1));
180:                    assertEquals("Mike" + i, rset.getString(3));
181:                }
182:                assertTrue(!rset.next());
183:
184:                _stmt.executeUpdate("delete from x where id = 1");
185:
186:                rset = _stmt.executeQuery("select id, xid, name from x");
187:
188:                for (int i = 1; i <= 5; i++) {
189:                    assertTrue(rset.next());
190:                    assertEquals(2, rset.getInt(1));
191:                    assertEquals("Mike" + i, rset.getString(3));
192:                }
193:                assertTrue(!rset.next());
194:            }
195:
196:            public void test005_IntBTree() throws Exception {
197:
198:                _stmt
199:                        .execute("create table x ( id int, xid integer, name varchar(10) )");
200:                _stmt.execute("create btree index id_index on x(id)");
201:
202:                for (int i = 0; i < MAX_LOOP; i++) {
203:                    _stmt.execute("insert into x values ( 1," + i
204:                            + ", 'Amy1' )");
205:                }
206:                for (int i = 0; i < MAX_LOOP; i++) {
207:                    _stmt.execute("insert into x values ( 1," + i
208:                            + ", 'Amy2' )");
209:                }
210:                for (int i = 0; i < MAX_LOOP; i++) {
211:                    _stmt.execute("insert into x values ( 2," + i
212:                            + ", 'Mike1' )");
213:                }
214:                for (int i = 0; i < MAX_LOOP; i++) {
215:                    _stmt.execute("insert into x values ( 2," + i
216:                            + ", 'Mike2' )");
217:                }
218:                for (int i = 0; i < MAX_LOOP; i++) {
219:                    _stmt.execute("insert into x values ( 3," + i
220:                            + ", 'Mike3' )");
221:                }
222:                for (int i = 0; i < MAX_LOOP; i++) {
223:                    _stmt.execute("insert into x values ( 3," + i
224:                            + ", 'Mike4' )");
225:                }
226:
227:                //long start = System.currentTimeMillis();
228:                _stmt.executeUpdate("delete from x where name='Amy1'");
229:                //long end = System.currentTimeMillis();
230:                //System.out.println("delete operation time =" + (end - start));
231:
232:                ResultSet rset = _stmt
233:                        .executeQuery("select id, xid, name from x where id = 1");
234:
235:                int count = 0;
236:                while (rset.next()) {
237:                    count++;
238:                    assertTrue(!"Amy1".equals(rset.getString(3)));
239:                }
240:                assertTrue(count == MAX_LOOP);
241:                assertTrue(!rset.next());
242:
243:                rset = _stmt
244:                        .executeQuery("select id, xid, name from x where id >= 2");
245:
246:                count = 0;
247:                while (rset.next()) {
248:                    count++;
249:                    assertTrue("Mike1".equals(rset.getString(3))
250:                            || "Mike2".equals(rset.getString(3))
251:                            || "Mike3".equals(rset.getString(3))
252:                            || "Mike4".equals(rset.getString(3)));
253:                }
254:                assertTrue(count == MAX_LOOP * 4);
255:                assertTrue(!rset.next());
256:
257:                _stmt.executeUpdate("delete from x where name='Mike1'");
258:                _stmt.executeUpdate("delete from x where name='Mike2'");
259:                rset = _stmt
260:                        .executeQuery("select id, xid, name from x where id = 2");
261:                assertTrue(!rset.next());
262:
263:                _stmt.executeUpdate("delete from x where name='Mike3'");
264:                _stmt.executeUpdate("delete from x where name='Mike4'");
265:                rset = _stmt
266:                        .executeQuery("select id, xid, name from x where id = 3");
267:                assertTrue(!rset.next());
268:
269:                _stmt.executeUpdate("delete from x where name='Amy2'");
270:                rset = _stmt
271:                        .executeQuery("select id, xid, name from x where id = 1");
272:                assertTrue(!rset.next());
273:            }
274:
275:            public void test006_IntBTree() throws Exception {
276:
277:                _stmt
278:                        .execute("create table x ( id int, xid integer, name varchar(10) )");
279:                _stmt.execute("create btree index id_index on x(id)");
280:
281:                for (int i = 0; i < MAX_LOOP; i++) {
282:                    _stmt.execute("insert into x values ( 1," + i
283:                            + ", 'Amy1' )");
284:                    _stmt.execute("insert into x values ( 2," + i
285:                            + ", 'Mike1' )");
286:                    _stmt.execute("insert into x values ( 1," + i
287:                            + ", 'Amy2' )");
288:                    _stmt.execute("insert into x values ( 2," + i
289:                            + ", 'Mike2' )");
290:                    _stmt.execute("insert into x values ( 3," + i
291:                            + ", 'Mike3' )");
292:                    _stmt.execute("insert into x values ( 3," + i
293:                            + ", 'Mike4' )");
294:                }
295:
296:                //long start = System.currentTimeMillis();
297:                _stmt.executeUpdate("delete from x where name='Amy1'");
298:                //long end = System.currentTimeMillis();
299:                //System.out.println("delete operation time =" + (end - start));
300:
301:                ResultSet rset = _stmt
302:                        .executeQuery("select id, xid, name from x where id = 1");
303:
304:                int count = 0;
305:                while (rset.next()) {
306:                    count++;
307:                    assertTrue(!"Amy1".equals(rset.getString(3)));
308:
309:                }
310:                assertTrue(count == MAX_LOOP);
311:                assertTrue(!rset.next());
312:
313:                rset = _stmt
314:                        .executeQuery("select id, xid, name from x where id = 2");
315:                count = 0;
316:                while (rset.next()) {
317:                    count++;
318:                    assertTrue("Mike1".equals(rset.getString(3))
319:                            || "Mike2".equals(rset.getString(3)));
320:                }
321:                assertTrue(count == MAX_LOOP * 2);
322:                assertTrue(!rset.next());
323:
324:                rset = _stmt
325:                        .executeQuery("select id, xid, name from x where id = 3");
326:                count = 0;
327:                while (rset.next()) {
328:                    count++;
329:                    assertTrue("Mike3".equals(rset.getString(3))
330:                            || "Mike4".equals(rset.getString(3)));
331:                }
332:                assertTrue(count == MAX_LOOP * 2);
333:                assertTrue(!rset.next());
334:            }
335:
336:            public void test008_IntBtree() throws Exception {
337:                Statement stmt = _conn.createStatement();
338:                stmt
339:                        .execute("create table mytable ( intcol integer, strcol varchar(10), extra integer )");
340:                stmt.execute("create btree index intindex on mytable (intcol)");
341:                stmt.execute("create btree index strindex on mytable (strcol)");
342:                for (int i = 0; i < 10; i++) {
343:                    stmt.execute("insert into mytable values ( 1, 'key', " + i
344:                            + " )");
345:                }
346:
347:                assertNRows(10, "select intcol, strcol, extra from mytable");
348:                assertNRows(10,
349:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
350:                assertNRows(10,
351:                        "select intcol, strcol, extra from mytable where intcol = 1");
352:
353:                assertEquals(1, stmt
354:                        .executeUpdate("delete from mytable where extra = 0"));
355:
356:                assertNRows(9, "select intcol, strcol, extra from mytable");
357:                {
358:                    ResultSet rset = stmt
359:                            .executeQuery("select extra from mytable");
360:                    while (rset.next()) {
361:                        assertTrue(rset.getInt(1) != 0);
362:                    }
363:                    rset.close();
364:                }
365:
366:                assertNRows(9,
367:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
368:                {
369:                    ResultSet rset = stmt
370:                            .executeQuery("select extra from mytable where strcol = 'key'");
371:                    while (rset.next()) {
372:                        assertTrue(rset.getInt(1) != 0);
373:                    }
374:                    rset.close();
375:                }
376:                assertNRows(9,
377:                        "select intcol, strcol, extra from mytable where intcol = 1");
378:
379:                {
380:                    ResultSet rset = stmt
381:                            .executeQuery("select extra from mytable where intcol = 1");
382:                    while (rset.next()) {
383:                        assertTrue(rset.getInt(1) != 0);
384:                    }
385:                    rset.close();
386:                }
387:                stmt.close();
388:            }
389:
390:            public void test001_StringBTree() throws Exception {
391:
392:                _stmt
393:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
394:                _stmt.execute("create btree index xid_index on x(xid)");
395:
396:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
397:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
398:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
399:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
400:
401:                _stmt.executeUpdate("delete from x where name='Amy1'");
402:
403:                ResultSet rset = _stmt
404:                        .executeQuery("select id, xid, name from x where id = 1");
405:
406:                while (rset.next()) {
407:                    assertTrue(!"Amy1".equals(rset.getString(3)));
408:                }
409:                assertTrue(!rset.next());
410:            }
411:
412:            public void test002_StringBTree() throws Exception {
413:
414:                _stmt
415:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
416:                _stmt.execute("create unique btree index xid_index on x(xid)");
417:
418:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
419:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
420:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
421:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
422:
423:                _stmt.execute("delete from x where name='Amy1'");
424:
425:                ResultSet rset = _stmt
426:                        .executeQuery("select id, xid, name from x where id = 1");
427:
428:                while (rset.next()) {
429:                    assertTrue(!"Amy1".equals(rset.getString(3)));
430:                }
431:                assertTrue(!rset.next());
432:            }
433:
434:            public void test003_StringBTree() throws Exception {
435:                _stmt
436:                        .execute("create table x ( id integer, xid varchar(10), name varchar(10) )");
437:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
438:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
439:                _stmt.execute("create unique btree index xid_index on x(xid)");
440:
441:                _stmt.executeUpdate("delete from x where id <= 1");
442:
443:                ResultSet rset = _stmt
444:                        .executeQuery("select id, xid, name from x");
445:
446:                for (int i = 1; i <= 1; i++) {
447:                    assertTrue(rset.next());
448:                    assertEquals(2, rset.getInt(1));
449:                    assertEquals("Mike" + i, rset.getString(3));
450:                }
451:                assertTrue(!rset.next());
452:            }
453:
454:            public void test004_StringBTree() throws Exception {
455:                _stmt
456:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
457:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
458:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
459:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
460:                _stmt.execute("insert into x values ( 1, 'Amy4', 'Amy4' )");
461:                _stmt.execute("insert into x values ( 1, 'Amy5', 'Amy5' )");
462:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
463:                _stmt.execute("insert into x values ( 2, 'Mike2', 'Mike2' )");
464:                _stmt.execute("insert into x values ( 2, 'Mike3', 'Mike3' )");
465:                _stmt.execute("insert into x values ( 2, 'Mike4', 'Mike4' )");
466:                _stmt.execute("insert into x values ( 2, 'Mike5', 'Mike5' )");
467:                _stmt.execute("create btree index xid_index on x(xid)");
468:
469:                ResultSet rset = _stmt
470:                        .executeQuery("select id, xid, name from x");
471:                assertNotNull(rset);
472:                for (int i = 1; i <= 5; i++) {
473:                    assertTrue(rset.next());
474:                    assertEquals(1, rset.getInt(1));
475:                    assertEquals("Amy" + i, rset.getString(3));
476:                }
477:
478:                for (int i = 1; i <= 5; i++) {
479:                    assertTrue(rset.next());
480:                    assertEquals(2, rset.getInt(1));
481:                    assertEquals("Mike" + i, rset.getString(3));
482:                }
483:                assertTrue(!rset.next());
484:
485:                _stmt.executeUpdate("delete from x where id = 1");
486:
487:                rset = _stmt.executeQuery("select id, xid, name from x");
488:
489:                for (int i = 1; i <= 5; i++) {
490:                    assertTrue(rset.next());
491:                    assertEquals(2, rset.getInt(1));
492:                    assertEquals("Mike" + i, rset.getString(3));
493:                }
494:                assertTrue(!rset.next());
495:            }
496:
497:            public void test005_StringBTree() throws Exception {
498:
499:                _stmt
500:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
501:                _stmt.execute("create btree index xid_index on x(xid)");
502:
503:                for (int i = 0; i < MAX_LOOP; i++) {
504:                    _stmt.execute("insert into x values ( " + i
505:                            + ", 'Amy', 'Amy1' )");
506:                }
507:                for (int i = 0; i < MAX_LOOP; i++) {
508:                    _stmt.execute("insert into x values ( " + i
509:                            + ", 'Amy', 'Amy2' )");
510:                }
511:                for (int i = 0; i < MAX_LOOP; i++) {
512:                    _stmt.execute("insert into x values ( " + i
513:                            + ", 'Mike', 'Mike1' )");
514:                }
515:                for (int i = 0; i < MAX_LOOP; i++) {
516:                    _stmt.execute("insert into x values ( " + i
517:                            + ", 'Mike', 'Mike2' )");
518:                }
519:
520:                //long start = System.currentTimeMillis();
521:                _stmt.executeUpdate("delete from x where name='Amy1'");
522:                //long end = System.currentTimeMillis();
523:                //System.out.println("delete operation time =" + (end - start));
524:
525:                ResultSet rset = _stmt
526:                        .executeQuery("select id, xid, name from x where xid = 'Amy'");
527:
528:                int count = 0;
529:                while (rset.next()) {
530:                    count++;
531:                    assertTrue(!"Amy1".equals(rset.getString(3)));
532:                }
533:
534:                assertTrue(count == MAX_LOOP);
535:                assertTrue(!rset.next());
536:
537:                rset = _stmt
538:                        .executeQuery("select id, xid, name from x where xid = 'Mike' ");
539:
540:                count = 0;
541:                while (rset.next()) {
542:                    count++;
543:                    assertTrue("Mike1".equals(rset.getString(3))
544:                            || "Mike2".equals(rset.getString(3)));
545:                }
546:                assertTrue(count == MAX_LOOP * 2);
547:                assertTrue(!rset.next());
548:            }
549:
550:            public void test008_StringBTree() throws Exception {
551:                Statement stmt = _conn.createStatement();
552:                stmt
553:                        .execute("create table mytable ( intcol integer, strcol varchar(10), extra integer )");
554:                stmt.execute("create btree index intindex on mytable (intcol)");
555:                stmt.execute("create btree index strindex on mytable (strcol)");
556:                for (int i = 0; i < 10; i++) {
557:                    stmt.execute("insert into mytable values ( 1, 'key', " + i
558:                            + " )");
559:                }
560:
561:                assertNRows(10, "select intcol, strcol, extra from mytable");
562:                assertNRows(10,
563:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
564:                assertNRows(10,
565:                        "select intcol, strcol, extra from mytable where intcol = 1");
566:
567:                assertEquals(1, stmt
568:                        .executeUpdate("delete from mytable where extra = 0"));
569:
570:                assertNRows(9, "select intcol, strcol, extra from mytable");
571:                {
572:                    ResultSet rset = stmt
573:                            .executeQuery("select extra from mytable");
574:                    while (rset.next()) {
575:                        assertTrue(rset.getInt(1) != 0);
576:                    }
577:                    rset.close();
578:                }
579:
580:                assertNRows(9,
581:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
582:                {
583:                    ResultSet rset = stmt
584:                            .executeQuery("select extra from mytable where strcol = 'key'");
585:                    while (rset.next()) {
586:                        assertTrue(rset.getInt(1) != 0);
587:                    }
588:                    rset.close();
589:                }
590:                assertNRows(9,
591:                        "select intcol, strcol, extra from mytable where intcol = 1");
592:
593:                {
594:                    ResultSet rset = stmt
595:                            .executeQuery("select extra from mytable where intcol = 1");
596:                    while (rset.next()) {
597:                        assertTrue(rset.getInt(1) != 0);
598:                    }
599:                    rset.close();
600:                }
601:                stmt.close();
602:            }
603:
604:            public void test006_StringBTree() throws Exception {
605:
606:                _stmt
607:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
608:                _stmt.execute("create btree index xid_index on x(xid)");
609:
610:                for (int i = 0; i < MAX_LOOP; i++) {
611:                    _stmt.execute("insert into x values ( " + 1
612:                            + ", 'Amy1', 'Amy1' )");
613:                    _stmt.execute("insert into x values ( " + 2
614:                            + ", 'Mike1', 'Mike1' )");
615:                    _stmt.execute("insert into x values ( " + 1
616:                            + ", 'Amy2', 'Amy2' )");
617:                    _stmt.execute("insert into x values ( " + 2
618:                            + ", 'Mike2', 'Mike2' )");
619:                    _stmt.execute("insert into x values ( " + 3
620:                            + ", 'Mike3', 'Mike3' )");
621:                    _stmt.execute("insert into x values ( " + 3
622:                            + ", 'Mike4', 'Mike4' )");
623:                }
624:
625:                //long start = System.currentTimeMillis();
626:                _stmt.executeUpdate("delete from x where name='Amy1'");
627:                //long end = System.currentTimeMillis();
628:                //System.out.println("delete operation time =" + (end - start));
629:
630:                ResultSet rset = _stmt
631:                        .executeQuery("select id, xid, name from x where id = 1");
632:
633:                int count = 0;
634:                while (rset.next()) {
635:                    count++;
636:                    assertTrue(!"Amy1".equals(rset.getString(3)));
637:
638:                }
639:                assertTrue(count == MAX_LOOP);
640:                assertTrue(!rset.next());
641:
642:                rset = _stmt
643:                        .executeQuery("select id, xid, name from x where id = 2");
644:                count = 0;
645:                while (rset.next()) {
646:                    count++;
647:                    assertTrue("Mike1".equals(rset.getString(3))
648:                            || "Mike2".equals(rset.getString(3)));
649:                }
650:                assertTrue(count == MAX_LOOP * 2);
651:                assertTrue(!rset.next());
652:
653:                rset = _stmt
654:                        .executeQuery("select id, xid, name from x where id = 3");
655:                count = 0;
656:                while (rset.next()) {
657:                    count++;
658:                    assertTrue("Mike3".equals(rset.getString(3))
659:                            || "Mike4".equals(rset.getString(3)));
660:                }
661:                assertTrue(count == MAX_LOOP * 2);
662:                assertTrue(!rset.next());
663:            }
664:
665:            private static int MAX_LOOP = 100; //1000; // test loop
666:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.