集成 JPA 与 pureQuery: 让 Java Persistence API 利用 DB2 静态执行
2009-09-29 00:00:00 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁炬儳缍婇弻鐔兼⒒鐎靛壊妲紒鐐劤缂嶅﹪寮婚悢鍏尖拻閻庨潧澹婂Σ顔剧磼閹冣挃闁硅櫕鎹囬垾鏃堝礃椤忎礁浜鹃柨婵嗙凹缁ㄧ粯銇勯幒瀣仾闁靛洤瀚伴獮鍥敍濮f寧鎹囬弻鐔哥瑹閸喖顬堝銈庡亝缁挸鐣烽崡鐐嶆棃鍩€椤掑嫮宓佸┑鐘插绾句粙鏌涚仦鎹愬闁逞屽墰閹虫捇锝炲┑瀣╅柍杞拌兌閻ゅ懐绱撴担鍓插剱妞ゆ垶鐟╁畷銉р偓锝庡枟閻撴洘銇勯幇闈涗簼缂佽埖姘ㄧ槐鎾诲礃閳哄倻顦板┑顔硷工椤嘲鐣烽幒鎴旀瀻闁规惌鍘借ⅵ濠电姷鏁告慨顓㈠磻閹剧粯鈷戞い鎺嗗亾缂佸鏁婚獮鍡涙倷閸濆嫮顔愬┑鐑囩秵閸撴瑦淇婇懖鈺冪<闁归偊鍙庡▓婊堟煛鐏炵硶鍋撻幇浣告倯闁硅偐琛ラ埀顒冨皺閺佹牕鈹戦悙鏉戠仸闁圭ǹ鎽滅划鏃堟偨缁嬭锕傛煕閺囥劌鐏犻柛鎰ㄥ亾婵$偑鍊栭崝锕€顭块埀顒佺箾瀹€濠侀偗婵﹨娅g槐鎺懳熺拠鑼舵暱闂備胶枪濞寸兘寮拠宸殨濠电姵纰嶉弲鎻掝熆鐠虹尨宸ョ€规挸妫濆铏圭磼濡搫顫嶇紓浣风劍閹稿啿鐣烽幋锕€绠婚悹鍥у级瀹撳秴顪冮妶鍡樺鞍缂佸鍨剁粋宥夋倷椤掍礁寮垮┑鈽嗗灣閸樠勭妤e啯鍊垫慨妯煎亾鐎氾拷

请注意,在调用此工具前,您需要设置 pdq 运行时 JAR、db2jcc JAR 和实体类 JAR 的类路径(或增强实体类所在的目录),以及 persistence.xml 文件的位置。
就本文而言,包括在下载中的 JPA_EE_SAMPLE.ear 文件将用作示例,以指导您完成收集语句和创建包所需的步骤。该示例应用程序允许您创建、更新和删除客户并检索订单。该示例的持久性单元名称为 JPASample。
使用静态绑定器实用工具生成 SQL
清单 1 向您显示了语法,以及如何使用命令行调用静态绑定器实用工具 wsdb2gen。
清单 1. 从命令行调用 wsdb2gen
C:\was70\bin>wsdb2gen
Syntax: WSDB2GEN -pu <puName> [Flags]
Where
puName Persistence-unit name defined in the
persistence.xml
-collection collectionId Collection id assigned to package names.
Default is NULLID.
-url type 2 or The URL is used to validate generated sql.
type 4 url If url option is specified, if overrides
the url value in the persistence.xml.
If the url is type 4, userid and password
are required for connection. If the url is
type2, userid and password are not required.
-user user The userid to connect to target datebase.
If user option is specified, it overrides
the user value in the persistence.xml.
-pw password The password to connect to target datebase.
If password option is specified, it
overrides the value in the persistence.xml.
-package packageName A name of 7 or fewer characters for the
package name. If specified, all SQL for
the application will be generated into
this single package. If package option
is not specified, then multiple packages
will be created; one for each entity
class. If the first 7 characters are not
unique, the package name will be changed
to ensure uniqueness.
-help
C:\was70\bin>set classpath=C:\db2jcc.jar;C:\pdq.jar;C:\pdqmgmt.jar;%classpath%
C:\was70\bin>set classpath=C:\test1\bin;%classpath%
C:\was70\bin>wsdb2gen -pu JPASample -url jdbc:db2://localhost:50000/demodb -user
db2admin -pw passw0rd
- ››JPA2.0 Join联结查询
- ››集成医疗保健服务,第 2 部分: 使用 Apache Servi...
- ››集成医疗保健服务,第 1 部分: 将 Enterprise Ser...
- ››集成 Rational Software Architect 和 Rational D...
- ››集成 Windows Azure:适用于企业的 Windows Azure...
- ››集成 Flex, Spring, Hibernate 构建应用程序
- ››jpa onetomany
- ››集成 Windows 本地应用到 Eclipse RCP 程序中
- ››集成 DB2 与 Apache Geronimo
- ››JPA 2.0 中的动态类型安全查询
- ››集成 Adobe Flex 和 IBM WebSphere Portal
- ››集成 JPA 与 pureQuery: 让 Java Persistence API...
更多精彩
赞助商链接