2007年12月 存档

基于fmpp的代码生成器–根据PowerDesigner的实体模型生成生成hibernate的hbm.xml等文件

2007年12月20日,星期四

曾有段时间,对代码生成器非常感兴趣,于是使用fmpp做了个简单的代码生成器,

生成的流程是,根据 PowerDesigner的cmd实体模型文件,生成每张表的hbm.xml,

然后再根据hbm.xml,生成对应的相关java代码,xml配置,jsp页面等文件。

大概有以下代码模板: spring-Hibernate.xml
struts-web_pojo.xml
Abstractpojo.java
pojo.java
pojoKey.java

IpojoLogic.java
pojoLogicImpl.java
spring-pojo.xml

IpojoDAO.java
pojoHibernateDAOImpl.java
compass-pojo.cmd.xml
compass-pojo.cpm.xml

pojoAddAction.java
pojoDelAction.java
pojoEditAction.java
pojoEditActionForm.java
pojoIndexAction.java
pojoSearchActionForm.java
pojoUpdateAction.java
struts-config_pojo.xml
struts-spring-pojo.xml
validator_pojo.xml
pojoindex.jspx

后来这些东西没有继续折腾了,这几天清理硬盘时发现了这些,因此在这里把代码贴出来,留作备忘。

cdm到hbm.xml 的fmpp 配置为:

config.fmpp

—————–

outputEncoding:UTF-8
sourceRoot: src
outputRoot: hbm2code
logFile: log.fmpp
data: {
pdcdmentity:xml(data/pdcdm.cdm)
}

hbm.xml的代码模板为(只实现基本的映射和复合主键判断,对于简单的单表够用,其它的没处理):

[code]

<#ftl encoding="UTF-8" ns_prefixes={"a":"attribute","c":"collection","o":"object"} >
<@pp.setOutputEncoding encoding="UTF-8"/>
<#list pdcdmentity["Model"]["o:RootObject"]["c:Children"]["o:Model"]["c:Entities"]["o:Entity"] as et>
<#assign x = et["a:Code"]?cap_first >
<@pp.changeOutputFile name="/src/webapp/WEB-INF/hbms/"+x+".hbm.xml" />
<?xml version="1.0" encoding='UTF-8'?>
<!--
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
-->
<hibernate-mapping package="net.share_info.dxw.hibernate">
<#if et["a:Comment"]?has_content><!-- ${et["a:Comment"]} --> </#if>
<class name="${et["a:Code"]?cap_first}" table="${et["a:Code"]?upper_case}" node="${et["a:Name"]}" optimistic-lock="version">
<#assign pkirefid = et["c:PrimaryIdentifier"]["o:Identifier"]["@Ref"]>
<#assign pkoi = getPKI(pdcdmentity["Model"]["o:RootObject"]["c:Children"]["o:Model"]["c:Entities"]["o:Entity"]["c:Identifiers"],pkirefid)>
<#assign pknum = pkoi["c:Identifier.Attributes"]["o:EntityAttribute"]?size>
<#if pknum >= 2 >
<composite-id name="id" class="${et["a:Code"]?cap_first}Key">
<#list pkoi["c:Identifier.Attributes"]["o:EntityAttribute"] as pkp>
<#assign oeRef = pkp["@Ref"] >
<#assign oEntityAttribute = getoEntityAttribute(et,oeRef) >
<#assign oModel = pdcdmentity["Model"]["o:RootObject"]["c:Children"]["o:Model"] >
<#assign oeDRef=oEntityAttribute["c:DataItem"]["o:DataItem"]["@Ref"] >
<#assign oDataItem = getoDataItem(oModel,oeDRef) >
<key-property name="${oDataItem["a:Code"]?uncap_first}" column="${oDataItem["a:Code"]?upper_case}" node="${oDataItem["a:Name"]}" type="${getJavaType(oDataItem["a:DataType"])}" <#if oDataItem["a:Length"]?has_content > length="${oDataItem["a:Length"]}"</#if> />
</#list>
</composite-id>
<#else>
<#list pkoi["c:Identifier.Attributes"]["o:EntityAttribute"] as pkp>
<#assign oeRef = pkp["@Ref"] >
<#assign oEntityAttribute = getoEntityAttribute(et,oeRef) >
<#assign oModel = pdcdmentity["Model"]["o:RootObject"]["c:Children"]["o:Model"] >
<#assign oeDRef=oEntityAttribute["c:DataItem"]["o:DataItem"]["@Ref"] >
<#assign oDataItem = getoDataItem(oModel,oeDRef) >
<id name="${oDataItem["a:Code"]?uncap_first}" column="${oDataItem["a:Code"]?upper_case}" node="${oDataItem["a:Name"]}" type="${getJavaType(oDataItem["a:DataType"])}" <#if oDataItem["a:Length"]?has_content > length="${oDataItem["a:Length"]}"</#if> >
<generator class="assigned"/>
</id>
</#list>
</#if>
<version name="version" column="VERSION" node="version" type="java.lang.Integer"/>
<property name="orderindex" column="ORDERINDEX" type="java.lang.Integer" node="orderindex"/>
<property name="addtime" column="ADDTIME" type="java.util.Date" node="addtime" update="false"/>
<property name="lastupdatetime" column="LASTUPDATETIME" type="java.util.Date" node="lastupdatetime"/>
<#list et["c:Attributes"]["o:EntityAttribute"] as oEntityAttribute >
<#assign oModel = pdcdmentity["Model"]["o:RootObject"]["c:Children"]["o:Model"] >
<#assign oeDRef=oEntityAttribute["c:DataItem"]["o:DataItem"]["@Ref"] >

