001    package org.apache.ojb.broker.cache;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import org.apache.ojb.broker.Identity;
019    
020    /**
021     * Internal used extension of the {@link ObjectCache}.
022     *
023     * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
024     * @version $Id: ObjectCacheInternal.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
025     */
026    public interface ObjectCacheInternal extends ObjectCache
027    {
028        /**
029         * Object was update or insert.
030         */
031        public static final int TYPE_WRITE = 5;
032        /**
033         * Object was read from a cache entity (e.g. from a second-level cache).
034         */
035        public static final int TYPE_CACHED_READ = 7;
036        /**
037         * Object was new materialized from persistence storage.
038         */
039        public static final int TYPE_NEW_MATERIALIZED = 11;
040        /**
041         * Object caching type was unkown.
042         */
043        public static final int TYPE_UNKNOWN = 0;
044        /**
045         * Object caching type used for temporary storage of objects,
046         * these objects will never be pushed to a higher level cache.
047         */
048        public static final int TYPE_TEMP = -1;
049    
050    
051        /**
052         * For internal use.
053         * This method have to be used by all OJB classes to cache objects.
054         * It allows to decide if an object should be cached or not. Useful
055         * for two level caches to reduce object copy costs.
056         */
057        public void doInternalCache(Identity oid, Object obj, int type);
058    
059        /**
060         * For internal use within <em>ObjectCache</em> implementations or to
061         * build two-level caches. Handle with care.
062         * <p>
063         * Used to cache new objects (not already cached) by it's
064         * {@link org.apache.ojb.broker.Identity}. This method was used to
065         * cache new materialized objects and should work as a "atomic" method
066         * (the check and the put of the object should be atomic) to avoid
067         * concurrency problems.
068         * </p>
069         * <p>
070         * Currently it's not mandatory that all <em>ObjectCache</em> implementations
071         * support this method, so in some cases it's allowed to delegate this
072         * method call to the standard {@link #cache(org.apache.ojb.broker.Identity, Object) cache}.
073         * </p>
074         *
075         * @param oid Identity of the object to cache.
076         * @param obj The object to cache.
077         * @return If object was added <em>true</em>, else <em>false</em>.
078         */
079        public boolean cacheIfNew(Identity oid, Object obj);
080    }