001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb.plugins.cmp.jdbc2.schema;
023:
024: import javax.transaction.Transaction;
025:
026: /**
027: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
028: * @version <tt>$Revision: 57209 $</tt>
029: */
030: public interface Cache {
031: class RemoveException extends RuntimeException {
032: public RemoveException() {
033: }
034:
035: public RemoveException(String message) {
036: super (message);
037: }
038:
039: public RemoveException(Throwable cause) {
040: super (cause);
041: }
042:
043: public RemoveException(String message, Throwable cause) {
044: super (message, cause);
045: }
046: }
047:
048: void lock();
049:
050: void lock(Object key);
051:
052: void unlock();
053:
054: void unlock(Object key);
055:
056: Object[] getFields(Object pk);
057:
058: Object[] getRelations(Object pk);
059:
060: void put(Transaction tx, Object pk, Object[] fields,
061: Object[] relations);
062:
063: void remove(Transaction tx, Object pk) throws RemoveException;
064:
065: boolean contains(Transaction tx, Object pk);
066:
067: void lockForUpdate(Transaction tx, Object pk) throws Exception;
068:
069: void releaseLock(Transaction tx, Object pk) throws Exception;
070:
071: void flush();
072:
073: Cache NONE = new Cache() {
074: public void lock() {
075: }
076:
077: public void lock(Object key) {
078: }
079:
080: public void unlock() {
081: }
082:
083: public void unlock(Object key) {
084: }
085:
086: public Object[] getFields(Object pk) {
087: return null;
088: }
089:
090: public Object[] getRelations(Object pk) {
091: return null;
092: }
093:
094: public void put(Transaction tx, Object pk, Object[] fields,
095: Object[] relations) {
096: }
097:
098: public void remove(Transaction tx, Object pk) {
099: }
100:
101: public boolean contains(Transaction tx, Object pk) {
102: return false;
103: }
104:
105: public void lockForUpdate(Transaction tx, Object pk)
106: throws Exception {
107: }
108:
109: public void releaseLock(Transaction tx, Object pk)
110: throws Exception {
111: }
112:
113: public void flush() {
114: }
115: };
116:
117: interface CacheLoader {
118: Object loadFromCache(Object value);
119:
120: Object getCachedValue();
121: }
122:
123: interface Listener {
124: void contention(int partitionIndex, long time);
125:
126: void eviction(int partitionIndex, Object pk, int size);
127:
128: void hit(int partitionIndex);
129:
130: void miss(int partitionIndex);
131:
132: public Listener NOOP = new Listener() {
133: public void contention(int partitionIndex, long time) {
134: }
135:
136: public void eviction(int partitionIndex, Object pk, int size) {
137: }
138:
139: public void hit(int partitionIndex) {
140: }
141:
142: public void miss(int partitionIndex) {
143: }
144: };
145: }
146: }
|