/*
* Image.java
*
* Generated by com.evutils.codegen.EntityObjectGenerator
*
* Use but DON'T TOUCH
* -> (can't touch this)
*/
package siprp.data.inner;


public class Image extends siprp.data.BaseObject
{
	private static final java.util.HashMap<String,Integer> FIELD_INDEXES = new java.util.HashMap<String,Integer>();

	static
	{
		FIELD_INDEXES.put( Image.ID, Image.ID_INDEX );
		FIELD_INDEXES.put( Image.ID_FULL, Image.ID_INDEX );
		FIELD_INDEXES.put( Image.NAME, Image.NAME_INDEX );
		FIELD_INDEXES.put( Image.NAME_FULL, Image.NAME_INDEX );
		FIELD_INDEXES.put( Image.IMAGE_DATA, Image.IMAGE_DATA_INDEX );
		FIELD_INDEXES.put( Image.IMAGE_DATA_FULL, Image.IMAGE_DATA_INDEX );
	}

	private final java.util.HashMap< String, Boolean > LAZY_LOADED_OBJECTS = new java.util.HashMap< String, Boolean >();


	public static final String TABLENAME = "image";


	public static final String CLASS_IDENTIFIER = "image1277401737175";

	public static final int _INVALID__INDEX = -1;
	public static final String ID = "id";
	public static final String ID_FULL = "image.id";
	public static final int ID_INDEX = 0;
	public static final String NAME = "name";
	public static final String NAME_FULL = "image.name";
	public static final int NAME_INDEX = 1;
	public static final String IMAGE_DATA = "image_data";
	public static final String IMAGE_DATA_FULL = "image.image_data";
	public static final int IMAGE_DATA_INDEX = 2;

	public static final String FIELD_NAMES[] = new String[]{
		NAME, IMAGE_DATA, };

	public static final String FIELD_NAMES_FULL[] = new String[]{
		TABLENAME + "." + NAME, TABLENAME + "." + IMAGE_DATA, };

	protected static final String DB_FIELD_NAMES[] = new String[]{
		ID, NAME, IMAGE_DATA, };


	protected static final String PK_FIELD_NAMES[] = new String[]{
		ID, };


	public static final String DEFAULT_LOAD_SET[] = new String[] {
		ID, NAME, };

	private Integer id;
	private String name;
	private byte[] image_data;

	protected com.evolute.entity.utils.IntegerPrimaryKey primaryKey;

	public Image()
	{
		super();
		dirtyProperties = new boolean[]{ false, false, false };
	}

	public Integer getId()
	{
		try
		{
			setLastAccess( System.currentTimeMillis() );
			prepare( ID );
		}
		catch( java.lang.Exception ex )
		{
			throw new RuntimeException( ex );
		}
		return this.id;
	}

	public void setId( Integer id )
	{
		try
		{
			setLockedForRefresh( true );
			preProcess( ID, id );
		}
		catch( com.evolute.entity.evo.EvoDataException edex )
		{
			throw new RuntimeException( edex );
		}
		this.id = id;
		LAZY_LOADED_OBJECTS.put( ID, Boolean.TRUE );
	}

	public java.util.List<siprp.data.outer.EmpresasData>fromEmpresas_empresa_logo_id()
	{
		java.util.List<siprp.data.outer.EmpresasData> result = null;
		try
		{
			result = fromReference( siprp.data.outer.EmpresasData.class , getPrimaryKey().getMap().get("id"), "empresa_logo_id" );
		}
		catch( com.evolute.entity.evo.EvoDataException edex )
		{
			throw new RuntimeException( edex );
		}
		return result;
	}

	public java.util.List<siprp.data.outer.MarcacoesTecnicosHstData>fromMarcacoesTecnicosHst_assinatura()
	{
		java.util.List<siprp.data.outer.MarcacoesTecnicosHstData> result = null;
		try
		{
			result = fromReference( siprp.data.outer.MarcacoesTecnicosHstData.class , getPrimaryKey().getMap().get("id"), "assinatura" );
		}
		catch( com.evolute.entity.evo.EvoDataException edex )
		{
			throw new RuntimeException( edex );
		}
		return result;
	}

	public String getName()
	{
		try
		{
			setLastAccess( System.currentTimeMillis() );
			prepare( NAME );
		}
		catch( java.lang.Exception ex )
		{
			throw new RuntimeException( ex );
		}
		return this.name;
	}

	public void setName( String name )
	{
		try
		{
			setLockedForRefresh( true );
			preProcess( NAME, name );
		}
		catch( com.evolute.entity.evo.EvoDataException edex )
		{
			throw new RuntimeException( edex );
		}
		this.name = name;
		LAZY_LOADED_OBJECTS.put( NAME, Boolean.TRUE );
	}

