Public Member Functions | |
MetadataCache (int maxNbOfMetadata, int maxNbOfField) | |
Field[] | getMetadata (AbstractRequest request) |
void | addMetadata (AbstractRequest request, Field[] metadata) |
Field | getField (String fullyQualifiedFieldName) |
void | addField (String fullyQualifiedFieldName, Field field) |
String | getXml () |
ResultSet Fields are kept here to prevent recomputing them and allocating them each time a query is executed.
Definition at line 44 of file MetadataCache.java.
|
Constructor for MetadataCache.
Definition at line 58 of file MetadataCache.java. 00059 { 00060 metadataCache = new Hashtable(maxNbOfMetadata == 0 00061 ? 10000 00062 : maxNbOfMetadata); 00063 fieldCache = new Hashtable(maxNbOfField == 0 ? 100 : maxNbOfField); 00064 if (maxNbOfMetadata < 0) 00065 throw new RuntimeException(Translate.get("cache.metadata.invalid.size", 00066 maxNbOfMetadata)); 00067 if (maxNbOfMetadata == 0) 00068 this.maxNbOfMetadata = Integer.MAX_VALUE; 00069 else 00070 this.maxNbOfMetadata = maxNbOfMetadata; 00071 if (maxNbOfField < 0) 00072 throw new RuntimeException(Translate.get("cache.metadata.invalid.size", 00073 maxNbOfField)); 00074 if (maxNbOfField == 0) 00075 this.maxNbOfField = Integer.MAX_VALUE; 00076 else 00077 this.maxNbOfField = maxNbOfField; 00078 }
|
|
Add a Field entry to the cache and associate it to the given name.
Definition at line 167 of file MetadataCache.java. 00168 { 00169 // Note that the underlying cache Hashtable is synchronized and we usually 00170 // do not need to synchronize on it. 00171 // As we will have to add a cache entry, check if the cache size is ok 00172 // else remove the first entry of the hashtable. 00173 while (fieldCache.size() > maxNbOfField) 00174 { // Remove first entry from Hashtable. We need to synchronize here to be 00175 // sure that we are not trying to concurrently remove the first cache 00176 // entry. 00177 synchronized (fieldCache) 00178 { 00179 try 00180 { 00181 fieldCache.remove(fieldCache.keys().nextElement()); 00182 } 00183 catch (Exception ignore) 00184 { 00185 break; 00186 } 00187 } 00188 } 00189 // Add to cache 00190 try 00191 { 00192 fieldCache.put(fullyQualifiedFieldName, field); 00193 } 00194 catch (OutOfMemoryError oome) 00195 { 00196 synchronized (fieldCache) 00197 { 00198 fieldCache.clear(); 00199 } 00200 System.gc(); 00201 logger.warn(Translate.get("cache.memory.error.cache.flushed", this 00202 .getClass())); 00203 } 00204 }
|
|
Add a metadata entry to the cache and associate it to the given request.
Definition at line 103 of file MetadataCache.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), and org.objectweb.cjdbc.common.sql.AbstractRequest.getSqlSkeleton(). 00104 { 00105 // Note that the underlying cache Hashtable is synchronized and we usually 00106 // do not need to synchronize on it. 00107 // As we will have to add a cache entry, check if the cache size is ok 00108 // else remove the first entry of the hashtable. 00109 while (metadataCache.size() > maxNbOfMetadata) 00110 { // Remove first entry from Hashtable. We need to synchronize here to be 00111 // sure that we are not trying to concurrently remove the first cache 00112 // entry. 00113 synchronized (metadataCache) 00114 { 00115 try 00116 { 00117 metadataCache.remove(metadataCache.keys().nextElement()); 00118 } 00119 catch (Exception ignore) 00120 { 00121 break; 00122 } 00123 } 00124 } 00125 00126 // Add to cache 00127 try 00128 { 00129 String sqlSkeleton = request.getSqlSkeleton(); 00130 if (sqlSkeleton != null) 00131 metadataCache.put(sqlSkeleton, metadata); 00132 else 00133 metadataCache.put(request.getSQL(), metadata); 00134 } 00135 catch (OutOfMemoryError oome) 00136 { 00137 synchronized (metadataCache) 00138 { 00139 metadataCache.clear(); 00140 } 00141 System.gc(); 00142 logger.warn(Translate.get("cache.memory.error.cache.flushed", this 00143 .getClass())); 00144 } 00145 }
|
|
Get the field corresponding to a column name. Returns null if the cache contains no field for the given name.
Definition at line 155 of file MetadataCache.java. 00156 {
00157 return (Field) fieldCache.get(fullyQualifiedFieldName);
00158 }
|
|
Get metadata associated to a request. Returns null if the cache contains no metadata for the given request.
Definition at line 88 of file MetadataCache.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.getSQL(), and org.objectweb.cjdbc.common.sql.AbstractRequest.getSqlSkeleton(). 00089 { 00090 String sqlSkeleton = request.getSqlSkeleton(); 00091 if (sqlSkeleton != null) 00092 return (Field[]) metadataCache.get(sqlSkeleton); 00093 else 00094 return (Field[]) metadataCache.get(request.getSQL()); 00095 }
|
|
Get xml information about this ParsingCache
Definition at line 211 of file MetadataCache.java. 00212 { 00213 return "<" + DatabasesXmlTags.ELT_MetadataCache + " " 00214 + DatabasesXmlTags.ATT_maxNbOfMetadata + "=\"" + maxNbOfMetadata 00215 + "\" " + DatabasesXmlTags.ATT_maxNbOfField + "=\"" 00216 + (maxNbOfField == Integer.MAX_VALUE ? 0 : maxNbOfField) + "\"/>"; 00217 }
|