/*
 * Created on 2004-5-29
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package workflow.store.spi;

import workflow.WorkflowException;
import workflow.services.WorkflowService;
import workflow.store.SchemaContext;

import com.zosatapo.commons.store.Store;

/**
 * @author Administrator
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public abstract class AbstractDatabase implements SpiDatabase
{
	protected Store storeConfig;
	protected SchemaContext schemaContext;
	protected WorkflowService workflowService;
	
	protected boolean opened=false;	
	protected int  referenceCount=0;
	
	protected AbstractDatabase()
	{
	}

	protected AbstractDatabase(Store storeConfig, SchemaContext schemaContext)
	{
		this.storeConfig = storeConfig;
		this.schemaContext = schemaContext;
	}

	public Store getStore()
	{
		return storeConfig;
	}

	public void setStore(Store storeConfig)
	{
		this.storeConfig = storeConfig;
	}

	public SchemaContext getSchemaContext()
	{
		return schemaContext;
	}

	public void setSchemaContext(SchemaContext schemaContext_)
	{
		this.schemaContext = schemaContext_;
	}

	public  WorkflowService      getWorkflowService()
	{
		return this.workflowService;
	}	
	
	public  void                 setWorkflowService(WorkflowService workflowService)
	{
		this.workflowService=workflowService;
	}


	public Object clone() throws CloneNotSupportedException
	{
		return super.clone();
	}

	synchronized public void start() throws WorkflowException
	{
		++referenceCount;
		
		if(opened)
		{
			return;
		}
		
		opened=true;
		
	}

	synchronized public void stop() throws WorkflowException
	{	
		--referenceCount;
		
		if(!opened || referenceCount>0)
		{
			return;
		}
		
		opened=false;
	}
}
