/* ======================================================================
   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.util.Enumeration;

import org.bodington.sqldatabase.*;
import org.bodington.database.*;
import org.bodington.server.BuildingServerException;
import org.bodington.text.BigString;


public class TextQResponse extends org.bodington.sqldatabase.SqlPersistentObject
	{
	private PrimaryKey textq_response_id;
	private PrimaryKey textq_result_id;
	private PrimaryKey text_question_id;
	private PrimaryKey response_big_string_id;
	private PrimaryKey feedback_big_string_id;
	private Integer mark;
	
	
	public static TextQResponse findTextQResponse( PrimaryKey key )
	    throws BuildingServerException
	    {
	    return (TextQResponse)findPersistentObject( key, "org.bodington.server.assessment.TextQResponse" );
	    }
	
	public static TextQResponse findTextQResponse( String where )
	    throws BuildingServerException
	    {
	    return (TextQResponse)findPersistentObject( where, "org.bodington.assessment.TextQResponse" );
	    }
	
	public static Enumeration findTextQResponses( String where )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, "org.bodington.assessment.TextQResponse" );
	    }
	
	public static Enumeration findTextQResponses( String where, String order )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, order, "org.bodington.assessment.TextQResponse" );
	    }
	

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

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

	
	public PrimaryKey getTextQResponseId()
		{
		return textq_response_id;
		}
		
	public void setTextQResponseId( PrimaryKey id )
		{
		textq_response_id = id;
		}


	public PrimaryKey getTextQResultId()
		{
		return textq_result_id;
		}
		
	public void setTextQResultId( PrimaryKey id )
		{
		textq_result_id = id;
		}


	public PrimaryKey getTextQuestionId()
		{
		return text_question_id;
		}
		
	public void setTextQuestionId( PrimaryKey id )
		{
		text_question_id = id;
		}


	public PrimaryKey getResponseBigStringId()
		{
		return response_big_string_id;
		}
		
	public void setResponseBigStringId( PrimaryKey s )
		{
		response_big_string_id = s;
		setUnsaved();
		}
		
	public String getResponse()
		throws BuildingServerException
		{
		if ( response_big_string_id == null )
			return null;
		BigString bstr = BigString.findBigString( response_big_string_id );
		if ( bstr == null )
			return null;
		return bstr.getString();
		}
		
	public void setResponse( String s )
		throws BuildingServerException
		{
		BigString bstr=null;
		if ( response_big_string_id != null )
			bstr = BigString.findBigString( response_big_string_id );
		if ( bstr == null )
			{
			bstr = new BigString();
			bstr.setString( s );
			bstr.save();
			response_big_string_id = bstr.getBigStringId();
			setUnsaved();
			return;
			}

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

	public PrimaryKey getFeedbackBigStringId()
		{
		return feedback_big_string_id;
		}
		
	public void setFeedbackBigStringId( PrimaryKey s )
		{
		feedback_big_string_id = s;
		setUnsaved();
		}

	public String getFeedback()
		throws BuildingServerException
		{
		if ( feedback_big_string_id == null )
			return null;
		BigString bstr = BigString.findBigString( feedback_big_string_id );
		if ( bstr == null )
			return null;
		return bstr.getString();
		}
		
	public void setFeedback( String s )
		throws BuildingServerException
		{
		BigString bstr=null;
		if ( feedback_big_string_id != null )
			bstr = BigString.findBigString( feedback_big_string_id );
		if ( bstr == null )
			{
			bstr = new BigString();
			bstr.setString( s );
			bstr.save();
			feedback_big_string_id = bstr.getBigStringId();
			setUnsaved();
			return;
			}

		bstr.setString( s );
		bstr.save();
		}
	
		
		
	public Integer getMark()
		{
		return mark;
		}
		
	public void setMark( Integer i )
		{
		mark = i;
		setUnsaved();
		}
		
	}