<#if isPKProperty(et,oEntityAttribute["@Id"]) = "false">
<#assign oDataItem = getoDataItem(oModel,oeDRef) >
<property name="${oDataItem["a:Code"]?uncap_first}" column="${oDataItem["a:Code"]?upper_case}" node="${oDataItem["a:Name"]}" type="${getJavaType(oDataItem["a:DataType"])}" <#if oEntityAttribute["a:BaseAttribute.Mandatory"]?has_content >not-null="true"</#if> <#if oDataItem["a:Length"]?has_content > length="${oDataItem["a:Length"]}"</#if> />
</#if>
</#list>
</class>

</hibernate-mapping>
</#list>
<#function getPKI oids pkoid>
<#list oids["o:Identifier"] as oid>
<#if oid["@Id"] = pkoid >
<#return oid>
</#if>
</#list>
</#function>

<#function getoEntityAttribute entity eid>
<#list entity["c:Attributes"]["o:EntityAttribute"] as oid>
<#if oid["@Id"] = eid >
<#return oid>
</#if>
</#list>
</#function>

<#function getoDataItem model eid>
<#list model["c:DataItems"]["o:DataItem"] as odi>
<#if odi["@Id"] = eid >
<#return odi>
</#if>
</#list>
</#function>

<#function isPKProperty et attRef>
<#assign pkirefid = et["c:PrimaryIdentifier"]["o:Identifier"]["@Ref"]>
<#assign pkoi = getPKI(pdcdmentity["Model"]["o:RootObject"]["c:Children"]["o:Model"]["c:Entities"]["o:Entity"]["c:Identifiers"],pkirefid)>
<#assign pknum = pkoi["c:Identifier.Attributes"]["o:EntityAttribute"]?size>
<#list pkoi["c:Identifier.Attributes"]["o:EntityAttribute"] as pkp>
<#assign oeRef = pkp["@Ref"] >
<#if oeRef = attRef >
<#return "true">
</#if>
</#list>
<#return "false">
</#function>

<#function getJavaType dataType>
<#if dataType?has_content >
<#if dataType?index_of("VA") =0 >
<#return "java.lang.String">
</#if>
</#if>
<#switch dataType>
<#case "DT">
<#return "java.sql.Timestamp">
<#case "I">
<#return "java.lang.Integer">
<#case "SI">
<#return "java.lang.Short">
<#case "LI">
<#return "java.lang.Long">
<#case "BL">
<#return "java.lang.Boolean">
<#case "TXT">
<#return "java.lang.String">
<#case "D">
<#return "java.sql.Date">
<#case "T">
<#return "java.sql.Time">
<#default>
<#return "java.lang.String">
</#switch>
</#function>

