|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.ibatis.ibator.api.IbatorPluginAdapter
org.apache.ibatis.ibator.plugins.EqualsHashCodePlugin
public class EqualsHashCodePlugin
This plugin adds equals() and hashCode() methods to the generated model classes. It demonstrates the process of adding methods to generated classes
The equals method generated by this class is correct in most cases, but will probably NOT be correct if you have specified a rootClass - because our equals method only checks the fields it knows about.
The hashCode method generated by this class is a very simplistic implementation. A better implementation would rely on the HashCodeUtil from www.javapractices.com - but we do not want to introduce another dependency in this simple plugin.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.apache.ibatis.ibator.api.IbatorPlugin |
---|
IbatorPlugin.ModelClassType |
Field Summary |
---|
Fields inherited from class org.apache.ibatis.ibator.api.IbatorPluginAdapter |
---|
ibatorContext, properties |
Constructor Summary | |
---|---|
EqualsHashCodePlugin()
|
Method Summary | |
---|---|
protected void |
generateEquals(TopLevelClass topLevelClass,
java.util.List<IntrospectedColumn> introspectedColumns,
IntrospectedTable introspectedTable)
Generates an equals method that does a comparison of all fields. |
protected void |
generateHashCode(TopLevelClass topLevelClass,
java.util.List<IntrospectedColumn> introspectedColumns,
IntrospectedTable introspectedTable)
Generates a hashCode method that multiplies the hashCodes of all fields. |
boolean |
modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable)
This method is called after the base record class is generated by the ibator supplied JavaModelGenerator. |
boolean |
modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable)
This method is called after the primary key class is generated by the ibator supplied JavaModelGenerator. |
boolean |
modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable)
This method is called after the record with BLOBs class is generated by the ibator supplied JavaModelGenerator. |
boolean |
validate(java.util.List<java.lang.String> warnings)
This plugin is always valid - no properties are required |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EqualsHashCodePlugin()
Method Detail |
---|
public boolean validate(java.util.List<java.lang.String> warnings)
warnings
- add strings to this list to specify warnings. For example,
if the plugin is invalid, you should specify why. Warnings are reported
to users after the completion of the ibator run.
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
IbatorPlugin
modelBaseRecordClassGenerated
in interface IbatorPlugin
modelBaseRecordClassGenerated
in class IbatorPluginAdapter
topLevelClass
- the generated base record classintrospectedTable
- ibator's class containing information
about the table as introspected from the database
public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
IbatorPlugin
modelPrimaryKeyClassGenerated
in interface IbatorPlugin
modelPrimaryKeyClassGenerated
in class IbatorPluginAdapter
topLevelClass
- the generated primary key classintrospectedTable
- ibator's class containing information
about the table as introspected from the database
public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
IbatorPlugin
modelRecordWithBLOBsClassGenerated
in interface IbatorPlugin
modelRecordWithBLOBsClassGenerated
in class IbatorPluginAdapter
topLevelClass
- the generated record with BLOBs classintrospectedTable
- ibator's class containing information
about the table as introspected from the database
protected void generateEquals(TopLevelClass topLevelClass, java.util.List<IntrospectedColumn> introspectedColumns, IntrospectedTable introspectedTable)
The generated equals method will be correct unless:
topLevelClass
- the class to which the method will be addedintrospectedColumns
- column definitions of this class and
any superclass of this classintrospectedTable
- the table corresponding to this classprotected void generateHashCode(TopLevelClass topLevelClass, java.util.List<IntrospectedColumn> introspectedColumns, IntrospectedTable introspectedTable)
Note that this is a very simplistic implementation of hashCode.
topLevelClass
- the class to which the method will be addedintrospectedColumns
- column definitions of this class and
any superclass of this classintrospectedTable
- the table corresponding to this class
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |