/*
* PermissoesDataAuto.java
*
* Generated by com.evutils.codegen.JDOObjectGenerator
*
* Use but DON'T TOUCH
*/
package com.evolute.siprp.server.db.data.siprp;

import com.evolute.utils.jdo.*;
import java.util.HashMap;
import java.util.Map;

class PermissoesDataAuto extends JDOObject
{

	public static final String TABLENAME = "permissoes";

	public static final String ID = "id";
	public static final String ID_FULL = "permissoes.id";
	public static final String USER_ID = "user_id";
	public static final String USER_ID_FULL = "permissoes.user_id";
	public static final String TO_USER_ID = "to user_id";
	public static final String CODIGO_PERMISSAO = "codigo_permissao";
	public static final String CODIGO_PERMISSAO_FULL = "permissoes.codigo_permissao";

	public static final String FIELD_NAMES[] = new String[]{
		USER_ID, TO_USER_ID, CODIGO_PERMISSAO, };


	protected static final String ALL_FIELD_NAMES[] = new String[]{
		ID, USER_ID, CODIGO_PERMISSAO, };

	private Map<String, Object> dataHash;

	public PermissoesDataAuto()
	{
		dataHash = new HashMap<String, Object>();
	}

	public Integer getId()
	{
		return (Integer) get(ID);
	}

	public void setId(Integer idValue )
	{
		this.set(ID, idValue );
	}

	public Integer getUser_id()
	{
		return (Integer) dataHash.get(USER_ID);
	}

	public void setUser_id(Integer user_idValue )
	{
		dataHash.put(TO_USER_ID, null);
		dataHash.put(USER_ID, user_idValue );
	}

	public com.evolute.siprp.server.db.data.siprp.UtilizadoresData toUser_id()
		throws Exception
	{
		if( dataHash.get(TO_USER_ID) == null && getUser_id() != null )
		{
			dataHash.put(TO_USER_ID, getJDOProvider().load(com.evolute.siprp.server.db.data.siprp.UtilizadoresData.class, new Object[]{ getUser_id() }, new String[]{ com.evolute.siprp.server.db.data.siprp.UtilizadoresData.ID }));
		}
		return (com.evolute.siprp.server.db.data.siprp.UtilizadoresData) dataHash.get(TO_USER_ID);
	}

	public void setToUser_id(com.evolute.siprp.server.db.data.siprp.UtilizadoresData user_idObject )
	{
		if( user_idObject == null )
		{
			dataHash.put(USER_ID, null);
		}
		else
		{
			dataHash.put(USER_ID, user_idObject.get( com.evolute.siprp.server.db.data.siprp.UtilizadoresData.ID ));
		}
		dataHash.put(TO_USER_ID, user_idObject);
	}

	public Integer getCodigo_permissao()
	{
		return (Integer) get(CODIGO_PERMISSAO);
	}

	public void setCodigo_permissao(Integer codigo_permissaoValue )
	{
		this.set(CODIGO_PERMISSAO, codigo_permissaoValue );
	}

	protected Object innerGet( String fieldName )
		throws Exception
	{
		Object value = null;
		if( USER_ID.equals( fieldName ) )
		{
			value =  getUser_id();
		}
		else if( TO_USER_ID.equals( fieldName ) )
		{
			value =  toUser_id();
		}
		else
		{
			value =  dataHash.get( fieldName );
		}
		return value;
	}

	protected void innerSet( String fieldName, Object value )
		throws Exception
	{
		if( USER_ID.equals( fieldName ) )
		{
			setUser_id( (Integer) value );
		}
		else if( TO_USER_ID.equals( fieldName ) )
		{
			setToUser_id( (com.evolute.siprp.server.db.data.siprp.UtilizadoresData) value );
		}
		else
		{
			dataHash.put( fieldName, value );
		}
	}

	public void save()
		throws Exception
	{
		if( dataHash.get(TO_USER_ID) != null )
		{
			toUser_id().save();
			dataHash.put(USER_ID, toUser_id().get( com.evolute.siprp.server.db.data.siprp.UtilizadoresData.ID ));
		}

		super.save();
	}

	public String []getFieldNames()
	{
		return FIELD_NAMES;
	}

	protected String []getAllFieldNames()
	{
		return ALL_FIELD_NAMES;
	}

	public Class<Permissoes> getInnerClass()
	{
		return Permissoes.class;
	}

	public Integer getJDOPrimaryKey()
	{
		Object obj = this.getId();
		if(obj instanceof JDOObject){
			 obj = ((JDOObject) obj).getInnerObject();
		}
		return (Integer) obj;
	}
}
