Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.openjpa.jdbc.kernel
Class PreparedQueryCacheImpl

    java.lang.Object
      org.apache.openjpa.jdbc.kernel.PreparedQueryCacheImpl

All Implemented Interfaces:
  PreparedQueryCache, Configurable

    public class PreparedQueryCacheImpl

extends Object
implements PreparedQueryCache

An implementation of the cache of `prepared queries`.

Since:
  2.0.0
Author:
  Pinaki Poddar

Nested Class Summary
`static class` | `PreparedQueryCacheImpl.StrongExclusion` Strong exclusion.
`static class` | `PreparedQueryCacheImpl.WeakExclusion` Weak exclusion.

Nested classes/interfaces inherited from interface org.apache.openjpa.kernel.PreparedQueryCache
`PreparedQueryCache.Exclusion`

Constructor Summary
`PreparedQueryCacheImpl()`

Method Summary
`void` | `addExclusionPattern(String pattern)` Adds a pattern for exclusion.
`boolean` | `cache(PreparedQuery q)` Cache the given query keyed by its identifier.
`void` | `clear()` Clears all cached queries.
`void` | `endConfiguration()` Invoked upon completion of bean property configuration for this object.
`PreparedQuery` | `get(String id)` Get the PreparedQuery with the given identifier if it exists.
`boolean` | `getEnableStatistics()` Affirm if statistics is gathered.
`List<PreparedQueryCache.Exclusion>` | `getExcludes()` Gets the exclusion patterns.
`Map<String,String>` | `getMapView()` Get a map view of the cached queries indexed by identifier.
`QueryStatistics<String>` | `getStatistics()` Gets the simple statistics for executed queries.
`PreparedQuery` | `initialize(String key, Object result)` Initialize the cached Prepared Query registered with the given key earlier by the given execution result.
`boolean` | `invalidate(String id)` Remove the PreparedQuery with the given identifier from this cache.
`Boolean` | `isCachable(String id)` Affirms if a PreparedQuery can be cached against the given key.
`PreparedQueryCache.Exclusion` | `isExcluded(String id)` Returns the exclusion status of if the given query key.
`(package private) boolean` | `isHinted(FetchConfiguration fetch, String hint)`
`protected void` | `lock(boolean readOnly)` Note: Care needs to be taken so that a read lock is never held while requesting a write lock.
`PreparedQuery` | `markUncachable(String id, PreparedQueryCache.Exclusion exclusion)` Marks the given key as not amenable to caching.
`(package private) boolean` | `matches(String pattern, String target)`
`Boolean` | `register(String id, Query query, FetchConfiguration hints)` Register the given query for caching against the given key if it has not already been cached.
`void` | `removeExclusionPattern(String pattern)` Removes a pattern for exclusion.
`void` | `setConfiguration(Configuration conf)` Invoked prior to setting bean properties.
`void` | `setEnableStatistics(boolean enable)` Enable/disable gathering of statistics.
`void` | `setExcludes(String excludes)` Sets one or more exclusion regular expression patterns separated by semicolon.
`void` | `startConfiguration()` Invoked before bean property configuration is begun on this object.
`protected void` | `unlock(boolean readOnly)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PreparedQueryCacheImpl

    public PreparedQueryCacheImpl()

Method Detail

### register

    public Boolean register(String id,
                            Query query,
                            FetchConfiguration hints)

  Description copied from interface: `PreparedQueryCache`
  Register the given query for caching against the given key if it has not already been cached. If the query can not be cached, then mark it as such to avoid computing for the same key again.

  Specified by:
    `register` in interface `PreparedQueryCache`
  Returns:
    TRUE the query is registered in the cache by this call null if the query is already registered in the cache FALSE if can not be registered in the cache, either because it is known not to be cacheable from a previous attempt or a hint is given to ignore the cached version.

### getMapView

    public Map<String,String> getMapView()

  Description copied from interface: `PreparedQueryCache`
  Get a map view of the cached queries indexed by identifier.

  Specified by:
    `getMapView` in interface `PreparedQueryCache`

### cache

    public boolean cache(PreparedQuery q)

  Cache the given query keyed by its identifier. Does not cache if the identifier matches any exclusion pattern or has been marked as non-cachable. Also register the identifier as not cachable against the matched exclusion pattern.

  Specified by:
    `cache` in interface `PreparedQueryCache`
  Returns:
    true if the given query is cached. false if it can not be cached due to exclusion.
  See Also:
    `#markUncachable(String)`, `PreparedQueryCache.setExcludes(String)`, `PreparedQueryCache.addExclusionPattern(String)`

### initialize

    public PreparedQuery initialize(String key,
                                    Object result)

  Description copied from interface: `PreparedQueryCache`
  Initialize the cached Prepared Query registered with the given key earlier by the given execution result. If it is not possible to initialize the Prepared Query from the given execution result, then the corresponding key will be marked as invalid for caching.

  Specified by:
    `initialize` in interface `PreparedQueryCache`
  Parameters:
    `key` - the key used during registration
    `result` - an opaque instance carrying the execution result of the original query.
  Returns:
    the initialized Prepared Query. If it is not possible to initialize the cached, possibly hollow Prepared Query from the given result, return null.

