Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ResultCacheColumn.java

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): Emmanuel Cecchet.
00022  * Contributor(s): Nicolas Modrzyk.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.cache.result;
00026 
00027 import java.util.ArrayList;
00028 import java.util.Iterator;
00029 
00030 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest;
00031 import org.objectweb.cjdbc.common.sql.ParsingGranularities;
00032 import org.objectweb.cjdbc.common.sql.SelectRequest;
00033 import org.objectweb.cjdbc.common.sql.UpdateRequest;
00034 import org.objectweb.cjdbc.common.sql.schema.TableColumn;
00035 import org.objectweb.cjdbc.controller.cache.result.entries.CacheEntry;
00036 import org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseColumn;
00037 import org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable;
00038 
00039 /**
00040  * This is a query cache implementation with a column granularity:
00041  * <ul>
00042  * <li><code>COLUMN</code>: column granularity, entries in the cache are
00043  * invalidated based on column dependencies</li>
00044  * </ul>
00045  * 
00046  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00047  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00048  * @version 1.0
00049  */
00050 
00051 public class ResultCacheColumn extends ResultCache
00052 {
00053   /**
00054    * Builds a new ResultCache with a Column granularity.
00055    * 
00056    * @param maxEntries maximum number of entries
00057    * @param pendingTimeout pending timeout for concurrent queries
00058    */
00059   public ResultCacheColumn(int maxEntries, int pendingTimeout)
00060   {
00061     super(maxEntries, pendingTimeout);
00062     parsingGranularity = ParsingGranularities.COLUMN;
00063   }
00064 
00065   /**
00066    * @see org.objectweb.cjdbc.controller.cache.result.ResultCache#processAddToCache(CacheEntry)
00067    */
00068   public void processAddToCache(CacheEntry qe)
00069   {
00070     SelectRequest request = qe.getRequest();
00071     ArrayList selectedColumns = request.getSelect();
00072     //  Update the tables columns dependencies
00073     if (selectedColumns == null || selectedColumns.isEmpty())
00074     {
00075       logger
00076           .warn("No parsing of select clause found - Fallback to table granularity");
00077       for (Iterator i = request.getFrom().iterator(); i.hasNext();)
00078       {
00079         CacheDatabaseTable table = cdbs.getTable((String) i.next());
00080         table.addCacheEntry(qe);
00081         // Add all columns, entries will be added below.
00082         ArrayList columns = table.getColumns();
00083         for (int j = 0; j < columns.size(); j++)
00084         {
00085           ((CacheDatabaseColumn) columns.get(j)).addCacheEntry(qe);
00086         }
00087         return;
00088       }
00089     }
00090     for (Iterator i = selectedColumns.iterator(); i.hasNext();)
00091     {
00092       TableColumn tc = (TableColumn) i.next();
00093       cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
00094           .addCacheEntry(qe);
00095     }
00096     if (request.getWhere() != null)
00097       for (Iterator i = request.getWhere().iterator(); i.hasNext();)
00098       {
00099         TableColumn tc = (TableColumn) i.next();
00100         cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
00101             .addCacheEntry(qe);
00102       }
00103   }
00104 
00105   /**
00106    * @see org.objectweb.cjdbc.controller.cache.result.AbstractResultCache#isUpdateNecessary(org.objectweb.cjdbc.common.sql.UpdateRequest)
00107    */
00108   public boolean isUpdateNecessary(UpdateRequest request)
00109   {
00110     return true;
00111   }
00112 
00113   /**
00114    * @see org.objectweb.cjdbc.controller.cache.result.ResultCache#processWriteNotify(org.objectweb.cjdbc.common.sql.AbstractWriteRequest)
00115    */
00116   protected void processWriteNotify(AbstractWriteRequest request)
00117   {
00118     //    Sanity check
00119     if (request.getColumns() == null)
00120     {
00121       logger.warn("No column parsing found - Fallback to table granularity ("
00122           + request.getSQL() + ")");
00123       cdbs.getTable(request.getTableName()).invalidateAll();
00124       return;
00125     }
00126     if (request.isAlter())
00127     {
00128       cdbs.getTable(request.getTableName()).invalidateAll();
00129       return;
00130     }
00131     for (Iterator i = request.getColumns().iterator(); i.hasNext();)
00132     {
00133       TableColumn tc = (TableColumn) i.next();
00134       cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
00135           .invalidateAll();
00136     }
00137   }
00138 
00139   /**
00140    * @see org.objectweb.cjdbc.controller.cache.result.ResultCache#getName()
00141    */
00142   public String getName()
00143   {
00144     return "column";
00145   }
00146 
00147 }

Generated on Mon Apr 11 22:01:34 2005 for C-JDBC by  doxygen 1.3.9.1