クラス org.objectweb.cjdbc.controller.cache.parsing.ParsingCache

すべてのメンバ一覧

説明

This class implements a request parsing cache.

作者:
Emmanuel Cecchet
バージョン:
1.0

ParsingCache.java44 行で定義されています。

Public メソッド

 ParsingCache (int size, boolean backgroundParsing)
int getGranularity ()
void setGranularity (int granularity)
RequestManager getRequestManager ()
void setRequestManager (RequestManager requestManager)
void getParsingFromCache (AbstractRequest request)
void getParsingFromCacheAndParseIfMissing (AbstractRequest request) throws SQLException
boolean isBackgroundParsing ()
void setBackgroundParsing (boolean backgroundParsing)
void setCaseSensitiveParsing (boolean isCaseSensitiveParsing)
boolean isCaseSensitiveParsing ()
String getXml ()

Private 変数

Hashtable cache
Hashtable currentlyParsing
RequestManager requestManager
int granularity
int maxNbOfEntries
boolean backgroundParsing
boolean caseSensitiveParsing


コンストラクタとデストラクタ

org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.ParsingCache int  size,
boolean  backgroundParsing
 

Constructor for ParsingCache.

引数:
size maximum cache size in nb of entries
backgroundParsing true if the parsing should be done in background by a ParserThread
ParsingCache.java108 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.cache, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.caseSensitiveParsing, と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.currentlyParsing.

00109 { 00110 cache = new Hashtable(size == 0 ? 10000 : size); 00111 currentlyParsing = new Hashtable(); 00112 if (size < 0) 00113 throw new RuntimeException(Translate.get("cache.parsing.invalid.size", 00114 size)); 00115 if (size == 0) 00116 this.maxNbOfEntries = Integer.MAX_VALUE; 00117 else 00118 this.maxNbOfEntries = size; 00119 this.backgroundParsing = backgroundParsing; 00120 caseSensitiveParsing = false; 00121 }


メソッド

int org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getGranularity  ) 
 

Returns the granularity value.

戻り値:
Returns the granularity.
ParsingCache.java128 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.granularity.

00129 { 00130 return granularity; 00131 }

void org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCache AbstractRequest  request  ) 
 

If the same SQL query is found in the cache, the parsing is cloned into the given request. If backgroundParsing is set to true, then a ParserThread starts parsing the request in background else nothing is done on a cache miss.

