KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 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.virtualdatabase.ControllerResultSet;
31
32 /**
33  * A <code>CacheEntry</code> that is to be recognized as Relaxed entry.
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
37  * @version 1.0
38  */

39 public class ResultCacheEntryRelaxed extends AbstractResultCacheEntry
40 {
41   private long timeout;
42   private long deadline;
43   private boolean keepIfNotDirty;
44
45   /**
46    * Create a new Relaxed Query Cache entry
47    *
48    * @param request Select request to cache
49    * @param result ResultSet to cache
50    * @param timeout timeout in ms for this entry
51    * @param keepIfNotDirty true if entry must be kept in cache if not dirty once
52    * timeout has expired
53    */

54   public ResultCacheEntryRelaxed(SelectRequest request,
55       ControllerResultSet result, long timeout, boolean keepIfNotDirty)
56   {
57     super(request, result);
58     this.timeout = timeout;
59     this.deadline = System.currentTimeMillis() + timeout;
60     this.keepIfNotDirty = keepIfNotDirty;
61   }
62
63   /**
64    * @see org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry#invalidate()
65    */

66   public void invalidate()
67   {
68     state = CACHE_DIRTY;
69   }
70
71   /**
72    * @see org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry#getType()
73    */

74   public String JavaDoc getType()
75   {
76     return "Relaxed";
77   }
78
79   /**
80    * Get the expiration deadline
81    *
82    * @return the expiration deadline
83    */

84   public long getDeadline()
85   {
86     return deadline;
87   }
88
89   /**
90    * Set the expiration deadline
91    *
92    * @param deadline time in ms relative to current time
93    */

94   public void setDeadline(long deadline)
95   {
96     this.deadline = deadline;
97   }
98
99   /**
100    * Get the timeout for this entry.
101    *
102    * @return timeout in ms
103    */

104   public long getTimeout()
105   {
106     return timeout;
107   }
108
109   /**
110    * @see org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry#toStringTable()
111    */

112   public String JavaDoc[] toStringTable()
113   {
114     return new String JavaDoc[]{request.getSQL(), getType(), getState(),
115         new Date JavaDoc(getDeadline()).toString(), "" + getSizeOfResult()};
116   }
117
118   /**
119    * Should the entry must be kept in the cache if the entry is not dirty once
120    * the timeout has expired.
121    *
122    * @return true if yes
123    */

124   public boolean getKeepIfNotDirty()
125   {
126     return keepIfNotDirty;
127   }
128
129 }
Popular Tags