KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > cache > result > entries > ResultCacheEntryEager


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.controller.cache.result.entries;
26
27 import java.util.Date JavaDoc;
28
29 import org.objectweb.cjdbc.common.sql.SelectRequest;
30 import org.objectweb.cjdbc.controller.cache.result.AbstractResultCache;
31 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet;
32
33 /**
34  * A <code>CacheEntry</code> that is to be recognized as Eager entry.
35  *
36  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
37  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
38  * @version 1.0
39  */

40 public class ResultCacheEntryEager extends AbstractResultCacheEntry
41 {
42   private AbstractResultCache cache;
43   private long timeout;
44   private long deadline;
45
46   /**
47    * Create a new Eager Query Cache entry
48    *
49    * @param cache The query cache we belong to
50    * @param request Select request to cache
51    * @param result ResultSet to cache
52    * @param timeout The timeout to use for the deadline (0 for no timeout)
53    */

54   public ResultCacheEntryEager(AbstractResultCache cache,
55       SelectRequest request, ControllerResultSet result, long timeout)
56   {
57     super(request, result);
58     this.cache = cache;
59     if (timeout > 0)
60       this.deadline = System.currentTimeMillis() + timeout;
61     else
62       this.deadline = NO_DEADLINE;
63   }
64
65   /**
66    * @see org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry#invalidate()
67    */

68   public void invalidate()
69   {
70     state = CACHE_INVALID;
71     if (cache != null)
72       cache.removeFromCache(request);
73     if (result != null)
74       result = null;
75     cache = null;
76   }
77
78   /**
79    * @see org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry#getType()
80    */

81   public String JavaDoc getType()
82   {
83     return "Eager";
84   }
85
86   /**
87    * @see org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry#toStringTable()
88    */

89   public String JavaDoc[] toStringTable()
90   {
91     return new String JavaDoc[]{request.getSQL(), getType(), getState(),
92         new Date JavaDoc(getDeadline()).toString(), "" + getSizeOfResult()};
93   }
94
95   /**
96    * Returns the deadline value.
97    *
98    * @return Returns the deadline.
99    */

100   public long getDeadline()
101   {
102     return deadline;
103   }
104
105   /**
106    * Returns the timeout value.
107    *
108    * @return Returns the timeout.
109    */

110   public long getTimeout()
111   {
112     return timeout;
113   }
114 }
Popular Tags