引数:
request the request you look for
ParsingCache.java171 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.backgroundParsing, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.cache, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.caseSensitiveParsing, org.objectweb.cjdbc.common.sql.AbstractRequest.cloneParsing(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.currentlyParsing, org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), org.objectweb.cjdbc.common.sql.AbstractRequest.getSqlSkeleton(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.granularity, org.objectweb.cjdbc.common.sql.AbstractRequest.isParsed, と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.requestManager.

00172 { 00173 if (request.isParsed()) 00174 return; 00175 00176 String sql = request.getSqlSkeleton(); 00177 if (sql == null) 00178 sql = request.getSQL(); 00179 AbstractRequest parsedRequest = (AbstractRequest) cache.get(sql); 00180 00181 if (parsedRequest != null) 00182 { // Cache hit, clone the parsing 00183 request.cloneParsing(parsedRequest); 00184 return; 00185 } 00186 else if (backgroundParsing) 00187 { // Cache miss, start parsing the request in background 00188 synchronized (currentlyParsing) 00189 { 00190 if (!currentlyParsing.contains(sql)) 00191 { // Nobody else is trying to parse the same SQL query 00192 ParserThread pt = new ParserThread(request, requestManager 00193 .getDatabaseSchema(), granularity, caseSensitiveParsing); 00194 currentlyParsing.put(sql, new CurrentlyParsingEntry(pt, request)); 00195 } 00196 } 00197 } 00198 }

void org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing AbstractRequest  request  )  throws SQLException
 

Method getParsingFromCacheAndParseIfMissing.

引数:
request the request we look for
例外:
SQLException if an error occurs
ParsingCache.java206 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.backgroundParsing, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.cache, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.caseSensitiveParsing, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.currentlyParsing, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.CurrentlyParsingEntry.getParserThread(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.CurrentlyParsingEntry.getRequest(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.granularity, org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.maxNbOfEntries, と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.requestManager.

00208 { 00209 if (request.isParsed()) 00210 return; 00211 00212 // Check cache 00213 String instanciatedSQL = request.getSQL(); 00214 AbstractRequest parsedRequest = (AbstractRequest) cache 00215 .get(instanciatedSQL); 00216 00217 if (parsedRequest == null) 00218 { // Cache miss 00219 String sqlSkeleton = request.getSqlSkeleton(); 00220 String sql; 00221 if (sqlSkeleton != null) 00222 { // Missed with instanciated query, try with skeleton 00223 sql = sqlSkeleton; 00224 parsedRequest = (AbstractRequest) cache.get(sql); 00225 if (parsedRequest != null) 00226 { // Cache hit with skeleton 00227 request.cloneParsing(parsedRequest); 00228 return; 00229 } 00230 } 00231 else 00232 sql = instanciatedSQL; 00233 00234 // Full cache miss. Note that the underlying cache Hashtable is 00235 // synchronized and we usually do not need to synchronize on it. 00236 // As we will have to add a cache entry, check if the cache size is ok 00237 // else remove the first entry of the hashtable. 00238 while (cache.size() > maxNbOfEntries) 00239 { // Remove first entry from Hashtable. We need to synchronize here to be 00240 // sure that we are not trying to concurrently remove the first cache 00241 // entry. 00242 synchronized (cache) 00243 { 00244 try 00245 { 00246 cache.remove(cache.keys().nextElement()); 00247 } 00248 catch (Exception ignore) 00249 { 00250 break; 00251 } 00252 } 00253 } 00254 00255 // Both skeleton and instanciated missed 00256 if (backgroundParsing) 00257 { 00258 // Find the parsing thread and request (note that Hasthtable is 00259 // synchronized) 00260 CurrentlyParsingEntry cpe = (CurrentlyParsingEntry) currentlyParsing 00261 .get(sql); 00262 if (cpe != null) 00263 { 00264 ParserThread pt = cpe.getParserThread(); 00265 try 00266 { 00267 if (pt != null) 00268 { 00269 // Wait for completion 00270 pt.join(); 00271 synchronized (currentlyParsing) 00272 { 00273 currentlyParsing.remove(sql); 00274 } 00275 00276 // Update cache 00277 if ((granularity != ParsingGranularities.COLUMN_UNIQUE) 00278 || (sqlSkeleton == null)) 00279 // No skeleton or no uniqueness criteria, add the query 00280 cache.put(instanciatedSQL, cpe.getRequest()); 00281 else 00282 { // We have a skeleton and COLUMN_UNIQUE parsing 00283 if (request.getCacheAbility() != RequestType.UNIQUE_CACHEABLE) 00284 // It is NOT UNIQUE, add the skeleton 00285 cache.put(sqlSkeleton, cpe.getRequest()); 00286 else 00287 // It is UNIQUE, add the instanciated query 00288 cache.put(instanciatedSQL, cpe.getRequest()); 00289 } 00290 } 00291 } 00292 catch (InterruptedException failed) 00293 { 00294 throw new SQLException(Translate.get( 00295 "cache.parsing.failed.join.parser.thread", new String[]{ 00296 "" + request.getId(), failed.getMessage()})); 00297 } 00298 } 00299 } 00300 // Parse it now because we didn't parse in background or 00301 // backgroundParsing has failed for any obscure reason. 00302 request.parse(requestManager.getDatabaseSchema(), granularity, 00303 caseSensitiveParsing); 00304 00305 // Update cache 00306 if ((sqlSkeleton != null) 00307 && (granularity == ParsingGranularities.COLUMN_UNIQUE) 00308 && (request.getCacheAbility() == RequestType.UNIQUE_CACHEABLE)) 00309 // If this is a unique request, we must put the instanciated query in 00310 // the cache to retrieve the exact pk value. 00311 cache.put(instanciatedSQL, request); 00312 else 00313 cache.put(sql, request); 00314 } 00315 else 00316 // Cache hit 00317 request.cloneParsing(parsedRequest); 00318 }

RequestManager org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getRequestManager  ) 
 

Returns the requestManager value.

戻り値:
Returns the requestManager.
ParsingCache.java148 行で定義されています。

参照先 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.requestManager.

00149 { 00150 return requestManager; 00151 }

String org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getXml  ) 
 

Get xml information about this ParsingCache

戻り値:
String in xml formatted text
ParsingCache.java366 行で定義されています。
00367 { 00368 return "<" + DatabasesXmlTags.ELT_ParsingCache + " " 00369 + DatabasesXmlTags.ATT_backgroundParsing + "=\"" + backgroundParsing 00370 + "\" " + DatabasesXmlTags.ATT_maxNbOfEntries + "=\"" + maxNbOfEntries 00371 + "\"/>"; 00372 }

boolean org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.isBackgroundParsing  ) 
 

Returns the backgroundParsing.

戻り値:
boolean
ParsingCache.java325 行で定義されています。
00326 { 00327 return backgroundParsing; 00328 }

boolean org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.isCaseSensitiveParsing  ) 
 

Returns the caseSensitiveParsin.

戻り値:
boolean
ParsingCache.java356 行で定義されています。
00357 { 00358 return caseSensitiveParsing; 00359 }

void org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.setBackgroundParsing boolean  backgroundParsing  ) 
 