[/code]

Tags: fmpp, Hibernate, PowerDesigner, 代码生成器

Related posts

Windows 2003 在自动更新后莫名奇妙的无法启动

2007年12月19日,星期三

前几天,一台操作系统为Windows 2003的服务器,在自动更新完成之后,无法再启动,
具体表现是,启动时输入用户名和密码之后,就挂掉了。
于是进到安全模式下,查看系统日志,看到下面这样的内容:
2007-12-13    11:38:19    EventLog    错误    无    6008    N/A    sever01    上一次系统的 4:09:02 在 2007-12-13 上的关闭是意外的。
2007-12-13    4:09:46    VMnetuserif    信息    无    4    N/A    sever01    (\Device\VMnetUserif) Driver entry exiting with status 0
2007-12-13    4:09:46    VMnetuserif    信息    无    1    N/A    sever01    () Starting up the User Interface Driver for VMware Virtual Networks
2007-12-13    4:09:43    IPSec    信息    无    4294    N/A    sever01    IPSec 驱动程序进入 Secure 状态。如果配置了 IPSec 策略, 将在现在被应用到此计算机。
2007-12-13    4:08:57    Tcpip    信息    无    4202    N/A    sever01    系统检测到网卡 Intel(R) PRO/1000 CT Network Connection 与网络断开, 而且网卡的网络配置已经释放。如果 网卡没有断开,这可能意味着它出现故障。 请与您的供应商联系以获得更新的驱动程序。
2007-12-13    4:08:52    Tcpip    信息    无    4201    N/A    sever01    系统检测到网卡 Intel(R) PRO/1000 MT Network Connection – 网络负载平衡筛选设备 与网络连接, 而且已通过网卡初始化一般操作。
2007-12-13    4:08:52    E1000    警告    无    30    N/A    sever01    Intel(R) PRO/1000 MT Network Connection 设定为自动协商,但链接伙伴未配置为自动协商。可能发生双工不匹配。
2007-12-13    4:08:52    E1000    信息    无    36    N/A    sever01      Intel(R) PRO/1000 MT Network Connection 链接已建立:10Mbps 半双工。
2007-12-13    4:08:49    E1000    信息    无    31    N/A    sever01    Intel(R) PRO/1000 MT Network Connection :已在您的网络所连接到的设备上检测到“生成树协议”。
2007-12-13    4:08:47    IPSec    信息    无    4295    N/A    sever01    IPSec 驱动程序以 Bypass 模式启动。在此计算机启动时没有 IPSec 安全性会被应用到此计算机。如果配置了IPSec 策略,它们将在  IPSec 服务启动后被应用到此计算机。
2007-12-13    4:08:47    WLBS    错误    无    35    N/A    sever01    NLB 群集 0.0.0.0 : 由于参数错误,群集模式无法被启用。所有通讯都会被传递给 TCP/IP。在运行 ‘wlbs reload’ 后运行 ‘wlbs start’ 纠正问题后,重新启动群集操作。
2007-12-13    4:08:45    VMnetAdapter    信息    无    34    N/A    sever01    () Driver entry successful.
2007-12-13    4:08:45    VMnetAdapter    信息    无    34    N/A    sever01    () Starting up: 0×89cb6a80, \REGISTRY\MACHINE\SYSTEM\Contr
2007-12-13    4:09:12    AeLookupSvc    信息    无    3    N/A    sever01    应用程序体验查找服务已成功地启动。
2007-12-13    4:09:02    DCOM    信息    无    10026    N/A    sever01    COM 子系统正在取消 86400 秒持续时间内重复的事件日志项。可以通过下列注册表项下名为 SuppressDuplicateDuration 的 REG_DWORD 值控制取消超时: HKLM\Software\Microsoft\Ole\EventLog。
2007-12-13    4:09:02    EventLog    信息    无    6005    N/A    sever01    事件日志服务已启动。
2007-12-13    4:09:02    EventLog    信息    无    6009    N/A    sever01    Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free。
2007-12-13    4:07:12    EventLog    信息    无    6006    N/A    sever01    事件日志服务已停止。
2007-12-13    4:07:03    USER32    信息    无    1074    NT AUTHORITY\SYSTEM    sever01    “进程 winlogon.exe 已因下列原因为用户 NT AUTHORITY\SYSTEM 开始计算机 sever01 的 重新启动: 没有找到这个原因的标题
原因代码: 0×80020002
关机类型: 重新启动
注释: ”
2007-12-13    4:05:25    Service Control Manager    信息    无    7036    N/A    sever01    WinHTTP Web Proxy Auto-Discovery Service 服务处于 正在运行 状态。
2007-12-13    4:05:25    Service Control Manager    信息    无    7035    NT AUTHORITY\SYSTEM    sever01    WinHTTP Web Proxy Auto-Discovery Service 服务成功发送一个 开始 控件。
2007-12-13    4:02:08    Windows Update Agent    信息    安装     22    N/A    sever01    “需要重新启动: 要完成下列更新的安装,计算机将在 5 分钟内重新启动:
- Windows Server 2003 更新程序 (KB942840)
- Windows Server 2003 安全更新程序 (KB944653)
- Windows Server 2003 更新程序 (KB942763)
- Windows 恶意软件删除工具 – 2007 年 12 月 (KB890830)
- Windows Server 2003 安全更新程序 (KB941569)
- 用于 Windows Server 2003 的 Internet Explorer 6 累积安全更新程序 (KB942615)
- Windows Server 2003 安全更新程序 (KB941568)”

