net.sf.blunder.service.persistence
Class InMemoryPersistenceService

java.lang.Object
  extended by net.sf.blunder.service.persistence.InMemoryPersistenceService
All Implemented Interfaces:
BlunderPersistenceService
Direct Known Subclasses:
BlunderBinaryService, BlunderOpenCsvService

public abstract class InMemoryPersistenceService
extends Object
implements BlunderPersistenceService

This class provides a basic implementation for in-memory persistent services. All implementations based on files or other could extend from this class instead of extending from BlunderPersistenceService.

Author:
Ambrosi Lucas
See Also:
BlunderPersistenceService

Constructor Summary
InMemoryPersistenceService()
           
 
Method Summary
 void delete(ExceptionRelation er)
          Deletes a new ExceptionRelation.
 List<ExceptionRelation> findBy(String leafClassname, String rootClassname, String businessClassname)
          Finds an ExceptionRelation for the following arguments.
 List<ExceptionRelation> findByBusiness(String businessClassname)
          Finds an ExceptionRelation for the following arguments.
 List<ExceptionRelation> findByLeaf(String leafClassname)
          Finds an ExceptionRelation for the following arguments.
 List<ExceptionRelation> findByLeafAndBusiness(String leafClassname, String businessClassname)
          Finds an ExceptionRelation for the following arguments.
 List<ExceptionRelation> findByLeafAndRoot(String leafClassname, String rootClassname)
          Finds an ExceptionRelation for the following arguments.
 List<ExceptionRelation> findByRoot(String rootClassname)
          Finds an ExceptionRelation for the following arguments.
 ExceptionRelation findDefaultRelation()
           
 HashMap<Long,ExceptionRelation> getData()
           
protected  String getEmptyOrValueString(String value)
          Analize the value and returns it or an empty String if null.
 String getFilePath()
           
protected  InputStream getInputStream()
          This method gets a InputStream for the specified persitence data file.
protected  OutputStream getOutputStream()
          This method gets a OutputStream for the specified persitence data file.
protected  Reader getReader()
          This method gets a Reader for the specified persitence data file.
protected  Writer getWriter()
          This method gets a Writer for the specified persitence data file.
 void learn(ExceptionRelation er)
          Learns a new ExceptionRelation.
abstract  HashMap<Long,ExceptionRelation> readData()
          Your implementation should write this method.
 void refresh()
          Refresh the persistence service.
 void setData(HashMap<Long,ExceptionRelation> data)
          Sets the datamap with the relations.
 void setFilePath(String filePath)
          Sets the file path with the path to the datamap file.
 void update(ExceptionRelation er)
          Updates a known ExceptionRelation.
abstract  void writeData()
          Your implementation should write this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryPersistenceService

public InMemoryPersistenceService()
Method Detail

getEmptyOrValueString

protected String getEmptyOrValueString(String value)
Analize the value and returns it or an empty String if null.

Parameters:
value -
Returns:
the value or an empty String.

findBy

public List<ExceptionRelation> findBy(String leafClassname,
                                      String rootClassname,
                                      String businessClassname)
Description copied from interface: BlunderPersistenceService
Finds an ExceptionRelation for the following arguments.

Specified by:
findBy in interface BlunderPersistenceService
Parameters:
leafClassname - class name of the highest level Exception in the chain.
rootClassname - class name of the lowest level Exception in the chain.
businessClassname - class name of the business Exception in the chain.
Returns:
a List of ExceptionRelation with all relations that matches with the previous parameters.
See Also:
BlunderPersistenceService.findBy(String, String, String)

findByBusiness

public List<ExceptionRelation> findByBusiness(String businessClassname)
Description copied from interface: BlunderPersistenceService
Finds an ExceptionRelation for the following arguments.

Specified by:
findByBusiness in interface BlunderPersistenceService
Parameters:
businessClassname - class name of the business Exception in the chain.
Returns:
a List of ExceptionRelation with all relations that matches with the previous parameters.
See Also:
BlunderPersistenceService.findByBusiness(String)

findByLeaf

public List<ExceptionRelation> findByLeaf(String leafClassname)
Description copied from interface: BlunderPersistenceService
Finds an ExceptionRelation for the following arguments.

Specified by:
findByLeaf in interface BlunderPersistenceService
Parameters:
leafClassname - class name of the highest level Exception in the chain.
Returns:
a List of ExceptionRelation with all relations that matches with the previous parameters.
See Also:
BlunderPersistenceService.findByLeaf(String)

findByLeafAndBusiness

public List<ExceptionRelation> findByLeafAndBusiness(String leafClassname,
                                                     String businessClassname)
