StoreDataAccesspublic class StoreDataAccess extends Object Title: Sams CD Rental Store
Description:
Copyright: Copyright (c) 2004
Company: |
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 void | dispose()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.StoreDataAccess | getInstance()
if ( theCollections == null )
{
theCollections = new StoreDataAccess();
}
return theCollections;
| public static com.samscdrental.dataaccess.StoreDataAccess | makeNew()
theCollections = new StoreDataAccess( true );
return theCollections;
|
|