KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc2 > schema > Cache


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.jdbc2.schema;
23
24
25 import javax.transaction.Transaction JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
29  * @version <tt>$Revision: 37459 $</tt>
30  */

31 public interface Cache
32 {
33    class RemoveException extends RuntimeException JavaDoc
34    {
35       public RemoveException()
36       {
37       }
38
39       public RemoveException(String JavaDoc message)
40       {
41          super(message);
42       }
43
44       public RemoveException(Throwable JavaDoc cause)
45       {
46          super(cause);
47       }
48
49       public RemoveException(String JavaDoc message, Throwable JavaDoc cause)
50       {
51          super(message, cause);
52       }
53    }
54
55    void lock();
56
57    void lock(Object JavaDoc key);
58
59    void unlock();
60
61    void unlock(Object JavaDoc key);
62
63    Object JavaDoc[] getFields(Object JavaDoc pk);
64
65    Object JavaDoc[] getRelations(Object JavaDoc pk);
66
67    void put(Transaction JavaDoc tx, Object JavaDoc pk, Object JavaDoc[] fields, Object JavaDoc[] relations);
68
69    void remove(Transaction JavaDoc tx, Object JavaDoc pk) throws RemoveException;
70
71    boolean contains(Transaction JavaDoc tx, Object JavaDoc pk);
72
73    void lockForUpdate(Transaction JavaDoc tx, Object JavaDoc pk) throws Exception JavaDoc;
74
75    void releaseLock(Transaction JavaDoc tx, Object JavaDoc pk) throws Exception JavaDoc;
76
77    void flush();
78
79    Cache NONE = new Cache()
80    {
81       public void lock()
82       {
83       }
84
85       public void lock(Object JavaDoc key)
86       {
87       }
88
89       public void unlock()
90       {
91       }
92
93       public void unlock(Object JavaDoc key)
94       {
95       }
96
97       public Object JavaDoc[] getFields(Object JavaDoc pk)
98       {
99          return null;
100       }
101
102       public Object JavaDoc[] getRelations(Object JavaDoc pk)
103       {
104          return null;
105       }
106
107       public void put(Transaction JavaDoc tx, Object JavaDoc pk, Object JavaDoc[] fields, Object JavaDoc[] relations)
108       {
109       }
110
111       public void remove(Transaction JavaDoc tx, Object JavaDoc pk)
112       {
113       }
114
115       public boolean contains(Transaction JavaDoc tx, Object JavaDoc pk)
116       {
117          return false;
118       }
119
120       public void lockForUpdate(Transaction JavaDoc tx, Object JavaDoc pk) throws Exception JavaDoc
121       {
122       }
123
124       public void releaseLock(Transaction JavaDoc tx, Object JavaDoc pk) throws Exception JavaDoc
125       {
126       }
127
128       public void flush()
129       {
130       }
131    };
132
133    interface CacheLoader
134    {
135       Object JavaDoc loadFromCache(Object JavaDoc value);
136
137       Object JavaDoc getCachedValue();
138    }
139
140    interface Listener
141    {
142       void contention(int partitionIndex, long time);
143
144       void eviction(int partitionIndex, Object JavaDoc pk, int size);
145
146       void hit(int partitionIndex);
147
148       void miss(int partitionIndex);
149
150       public Listener NOOP = new Listener()
151       {
152          public void contention(int partitionIndex, long time)
153          {
154          }
155
156          public void eviction(int partitionIndex, Object JavaDoc pk, int size)
157          {
158          }
159
160          public void hit(int partitionIndex)
161          {
162          }
163
164          public void miss(int partitionIndex)
165          {
166          }
167       };
168    }
169 }
170
Popular Tags