Description copied from interface: BlunderPersistenceService
Finds an ExceptionRelation for the following arguments.

Specified by:
findByLeafAndBusiness in interface BlunderPersistenceService
Parameters:
leafClassname - class name of the highest level Exception in the chain.
businessClassname - class name of the business Exception in the chain.
Returns:
a List of ExceptionRelation with all relations that matches with the previous parameters.
See Also:
BlunderPersistenceService.findByLeafAndBusiness(String,String)

findByLeafAndRoot

public List<ExceptionRelation> findByLeafAndRoot(String leafClassname,
                                                 String rootClassname)
Description copied from interface: BlunderPersistenceService
Finds an ExceptionRelation for the following arguments.

Specified by:
findByLeafAndRoot in interface BlunderPersistenceService
Parameters:
leafClassname - class name of the highest level Exception in the chain.
rootClassname - class name of the lowest level Exception in the chain.
Returns:
a List of ExceptionRelation with all relations that matches with the previous parameters.
See Also:
BlunderPersistenceService.findByLeafAndRoot(String,String)

findByRoot

public List<ExceptionRelation> findByRoot(String rootClassname)
Description copied from interface: BlunderPersistenceService
Finds an ExceptionRelation for the following arguments.

Specified by:
findByRoot in interface BlunderPersistenceService
Parameters:
rootClassname - class name of the lowest level Exception in the chain.
Returns:
a List of ExceptionRelation with all relations that matches with the previous parameters.
See Also:
BlunderPersistenceService.findByRoot(String)

findDefaultRelation

public ExceptionRelation findDefaultRelation()
Specified by:
findDefaultRelation in interface BlunderPersistenceService
Returns:
the default ExceptionRelation.
See Also:
BlunderPersistenceService.findDefaultRelation()

learn

public void learn(ExceptionRelation er)
Description copied from interface: BlunderPersistenceService
Learns a new ExceptionRelation.

Specified by:
learn in interface BlunderPersistenceService
Parameters:
er - the ExceptionRelation to learn.
See Also:
BlunderPersistenceService.learn(ExceptionRelation)

update

public void update(ExceptionRelation er)
Description copied from interface: BlunderPersistenceService
Updates a known ExceptionRelation.

Specified by:
update in interface BlunderPersistenceService
Parameters:
er - the ExceptionRelation to update.
See Also:
BlunderPersistenceService.update(ExceptionRelation)

delete

public void delete(ExceptionRelation er)
Description copied from interface: BlunderPersistenceService
Deletes a new ExceptionRelation.

Specified by:
delete in interface BlunderPersistenceService
Parameters:
er - the ExceptionRelation to delete.
See Also:
BlunderPersistenceService.delete(ExceptionRelation)

refresh

public void refresh()
Description copied from interface: BlunderPersistenceService
Refresh the persistence service. This should be used to clear all data in the local cache.

Specified by:
refresh in interface BlunderPersistenceService
See Also:
BlunderPersistenceService.refresh()

setData

public void setData(HashMap<Long,ExceptionRelation> data)
Sets the datamap with the relations.

Parameters:
data -

getData

public HashMap<Long,ExceptionRelation> getData()
Returns:
Gets the datamap with the relations.

getFilePath

public String getFilePath()
Returns:
Gets the file path with the path to the datamap file.

setFilePath

public void setFilePath(String filePath)
Sets the file path with the path to the datamap file.

Parameters:
filePath -

writeData

public abstract void writeData()
Your implementation should write this method. It is responsible for saving the data to the specified file.


readData

public abstract HashMap<Long,ExceptionRelation> readData()
Your implementation should write this method. It is responsible for reading the data to the specified file.


getReader

protected Reader getReader()
This method gets a Reader for the specified persitence data file.

Returns:
A Reader for the persistence data file.
Throws:
{@link - java.lang.NullPointerException} if the file can not be reached.

getWriter

protected Writer getWriter()
                    throws IOException
This method gets a Writer for the specified persitence data file.

Returns:
A Writer for the persistence data file.
Throws:
{@link - java.lang.NullPointerException} if the file can not be reached.
IOException

getInputStream

protected InputStream getInputStream()
This method gets a InputStream for the specified persitence data file.

Returns:
A InputStream for the persistence data file.
Throws:
{@link - java.lang.NullPointerException} if the file can not be reached.

getOutputStream

protected OutputStream getOutputStream()
                                throws FileNotFoundException
This method gets a OutputStream for the specified persitence data file.

Returns:
A OutputStream for the persistence data file.
Throws:
{@link - java.lang.NullPointerException} if the file can not be reached.
FileNotFoundException


Copyright © 2009 Blunder. All Rights Reserved.