/*
 * Copyright (C) 2004-2006  exedio GmbH (www.exedio.com)
 *
 * This library 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.
 *
 * This library 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.exedio.cope;

import java.util.Map;

final class Entity
{
	private final Transaction transaction;
	private State state;
	
	Entity( final Transaction transaction, final State state )
	{
		this.transaction = transaction;
		this.state = state;
	}
	
	Object get(final FunctionField attribute)
	{
		return state.get( attribute );
	}
	
	<E> void put(final FunctionField<E> attribute, final E value)
	{
		state = state.put( transaction, attribute, value );
	}
	
	@SuppressWarnings("unchecked") // TODO dont know how
	void put(final Map<Field, Object> attributeValues)
	{
		for(final Field attribute : attributeValues.keySet())
		{
			if(attribute instanceof FunctionField)
				put((FunctionField)attribute, attributeValues.get(attribute));
			else
				assert attribute instanceof DataField;
		}	
	}
	
	void write(final Map<BlobColumn, byte[]> blobs) throws UniqueViolationException
	{
		state = state.write(transaction, blobs);
	}
	
	void delete()
	{
		state = state.delete( transaction );
	}
	
	Item getItem()
	{
		return state.item;
	}
	
	boolean exists()
	{
		return state.exists();
	}
	
	@Override
	public String toString()
	{
		return "Entity["+(state==null?"no state":state.toString())+"]";
	}
}

@@ -1391,25 +1391,17 @@
 l Field 
-attribute
+f
  : attri
@@ -1431,25 +1431,17 @@
 %7B%0A%09%09%09if(
-attribute
+f
  instanc
@@ -1482,25 +1482,17 @@
 onField)
-attribute
+f
 , attrib
@@ -1505,25 +1505,17 @@
 ues.get(
-attribute
+f
 ));%0A%09%09%09e
@@ -1529,25 +1529,17 @@
 %09assert 
-attribute
+f
  instanc

rename attribute to field