快速业务通道

开源-给hibernateTools写个插件 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-17
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")); } }

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号