1 24 25 package org.objectweb.cjdbc.controller.cache.result; 26 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 30 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest; 31 import org.objectweb.cjdbc.common.sql.ParsingGranularities; 32 import org.objectweb.cjdbc.common.sql.SelectRequest; 33 import org.objectweb.cjdbc.common.sql.UpdateRequest; 34 import org.objectweb.cjdbc.common.sql.schema.TableColumn; 35 import org.objectweb.cjdbc.controller.cache.result.entries.AbstractResultCacheEntry; 36 import org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseColumn; 37 import org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseTable; 38 39 50 51 public class ResultCacheColumn extends ResultCache 52 { 53 59 public ResultCacheColumn(int maxEntries, int pendingTimeout) 60 { 61 super(maxEntries, pendingTimeout); 62 parsingGranularity = ParsingGranularities.COLUMN; 63 } 64 65 68 public void processAddToCache(AbstractResultCacheEntry qe) 69 { 70 SelectRequest request = qe.getRequest(); 71 ArrayList selectedColumns = request.getSelect(); 72 if (selectedColumns == null || selectedColumns.isEmpty()) 74 { 75 logger 76 .warn("No parsing of select clause found - Fallback to table granularity"); 77 for (Iterator i = request.getFrom().iterator(); i.hasNext();) 78 { 79 CacheDatabaseTable table = cdbs.getTable((String ) i.next()); 80 table.addCacheEntry(qe); 81 ArrayList columns = table.getColumns(); 83 for (int j = 0; j < columns.size(); j++) 84 { 85 ((CacheDatabaseColumn) columns.get(j)).addCacheEntry(qe); 86 } 87 return; 88 } 89 } 90 for (Iterator i = selectedColumns.iterator(); i.hasNext();) 91 { 92 TableColumn tc = (TableColumn) i.next(); 93 cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName()) 94 .addCacheEntry(qe); 95 } 96 if (request.getWhere() != null) 97 for (Iterator i = request.getWhere().iterator(); i.hasNext();) 98 { 99 TableColumn tc = (TableColumn) i.next(); 100 cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName()) 101 .addCacheEntry(qe); 102 } 103 } 104 105 108 public boolean isUpdateNecessary(UpdateRequest request) 109 { 110 return true; 111 } 112 113 116 protected void processWriteNotify(AbstractWriteRequest request) 117 { 118 if (request.getColumns() == null) 120 { 121 logger.warn("No column parsing found - Fallback to table granularity (" 122 + request.getSQL() + ")"); 123 cdbs.getTable(request.getTableName()).invalidateAll(); 124 return; 125 } 126 if (request.isAlter()) 127 { 128 cdbs.getTable(request.getTableName()).invalidateAll(); 129 return; 130 } 131 for (Iterator i = request.getColumns().iterator(); i.hasNext();) 132 { 133 TableColumn tc = (TableColumn) i.next(); 134 cdbs.getTable(tc.getTableName()).getColumn(tc.getColumnName()) 135 .invalidateAll(); 136 } 137 } 138 139 142 public String getName() 143 { 144 return "column"; 145 } 146 147 } | Popular Tags |