Sets the background parsing. If true the request are parsed in background by a separate thread that is created for this purpose.

引数:
backgroundParsing The backgroundParsing to set
ParsingCache.java336 行で定義されています。
00337 { 00338 this.backgroundParsing = backgroundParsing; 00339 }

void org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.setCaseSensitiveParsing boolean  isCaseSensitiveParsing  ) 
 

Sets the parsing case sensitivity

引数:
isCaseSensitiveParsing true if parsing is case sensitive
ParsingCache.java346 行で定義されています。
00347 { 00348 this.caseSensitiveParsing = isCaseSensitiveParsing; 00349 }

void org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.setGranularity int  granularity  ) 
 

Sets the granularity value.

引数:
granularity The granularity to set.
ParsingCache.java138 行で定義されています。
00139 { 00140 this.granularity = granularity; 00141 }

void org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.setRequestManager RequestManager  requestManager  ) 
 

Sets the requestManager value.

引数:
requestManager The requestManager to set.
ParsingCache.java158 行で定義されています。
00159 { 00160 this.requestManager = requestManager; 00161 }


変数

boolean org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.backgroundParsing [private]
 

ParsingCache.java51 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCache(), と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing().

Hashtable org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.cache [private]
 

ParsingCache.java46 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCache(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing(), と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.ParsingCache().

boolean org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.caseSensitiveParsing [private]
 

ParsingCache.java52 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCache(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing(), と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.ParsingCache().

Hashtable org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.currentlyParsing [private]
 

ParsingCache.java47 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCache(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing(), と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.ParsingCache().

int org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.granularity [private]
 

ParsingCache.java49 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getGranularity(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCache(), と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing().

int org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.maxNbOfEntries [private]
 

ParsingCache.java50 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing().

RequestManager org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.requestManager [private]
 

ParsingCache.java48 行で定義されています。

参照元 org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCache(), org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getParsingFromCacheAndParseIfMissing(), と org.objectweb.cjdbc.controller.cache.parsing.ParsingCache.getRequestManager().


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0.4に対してTue Oct 12 15:16:36 2004に生成されました。 doxygen 1.3.8