IsolatorContext.java

package org.microspace.table;

import org.microspace.specific.CurrentTimeProvider;
import org.microspace.table.column.Accessor;
import org.microspace.table.column.IndexedSet;

/**
 * IsolatorContext can be used to create threads within threads and having another transaction.
 * 
 * @author Gaspar Sinai - {@literal gaspar.sinai@microspace.org}
 * @version 2016-06-26
 * @param <T> is the Table type.
 */
public class IsolatorContext<T> {

	Isolator<T> isolator;
	IndexedSet<Object> lockedKeys;
	final Accessor<T> accessor;
	final CurrentTimeProvider timeProvider;
	
	public IsolatorContext (Accessor<T> accessor, CurrentTimeProvider timeProvider) {
		this.accessor = accessor;
		this.timeProvider = timeProvider;
		this.isolator = new Isolator<T> (accessor, timeProvider);
		this.lockedKeys = new IndexedSet<Object> (accessor.getPrimaryKeyGetSetPair().getIndexType());
	}
	
	public void clear() {
		isolator = new Isolator<T> (accessor, timeProvider);
		lockedKeys = new IndexedSet<Object> (accessor.getPrimaryKeyGetSetPair().getIndexType());
	}
	
	public Isolator<T> getIsolator() {
		return isolator;
	}

	public IndexedSet<Object> getLockedKeys() {
		return lockedKeys;
	}

}