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

org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique Class Reference

Inheritance diagram for org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique:

Inheritance graph
[legend]
Collaboration diagram for org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ResultCacheColumnUnique (int maxEntries, int pendingTimeout)
void processAddToCache (CacheEntry qe)
boolean isUpdateNecessary (UpdateRequest request)
String getName ()

Protected Member Functions

void processWriteNotify (AbstractWriteRequest request)

Detailed Description

This is a query cache implementation with a column unique granularity:

Author:
Emmanuel Cecchet

Nicolas Modrzyk

Version:
1.0

Definition at line 55 of file ResultCacheColumnUnique.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.ResultCacheColumnUnique int  maxEntries,
int  pendingTimeout
 

Builds a new ResultCache with a column unique granularity.

Parameters:
maxEntries maximum number of entries
pendingTimeout pending timeout for concurrent queries

Definition at line 64 of file ResultCacheColumnUnique.java.

00065   {
00066     super(maxEntries, pendingTimeout);
00067     parsingGranularity = ParsingGranularities.COLUMN_UNIQUE;
00068   }


Member Function Documentation

String org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.getName  )  [virtual]
 

See also:
org.objectweb.cjdbc.controller.cache.result.ResultCache.getName()

Implements org.objectweb.cjdbc.controller.cache.result.ResultCache.

Definition at line 227 of file ResultCacheColumnUnique.java.

00228   {
00229     return "columnUnique";
00230   }

boolean org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.isUpdateNecessary UpdateRequest  request  )  [virtual]
 

See also:
org.objectweb.cjdbc.controller.cache.result.AbstractResultCache.isUpdateNecessary(org.objectweb.cjdbc.common.sql.UpdateRequest)

Implements org.objectweb.cjdbc.controller.cache.result.ResultCache.

Definition at line 132 of file ResultCacheColumnUnique.java.