### invalidate

    public boolean invalidate(String id)

  Description copied from interface: `PreparedQueryCache`
  Remove the PreparedQuery with the given identifier from this cache.

  Specified by:
    `invalidate` in interface `PreparedQueryCache`

### get

    public PreparedQuery get(String id)

  Description copied from interface: `PreparedQueryCache`
  Get the PreparedQuery with the given identifier if it exists. null otherwise.

  Specified by:
    `get` in interface `PreparedQueryCache`

### isCachable

    public Boolean isCachable(String id)

  Description copied from interface: `PreparedQueryCache`
  Affirms if a PreparedQuery can be cached against the given key.

  Specified by:
    `isCachable` in interface `PreparedQueryCache`
  Returns:
    Boolean.FALSE if the given key is explicitly marked before as not be cached or matches any of the exclusion patterns. Boolean.TRUE if the given key currently exists in the cache. Otherwise, return null implying this receiver can not determine whether this key can be cached on not.

### markUncachable

    public PreparedQuery markUncachable(String id,
                                        PreparedQueryCache.Exclusion exclusion)

  Description copied from interface: `PreparedQueryCache`
  Marks the given key as not amenable to caching. Explicit marking helps to avoid repeated computational cost of determining whether a query can be cached or not.

  Specified by:
    `markUncachable` in interface `PreparedQueryCache`
  Parameters:
    `id` - is the key to be excluded
    `exclusion` - directs whether exclusion is irreversible or not.
  Returns:
    The value for the given key if it had been cached before. null otherwise.

### isExcluded

    public PreparedQueryCache.Exclusion isExcluded(String id)

  Description copied from interface: `PreparedQueryCache`
  Returns the exclusion status of if the given query key.

  Specified by:
    `isExcluded` in interface `PreparedQueryCache`
  Returns:
    null implies that the key is not excluded.

### setExcludes

    public void setExcludes(String excludes)

  Description copied from interface: `PreparedQueryCache`
  Sets one or more exclusion regular expression patterns separated by semicolon. Any existing cache entry whose key matches any of the given pattern will be marked non-cachable in a reversible manner.

  Specified by:
    `setExcludes` in interface `PreparedQueryCache`

### getExcludes

    public List<PreparedQueryCache.Exclusion> getExcludes()

  Description copied from interface: `PreparedQueryCache`
  Gets the exclusion patterns.

  Specified by:
    `getExcludes` in interface `PreparedQueryCache`

### addExclusionPattern

    public void addExclusionPattern(String pattern)

  Adds a pattern for exclusion. Any query cached currently whose identifier matches the given pattern will be marked invalidated as a side-effect.

  Specified by:
    `addExclusionPattern` in interface `PreparedQueryCache`

### removeExclusionPattern

    public void removeExclusionPattern(String pattern)

  Removes a pattern for exclusion. Any query identifier marked as not cachable due to the given pattern will now be removed from the list of uncachables as a side-effect.

  Specified by:
    `removeExclusionPattern` in interface `PreparedQueryCache`
  See Also:
    `PreparedQueryCache.markUncachable(String, Exclusion)`

### getStatistics

    public QueryStatistics<String> getStatistics()

  Description copied from interface: `PreparedQueryCache`
  Gets the simple statistics for executed queries. If the statistics gathering is disabled, an empty statistics is returned.

  Specified by:
    `getStatistics` in interface `PreparedQueryCache`

### lock

    protected void lock(boolean readOnly)

  Note: Care needs to be taken so that a read lock is never held while requesting a write lock. This will result in a deadlock.

  Parameters:
    `readOnly` - - If true, a read lock will be acquired. Else a write lock will be acquired.

### unlock

    protected void unlock(boolean readOnly)

  Parameters:
    `readOnly` - - If true, the read lock will be released. Else a write lock will be released.

### matches

    boolean matches(String pattern,
                    String target)

### isHinted

    boolean isHinted(FetchConfiguration fetch,
                     String hint)

### clear

    public void clear()

  Description copied from interface: `PreparedQueryCache`
  Clears all cached queries.

  Specified by:
    `clear` in interface `PreparedQueryCache`

### setEnableStatistics

    public void setEnableStatistics(boolean enable)

  Description copied from interface: `PreparedQueryCache`
  Enable/disable gathering of statistics.

  Specified by:
    `setEnableStatistics` in interface `PreparedQueryCache`

### getEnableStatistics

    public boolean getEnableStatistics()

  Description copied from interface: `PreparedQueryCache`
  Affirm if statistics is gathered.

  Specified by:
    `getEnableStatistics` in interface `PreparedQueryCache`

### setConfiguration

    public void setConfiguration(Configuration conf)

  Description copied from interface: `Configurable`
  Invoked prior to setting bean properties.

  Specified by:
    `setConfiguration` in interface `Configurable`

### startConfiguration

    public void startConfiguration()

  Description copied from interface: `Configurable`
  Invoked before bean property configuration is begun on this object.

  Specified by:
    `startConfiguration` in interface `Configurable`

### endConfiguration

    public void endConfiguration()

  Description copied from interface: `Configurable`
  Invoked upon completion of bean property configuration for this object.

  Specified by:
    `endConfiguration` in interface `Configurable`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.