/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

package org.bodington.assessment;

import java.math.BigDecimal;
import java.util.Enumeration;
import org.bodington.server.*;
import org.bodington.sqldatabase.*;
import org.bodington.database.*;
import org.bodington.text.BigString;

public class PigeonHoleQuestion extends org.bodington.sqldatabase.SqlPersistentObject
	{
	private PrimaryKey pigeonhole_question_id;
	private PrimaryKey resource_id;
	private PrimaryKey notes_big_string_id;
	private int ordinal;
	private int available;
	private BigDecimal weight;
	
	

   	public static PigeonHoleQuestion findPigeonHoleQuestion( PrimaryKey key )
		throws BuildingServerException
		{
		return (PigeonHoleQuestion)findPersistentObject( key, "org.bodington.assessment.PigeonHoleQuestion" );
		}
	public static Enumeration findPigeonHoleQuestions( String where )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, "org.bodington.assessment.PigeonHoleQuestion" );
	    }
	public static Enumeration findPigeonHoleQuestions( String where, String order )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, order, "org.bodington.assessment.PigeonHoleQuestion" );
	    }


    public PrimaryKey getPrimaryKey()
    	{
        return getPigeonHoleQuestionId();
    	}

    public void setPrimaryKey(PrimaryKey key)
    	{
    	setPigeonHoleQuestionId( key );
    	}

	
	public PrimaryKey getPigeonHoleQuestionId()
		{
		return pigeonhole_question_id;
		}
		
	public void setPigeonHoleQuestionId( PrimaryKey id )
		{
		pigeonhole_question_id = id;
		}

		
	public PrimaryKey getResourceId()
		{
		return resource_id;
		}
		
	public void setResourceId( PrimaryKey id )
		{
		resource_id = id;
		setUnsaved();
		}


		
		
		
	public PrimaryKey getNotesBigStringId()
		{
		return notes_big_string_id;
		}

	public void setNotesBigStringId( PrimaryKey id )
		{
		notes_big_string_id = id;
		setUnsaved();
		}
		
		
	public String getNotes()
		throws BuildingServerException
		{
		if ( notes_big_string_id == null )
			return null;
		BigString bstr = BigString.findBigString( notes_big_string_id );
		if ( bstr == null )
			return null;
		return bstr.getString();
		}
		
	public void setNotes( String s )
		throws BuildingServerException
		{
		BigString bstr=null;
		if ( notes_big_string_id != null )
			bstr = BigString.findBigString( notes_big_string_id );
		if ( bstr == null )
			{
			bstr = new BigString();
			bstr.setString( s );
			bstr.save();
			notes_big_string_id = bstr.getBigStringId();
			setUnsaved();
			return;
			}

		bstr.setString( s );
		bstr.save();
		}
	
		

		
		
	public int getOrdinal()
		{
		return ordinal;
		}
		
	public void setOrdinal( int o )
		{
		if ( o==ordinal )
			return;
		ordinal = o;
		setUnsaved();
		}
		
		
	public int getAvailable()
		{
		return available;
		}
		
	public void setAvailable( int o )
		{
		if ( o==available )
			return;
		available = o;
		setUnsaved();
		}
		
		
	public BigDecimal getWeight()
		{
		return weight;
		}
		
	public void setWeight( BigDecimal w )
		{
		if ( weight==null && w == null )
			return;
		if ( weight!=null && w!=null && weight.equals(w) )
			return;
		weight = w;
		setUnsaved();
		}
		
	}
