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

import org.bodington.server.*;
import org.bodington.sqldatabase.*;
import org.bodington.database.*;



/**
 * This class is used to represent substantial blocks of text.
 * Used with a caching regime with can lead to good memory
 * mangement.  A class that otherwise would take up a lot of
 * memory can be allowed to stay in the cache longer if the
 * associated text can be ditched from the cache sooner.
 * E.g. the text of messages can be separated from an index
 * of messages containing authors, date of posting etc.
 * 
 * @author Jon Maber
 * @version 1.0
 */
public class BigString extends org.bodington.sqldatabase.SqlPersistentObject
	{
	private PrimaryKey big_string_id;
	private String string="";
	
	public static BigString findBigString( PrimaryKey key )
	    throws BuildingServerException
	    {
	    return (BigString)findPersistentObject( key, "org.bodington.text.BigString" );
	    }
	
    public PrimaryKey getPrimaryKey()
	    {
        return getBigStringId();
    	}

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

	public PrimaryKey getBigStringId()
		{
		return big_string_id;
		}
		
	public void setBigStringId( PrimaryKey key )
		{
		big_string_id = key;
		}
		
	public String getString()
		{
		return string;
		}

	public void setString( String m )
		{
		string = m;
		
		// This modification is to help cope with the idiosyncracy of Oracle
		// which treats zero length strings as null.  This ensures that the
		// BigString object never returns a null from getString() even if we
		// have to allow nulls in the database.
		if ( string == null )
			string = "";
		}
		
	public String toString()
		{
		return getString();
		}
	}
