FileDocCategorySizeDatePackage
StoreDataAccess.javaAPI DocExample3823Wed May 04 06:18:30 BST 2005com.samscdrental.dataaccess

StoreDataAccess

public class StoreDataAccess extends Object

Title: Sams CD Rental Store

Description:

Copyright: Copyright (c) 2004

Company:

author
Ken Pugh
version
1.0

Fields Summary
public CDDiscDataAccess
theCDDiscDataAccess
public CustomerDataAccess
theCustomerDataAccess
public CDReleaseDataAccess
theCDReleaseDataAccess
private static StoreDataAccess
theCollections
private static final String
ERROR_OPENING_FILE
private static final String
ERROR_CREATING_OBJECT_STREAM
private static final String
ERROR_STREAM_NOT_CLOSED
private static String
DATA_FILENAME
Constructors Summary
private StoreDataAccess(boolean other)

		Configuration configuration = Configuration.getInstance();
		DataAccessConfiguration dac = configuration.getDataAccessConfiguration();
		DATA_FILENAME = dac.dataFilename;
		theCDDiscDataAccess = new CDDiscDataAccess();
		theCustomerDataAccess = new CustomerDataAccess();
		theCDReleaseDataAccess = new CDReleaseDataAccess();
	
private StoreDataAccess()


		Configuration configuration = Configuration.getInstance();
		DataAccessConfiguration dac = configuration.getDataAccessConfiguration();
		DATA_FILENAME = dac.dataFilename;
		// Read the serialized file
		FileInputStream fileinput = null;
		ObjectInputStream input = null;
		try
		{
			fileinput = new FileInputStream( DATA_FILENAME );
			input = new ObjectInputStream( fileinput );
		}
		catch ( FileNotFoundException exception )
		{
			throw new SeriousErrorException(
				ERROR_OPENING_FILE + DATA_FILENAME, exception );
		}
		catch ( IOException exception )
		{
			throw new SeriousErrorException(
				ERROR_CREATING_OBJECT_STREAM + DATA_FILENAME, exception );

		}

		theCDDiscDataAccess =
			( CDDiscDataAccess ) DataAccessHelper.readObjectFromOpenStream(
			theCDDiscDataAccess.getClass(), input );
		theCustomerDataAccess =
			( CustomerDataAccess ) DataAccessHelper.
			readObjectFromOpenStream(
			theCustomerDataAccess.getClass(), input );
		theCDReleaseDataAccess =
			( CDReleaseDataAccess ) DataAccessHelper.
			readObjectFromOpenStream(
			theCDReleaseDataAccess.getClass(), input );

		try
		{
			input.close();
		}
		catch ( IOException exception )
		{
			throw new SeriousErrorException(
				ERROR_STREAM_NOT_CLOSED + DATA_FILENAME, exception );
		}
	
Methods Summary
public voiddispose()
dispose

		try
		{
			FileOutputStream fileoutput = new FileOutputStream(
				DATA_FILENAME );
			ObjectOutputStream output = new ObjectOutputStream( fileoutput );
			DataAccessHelper.writeObjectToOpenStream(
				theCDDiscDataAccess, output );
			DataAccessHelper.writeObjectToOpenStream(
				theCustomerDataAccess, output );
			DataAccessHelper.writeObjectToOpenStream(
				theCDReleaseDataAccess, output );
			output.close();
		}
		catch ( FileNotFoundException exception )
		{
			throw new SeriousErrorException(
				ERROR_OPENING_FILE + DATA_FILENAME, exception );
		}
		catch ( IOException exception )
		{
			throw new SeriousErrorException(
				ERROR_CREATING_OBJECT_STREAM + DATA_FILENAME, exception );
		}

	
public static com.samscdrental.dataaccess.StoreDataAccessgetInstance()

	   
	
		if ( theCollections == null )
		{
			theCollections = new StoreDataAccess();
		}
		return theCollections;
	
public static com.samscdrental.dataaccess.StoreDataAccessmakeNew()

		theCollections = new StoreDataAccess( true );

		return theCollections;