KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > tuning > TuningMemberFieldQuery


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test.tuning;
22
23 import com.db4o.*;
24 import com.db4o.query.*;
25 import com.db4o.test.*;
26
27
28 /**
29  * Original performance on Carls machine with Skype on:
30  * Querying 10000 objects for member identity: 500ms
31  * @author root_rosenberger
32  *
33  */

34
35 public class TuningMemberFieldQuery {
36     
37     static final int COUNT = 2;
38     
39     TMFMember member;
40     
41     public TuningMemberFieldQuery(){
42     }
43     
44     public TuningMemberFieldQuery(TMFMember member){
45         this.member = member;
46     }
47     
48     public void configure() {
49         Db4o.configure().objectClass(this).objectField("member").indexed(true);
50         Db4o.configure().objectClass(TMFMember.class).objectField("name").indexed(true);
51     }
52     
53     public void store(){
54         for (int i = 0; i < COUNT; i++) {
55             Test.store(new TuningMemberFieldQuery(new TMFMember("" + i)));
56         }
57     }
58     
59     public void test(){
60         Query q = Test.query();
61         q.constrain(TuningMemberFieldQuery.class);
62         
63         q.descend("member").descend("name").constrain("1");
64         
65         
66         
67         long start = System.currentTimeMillis();
68         ObjectSet objectSet = q.execute();
69         
70         long stop = System.currentTimeMillis();
71         
72         Test.ensure(objectSet.size() == 1);
73         TuningMemberFieldQuery tmf = (TuningMemberFieldQuery)objectSet.next();
74         Test.ensure(tmf.member.name.equals("1"));
75         
76         long duration = stop - start;
77         System.out.println("Querying " + COUNT + " objects for member identity: " + duration + "ms");
78     }
79     
80     public static class TMFMember{
81         
82         String JavaDoc name;
83         
84         public TMFMember(){
85         }
86         
87         public TMFMember(String JavaDoc name){
88             this.name = name;
89         }
90         
91     }
92     
93 }
94
Popular Tags