package siprp.database.cayenne.providers;

import org.apache.cayenne.access.DataContext;

import siprp.database.cayenne.objects.BaseObject;

public class MainDAO
{
	protected static DataContext context = null;
	
	public MainDAO()
	{
		if( context == null )
		{
			context = DataContext.createDataContext();
		}
	}
	
	public void commit()
	{
		context.commitChanges();
	}
	
	public void rollback()
	{
		context.rollbackChanges();
		context.unregisterObjects( context.uncommittedObjects() );
	}
	
	public DataContext getContext()
	{
		return context;
	}

	public boolean hasOrder( BaseObject baseObject )
	{
		if( baseObject == null || baseObject.getObjEntity() == null )
		{
			return false;
		}
		else
		{
			return baseObject == null ? false : ( null != baseObject.getObjEntity().getAttribute( "ordem" ) || null != baseObject.getObjEntity().getAttribute( "order" ));
		}
	}
	
}
