Serial Module

Serial Module

The Serial Module creates 1-tier, implementations of the JBeans Session and Home interfaces that persist down to serialized files. The Serial Home and Session classes extend the Memory classes. The In-Memory Home and Session classes provide the findBy and countBy functionality.

Serial implementations are useful to create data access to small databases containing only a few thousand beans. These can be used for long term caches or demos of software; where a database is too heavy weight.

The Serial files are stored in a directory structure that reflects the database:-

+ root directory
     + database directory
           + pk file
           + table directory
               + bean file

The root directory defaults to the /tmp directory but can be overriden with the property: -

"serial.rootpath" being set in the ContextProperties property at run time. For example:

FurnitureContext.getDefault().getContextProperties().put( "serial.rootpath", "/tmp" );

This can also be set in the properties file as: -

SerialContextProperties.code.0=getDefault().getContextProperties().put( "serial.rootpath", "/tmp" );

The database directory is named after the database source name.

The table directory is named after the table.

The bean file is named after the primary key (e.g. 1).

The database directory contains files called <ClassName>.pky that hold a single number representing the next pk to be allocated. The PK values are picked up from this file, otherwise a function checks the directory for the highest PK value.

The Serial Module contains the following classes:-

  • com.javelin.generator.Serial.SerialSessionClassWriter
  • com.javelin.generator.Serial.SerialHomeClassWriter
  • com.javelin.generator.Serial.SerialContextPropertiesWriter

In order to use the Serial module you need to include the following writer:-

$GENERATOR.AggregateWriter Serial

Class Hierarchy

The top-level ServiceWriter class hierarchy is illustrated below: -

Serial Properties

The Serial Home class path name

 

Abstract Serial Writer (com.javelin.generator.Serial.AbstractSerialWriter)

The AbstractSerialWriter is a super class that all Serial writers extend.

The AbstractSerialWriter has the following methods: -

  • public String getSerialHomeClassName()
  • public String getSerialSessionClassName()
  • public String getContextPropertiesClassName()

Serial Session Class Writer (com.javelin.generator.Serial.SerialSessionClassWriter)

The Serial Session Class Writer creates in-Serial BeanSessions.

The Sessions are created in the Serial package, with the name pattern: -

Serial<ClassName>Session

SerialSessions are responsible for persisting dependent graphs of Beans. SerialSessions defer loading, finding and counting beans to the SerialHome classes.

There is (currently) no transactional functionality in the SerialSessions.

By default the classes generated have the name and pattern: -

$SerialSESSION=public class $PACKAGE.Serial.$THIS extends $BEANS.SerialSession implements $PACKAGE

Serial Home Class Writer (com.javelin.generator.Serial.SerialHomeClassWriter)

The Serial Home Class Writer creates in-Serial BeanHomes.

The Homes are created in the Serial package, with the name pattern: -

Serial<ClassName>Home

SerialHomes are responsible for persisting, loading, finding and counting individual Beans.

By default the classes generated have the name and pattern: -

$SerialHOME=public class $PACKAGE.Serial.$THIS extends $BEANS.Serial.SerialHome implements $PACKAGE

Serial Context Properties Writer (com.javelin.generator.Serial.SerialContextPropertiesWriter)

The Serial Context Properties Writer creates a Context Properties file in the Serial package, with the name: -

SerialContextProperties

The SerialContextProperties class is responsible for binding the JBeans interface names to implementations. The binding patterns are as follows: -

<packageName>.<ClassName>=<packageName>.<ClassName>

<packageName>.<ClassName>=<packageName>.Lazy<ClassName>
<packageName>.<ClassName>Session=<packageName>.Serial.Serial<ClassName>Session
<packageName>.<ClassName>Home=<packageName>.Serial.Serial<ClassName>Home
<packageName>.<ClassName>Validator =<packageName>.<ClassName>Validator

To override the bindings in the Serial properties class do the following: -

<ClassName>.Serial.Object=<fully qualified class name>

<ClassName>.Serial.Bean=<fully qualified class name>
<ClassName>.Serial.Session=<fully qualified class name>
<ClassName>.Serial.Home=<fully qualified class name>
<ClassName>.Serial.Validator=<fully qualified class name>