	public byte[] getImage_data()
	{
		try
		{
			setLastAccess( System.currentTimeMillis() );
			prepare( IMAGE_DATA );
			Boolean isLazyLoaded = isPropertyLoaded( IMAGE_DATA );
			if ( ! isLazyLoaded )
			{
				this.image_data = ( byte[] ) getProvider().loadFieldFromDatabase( IMAGE_DATA, this );
				LAZY_LOADED_OBJECTS.put( IMAGE_DATA, Boolean.TRUE );
			}
		}
		catch( java.lang.Exception ex )
		{
			throw new RuntimeException( ex );
		}
		return this.image_data;
	}

	public void setImage_data( byte[] image_data )
	{
		try
		{
			setLockedForRefresh( true );
			preProcess( IMAGE_DATA, image_data );
		}
		catch( com.evolute.entity.evo.EvoDataException edex )
		{
			throw new RuntimeException( edex );
		}
		this.image_data = image_data;
		LAZY_LOADED_OBJECTS.put( IMAGE_DATA, Boolean.TRUE );
	}

	public Object get( String fieldName )
	{
		Object value = null;
		Integer index = getFieldIndex( fieldName );
		switch( index )
		{
			case Image.ID_INDEX:
				value = getId();
				break;
			case Image.NAME_INDEX:
				value = getName();
				break;
			case Image.IMAGE_DATA_INDEX:
				value = getImage_data();
				break;
		}
		return value;
	}

	public Object rawGet( String fieldName )
	{
		Object value = null;
		Integer index = getFieldIndex( fieldName );
		switch( index )
		{
			case Image.ID_INDEX:
				value = this.id;
				break;
			case Image.NAME_INDEX:
				value = this.name;
				break;
			case Image.IMAGE_DATA_INDEX:
				value = this.image_data;
				break;
		}
		return value;
	}

	public void set( String fieldName, Object value )
	{
		Integer index = getFieldIndex( fieldName );
		switch( index )
		{
			case Image.ID_INDEX:
				setId( ( Integer ) value );
				break;
			case Image.NAME_INDEX:
				setName( ( String ) value );
				break;
			case Image.IMAGE_DATA_INDEX:
				setImage_data( ( byte[] ) value );
				break;
		}
	}

	public void rawSet( String fieldName, Object value )
	{
		Integer index = getFieldIndex( fieldName );
		switch( index )
		{
			case Image.ID_INDEX:
				this.id = ( Integer ) value;
				break;
			case Image.NAME_INDEX:
				this.name = ( String ) value;
				break;
			case Image.IMAGE_DATA_INDEX:
				this.image_data = ( byte[] ) value;
				break;
		}
	}

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

	public String []getFieldNamesFull()
	{
		return FIELD_NAMES_FULL;
	}

	public String []getDBFieldNames()
	{
		return DB_FIELD_NAMES;
	}

	public String []getPrimaryKeyNames()
	{
		return PK_FIELD_NAMES;
	}

	public String []getDefaultLoadSet()
	{
		return DEFAULT_LOAD_SET;
	}

	public String getPrimaryKeyName()
	{
		return PK_FIELD_NAMES[ 0 ];
	}

	public Class<?> getFieldClass( String fieldName )
	{
		Integer index = getFieldIndex( fieldName );
		Class<?> theClass = null;
		switch( index )
		{
			case Image.ID_INDEX:
				theClass = Integer.class;
				break;
			case Image.NAME_INDEX:
				theClass = String.class;
				break;
			case Image.IMAGE_DATA_INDEX:
				theClass = byte[].class;
				break;
		}
		return theClass;
	}

	public Integer getFieldIndex( String fieldName )
	{
		Integer index = FIELD_INDEXES.get( fieldName );
		return index != null ? index : Image._INVALID__INDEX;
	}

	public String getTableName()
	{
		return TABLENAME;
	}

	public String getClassIdentifier()
	{
		return CLASS_IDENTIFIER;
	}

	@Override
	protected void setPrimaryKeyFromVirtual2DArray( com.evolute.utils.arrays.Virtual2DArray array, int row, int col )
	{
		if( primaryKey == null )
		{
			primaryKey = new com.evolute.entity.utils.IntegerPrimaryKey( TABLENAME, Image.PK_FIELD_NAMES );
			primaryKey.set( 0, ( Integer ) array.get( row, col + 0 ) );
		}
		setId( ( Integer ) array.get( row, col + 0 ) );
	}

	@Override
	public com.evolute.entity.utils.IntegerPrimaryKey getPrimaryKey()
	{
		return primaryKey;
	}

	public void initLazyLoadFields()
	{
		LAZY_LOADED_OBJECTS.put( IMAGE_DATA, Boolean.FALSE );
	}

	public boolean isPropertyLoaded( String fieldName )
	{
		if ( LAZY_LOADED_OBJECTS.get( fieldName ) == null )
		{
			return true;
		}
		else
		{
			return LAZY_LOADED_OBJECTS.get( fieldName );
		}
	}
}
