001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.storagemanager;
012:
013: import com.versant.core.server.CachedQueryResult;
014: import com.versant.core.server.CompiledQuery;
015: import com.versant.core.metadata.FetchGroup;
016: import com.versant.core.metadata.ClassMetaData;
017: import com.versant.core.metadata.ModelMetaData;
018: import com.versant.core.common.OID;
019: import com.versant.core.common.State;
020: import com.versant.core.common.*;
021:
022: /**
023: * Cache of State's and query results shared by multiple StorageManager's.
024: * A single class is used to cache both State's and query results so that
025: * query results can be efficiently evicted when States of classes they
026: * depend on are evicted. Only data read in a committed database transaction
027: * may be added to the cache.
028: */
029: public interface StorageCache {
030:
031: /**
032: * This is invoked when the meta data is available.
033: */
034: public void setJDOMetaData(ModelMetaData jmd);
035:
036: /**
037: * Is the cache enabled?
038: */
039: public boolean isEnabled();
040:
041: /**
042: * Is query caching enabled?
043: */
044: public boolean isQueryCacheEnabled();
045:
046: /**
047: * Begin a cache transaction and return an identifier for it. This
048: * must be called before a new database transaction is started.
049: */
050: public Object beginTx();
051:
052: /**
053: * End a cache transaction.
054: */
055: public void endTx(Object tx);
056:
057: /**
058: * Get the State for an OID or null if it is not in cache or does not
059: * contain the fields in the fetchGroup. This returns a copy of the
060: * data in the cache. If fetchGroup is null then if any state is
061: * present it is returned.
062: */
063: public State getState(OID oid, FetchGroup fetchGroup);
064:
065: /**
066: * Does the cache contain any data for the oid? Note that the data could
067: * be evicted at any time.
068: */
069: public boolean contains(OID oid);
070:
071: /**
072: * Get cached query results or null if there are none.
073: * @param cq
074: * @param params
075: */
076: public CachedQueryResult getQueryResult(CompiledQuery cq,
077: Object[] params);
078:
079: /**
080: * Get result count or -1 if there are none.
081: * @param cq
082: * @param params
083: */
084: public int getQueryResultCount(CompiledQuery cq, Object[] params);
085:
086: /**
087: * Add all the states in the container to the cache.
088: */
089: public void add(Object tx, StatesReturned container);
090:
091: /**
092: * Add query results to the cache.
093: */
094: public void add(Object tx, CompiledQuery cq, Object[] params,
095: CachedQueryResult queryData);
096:
097: /**
098: * Add query result count to the cache.
099: */
100: public void add(Object tx, CompiledQuery cq, Object[] params,
101: int count);
102:
103: /**
104: * Evict length OIDs from oids starting at offset. Expected is the total
105: * number of OIDs we expect to evict in the transaction or 0 if this is
106: * not known. This may be used to optimize cache storage allocation.
107: */
108: public void evict(Object tx, OID[] oids, int offset, int length,
109: int expected);
110:
111: /**
112: * Evict all data for the classes.
113: */
114: public void evict(Object tx, ClassMetaData[] classes, int classCount);
115:
116: /**
117: * Evict all data.
118: */
119: public void evictAll(Object tx);
120:
121: /**
122: * Evict any cached information for the query.
123: */
124: public void evict(Object tx, CompiledQuery cq, Object[] params);
125: }
|