-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust freemarker pojo templates for uniform whitespace usage. ImportContextImpl - normalise line separators: remove carriage return char. Add a template for field annotations. Allow selection of field annotations over default property annotations by configuration of a toolclass property "hibernatetool.annotateField.toolclass". The class allocated to this property is not important only the name "annotateField". Tweak existing h2 database EntityNamingTest for testing of all the freemarker templates.
- Loading branch information
Showing
16 changed files
with
362 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<#if ejb3> | ||
<#if pojo.hasIdentifierProperty()> | ||
<#if field.equals(clazz.identifierProperty)> | ||
${pojo.generateAnnIdGenerator()}<#--has space prepended--> | ||
</#if> | ||
</#if> | ||
<#if c2h.isOneToOne(field)> | ||
${pojo.generateOneToOneAnnotation(field, md)} | ||
<#elseif c2h.isManyToOne(field)> | ||
${pojo.generateManyToOneAnnotation(field)} | ||
<#--TODO support optional and targetEntity--> | ||
${pojo.generateJoinColumnsAnnotation(field, md)} | ||
<#elseif c2h.isCollection(field)> | ||
${pojo.generateCollectionAnnotation(field, md)} | ||
<#else> | ||
<#if pojo.generateBasicAnnotation(field)?has_content > | ||
<#if pojo.generateBasicAnnotation(field)?trim?length gt 0 > | ||
${(pojo.generateBasicAnnotation(field))}<#--has space prepended--> | ||
</#if> | ||
</#if> | ||
${pojo.generateAnnColumnAnnotation(field)}<#--has space prepended--> | ||
</#if> | ||
</#if> |
35 changes: 18 additions & 17 deletions
35
orm/src/main/resources/pojo/Ejb3PropertyGetAnnotation.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
<#if ejb3> | ||
<#if pojo.hasIdentifierProperty()> | ||
<#if property.equals(clazz.identifierProperty)> | ||
${pojo.generateAnnIdGenerator()} | ||
<#-- if this is the id property (getter)--> | ||
<#-- explicitly set the column name for this property--> | ||
</#if> | ||
</#if> | ||
|
||
<#if c2h.isOneToOne(property)> | ||
${pojo.generateOneToOneAnnotation(property, md)} | ||
<#elseif c2h.isManyToOne(property)> | ||
${pojo.generateManyToOneAnnotation(property)} | ||
<#--TODO support optional and targetEntity--> | ||
<#if pojo.hasIdentifierProperty()> | ||
<#if property.equals(clazz.identifierProperty)> | ||
${pojo.generateAnnIdGenerator()} | ||
<#-- if this is the id property (getter)--> | ||
<#-- explicitly set the column name for this property--> | ||
</#if> | ||
</#if> | ||
<#if c2h.isOneToOne(property)> | ||
${pojo.generateOneToOneAnnotation(property, md)} | ||
<#elseif c2h.isManyToOne(property)> | ||
${pojo.generateManyToOneAnnotation(property)} | ||
<#--TODO support optional and targetEntity--> | ||
${pojo.generateJoinColumnsAnnotation(property, md)} | ||
<#elseif c2h.isCollection(property)> | ||
${pojo.generateCollectionAnnotation(property, md)} | ||
<#else> | ||
<#elseif c2h.isCollection(property)> | ||
${pojo.generateCollectionAnnotation(property, md)} | ||
<#else> | ||
<#if pojo.generateBasicAnnotation(property) != " " > | ||
${pojo.generateBasicAnnotation(property)} | ||
</#if> | ||
${pojo.generateAnnColumnAnnotation(property)} | ||
</#if> | ||
</#if> | ||
</#if> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
|
||
<#-- /** default constructor */ --> | ||
public ${pojo.getDeclarationName()}() { | ||
} | ||
<#if pojo.needsMinimalConstructor()><#-- /** minimal constructor */ --> | ||
|
||
<#if pojo.needsMinimalConstructor()> <#-- /** minimal constructor */ --> | ||
public ${pojo.getDeclarationName()}(${c2j.asParameterList(pojo.getPropertyClosureForMinimalConstructor(), jdk5, pojo)}) { | ||
<#if pojo.isSubclass() && !pojo.getPropertyClosureForSuperclassMinimalConstructor().isEmpty()> | ||
super(${c2j.asArgumentList(pojo.getPropertyClosureForSuperclassMinimalConstructor())}); | ||
</#if> | ||
<#list pojo.getPropertiesForMinimalConstructor() as field> | ||
<#if pojo.isSubclass() && !pojo.getPropertyClosureForSuperclassMinimalConstructor().isEmpty()> | ||
super(${c2j.asArgumentList(pojo.getPropertyClosureForSuperclassMinimalConstructor())}); | ||
</#if> | ||
<#list pojo.getPropertiesForMinimalConstructor() as field> | ||
this.${c2j.keyWordCheck(field.name)} = ${c2j.keyWordCheck(field.name)}; | ||
</#list> | ||
</#list> | ||
} | ||
</#if> | ||
<#if pojo.needsFullConstructor()> | ||
<#-- /** full constructor */ --> | ||
public ${pojo.getDeclarationName()}(${c2j.asParameterList(pojo.getPropertyClosureForFullConstructor(), jdk5, pojo)}) { | ||
<#if pojo.isSubclass() && !pojo.getPropertyClosureForSuperclassFullConstructor().isEmpty()> | ||
super(${c2j.asArgumentList(pojo.getPropertyClosureForSuperclassFullConstructor())}); | ||
</#if> | ||
<#list pojo.getPropertiesForFullConstructor() as field> | ||
this.${c2j.keyWordCheck(field.name)} = ${c2j.keyWordCheck(field.name)}; | ||
</#list> | ||
<#if pojo.needsFullConstructor()><#-- /** full constructor */ --> | ||
|
||
public ${pojo.getDeclarationName()}(${c2j.asParameterList(pojo.getPropertyClosureForFullConstructor(), jdk5, pojo)}) { | ||
<#if pojo.isSubclass() && !pojo.getPropertyClosureForSuperclassFullConstructor().isEmpty()> | ||
super(${c2j.asArgumentList(pojo.getPropertyClosureForSuperclassFullConstructor())}); | ||
</#if> | ||
<#list pojo.getPropertiesForFullConstructor() as field> | ||
this.${c2j.keyWordCheck(field.name)} = ${c2j.keyWordCheck(field.name)}; | ||
</#list> | ||
} | ||
</#if> | ||
</#if> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
<#if pojo.needsEqualsHashCode() && !clazz.superclass?exists> | ||
<#assign classNameToCastTo><#if clazz.getProxyInterfaceName?exists>${clazz.getProxyInterfaceName()}<#else>${pojo.getDeclarationName()}</#if></#assign> | ||
public boolean equals(Object other) { | ||
if ( (this == other ) ) return true; | ||
if ( (other == null ) ) return false; | ||
if ( !(other instanceof ${classNameToCastTo}) ) return false; | ||
${classNameToCastTo} castOther = ( ${classNameToCastTo} ) other; | ||
|
||
return ${pojo.generateEquals("this", "castOther", jdk5)}; | ||
} | ||
|
||
public int hashCode() { | ||
int result = 17; | ||
|
||
<#list pojo.getAllPropertiesIterator() as property> ${pojo.generateHashCode(property, "result", "this", jdk5)} | ||
</#list> return result; | ||
} | ||
</#if> | ||
|
||
public boolean equals(Object other) { | ||
if ( (this == other ) ) return true; | ||
if ( (other == null ) ) return false; | ||
if ( !(other instanceof ${classNameToCastTo}) ) return false; | ||
${classNameToCastTo} castOther = ( ${classNameToCastTo} ) other; | ||
return ${pojo.generateEquals("this", "castOther", jdk5)}; | ||
} | ||
|
||
public int hashCode() { | ||
int result = 17; | ||
<#list pojo.getAllPropertiesIterator() as property> | ||
<#if pojo.generateHashCode(property, "result", "this", jdk5)?trim?length gt 0 > | ||
${pojo.generateHashCode(property, "result", "this", jdk5)} | ||
</#if> | ||
</#list> | ||
return result; | ||
} | ||
</#if> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<#if pojo.hasMetaAttribute("class-code")> // The following is extra code specified in the hbm.xml files | ||
<#if pojo.hasMetaAttribute("class-code")> | ||
|
||
// Extra-code via hbm.xml/RevengStrategy config. | ||
${pojo.getExtraClassCode()} | ||
// end of extra code specified in the hbm.xml files | ||
</#if> | ||
// Extra-code end. | ||
</#if> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
<#-- // Fields --> | ||
|
||
<#list pojo.getAllPropertiesIterator() as field><#if pojo.getMetaAttribAsBool(field, "gen-property", true)> <#if pojo.hasMetaAttribute(field, "field-description")> /** | ||
<#list pojo.getAllPropertiesIterator() as field> | ||
<#if pojo.getMetaAttribAsBool(field, "gen-property", true)> | ||
<#if pojo.hasMetaAttribute(field, "field-description")> | ||
/** | ||
${pojo.getFieldJavaDoc(field, 0)} | ||
*/ | ||
</#if> ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${c2j.keyWordCheck(field.name)}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>; | ||
</#if> | ||
</#if> | ||
<#if annotateField??><#include "Ejb3FieldGetAnnotation.ftl"/></#if><#--an alternative to property annotation, configured in PojoPropertyAccessors.ftl--> | ||
${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${c2j.keyWordCheck(field.name)}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>; | ||
</#if> | ||
</#list> | ||
|
17 changes: 12 additions & 5 deletions
17
orm/src/main/resources/pojo/PojoInterfacePropertyAccessors.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
<#-- if interface --> | ||
<#-- Property accessors for interface --> | ||
<#list pojo.getAllPropertiesIterator() as property><#if pojo.getMetaAttribAsBool(property, "gen-property", true)> /** | ||
${c2j.toJavaDoc(c2j.getMetaAsString(property, "field-description"), 4)} */ | ||
${pojo.getPropertyGetModifiers(property)} ${pojo.getJavaTypeName(property, jdk5)} ${pojo.getGetterSignature(property)}(); | ||
<#list pojo.getAllPropertiesIterator() as property> | ||
<#if pojo.getMetaAttribAsBool(property, "gen-property", true)> | ||
|
||
<#if c2j.getMetaAsString(property, "field-description")?trim?length gt 0> | ||
/** | ||
${c2j.toJavaDoc(c2j.getMetaAsString(property, "field-description"), 0)} | ||
*/ | ||
</#if> | ||
${pojo.getPropertyGetModifiers(property)} ${pojo.getJavaTypeName(property, jdk5)} ${pojo.getGetterSignature(property)}(); | ||
|
||
${pojo.getPropertySetModifiers(property)} void set${pojo.getPropertyName(property)}(${pojo.getJavaTypeName(property, jdk5)} ${property.name}); | ||
</#if></#list> | ||
${pojo.getPropertySetModifiers(property)} void set${pojo.getPropertyName(property)}(${pojo.getJavaTypeName(property, jdk5)} ${property.name}); | ||
</#if> | ||
</#list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
<#-- // Property accessors --> | ||
<#list pojo.getAllPropertiesIterator() as property> | ||
<#if pojo.getMetaAttribAsBool(property, "gen-property", true)> | ||
<#if pojo.hasFieldJavaDoc(property)> | ||
/** | ||
<#if pojo.getMetaAttribAsBool(property, "gen-property", true)> | ||
<#if pojo.hasFieldJavaDoc(property)> | ||
/** | ||
* ${pojo.getFieldJavaDoc(property, 4)} | ||
*/ | ||
</#if> | ||
<#include "GetPropertyAnnotation.ftl"/> | ||
</#if> | ||
|
||
<#if !annotateField??><#include "GetPropertyAnnotation.ftl"/></#if><#-- Property annotations. Field annotation configured in PojoFields.ftl --> | ||
${pojo.getPropertyGetModifiers(property)} ${pojo.getJavaTypeName(property, jdk5)} ${pojo.getGetterSignature(property)}() { | ||
return this.${c2j.keyWordCheck(property.name)}; | ||
} | ||
|
||
${pojo.getPropertySetModifiers(property)} void set${pojo.getPropertyName(property)}(${pojo.getJavaTypeName(property, jdk5)} ${c2j.keyWordCheck(property.name)}) { | ||
this.${c2j.keyWordCheck(property.name)} = ${c2j.keyWordCheck(property.name)}; | ||
} | ||
</#if> | ||
</#if> | ||
</#list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<#if pojo.needsToString()> /** | ||
<#if pojo.needsToString()> | ||
|
||
/** | ||
* toString | ||
* @return String | ||
*/ | ||
public String toString() { | ||
StringBuffer buffer = new StringBuffer(); | ||
|
||
buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" ["); | ||
<#list pojo.getToStringPropertiesIterator() as property> buffer.append("${property.getName()}").append("='").append(${pojo.getGetterSignature(property)}()).append("' "); | ||
</#list> buffer.append("]"); | ||
|
||
return buffer.toString(); | ||
} | ||
</#if> | ||
public String toString() { | ||
StringBuffer buffer = new StringBuffer(); | ||
buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" ["); | ||
<#list pojo.getToStringPropertiesIterator() as property> | ||
buffer.append("${property.getName()}").append("='").append(${pojo.getGetterSignature(property)}()).append("' "); | ||
</#list> | ||
buffer.append("]"); | ||
return buffer.toString(); | ||
} | ||
</#if> |
Oops, something went wrong.