[Home] DMelt member access. Java source code: org.neodatis.odb.impl.core.transaction.CrossSessionCache
/**
NeoDatis ODB : Native Object Database (odb.info@neodatis.org)
Copyright (C) 2007 NeoDatis Inc. http://www.neodatis.org
"This file is part of the NeoDatis ODB open source object database".
NeoDatis ODB is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
NeoDatis ODB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Contributors: Marcelo Mayworm - initial API and implementation
*/
package org.neodatis.odb.impl.core.transaction;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
import org.neodatis.odb.ODBRuntimeException;
import org.neodatis.odb.OID;
import org.neodatis.odb.core.NeoDatisError;
import org.neodatis.odb.core.transaction.ICrossSessionCache;
import org.neodatis.tool.wrappers.map.OdbHashMap;
/**
* A cache that survives the sessions. It is uses to automatically reconnect
* object to sessions
*
*
* When active, the cross session cache keeps track of all objects and their OID. It contains a map<Object,OID>.
* When objects are stored or deleted in NeoDatis, if cross session cache is on, NeoDatis check if the object is in the cross session cache
* If it is, the object is then added to the session cache (this is the reconnection).
*
* When an object is deleted from the database, the object is also removed from the cross session cache. When the deleted is done by OID, it is not
* immediately deleted, instead, it is inserted in a map of deleted object (as it would be very expensive to iterate throw all oids to find the right one.
*
* Issues:
*
* 1) when deleting object using cross session cache : as the cross session cache is static, it is not session dependent, when deleting an object
* from the cross session cache, it will be seen as deleted by all the transactions even before committed. This is bad.
*
* 2) as cross session cache is static, the following case can happen:
* - create a NeoDatis database test1.neodatis. Create an object o1 and it. delete the database. re-create the database with the same name and store the o1 object.
* as o1 is the cross session cache, NeoDatis will try to reconnect the object and will fail as the OID won't exist.
* see for more details
*
*
*
* @author mayworm,olivier
* @sharpen.ignore
*
*/
public class CrossSessionCache implements ICrossSessionCache {
/**
* The cache for NeoDatis OID. This cache supports a weak reference and it
* is sync
*/
private Map