001: /*
002:
003: Derby - Class org.apache.derbyTesting.unitTests.services.T_CachedInteger
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.unitTests.services;
023:
024: import org.apache.derby.iapi.services.cache.*;
025:
026: import org.apache.derby.iapi.error.StandardException;
027:
028: /**
029:
030: */
031: public class T_CachedInteger extends T_Cacheable {
032:
033: protected T_Key keyValue;
034:
035: public T_CachedInteger() {
036: }
037:
038: /*
039: ** Cacheable methods
040: */
041:
042: /**
043: @exception StandardException Standard Derby Error policy
044: */
045: public Cacheable setIdentity(Object key) throws StandardException {
046:
047: super .setIdentity(key);
048:
049: T_Key tkey = (T_Key) key; // instanceof check provided by superclass
050:
051: if (!(tkey.getValue() instanceof Integer)) {
052:
053: return getCorrectObject(tkey.getValue()).setIdentity(key);
054: }
055:
056: // potentially pretend to wait and potentally behave as not found.
057: if (!dummySet(tkey))
058: return null;
059: keyValue = tkey;
060:
061: return this ;
062: }
063:
064: /**
065: @exception StandardException Standard Derby Error policy
066: */
067: public Cacheable createIdentity(Object key, Object createParameter)
068: throws StandardException {
069: super .createIdentity(key, createParameter);
070:
071: T_Key tkey = (T_Key) key; // instanceof check provided by superclass
072:
073: if (!(tkey.getValue() instanceof Integer)) {
074:
075: return getCorrectObject(tkey.getValue()).createIdentity(
076: key, createParameter);
077: }
078:
079: // potentially pretend to wait and potentally behave as not found.
080: if (!dummySet(tkey))
081: return null;
082:
083: keyValue = tkey;
084:
085: return this ;
086: }
087:
088: /**
089: Put the object into the No Identity state.
090:
091: <BR> MT - single thread required - Method must only be called be cache manager
092: and the cache manager will guarantee only one thread can be calling it.
093:
094: */
095: public void clearIdentity() {
096: keyValue = null;
097: }
098:
099: /**
100: Get the identity of this object.
101:
102: <BR> MT - thread safe.
103:
104: */
105: public Object getIdentity() {
106: return keyValue;
107: }
108:
109: /**
110: @exception StandardException Standard Derby Error policy
111: */
112: public void clean(boolean forRemove) throws StandardException {
113: super.clean(forRemove);
114: }
115: }
|