ineeringStrategy delegate”的构造函数,重新打包,重新启动eclipse,哈哈,一切搞定,终于生成我可爱的,
开源-给hibernateTools写个插件(2)
时间:2011-03-29
public class PersonInfo
{
public String getNumber()。。。
public String getId()。。。
}
了。
附全部代码:
package com.cownew.DevTools.hibtools.RevEng;
import java.beans.Introspector;
import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategyUtil;
import org.hibernate.cfg.reveng.TableIdentifier;
import org.hibernate.util.StringHelper;
public class CowNewReverseEngineeringStrategy extends
DefaultReverseEngineeringStrategy
{
public CowNewReverseEngineeringStrategy(ReverseEngineeringStrategy delegate)
{
super();
}
private ReverseEngineeringSettings settings = new ReverseEngineeringSettings();
public String tableToClassName(TableIdentifier table)
{
String tableName = table.getName();
if (tableName != null && tableName.toUpperCase().startsWith("T_"))
{
String pkgName = settings.getDefaultPackageName();
int lastIndex = tableName.lastIndexOf(''_'');
tableName = tableName.substring(lastIndex + 1, tableName.length())
+ "Info";
String className = toUpperCamelCase(tableName);
if (pkgName.length() > 0)
return StringHelper.qualify(pkgName, className);
return className;
} else
{
return super.tableToClassName(table);
}
};
public String columnToPropertyName(TableIdentifier table, String column)
{
if (column != null && column.toUpperCase().startsWith("F"))
{
String cownewColName = column.substring(1, column.length());
String decapitalize = Introspector
.decapitalize(toUpperCamelCase(cownewColName));
return keywordCheck(decapitalize);
} else
{
return super.columnToPropertyName(table, column);
}
}
private String keywordCheck(String possibleKeyword)
{
if (ReverseEngineeringStrategyUtil
.isReservedJavaKeyword(possibleKeyword))
possibleKeyword += "_";
return possibleKeyword;
}
public void setSettings(ReverseEngineeringSettings settings)
{
super.setSettings(settings);
this.settings = settings;
}
public static void main(String[] args)
{
TableIdentifier table = new TableIdentifier("T_BD_Person");
//TableIdentifier table = new TableIdentifier("T_Person");
//TableIdentifier table = new TableIdentifier("Person");
CowNewReverseEngineeringStrategy revEng = new CowNewReverseEngineeringStrategy(null);
String className = revEng.tableToClassName(table);
System.out.println(className);
System.out.println(revEng.columnToPropertyName(table, "FId"));
System.out.println(revEng.columnToPropertyName(table, "Id"));
}
}
|