KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > eval > cache > lib > WindowCachedTupleCollection


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 package org.objectweb.medor.eval.cache.lib;
25
26 /**
27  * This class implements a basic TupleCollection wich is cached.
28  */

29
30 import org.objectweb.medor.api.MedorException;
31 import org.objectweb.medor.api.TupleStructure;
32 import org.objectweb.medor.eval.cache.api.CachedTupleCollection;
33 import org.objectweb.medor.eval.cache.api.CollectionCache;
34 import org.objectweb.medor.tuple.api.Tuple;
35 import org.objectweb.medor.tuple.api.TupleCollection;
36
37 public class WindowCachedTupleCollection implements CachedTupleCollection {
38
39     private boolean closed = false;
40     public WindowCachedTupleCollection(TupleCollection tc,
41                                        CollectionCache tupleCache)
42         throws MedorException {
43         this.tupleCache = tupleCache;
44         this.tc = tc;
45     }
46
47     private CollectionCache tupleCache;
48     private TupleCollection tc;
49     private int cursor = 1;
50
51     public void close() throws MedorException {
52         closed =true;
53     }
54
55     public TupleStructure getMetaData() throws MedorException{
56         return tc.getMetaData();
57     }
58
59     public CollectionCache getCache() {
60         return tupleCache;
61     }
62
63     public boolean isLast() throws MedorException {
64         if (tc.getRow() == cursor) {
65             return tc.isLast();
66         } else
67             return (!tupleCache.contains(cursor + 1));
68     }
69
70     public boolean next() throws MedorException {
71         if (!isLast()) {
72             cursor++;
73             if (!tupleCache.contains(cursor + 1)) tc.next();
74             return true;
75         } else
76             return false;
77     }
78
79     public void first() throws MedorException {
80         cursor = 1;
81         tupleCache.initialize();
82         tc.first();
83     }
84
85     public Tuple getTuple() throws MedorException {
86         Tuple t = null;
87         t = tupleCache.getTuple(cursor);
88         if (t == null) {
89             //System.out.println("Not From Cache memory ");
90
//TODO use cloning process, to be implemented by Tuple
91
//t = (Tuple) tc.getTuple().clone();
92
t = (Tuple) tc.getTuple();
93             tupleCache.putTuple(cursor, t);
94             if (tc.isLast()) {
95                 tupleCache.setCanInsert(false);
96             }
97         } else {
98             //System.out.println("from cache memory");
99
}
100         return t;
101     }
102
103     public Tuple getTuple(int row) throws MedorException {
104         Tuple t = null;
105         t = tupleCache.getTuple(row);
106         if (t == null) {
107             //System.out.println("Not From Cache memory ");
108
//TODO use cloning process, to be implemented by Tuple
109
//t = (Tuple) tc.getTuple().clone();
110
t = (Tuple)tc.getTuple(row);
111             tupleCache.putTuple(row, t);
112             if (tc.isLast()) {
113                 tupleCache.setCanInsert(false);
114             }
115         } //isGetFromCache = true;
116
return t;
117     }
118
119     public boolean row(int numTuple) throws MedorException {
120         //isGetFromCache = false;
121
cursor = numTuple;
122         tupleCache.initialize();
123         return (tc.row(numTuple));
124     }
125
126     public int getRow() throws MedorException {
127         return cursor;
128     }
129
130     public boolean isEmpty() throws MedorException{
131         return tc.isEmpty();
132     }
133
134     /**
135      * This method is used when nesting data. It must be carrefully implemented
136      */

137     public int getLeftTCCursor() {
138         return 0;
139     }
140
141     /**
142      * This method is used when nesting data. It must be carrefully implemented
143      */

144     public int getRightTCCursor() {
145         return 0;
146     }
147
148 }
149
Popular Tags