References org.objectweb.cjdbc.common.sql.AbstractRequest.getCacheAbility(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.getColumns(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.getPk(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.getPkResultCacheEntry(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getResult(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseSchema.getTable(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.getTableName(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.isValid(), and org.objectweb.cjdbc.controller.cache.result.ResultCache.needInvalidate().

00133   {
00134     if (request.getCacheAbility() != RequestType.UNIQUE_CACHEABLE)
00135       return true;
00136     CacheDatabaseTable cacheTable = cdbs.getTable(request.getTableName());
00137     if (request.getColumns() == null)
00138       return true;
00139     String pk = request.getPk();
00140     ResultCacheEntry qce = cacheTable.getPkResultCacheEntry(pk);
00141     if (qce != null)
00142     {
00143       if (!qce.isValid())
00144         return true;
00145       ControllerResultSet rs = qce.getResult();
00146       if (rs == null)
00147         return true;
00148       else
00149         return needInvalidate(rs, request)[1];
00150     }
00151     else
00152       return true;
00153   }

void org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processAddToCache CacheEntry  qe  )  [virtual]
 

See also:
org.objectweb.cjdbc.controller.cache.result.ResultCache.processAddToCache(CacheEntry)

Implements org.objectweb.cjdbc.controller.cache.result.ResultCache.

Definition at line 73 of file ResultCacheColumnUnique.java.

References org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseColumn.addCacheEntry(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.addCacheEntry(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.addPkCacheEntry(), org.objectweb.cjdbc.common.sql.AbstractRequest.getCacheAbility(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.getColumn(), org.objectweb.cjdbc.common.sql.schema.TableColumn.getColumnName(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.getColumns(), org.objectweb.cjdbc.common.sql.SelectRequest.getFrom(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.getPkResultCacheEntry(), org.objectweb.cjdbc.common.sql.SelectRequest.getPkValue(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getRequest(), org.objectweb.cjdbc.controller.cache.result.entries.CacheEntry.getRequest(), org.objectweb.cjdbc.common.sql.SelectRequest.getSelect(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseSchema.getTable(), org.objectweb.cjdbc.common.sql.schema.TableColumn.getTableName(), org.objectweb.cjdbc.common.sql.SelectRequest.getWhere(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.isValid(), and org.objectweb.cjdbc.common.log.Trace.warn().

00074   {
00075     SelectRequest request = qe.getRequest();
00076     ArrayList selectedColumns = request.getSelect();
00077     //  Update the tables columns dependencies
00078     if (selectedColumns == null || selectedColumns.isEmpty())
00079     {
00080       logger
00081           .warn("No parsing of select clause found - Fallback to table granularity");
00082       for (Iterator i = request.getFrom().iterator(); i.hasNext();)
00083       {
00084         CacheDatabaseTable table = cdbs.getTable((String) i.next());
00085         table.addCacheEntry(qe);
00086         // Add all columns, entries will be added below.
00087         ArrayList columns = table.getColumns();
00088         for (int j = 0; j < columns.size(); j++)
00089         {
00090           ((CacheDatabaseColumn) columns.get(j)).addCacheEntry(qe);
00091         }
00092         return;
00093       }
00094     }
00095     for (Iterator i = request.getSelect().iterator(); i.hasNext();)
00096     {
00097       TableColumn tc = (TableColumn) i.next();
00098       cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
00099           .addCacheEntry(qe);
00100     }
00101     if (request.getWhere() != null)
00102     { // Add all columns dependencies
00103       for (Iterator i = request.getWhere().iterator(); i.hasNext();)
00104       {
00105         TableColumn tc = (TableColumn) i.next();
00106         cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
00107             .addCacheEntry(qe);
00108       }
00109       if (request.getCacheAbility() == RequestType.UNIQUE_CACHEABLE)
00110       { // Add a specific entry for this pk
00111         String tableName = (String) request.getFrom().get(0);
00112         ResultCacheEntry entry = cdbs.getTable(tableName)
00113             .getPkResultCacheEntry(request.getPkValue());
00114         if (entry != null)
00115         {
00116           if (entry.isValid())
00117           { // Do not add an entry which has a lower selection than the current
00118             // one
00119             if (entry.getRequest().getSelect().size() >= request.getSelect()
00120                 .size())
00121               return;
00122           }
00123         }
00124         cdbs.getTable(tableName).addPkCacheEntry(request.getPkValue(), qe);
00125       }
00126     }
00127   }

void org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processWriteNotify AbstractWriteRequest  request  )  [protected, virtual]
 

See also:
org.objectweb.cjdbc.controller.cache.result.ResultCache.processWriteNotify(org.objectweb.cjdbc.common.sql.AbstractWriteRequest)

Implements org.objectweb.cjdbc.controller.cache.result.ResultCache.

Definition at line 158 of file ResultCacheColumnUnique.java.

References org.objectweb.cjdbc.common.log.Trace.debug(), org.objectweb.cjdbc.common.sql.AbstractRequest.getCacheAbility(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.getColumn(), org.objectweb.cjdbc.common.sql.schema.TableColumn.getColumnName(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.getColumns(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.getPkResultCacheEntry(), org.objectweb.cjdbc.controller.cache.result.entries.ResultCacheEntry.getResult(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSQLShortForm(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseSchema.getTable(), org.objectweb.cjdbc.common.sql.schema.TableColumn.getTableName(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.getTableName(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseColumn.invalidateAll(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.invalidateAll(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseColumn.invalidateAllNonUnique(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isAlter(), org.objectweb.cjdbc.common.log.Trace.isDebugEnabled(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isDelete(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isInsert(), org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isUpdate(), org.objectweb.cjdbc.controller.cache.result.ResultCache.needInvalidate(), org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable.removePkResultCacheEntry(), and org.objectweb.cjdbc.common.log.Trace.warn().

00159   {
00160     // Sanity check
00161     CacheDatabaseTable cacheTable = cdbs.getTable(request.getTableName());
00162     if (request.getColumns() == null)
00163     {
00164       logger.warn("No column parsing found - Fallback to table granularity ("
00165           + request.getSQL() + ")");
00166       cacheTable.invalidateAll();
00167       return;
00168     }
00169     if (request.isInsert())
00170     {
00171       for (Iterator i = request.getColumns().iterator(); i.hasNext();)
00172       {
00173         TableColumn tc = (TableColumn) i.next();
00174         cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName())
00175             .invalidateAllNonUnique();
00176       }
00177     }
00178     else
00179     {
00180       if (request.getCacheAbility() == RequestType.UNIQUE_CACHEABLE)
00181       {
00182         if (request.isUpdate())
00183         {
00184           String pk = ((UpdateRequest) request).getPk();
00185           ResultCacheEntry qce = cacheTable.getPkResultCacheEntry(pk);
00186           if (qce != null)
00187           {
00188             boolean[] invalidate = needInvalidate(qce.getResult(),
00189                 (UpdateRequest) request);
00190             if (invalidate[0])
00191             { // We must invalidate this entry
00192               cacheTable.removePkResultCacheEntry(pk);
00193               return;
00194             }
00195             else
00196             {
00197               if (logger.isDebugEnabled())
00198                 logger.debug("No invalidate needed for request:"
00199                     + request.getSQLShortForm(20));
00200               return; // We don't need to invalidate
00201             }
00202           }
00203         }
00204         else if (request.isDelete())
00205         { // Invalidate the corresponding cache entry
00206           cacheTable
00207               .removePkResultCacheEntry(((DeleteRequest) request).getPk());
00208           return;
00209         }
00210       }
00211       // At this point this is a non unique write query or a request
00212       // we didn't handle properly (unknown request for example)
00213       for (Iterator i = request.getColumns().iterator(); i.hasNext();)
00214       {
00215         TableColumn tc = (TableColumn) i.next();
00216         CacheDatabaseTable table = cdbs.getTable(tc.getTableName());
00217         table.invalidateAll(); // Pk are associated to tables
00218         if (!request.isAlter())
00219           table.getColumn(tc.getColumnName()).invalidateAll();
00220       }
00221     }
00222   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:03:31 2005 for C-JDBC by  doxygen 1.3.9.1