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


001:        /*
002:         * $Id: TestAxionTTreeDelete.java,v 1.1 2005/06/30 01:14:44 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.ext.indexes.ttree;
042:
043:        import java.io.File;
044:        import java.sql.ResultSet;
045:        import java.sql.Statement;
046:
047:        import org.axiondb.functional.AbstractFunctionalTest;
048:
049:        import junit.framework.Test;
050:        import junit.framework.TestSuite;
051:
052:        /**
053:         * @version $Revision: 1.1 $ $Date: 2005/06/30 01:14:44 $
054:         * @author Charles Ye
055:         * @author Ahimanikya Satapathy
056:         */
057:        public class TestAxionTTreeDelete extends AbstractFunctionalTest {
058:
059:            //------------------------------------------------------------ Conventional
060:
061:            public TestAxionTTreeDelete(String testName) {
062:                super (testName);
063:            }
064:
065:            public static Test suite() {
066:                return new TestSuite(TestAxionTTreeDelete.class);
067:            }
068:
069:            //--------------------------------------------------------------- Lifecycle
070:
071:            public void setUp() throws Exception {
072:                super .setUp();
073:            }
074:
075:            public void tearDown() throws Exception {
076:                super .tearDown();
077:            }
078:
079:            protected String getConnectString() {
080:                // disk table
081:                //return "jdbc:axiondb:diskdb:testdb";
082:                // memory table
083:                return "jdbc:axiondb:memdb";
084:            }
085:
086:            protected File getDatabaseDirectory() {
087:                return new File(new File("."), "testdb");
088:            }
089:
090:            //------------------------------------------------------------------- Tests
091:            public void test001_IntTTree() throws Exception {
092:
093:                _stmt
094:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
095:                _stmt.execute("create ttree index id_index on x(id)");
096:
097:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
098:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
099:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
100:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
101:
102:                _stmt.executeUpdate("delete from x where name='Amy1'");
103:
104:                ResultSet rset = _stmt
105:                        .executeQuery("select id, xid, name from x where id = 1");
106:
107:                while (rset.next()) {
108:                    assertTrue(!"Amy1".equals(rset.getString(3)));
109:                }
110:                assertTrue(!rset.next());
111:            }
112:
113:            public void test002_IntTTree() throws Exception {
114:
115:                _stmt
116:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
117:                _stmt.execute("create ttree index id_index on x(id)");
118:
119:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
120:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
121:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
122:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
123:
124:                _stmt.execute("delete from x where name='Amy1'");
125:
126:                ResultSet rset = _stmt
127:                        .executeQuery("select id, xid, name from x where id = 1");
128:
129:                while (rset.next()) {
130:                    assertTrue(!"Amy1".equals(rset.getString(3)));
131:                }
132:                assertTrue(!rset.next());
133:            }
134:
135:            public void test003_IntTTree() throws Exception {
136:                _stmt
137:                        .execute("create table x ( id integer, xid varchar(10), name varchar(10) )");
138:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
139:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
140:                _stmt.execute("create unique ttree index id_index on x(id)");
141:
142:                _stmt.executeUpdate("delete from x where id <= 1");
143:
144:                ResultSet rset = _stmt
145:                        .executeQuery("select id, xid, name from x");
146:
147:                for (int i = 1; i <= 1; i++) {
148:                    assertTrue(rset.next());
149:                    assertEquals(2, rset.getInt(1));
150:                    assertEquals("Mike" + i, rset.getString(3));
151:                }
152:                assertTrue(!rset.next());
153:            }
154:
155:            public void test004_IntTTree() throws Exception {
156:                _stmt
157:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
158:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
159:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
160:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
161:                _stmt.execute("insert into x values ( 1, 'Amy4', 'Amy4' )");
162:                _stmt.execute("insert into x values ( 1, 'Amy5', 'Amy5' )");
163:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
164:                _stmt.execute("insert into x values ( 2, 'Mike2', 'Mike2' )");
165:                _stmt.execute("insert into x values ( 2, 'Mike3', 'Mike3' )");
166:                _stmt.execute("insert into x values ( 2, 'Mike4', 'Mike4' )");
167:                _stmt.execute("insert into x values ( 2, 'Mike5', 'Mike5' )");
168:                _stmt.execute("create ttree index id_index on x(id)");
169:
170:                ResultSet rset = _stmt
171:                        .executeQuery("select id, xid, name from x");
172:                assertNotNull(rset);
173:                for (int i = 1; i <= 5; i++) {
174:                    assertTrue(rset.next());
175:                    assertEquals(1, rset.getInt(1));
176:                    assertEquals("Amy" + i, rset.getString(3));
177:                }
178:
179:                for (int i = 1; i <= 5; i++) {
180:                    assertTrue(rset.next());
181:                    assertEquals(2, rset.getInt(1));
182:                    assertEquals("Mike" + i, rset.getString(3));
183:                }
184:                assertTrue(!rset.next());
185:
186:                _stmt.executeUpdate("delete from x where id = 1");
187:
188:                rset = _stmt.executeQuery("select id, xid, name from x");
189:
190:                for (int i = 1; i <= 5; i++) {
191:                    assertTrue(rset.next());
192:                    assertEquals(2, rset.getInt(1));
193:                    assertEquals("Mike" + i, rset.getString(3));
194:                }
195:                assertTrue(!rset.next());
196:            }
197:
198:            public void test005_IntTTree() throws Exception {
199:
200:                _stmt
201:                        .execute("create table x ( id int, xid integer, name varchar(10) )");
202:                _stmt.execute("create ttree index id_index on x(id)");
203:
204:                for (int i = 0; i < MAX_LOOP; i++) {
205:                    _stmt.execute("insert into x values ( 1," + i
206:                            + ", 'Amy1' )");
207:                }
208:                for (int i = 0; i < MAX_LOOP; i++) {
209:                    _stmt.execute("insert into x values ( 1," + i
210:                            + ", 'Amy2' )");
211:                }
212:                for (int i = 0; i < MAX_LOOP; i++) {
213:                    _stmt.execute("insert into x values ( 2," + i
214:                            + ", 'Mike1' )");
215:                }
216:                for (int i = 0; i < MAX_LOOP; i++) {
217:                    _stmt.execute("insert into x values ( 2," + i
218:                            + ", 'Mike2' )");
219:                }
220:                for (int i = 0; i < MAX_LOOP; i++) {
221:                    _stmt.execute("insert into x values ( 3," + i
222:                            + ", 'Mike3' )");
223:                }
224:                for (int i = 0; i < MAX_LOOP; i++) {
225:                    _stmt.execute("insert into x values ( 3," + i
226:                            + ", 'Mike4' )");
227:                }
228:
229:                //long start = System.currentTimeMillis();
230:                _stmt.executeUpdate("delete from x where name='Amy1'");
231:                //long end = System.currentTimeMillis();
232:                //System.out.println("delete operation time =" + (end - start));
233:
234:                ResultSet rset = _stmt
235:                        .executeQuery("select id, xid, name from x where id = 1");
236:
237:                int count = 0;
238:                while (rset.next()) {
239:                    count++;
240:                    assertTrue(!"Amy1".equals(rset.getString(3)));
241:                }
242:                assertTrue(count == MAX_LOOP);
243:                assertTrue(!rset.next());
244:
245:                rset = _stmt
246:                        .executeQuery("select id, xid, name from x where id >= 2");
247:
248:                count = 0;
249:                while (rset.next()) {
250:                    count++;
251:                    assertTrue("Mike1".equals(rset.getString(3))
252:                            || "Mike2".equals(rset.getString(3))
253:                            || "Mike3".equals(rset.getString(3))
254:                            || "Mike4".equals(rset.getString(3)));
255:                }
256:                assertTrue(count == MAX_LOOP * 4);
257:                assertTrue(!rset.next());
258:
259:                _stmt.executeUpdate("delete from x where name='Mike1'");
260:                _stmt.executeUpdate("delete from x where name='Mike2'");
261:                rset = _stmt
262:                        .executeQuery("select id, xid, name from x where id = 2");
263:                assertTrue(!rset.next());
264:
265:                _stmt.executeUpdate("delete from x where name='Mike3'");
266:                _stmt.executeUpdate("delete from x where name='Mike4'");
267:                rset = _stmt
268:                        .executeQuery("select id, xid, name from x where id = 3");
269:                assertTrue(!rset.next());
270:
271:                _stmt.executeUpdate("delete from x where name='Amy2'");
272:                rset = _stmt
273:                        .executeQuery("select id, xid, name from x where id = 1");
274:                assertTrue(!rset.next());
275:            }
276:
277:            public void test006_IntTTree() throws Exception {
278:
279:                _stmt
280:                        .execute("create table x ( id int, xid integer, name varchar(10) )");
281:                _stmt.execute("create ttree index id_index on x(id)");
282:
283:                for (int i = 0; i < MAX_LOOP; i++) {
284:                    _stmt.execute("insert into x values ( 1," + i
285:                            + ", 'Amy1' )");
286:                    _stmt.execute("insert into x values ( 2," + i
287:                            + ", 'Mike1' )");
288:                    _stmt.execute("insert into x values ( 1," + i
289:                            + ", 'Amy2' )");
290:                    _stmt.execute("insert into x values ( 2," + i
291:                            + ", 'Mike2' )");
292:                    _stmt.execute("insert into x values ( 3," + i
293:                            + ", 'Mike3' )");
294:                    _stmt.execute("insert into x values ( 3," + i
295:                            + ", 'Mike4' )");
296:                }
297:
298:                //long start = System.currentTimeMillis();
299:                _stmt.executeUpdate("delete from x where name='Amy1'");
300:                //long end = System.currentTimeMillis();
301:                //System.out.println("delete operation time =" + (end - start));
302:
303:                ResultSet rset = _stmt
304:                        .executeQuery("select id, xid, name from x where id = 1");
305:
306:                int count = 0;
307:                while (rset.next()) {
308:                    count++;
309:                    assertTrue(!"Amy1".equals(rset.getString(3)));
310:                }
311:                assertTrue(count == MAX_LOOP);
312:                assertTrue(!rset.next());
313:
314:                rset = _stmt
315:                        .executeQuery("select id, xid, name from x where id = 2");
316:                count = 0;
317:                while (rset.next()) {
318:                    count++;
319:                    assertTrue("Mike1".equals(rset.getString(3))
320:                            || "Mike2".equals(rset.getString(3)));
321:                }
322:                assertTrue(count == MAX_LOOP * 2);
323:                assertTrue(!rset.next());
324:
325:                rset = _stmt
326:                        .executeQuery("select id, xid, name from x where id = 3");
327:                count = 0;
328:                while (rset.next()) {
329:                    count++;
330:                    assertTrue("Mike3".equals(rset.getString(3))
331:                            || "Mike4".equals(rset.getString(3)));
332:                }
333:                assertTrue(count == MAX_LOOP * 2);
334:                assertTrue(!rset.next());
335:            }
336:
337:            public void test008_IntTTree() throws Exception {
338:                Statement stmt = _conn.createStatement();
339:                stmt
340:                        .execute("create table mytable ( intcol integer, strcol varchar(10), extra integer )");
341:                stmt.execute("create ttree index intindex on mytable (intcol)");
342:                stmt.execute("create ttree index strindex on mytable (strcol)");
343:                for (int i = 0; i < 10; i++) {
344:                    stmt.execute("insert into mytable values ( 1, 'key', " + i
345:                            + " )");
346:                }
347:
348:                assertNRows(10, "select intcol, strcol, extra from mytable");
349:                assertNRows(10,
350:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
351:                assertNRows(10,
352:                        "select intcol, strcol, extra from mytable where intcol = 1");
353:
354:                assertEquals(1, stmt
355:                        .executeUpdate("delete from mytable where extra = 0"));
356:
357:                assertNRows(9, "select intcol, strcol, extra from mytable");
358:                {
359:                    ResultSet rset = stmt
360:                            .executeQuery("select extra from mytable");
361:                    while (rset.next()) {
362:                        assertTrue(rset.getInt(1) != 0);
363:                    }
364:                    rset.close();
365:                }
366:
367:                assertNRows(9,
368:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
369:                {
370:                    ResultSet rset = stmt
371:                            .executeQuery("select extra from mytable where strcol = 'key'");
372:                    while (rset.next()) {
373:                        assertTrue(rset.getInt(1) != 0);
374:                    }
375:                    rset.close();
376:                }
377:                assertNRows(9,
378:                        "select intcol, strcol, extra from mytable where intcol = 1");
379:
380:                {
381:                    ResultSet rset = stmt
382:                            .executeQuery("select extra from mytable where intcol = 1");
383:                    while (rset.next()) {
384:                        assertTrue(rset.getInt(1) != 0);
385:                    }
386:                    rset.close();
387:                }
388:                stmt.close();
389:            }
390:
391:            public void test001_StringTTree() throws Exception {
392:
393:                _stmt
394:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
395:                _stmt.execute("create ttree index xid_index on x(xid)");
396:
397:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
398:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
399:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
400:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
401:
402:                _stmt.executeUpdate("delete from x where name='Amy1'");
403:
404:                ResultSet rset = _stmt
405:                        .executeQuery("select id, xid, name from x where id = 1");
406:
407:                while (rset.next()) {
408:                    assertTrue(!"Amy1".equals(rset.getString(3)));
409:                }
410:                assertTrue(!rset.next());
411:            }
412:
413:            public void test002_StringTTree() throws Exception {
414:
415:                _stmt
416:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
417:                _stmt.execute("create unique ttree index xid_index on x(xid)");
418:
419:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
420:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
421:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
422:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
423:
424:                _stmt.execute("delete from x where name='Amy1'");
425:
426:                ResultSet rset = _stmt
427:                        .executeQuery("select id, xid, name from x where id = 1");
428:
429:                while (rset.next()) {
430:                    assertTrue(!"Amy1".equals(rset.getString(3)));
431:                }
432:                assertTrue(!rset.next());
433:            }
434:
435:            public void test003_StringTTree() throws Exception {
436:                _stmt
437:                        .execute("create table x ( id integer, xid varchar(10), name varchar(10) )");
438:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
439:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
440:                _stmt.execute("create unique ttree index xid_index on x(xid)");
441:
442:                _stmt.executeUpdate("delete from x where id <= 1");
443:
444:                ResultSet rset = _stmt
445:                        .executeQuery("select id, xid, name from x");
446:
447:                for (int i = 1; i <= 1; i++) {
448:                    assertTrue(rset.next());
449:                    assertEquals(2, rset.getInt(1));
450:                    assertEquals("Mike" + i, rset.getString(3));
451:                }
452:                assertTrue(!rset.next());
453:            }
454:
455:            public void test004_StringTTree() throws Exception {
456:                _stmt
457:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
458:                _stmt.execute("insert into x values ( 1, 'Amy1', 'Amy1' )");
459:                _stmt.execute("insert into x values ( 1, 'Amy2', 'Amy2' )");
460:                _stmt.execute("insert into x values ( 1, 'Amy3', 'Amy3' )");
461:                _stmt.execute("insert into x values ( 1, 'Amy4', 'Amy4' )");
462:                _stmt.execute("insert into x values ( 1, 'Amy5', 'Amy5' )");
463:                _stmt.execute("insert into x values ( 2, 'Mike1', 'Mike1' )");
464:                _stmt.execute("insert into x values ( 2, 'Mike2', 'Mike2' )");
465:                _stmt.execute("insert into x values ( 2, 'Mike3', 'Mike3' )");
466:                _stmt.execute("insert into x values ( 2, 'Mike4', 'Mike4' )");
467:                _stmt.execute("insert into x values ( 2, 'Mike5', 'Mike5' )");
468:                _stmt.execute("create ttree index xid_index on x(xid)");
469:
470:                ResultSet rset = _stmt
471:                        .executeQuery("select id, xid, name from x");
472:                assertNotNull(rset);
473:                for (int i = 1; i <= 5; i++) {
474:                    assertTrue(rset.next());
475:                    assertEquals(1, rset.getInt(1));
476:                    assertEquals("Amy" + i, rset.getString(3));
477:                }
478:
479:                for (int i = 1; i <= 5; i++) {
480:                    assertTrue(rset.next());
481:                    assertEquals(2, rset.getInt(1));
482:                    assertEquals("Mike" + i, rset.getString(3));
483:                }
484:                assertTrue(!rset.next());
485:
486:                _stmt.executeUpdate("delete from x where id = 1");
487:
488:                rset = _stmt.executeQuery("select id, xid, name from x");
489:
490:                for (int i = 1; i <= 5; i++) {
491:                    assertTrue(rset.next());
492:                    assertEquals(2, rset.getInt(1));
493:                    assertEquals("Mike" + i, rset.getString(3));
494:                }
495:                assertTrue(!rset.next());
496:            }
497:
498:            public void test005_StringTTree() throws Exception {
499:
500:                _stmt
501:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
502:                _stmt.execute("create ttree index xid_index on x(xid)");
503:
504:                for (int i = 0; i < MAX_LOOP; i++) {
505:                    _stmt.execute("insert into x values ( " + i
506:                            + ", 'Amy', 'Amy1' )");
507:                }
508:                for (int i = 0; i < MAX_LOOP; i++) {
509:                    _stmt.execute("insert into x values ( " + i
510:                            + ", 'Amy', 'Amy2' )");
511:                }
512:                for (int i = 0; i < MAX_LOOP; i++) {
513:                    _stmt.execute("insert into x values ( " + i
514:                            + ", 'Mike', 'Mike1' )");
515:                }
516:                for (int i = 0; i < MAX_LOOP; i++) {
517:                    _stmt.execute("insert into x values ( " + i
518:                            + ", 'Mike', 'Mike2' )");
519:                }
520:
521:                //long start = System.currentTimeMillis();
522:                _stmt.executeUpdate("delete from x where name='Amy1'");
523:                //long end = System.currentTimeMillis();
524:                //System.out.println("delete operation time =" + (end - start));
525:
526:                ResultSet rset = _stmt
527:                        .executeQuery("select id, xid, name from x where xid = 'Amy'");
528:
529:                int count = 0;
530:                while (rset.next()) {
531:                    count++;
532:                    assertTrue(!"Amy1".equals(rset.getString(3)));
533:                }
534:
535:                assertTrue(count == MAX_LOOP);
536:                assertTrue(!rset.next());
537:
538:                rset = _stmt
539:                        .executeQuery("select id, xid, name from x where xid = 'Mike' ");
540:
541:                count = 0;
542:                while (rset.next()) {
543:                    count++;
544:                    assertTrue("Mike1".equals(rset.getString(3))
545:                            || "Mike2".equals(rset.getString(3)));
546:                }
547:                assertTrue(count == MAX_LOOP * 2);
548:                assertTrue(!rset.next());
549:            }
550:
551:            public void test008_StringTTree() throws Exception {
552:                Statement stmt = _conn.createStatement();
553:                stmt
554:                        .execute("create table mytable ( intcol integer, strcol varchar(10), extra integer )");
555:                stmt.execute("create ttree index intindex on mytable (intcol)");
556:                stmt.execute("create ttree index strindex on mytable (strcol)");
557:                for (int i = 0; i < 10; i++) {
558:                    stmt.execute("insert into mytable values ( 1, 'key', " + i
559:                            + " )");
560:                }
561:
562:                assertNRows(10, "select intcol, strcol, extra from mytable");
563:                assertNRows(10,
564:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
565:                assertNRows(10,
566:                        "select intcol, strcol, extra from mytable where intcol = 1");
567:
568:                assertEquals(1, stmt
569:                        .executeUpdate("delete from mytable where extra = 0"));
570:
571:                assertNRows(9, "select intcol, strcol, extra from mytable");
572:                {
573:                    ResultSet rset = stmt
574:                            .executeQuery("select extra from mytable");
575:                    while (rset.next()) {
576:                        assertTrue(rset.getInt(1) != 0);
577:                    }
578:                    rset.close();
579:                }
580:
581:                assertNRows(9,
582:                        "select intcol, strcol, extra from mytable where strcol = 'key'");
583:                {
584:                    ResultSet rset = stmt
585:                            .executeQuery("select extra from mytable where strcol = 'key'");
586:                    while (rset.next()) {
587:                        assertTrue(rset.getInt(1) != 0);
588:                    }
589:                    rset.close();
590:                }
591:                assertNRows(9,
592:                        "select intcol, strcol, extra from mytable where intcol = 1");
593:
594:                {
595:                    ResultSet rset = stmt
596:                            .executeQuery("select extra from mytable where intcol = 1");
597:                    while (rset.next()) {
598:                        assertTrue(rset.getInt(1) != 0);
599:                    }
600:                    rset.close();
601:                }
602:                stmt.close();
603:            }
604:
605:            public void test006_StringTTree() throws Exception {
606:
607:                _stmt
608:                        .execute("create table x ( id int, xid varchar(10), name varchar(10) )");
609:                _stmt.execute("create ttree index xid_index on x(xid)");
610:
611:                for (int i = 0; i < MAX_LOOP; i++) {
612:                    _stmt.execute("insert into x values ( " + 1
613:                            + ", 'Amy1', 'Amy1' )");
614:                    _stmt.execute("insert into x values ( " + 2
615:                            + ", 'Mike1', 'Mike1' )");
616:                    _stmt.execute("insert into x values ( " + 1
617:                            + ", 'Amy2', 'Amy2' )");
618:                    _stmt.execute("insert into x values ( " + 2
619:                            + ", 'Mike2', 'Mike2' )");
620:                    _stmt.execute("insert into x values ( " + 3
621:                            + ", 'Mike3', 'Mike3' )");
622:                    _stmt.execute("insert into x values ( " + 3
623:                            + ", 'Mike4', 'Mike4' )");
624:                }
625:
626:                //long start = System.currentTimeMillis();
627:                _stmt.executeUpdate("delete from x where name='Amy1'");
628:                //long end = System.currentTimeMillis();
629:                //System.out.println("delete operation time =" + (end - start));
630:
631:                ResultSet rset = _stmt
632:                        .executeQuery("select id, xid, name from x where id = 1");
633:
634:                int count = 0;
635:                while (rset.next()) {
636:                    count++;
637:                    assertTrue(!"Amy1".equals(rset.getString(3)));
638:
639:                }
640:                assertTrue(count == MAX_LOOP);
641:                assertTrue(!rset.next());
642:
643:                rset = _stmt
644:                        .executeQuery("select id, xid, name from x where id = 2");
645:                count = 0;
646:                while (rset.next()) {
647:                    count++;
648:                    assertTrue("Mike1".equals(rset.getString(3))
649:                            || "Mike2".equals(rset.getString(3)));
650:                }
651:                assertTrue(count == MAX_LOOP * 2);
652:                assertTrue(!rset.next());
653:
654:                rset = _stmt
655:                        .executeQuery("select id, xid, name from x where id = 3");
656:                count = 0;
657:                while (rset.next()) {
658:                    count++;
659:                    assertTrue("Mike3".equals(rset.getString(3))
660:                            || "Mike4".equals(rset.getString(3)));
661:                }
662:                assertTrue(count == MAX_LOOP * 2);
663:                assertTrue(!rset.next());
664:            }
665:
666:            private static int MAX_LOOP = 100; //1000; // test loop
667:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.