01: /*
02: Copyright 2004 Philip Jacob <phil@whirlycott.com>
03: Seth Fitzsimmons <seth@note.amherst.edu>
04:
05: Licensed under the Apache License, Version 2.0 (the "License");
06: you may not use this file except in compliance with the License.
07: You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: */
17:
18: /*
19: * Created on May 16, 2004
20: *
21: */
22: package com.whirlycott.cache.test;
23:
24: import java.io.Serializable;
25:
26: import net.sf.ehcache.Cache;
27: import net.sf.ehcache.CacheException;
28: import net.sf.ehcache.CacheManager;
29: import net.sf.ehcache.Element;
30:
31: import org.apache.commons.logging.Log;
32: import org.apache.commons.logging.LogFactory;
33:
34: /**
35: * @author phil
36: */
37: public class ReferenceTest {
38:
39: private static Log log = LogFactory.getLog(ReferenceTest.class);
40:
41: public static void main(String[] args) throws CacheException {
42:
43: CacheManager cm = CacheManager.create();
44:
45: Cache cache = new Cache("test", 1000, true, false, 500, 200);
46: cm.addCache(cache);
47:
48: Outer outer = new Outer();
49:
50: log.debug("The outer default value is: "
51: + outer.getIn().innerName);
52: Element e = new Element("outer", outer);
53: cache.put(e);
54: log.debug("Now the outer is in the cache");
55:
56: outer.getIn().innerName = "changed the inner string!!!!!!!";
57:
58: Element modifiedElement = cache.get("outer");
59:
60: log
61: .debug("The value from the cache is: "
62: + ((Outer) modifiedElement.getValue()).getIn().innerName);
63:
64: cache.put(e);
65:
66: cm.shutdown();
67:
68: }
69: }
70:
71: class Outer implements Serializable {
72:
73: private Inner in;
74:
75: Outer() {
76: in = new Inner();
77: }
78:
79: /**
80: * @return Returns the in.
81: */
82: public Inner getIn() {
83: return in;
84: }
85:
86: /**
87: * @param in The in to set.
88: */
89: public void setIn(Inner in) {
90: this .in = in;
91: }
92:
93: }
94:
95: class Inner {
96:
97: public String innerName = "default phil inner name";
98:
99: }
|