Impressive. That's a real fast response.
And it works perfect.
I implemented an accoring comment generator.
Maybe someone who's reading this thread later on will find this useful so up
to now I paste this first version of a comment generator below.
Thank you Jeff!
Benjamin
-------------------------------------------------------------------
<commentGenerator type="de.bar54.ibator.JavaModelCommentGenerator">
<property name="suppressDate" value="true" />
</commentGenerator>
-------------------------------------------------------------------
package de.bar54.ibator;
import org.apache.ibatis.ibator.api.IntrospectedColumn;
import org.apache.ibatis.ibator.api.IntrospectedTable;
import org.apache.ibatis.ibator.api.dom.java.Field;
import org.apache.ibatis.ibator.api.dom.java.Method;
import org.apache.ibatis.ibator.api.dom.java.Parameter;
import org.apache.ibatis.ibator.internal.DefaultCommentGenerator;
import org.apache.ibatis.ibator.internal.util.JavaBeansUtil;
/**
* ibator comment generator to read the column comments from the database
and
* to write them into the java doc of the data model classes
*
* @author Benjamin Klatt
*
*/
public class JavaModelCommentGenerator extends DefaultCommentGenerator {
/**
* Enhanced field comment generation method to use the database
field remark to
* produce the java doc of the appropriate field
*
* if a remark is available this will be used
* if not, the default ibator comment is generated
*
* This method still adds the ibatorgenerated annotation to support
the eclipse merge tool
*
* @param field The java field to
work on
* @param introspectedTable The currently processed
table
* @param introspectedColumn The currently processed column
*
*/
public void addFieldComment(Field field,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if(remarkExists(introspectedColumn)){
field.addJavaDocLine("/**"); //$NON-NLS-1$
field.addJavaDocLine(" * "+introspectedColumn.getRemarks());
//$NON-NLS-1$
addIbatorJavadocTag(field);
field.addJavaDocLine(" */"); //$NON-NLS-1$
} else {
StringBuilder sb = new StringBuilder();
field.addJavaDocLine("/**"); //$NON-NLS-1$
field.addJavaDocLine(" * This field was generated by Apache
iBATIS Ibator."); //$NON-NLS-1$
sb.append(" * This field corresponds to the database column ");
//$NON-NLS-1$
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
field.addJavaDocLine(sb.toString());
addIbatorJavadocTag(field);
field.addJavaDocLine(" */"); //$NON-NLS-1$
}
}
public void addGetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if(remarkExists(introspectedColumn)){
method.addJavaDocLine("/**"); //$NON-NLS-1$
method.addJavaDocLine(" * Get
"+introspectedColumn.getRemarks()); //$NON-NLS-1$
method.addJavaDocLine(" *"); //$NON-NLS-1$
StringBuilder sb = new StringBuilder();
sb.append(" * @return the value of "); //$NON-NLS-1$
sb.append(JavaBeansUtil.getCamelCaseString(introspectedColumn.getActualColum
nName(), false));
if(introspectedColumn.isNullable()){
sb.append(" (can be null)");
}
method.addJavaDocLine(sb.toString());
addIbatorJavadocTag(method);
method.addJavaDocLine(" */"); //$NON-NLS-1$
} else {
StringBuilder sb = new StringBuilder();
method.addJavaDocLine("/**"); //$NON-NLS-1$
method.addJavaDocLine(" * This method was generated
by Apache iBATIS Ibator."); //$NON-NLS-1$
sb.append(" * This method returns the value of the
database column "); //$NON-NLS-1$
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
method.addJavaDocLine(" *"); //$NON-NLS-1$
sb.setLength(0);
sb.append(" * @return the value of "); //$NON-NLS-1$
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
addIbatorJavadocTag(method);
method.addJavaDocLine(" */"); //$NON-NLS-1$
}
}
public void addSetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) {
if(remarkExists(introspectedColumn)){
method.addJavaDocLine("/**"); //$NON-NLS-1$
method.addJavaDocLine(" * Set
"+introspectedColumn.getRemarks()); //$NON-NLS-1$
method.addJavaDocLine(" *"); //$NON-NLS-1$
StringBuilder sb = new StringBuilder();
Parameter parm = method.getParameters().get(0);
sb.setLength(0);
sb.append(" * @param "); //$NON-NLS-1$
sb.append(parm.getName());
sb.append(" the value for "); //$NON-NLS-1$
sb.append(JavaBeansUtil.getCamelCaseString(introspectedColumn.getActualColum
nName(), false)); //$NON-NLS-1$
method.addJavaDocLine(sb.toString());
addIbatorJavadocTag(method);
method.addJavaDocLine(" */"); //$NON-NLS-1$
} else {
StringBuilder sb = new StringBuilder();
method.addJavaDocLine("/**"); //$NON-NLS-1$
method.addJavaDocLine(" * This method was generated by
Apache iBATIS Ibator."); //$NON-NLS-1$
sb.append(" * This method sets the value of the database
column "); //$NON-NLS-1$
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
method.addJavaDocLine(" *"); //$NON-NLS-1$
Parameter parm = method.getParameters().get(0);
sb.setLength(0);
sb.append(" * @param "); //$NON-NLS-1$
sb.append(parm.getName());
sb.append(" the value for "); //$NON-NLS-1$
sb.append(introspectedTable.getFullyQualifiedTable());
sb.append('.');
sb.append(introspectedColumn.getActualColumnName());
method.addJavaDocLine(sb.toString());
addIbatorJavadocTag(method);
method.addJavaDocLine(" */"); //$NON-NLS-1$
}
}
/**
* Utility method to check if a column remark is available
* @param introspectedColumn The column to check for a remark
*
* @return true if a non empty remark is available
*/
private boolean remarkExists(IntrospectedColumn introspectedColumn){
return introspectedColumn.getRemarks() != null &&
!"".equals(introspectedColumn.getRemarks());
}
}
-------------------------------------------------------------------
-----Ursprüngliche Nachricht-----
Von: Jeff Butler [mailto:[email protected]]
Gesendet: Freitag, 20. März 2009 23:23
An: [email protected]
Betreff: Re: iBator CommentGenerator: Java Model Class with database column
comment
Support for this is now available in SVN.
Jeff Butler
On Fri, Mar 20, 2009 at 6:57 AM, Jeff Butler <[email protected]> wrote:
> Interesting idea.
>
> Ibator does not currently capture database field comments from the
> metadata, so there's no simple way to do this now.
>
> It's a relatively simple change to add it. I'd need to change the
> CommentGenerator interface to expose it - hopefully that won't cause
> too much trouble for people. I'll look into it.
>
> Jeff Butler
>
>
> On Thu, Mar 19, 2009 at 4:30 PM, Benjamin-Klatt <[email protected]> wrote:
>>
>> Hi all,
>>
>> I am trying to use the comment I modeled in my database to be
automatically
>> used in javadoc comment of the data fields within the java data model
source
>> code.
>>
>> I started to implement my own commentGenerator, but the method
>> addFieldComment(Field field, FullyQualifiedTable, String columnName)
>> does not provide the required information. There is no element that
provides
>> access to the comment of the appropriate column in the database.
>>
>> Does someone has implement a solution for this or at least does know this
>> information could be accessed?
>>
>> Thanks in advance
>> Benjamin
>> --
>> View this message in context:
http://www.nabble.com/iBator-CommentGenerator%3A-Java-Model-Class-with-datab
ase-column-comment-tp22608433p22608433.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
>