|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mybatis.generator.api.PluginAdapter
org.mybatis.generator.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.
Similarly, the hashCode method generated by this class only relies on fields it knows about. Anything you add, or fields in a super class will not be factored into the hash code.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.mybatis.generator.api.Plugin |
---|
Plugin.ModelClassType |
Field Summary |
---|
Fields inherited from class org.mybatis.generator.api.PluginAdapter |
---|
context, properties |
Constructor Summary | |
---|---|
EqualsHashCodePlugin()
|
Method Summary | |
---|---|
protected void |
generateEquals(TopLevelClass topLevelClass,
List<IntrospectedColumn> introspectedColumns,
IntrospectedTable introspectedTable)
Generates an equals method that does a comparison of all fields. |
protected void |
generateHashCode(TopLevelClass topLevelClass,
List<IntrospectedColumn> introspectedColumns,
IntrospectedTable introspectedTable)
Generates a hashCode method that includes all fields. |
boolean |
modelBaseRecordClassGenerated(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable)
This method is called after the base record class is generated by the JavaModelGenerator. |
boolean |
modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable)
This method is called after the primary key class is generated by the JavaModelGenerator. |
boolean |
modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass,
IntrospectedTable introspectedTable)
This method is called after the record with BLOBs class is generated by the JavaModelGenerator. |
boolean |
validate(List<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(List<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 run.
public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
Plugin
modelBaseRecordClassGenerated
in interface Plugin
modelBaseRecordClassGenerated
in class PluginAdapter
topLevelClass
- the generated base record classintrospectedTable
- The class containing information about the table as
introspected from the database
public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
Plugin
modelPrimaryKeyClassGenerated
in interface Plugin
modelPrimaryKeyClassGenerated
in class PluginAdapter
topLevelClass
- the generated primary key classintrospectedTable
- The class containing information about the table as
introspected from the database
public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable)
Plugin
modelRecordWithBLOBsClassGenerated
in interface Plugin
modelRecordWithBLOBsClassGenerated
in class PluginAdapter
topLevelClass
- the generated record with BLOBs classintrospectedTable
- The class containing information about the table as
introspected from the database
protected void generateEquals(TopLevelClass topLevelClass, 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, List<IntrospectedColumn> introspectedColumns, IntrospectedTable introspectedTable)
Note that this implementation is based on the eclipse foundation hashCode generator.
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 |