看不出什么问题,于是只好在安全模式下把日志里列出的自动更新的补丁卸载,然后重启就正常了。
最后禁用了2003的自动更新。

该文章没有标签.

Related posts

解决iframe中jsessionid无法传递导致session丢失的问题

2007年12月19日,星期三

在实现 ISMP2.1.1 接口的适合需要用到sso,而ISMP里定义的接口是需要在iframe等嵌入页面中调用sso接口,在实际开发中发现session无法正常传递。

重现问题的场景是:

1.先访问a站点:http://192.168.18.2/test.jsp

test.jsp的代码为:

<html>
<head>
<title> 618119.com </title>
</head>
<body>
<iframe src=”http://192.168.18.3/sso.jsp?ssoinfo=xxxx“>
</iframe>
</body>
</html>

sso.jsp里读取传递的ssoinfo,反向调用ISMP认证接口,

生成session,然后放入指定的属性值,

session.setAttribute(“ssoUser”,”lizongbo”);
页面再重定向到 http://192.168.18.3/iframe.jsp

response.sendRedirect(“/iframe.jsp”);

iframe.jsp中读取session中ssoUser的属性值,会发现无法读取。
2.如果先访问了 192.168.18.3的页面,再访问192.168.18.2的页面,此时的iframe嵌入是可以传递已生成好的jsessionid Cookie.

因此解决的办法有:

a.在url中加上jsessionid.

例如重定向到 response.sendRedirect(“/iframe.jsp;jsessionid=lizongbo”);
而这种情况下,如果iframe.jsp页面内的其它连接的url没有加上jsessionid,

也无法继续传递session,不过通过在客户端的js来为每个超连接的href属性重写加上jsessionid.

b.sso.jsp里设置P3P头信息
例如 P3P: CP=”CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR”

或 P3P:CP=”CAO PSA OUR”

java代码为:

response.addHeader(“P3P”,”\”CAO PSA OUR\”");

问题描述及解决办法可参考:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q323752

http://blog.csdn.net/mshust2006/archive/2007/06/03/1636807.aspx

http://www.dreamcoder.cn/blog/?p=72

http://www.kingmx.com/article/15061

http://www.dup2.org/node/384

Tags: iframe, jsessionid, session, sso

Related posts