net.sf.jaxme.js.pattern
Class VersionGenerator

java.lang.Object
  extended bynet.sf.jaxme.js.pattern.VersionGenerator

public class VersionGenerator
extends java.lang.Object

The VersionGenerator is able to clone a version of a row in a database. That is nothing special. A simple INSERT does the same.

The difference is that the VersionGenerator is able to clone rows in other tables referencing the cloned table as well, updating the references, and clone and update rows referencing these cloned and updated rows, and so on.

In other words: The VersionGenerator derives a new version of a complex object stored in the database.

The VersionGenerator operates on a list of tables. This list must not contain forward or self references. In other words: Under no circumstances may a table in the list contain a foreign key referencing another table, which follows later.

Author:
Jochen Wiedmann

Nested Class Summary
static interface VersionGenerator.ColumnUpdater
          The ColumnUpdater is able to update one or more columns in a table.
static class VersionGenerator.TableInfo
          This class is used internally to maintain the informations on the tables being cloned.
 
Constructor Summary
VersionGenerator()
           
 
Method Summary
 void addTable(Table pTable, VersionGenerator.ColumnUpdater pUpdater)
          Adds a new table to the list of tables.
protected  void getApplyCacheData(JavaMethod pMethod, VersionGenerator.TableInfo pTableInfo, ColumnSet pColumnSet, DirectAccessible pRow, DirectAccessible pData)
          Updates a row by reading the values from an instance of the inner class CacheData.
protected  JavaInnerClass getCacheDataClass(JavaSource pSource)
          Generates the innner class CacheData.
protected  LocalJavaField getCacheDataClassInstance(JavaMethod pMethod, VersionGenerator.TableInfo pTableInfo, ColumnSet pColumnSet, DirectAccessible pValues)
          Creates an instance of the inner class CacheData by reading the key from the given row.
protected  JavaQName getCacheDataClassName(JavaQName pQName)
          Returns the name of the inner class CacheData.
 JavaMethod getCloneMethod(JavaSource pSource)
          Creates a method for updating one row in the head table.
protected  JavaMethod getInnerInsertRowMethod(JavaSource pSource, VersionGenerator.TableInfo pTableInfo)
          Creates a method for cloning one row from the given table.
protected  JavaMethod getInsertRowMethod(JavaSource pSource, VersionGenerator.TableInfo pTableInfo)
          Creates a method for cloning one row from the given table.
protected  java.lang.String getInsertRowMethodName(VersionGenerator.TableInfo pTableInfo)
          Returns the name of the method for cloning one row from the given table.
protected  JavaMethod getPublicCloneMethod(JavaSource pSource)
          Actually creates the public "clone" method.
protected  void getSelectRowsCode(JavaMethod pMethod, VersionGenerator.TableInfo pTableInfo, ColumnSet pColumnSet, DirectAccessible pConn, DirectAccessible pMap, DirectAccessible pValues, boolean pReturnValue)
          Generates code for reading all rows matching the given key.
protected  void initLogging(JavaSource pSource)
          Creates the code for initialization of the logging framework.
 boolean isGeneratingLogging()
          Returns whether the generator is creating logging statements.
protected  void logEntering(JavaMethod pMethod, java.lang.Object pValues)
          Creates code for logging the entrance into a method with fine level.
protected  void logExiting(JavaMethod pMethod, java.lang.Object pValues)
          Creates code for logging the exit from a method with fine level.
protected  void logFinest(JavaMethod pMethod, java.lang.Object pMsg, java.lang.Object pValues)
          Creates code for logging a message with finest level.
protected  void logFinestEntering(JavaMethod pMethod, java.lang.Object pValues)
          Creates code for logging the entrance into a method with finest level.
protected  void logFinestExiting(JavaMethod pMethod, java.lang.Object pValues)
          Creates code for logging the exit from a method with fine level.
 void setGeneratingLogging(boolean pGeneratingLogging)
          Sets whether the generator is creating logging statements.
protected  void setPreparedStatementValue(JavaMethod pMethod, Column pColumn, java.lang.Object pStmt, java.lang.Object pParamNum, java.lang.Object pValue)
          Generates code for setting a PreparedStatement's parameter.
protected  void setResultSetValue(JavaMethod pMethod, Column pColumn, DirectAccessible pResultSet, int pColumnNum, java.lang.Object pTarget)
          Generates code for reading a ResultSet's column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersionGenerator

public VersionGenerator()
Method Detail

isGeneratingLogging

public boolean isGeneratingLogging()

Returns whether the generator is creating logging statements. By default no logging statements are created.

The default implementation creates logging statements suitable for the JaxMe logging package. To change this, create a subclass and overwrite the following methods: logEntering(JavaMethod, Object), logExiting(JavaMethod, Object), logFinest(JavaMethod, Object, Object), logFinestEntering(JavaMethod, Object), and logFinestExiting(JavaMethod, Object).

See Also:
setGeneratingLogging(boolean)

setGeneratingLogging

public void setGeneratingLogging(boolean pGeneratingLogging)

Sets whether the generator is creating logging statements. By default no logging statements are created.

