Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
| SolarMetric Kodo JDO 2.4.3 generated on March 27 2003
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.solarmetric.datasource
Class PreparedStatementCache

    java.lang.Object
      |
      +--com.solarmetric.datasource.PreparedStatementCache

public class PreparedStatementCache
extends Object

Implements a cache mapping a SQL string, `Connection` pair to a `PreparedStatement` containing the same SQL using the same connection. Use the `newCacheAwareConnection(java.sql.Connection)` to create a connection wrapper that will automatically use this cache.

The cache uses a LRU algorithm to kick out old prepared statements when the given max size is exceeded. Only statements prepared using the default result set type and concurrency are cached.

Constructor Summary
`PreparedStatementCache(DataSourceImpl ds)` Default constructor.
`PreparedStatementCache(DataSourceImpl ds, int maxSize)` Constructor.

Method Summary
`int` | `getMaxSize()` Return the maximum size of the cache.
`Connection` | `newCacheAwareConnection(Connection conn)` Return a `Connection` wrapper that is aware of this cache and will use it when possible.
`void` | `setMaxSize(int maxSize)` Set the maximum size of the cache.
`String` | `toString()`
`StringBuffer` | `toString(StringBuffer buffer)`

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

Constructor Detail

### PreparedStatementCache

    public PreparedStatementCache(DataSourceImpl ds)

  Default constructor. Create a cache with a default maximum size of 50.

### PreparedStatementCache

    public PreparedStatementCache(DataSourceImpl ds,
                                  int maxSize)

  Constructor.
  Parameters:
    `maxSize` - the size of the prepared statement cache

Method Detail

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### toString

    public StringBuffer toString(StringBuffer buffer)

### getMaxSize

    public int getMaxSize()

  Return the maximum size of the cache.

### setMaxSize

    public void setMaxSize(int maxSize)

  Set the maximum size of the cache. If lower than the current size, the cache will be trimmed the next time something is added.

### newCacheAwareConnection

    public Connection newCacheAwareConnection(Connection conn)

  Return a `Connection` wrapper that is aware of this cache and will use it when possible.

Overview | Package | Class | Tree | Serialized | Deprecated | Index | Help
| SolarMetric Kodo JDO 2.4.3 generated on March 27 2003
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright 2001,2002 SolarMetric, Inc. All Rights Reserved.