00001 /** 00002 * C-JDBC: Clustered JDBC. 00003 * Copyright (C) 2002-2004 French National Institute For Research In Computer 00004 * Science And Control (INRIA). 00005 * Contact: c-jdbc@objectweb.org 00006 * 00007 * This library is free software; you can redistribute it and/or modify it 00008 * under the terms of the GNU Lesser General Public License as published by the 00009 * Free Software Foundation; either version 2.1 of the License, or any later 00010 * version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00015 * for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library; if not, write to the Free Software Foundation, 00019 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00020 * 00021 * Initial developer(s): Nicolas Modrzyk. 00022 * Contributor(s): Emmanuel Cecchet. 00023 */ 00024 00025 package org.objectweb.cjdbc.controller.cache.result.entries; 00026 00027 import java.util.Date; 00028 00029 import org.objectweb.cjdbc.common.sql.SelectRequest; 00030 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet; 00031 00032 /** 00033 * A <code>CacheEntry</code> that is to be recognized as Relaxed entry. 00034 * 00035 * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a> 00036 * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a> 00037 * @version 1.0 00038 */ 00039 public class ResultCacheEntryRelaxed extends ResultCacheEntry 00040 { 00041 private long timeout; 00042 private long deadline; 00043 private boolean keepIfNotDirty; 00044 00045 /** 00046 * Create a new Relaxed Query Cache entry 00047 * 00048 * @param request Select request to cache 00049 * @param result ResultSet to cache 00050 * @param timeout timeout in ms for this entry 00051 * @param keepIfNotDirty true if entry must be kept in cache if not dirty once 00052 * timeout has expired 00053 */ 00054 public ResultCacheEntryRelaxed(SelectRequest request, 00055 ControllerResultSet result, long timeout, boolean keepIfNotDirty) 00056 { 00057 super(request, result); 00058 this.timeout = timeout; 00059 this.deadline = System.currentTimeMillis() + timeout; 00060 this.keepIfNotDirty = keepIfNotDirty; 00061 } 00062 00063 /** 00064 * @see org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry#invalidate() 00065 */ 00066 public void invalidate() 00067 { 00068 state = CACHE_DIRTY; 00069 } 00070 00071 /** 00072 * @see org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry#getType() 00073 */ 00074 public String getType() 00075 { 00076 return "Relaxed"; 00077 } 00078 00079 /** 00080 * Get the expiration deadline 00081 * 00082 * @return the expiration deadline 00083 */ 00084 public long getDeadline() 00085 { 00086 return deadline; 00087 } 00088 00089 /** 00090 * Set the expiration deadline 00091 * 00092 * @param deadline time in ms relative to current time 00093 */ 00094 public void setDeadline(long deadline) 00095 { 00096 this.deadline = deadline; 00097 } 00098 00099 /** 00100 * Get the timeout for this entry. 00101 * 00102 * @return timeout in ms 00103 */ 00104 public long getTimeout() 00105 { 00106 return timeout; 00107 } 00108 00109 /** 00110 * @see org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry#toStringTable() 00111 */ 00112 public String[] toStringTable() 00113 { 00114 return new String[]{request.getSQL(), getType(), getState(), 00115 new Date(getDeadline()).toString(), "" + getSizeOfResult()}; 00116 } 00117 00118 /** 00119 * Should the entry must be kept in the cache if the entry is not dirty once 00120 * the timeout has expired. 00121 * 00122 * @return true if yes 00123 */ 00124 public boolean getKeepIfNotDirty() 00125 { 00126 return keepIfNotDirty; 00127 } 00128 00129 }