org.apache.openjpa.datacache.DataCache Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.datacache;
import java.util.BitSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.openjpa.lib.util.Clearable;
import org.apache.openjpa.lib.util.Closeable;
/**
* Interface that must be implemented by any level 2 cache used by
* OpenJPA. Most data caches will choose to implement the
* {@link org.apache.openjpa.lib.conf.Configurable} interface as well so that
* they will be given the system configuration just after construction.
* Implementations should take care not to return timed out data.
*
* @see AbstractDataCache
* @see DataCachePCData#isTimedOut
* @author Patrick Linskey
* @author Abe White
* @author Pinaki Poddar
*/
public interface DataCache
extends Closeable, Clearable {
/**
* The name of the default data cache: default
*/
String NAME_DEFAULT = "default";
/**
* Returns a string name that can be used by end-user-visible
* code to identify this cache.
*
* @since 0.2.5.0
*/
String getName();
/**
* Sets a string name to be used to identify this cache to end-user needs.
*
* @since 0.2.5.0
*/
void setName(String name);
/**
* Initialize any resources associated with the given
* {@link DataCacheManager}.
*/
void initialize(DataCacheManager manager);
/**
* Perform a batch update of the cache. Add all {@link DataCachePCData}
* objects in additions
and in
* newUpdates
, make the appropriate modifications to
* all DataCachePCDatas in existingUpdates
, and delete all
* OIDs in deletes
.
* All changes made to cached data must be made via this
* method. It is this method that is responsible for performing
* any side-effects that should happen on meaningful cache changes.
* Implementations should bear in mind that the
* deletes
collection may contain oids that are also
* in the additions
map. This is possible because it
* is valid for a user to delete an object with a particular oid
* and then add that object in the same batch.
*
* @param additions A collection of {@link DataCachePCData} objects.
* These represent data that have been newly created,
* and thus must be added to the cache.
* @param newUpdates A collection of {@link DataCachePCData} objects.
* These represent data that have been modified but
* were not originally in the cache, and thus must be added to the cache.
* @param existingUpdates A collection of {@link DataCachePCData} objects.
* These represent data that have been modified and
* were originally loaded from the cache. It is
* up to the cache implementation to decide if
* these values must be re-enlisted in the cache.
* Some caches may return live data from {@link #get}
* invocations, in which case these values need not be re-enlisted.
* @param deletes A collection of object IDs that have been deleted
* and must therefore be dropped from the cache.
*/
void commit(Collection additions, Collection newUpdates,
Collection existingUpdates, Collection