Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.event.RemoteCommitEvent;
import org.apache.openjpa.event.RemoteCommitListener;
import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.lib.conf.Configurable;
import org.apache.openjpa.lib.conf.Configuration;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.StringUtil;
import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
import org.apache.openjpa.util.GeneralException;
/**
* Abstract {@link DataCache} implementation that provides various
* statistics, logging, and timeout functionality common across cache
* implementations.
*
* @author Patrick Linskey
* @author Abe White
*/
public abstract class AbstractDataCache extends AbstractConcurrentEventManager
implements DataCache, Configurable {
private static final long serialVersionUID = 1L;
protected CacheStatisticsSPI _stats = new CacheStatisticsImpl();
private static final BitSet EMPTY_BITSET = new BitSet(0);
private static final Localizer s_loc = Localizer.forPackage(AbstractDataCache.class);
/**
* The configuration set by the system.
*/
protected OpenJPAConfiguration conf;
/**
* The log to use.
*/
protected Log log;
private String _name = null;
private boolean _closed = false;
private String _schedule = null;
protected Set _includedTypes = new HashSet<>();
protected Set _excludedTypes = new HashSet<>();
protected boolean _evictOnBulkUpdate = true;
@Override
public String getName() {
return _name;
}
@Override
public void setName(String name) {
_name = name;
}
public void setEnableStatistics(boolean enable){
if(enable){
_stats.enable();
}
}
public void getEnableStatistics(){
_stats.isEnabled();
}
public String getEvictionSchedule() {
return _schedule;
}
public void setEvictionSchedule(String s) {
_schedule = s;
}
@Override
public void initialize(DataCacheManager manager) {
if (_schedule != null && !"".equals(_schedule)) {
ClearableScheduler scheduler = manager.getClearableScheduler();
if (scheduler != null)
scheduler.scheduleEviction(this, _schedule);
}
// Cast here rather than add to the interface because this is a hack to support an older way of configuring
if(manager instanceof DataCacheManagerImpl){
List invalidConfigured = new ArrayList<>();
// assert that things are configured properly
if(_includedTypes!=null){
for(String s : _includedTypes){
if(_excludedTypes.contains(s)){
invalidConfigured.add(s);
}
}
if (invalidConfigured.size() > 0) {
throw new GeneralException(s_loc.get("invalid-types-excluded-types", invalidConfigured.toString()));
}
}
((DataCacheManagerImpl)manager).setTypes(_includedTypes, _excludedTypes);
}
}
@Override
public void commit(Collection additions, Collection newUpdates,
Collection existingUpdates, Collection