The default implementation creates logging statements suitable for the JaxMe logging package. To change this, create a subclass and overwrite the following methods: logEntering(JavaMethod, Object), logExiting(JavaMethod, Object), logFinest(JavaMethod, Object, Object), logFinestEntering(JavaMethod, Object), and logFinestExiting(JavaMethod, Object).

See Also:
isGeneratingLogging()

initLogging

protected void initLogging(JavaSource pSource)

Creates the code for initialization of the logging framework. The default implementation generates code creating an instance of Logger.


logEntering

protected void logEntering(JavaMethod pMethod,
                           java.lang.Object pValues)

Creates code for logging the entrance into a method with fine level.

Note: The method should consider the isGeneratingLogging() value.

Parameters:
pMethod - The method in which a logging statement should be inserted
pValues - An array of additional values, possibly null

logFinestEntering

protected void logFinestEntering(JavaMethod pMethod,
                                 java.lang.Object pValues)

Creates code for logging the entrance into a method with finest level.

Note: The method should consider the isGeneratingLogging() value.

Implementation note: The default implementation is equivalent to logFinest(pMethod, "->", pValues).

Parameters:
pMethod - The method in which a logging statement should be inserted
pValues - An array of additional values, possibly null

logExiting

protected void logExiting(JavaMethod pMethod,
                          java.lang.Object pValues)

Creates code for logging the exit from a method with fine level.

Note: The method should consider the isGeneratingLogging() value.

Parameters:
pMethod - The method in which a logging statement should be inserted
pValues - An array of additional values, possibly null

logFinestExiting

protected void logFinestExiting(JavaMethod pMethod,
                                java.lang.Object pValues)

Creates code for logging the exit from a method with fine level.

Note: The method should consider the isGeneratingLogging() value.

Implementation note: The default implementation is equivalent to logFinest(pMethod, "<-", pValues).

Parameters:
pMethod - The method in which a logging statement should be inserted
pValues - An array of additional values, possibly null

logFinest

protected void logFinest(JavaMethod pMethod,
                         java.lang.Object pMsg,
                         java.lang.Object pValues)

Creates code for logging a message with finest level.

Note: The method should consider the isGeneratingLogging() value.

Parameters:
pMethod - The method in which a logging statement should be inserted
pMsg - The message being logged
pValues - An array of additional values, possibly null

addTable

public void addTable(Table pTable,
                     VersionGenerator.ColumnUpdater pUpdater)
Adds a new table to the list of tables. The table must not contain a forward reference. Additionally, the table must not be referenced by any other table, which has already been added to the list.

Parameters:
pTable - The table being cloned
pUpdater - The column updater to use for changing the updated columns.

getCacheDataClassName

protected JavaQName getCacheDataClassName(JavaQName pQName)

Returns the name of the inner class CacheData.


getCacheDataClass

protected JavaInnerClass getCacheDataClass(JavaSource pSource)

Generates the innner class CacheData.


setResultSetValue

protected void setResultSetValue(JavaMethod pMethod,
                                 Column pColumn,
                                 DirectAccessible pResultSet,
                                 int pColumnNum,
                                 java.lang.Object pTarget)

Generates code for reading a ResultSet's column.


setPreparedStatementValue

protected void setPreparedStatementValue(JavaMethod pMethod,
                                         Column pColumn,
                                         java.lang.Object pStmt,
                                         java.lang.Object pParamNum,
                                         java.lang.Object pValue)

Generates code for setting a PreparedStatement's parameter.


getSelectRowsCode

protected void getSelectRowsCode(JavaMethod pMethod,
                                 VersionGenerator.TableInfo pTableInfo,
                                 ColumnSet pColumnSet,
                                 DirectAccessible pConn,
                                 DirectAccessible pMap,
                                 DirectAccessible pValues,
                                 boolean pReturnValue)

Generates code for reading all rows matching the given key.


getInsertRowMethodName

protected java.lang.String getInsertRowMethodName(VersionGenerator.TableInfo pTableInfo)

Returns the name of the method for cloning one row from the given table.


getCacheDataClassInstance

protected LocalJavaField getCacheDataClassInstance(JavaMethod pMethod,
                                                   VersionGenerator.TableInfo pTableInfo,
                                                   ColumnSet pColumnSet,
                                                   DirectAccessible pValues)

Creates an instance of the inner class CacheData by reading the key from the given row.


getApplyCacheData

protected void getApplyCacheData(JavaMethod pMethod,
                                 VersionGenerator.TableInfo pTableInfo,
                                 ColumnSet pColumnSet,
                                 DirectAccessible pRow,
                                 DirectAccessible pData)

Updates a row by reading the values from an instance of the inner class CacheData.


getInsertRowMethod

protected JavaMethod getInsertRowMethod(JavaSource pSource,
                                        VersionGenerator.TableInfo pTableInfo)

Creates a method for cloning one row from the given table.


getInnerInsertRowMethod

protected JavaMethod getInnerInsertRowMethod(JavaSource pSource,
                                             VersionGenerator.TableInfo pTableInfo)

Creates a method for cloning one row from the given table.


getPublicCloneMethod

protected JavaMethod getPublicCloneMethod(JavaSource pSource)

Actually creates the public "clone" method.


getCloneMethod

public JavaMethod getCloneMethod(JavaSource pSource)

Creates a method for updating one row in the head table.