网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用UltraEdit打造自己的Java IDE.
.[JAVA100例]028、图片的处理.
.Java环境变量的设置与调试.
.对于JAVA基础测试中常见的异常问.
.使用Jakarta Commons Pool处理对.
.Java中“异常机制”深入研究.
.哈希(不可逆)加密通用类库函数.
.使用JavaMail发送邮件.
.pnews.template模板.
.Struts的优点及其在Apusic上的安.
.要进入Java殿堂必须知道的名词.
.EJB 3.0开发指南之实体Bean的设计.
.超线程多核心下Java多线程编程技.
.J2EE1.4新特性之JDBC3.0的新特性.
.Java学习之神奇的i=i++.
.void 运算符.
.使用技巧:Java实现随机验证码功.
.Servlet实现动态图文结合输出.
.java虚拟机学习笔记2.
.基于Java线程实现后台定时监控.

源代码分享——进化中Hibernate3脚本

发表日期:2008-1-5



  在Hibernate有一些相当方便的辅助工具: hbm2Java,hbm2ddl, 数据库的逆向工程,Mapping Editor.
  
  这些任务可以通过Ant构建完成,Hibernate提供了Ant Tasks及其构建脚本.由于Hibernate从2到3进行了重大重构,且包重新做了组织,因此Ant构建脚本也发生了巨大变化.在2中脚本样式为:
  
  <?XML version="1.0"?>
  
  <project name="anto builder"
  
  default="db" basedir=".">
  
  <!-- Set up properties containing important project Directories -->
  
  <property name="source.root" value="src"/>
  
  <property name="class.root" value="classes"/>
  
  <property name="lib.dir" value="lib"/>
  
  <property name="data.dir" value="data"/>
  
  <!-- Set up the class path for compilation and execution -->
  
  <path id="project.class.path">
  
  <!-- Include our own classes, of course -->
  
  <pathelement location="${class.root}" />
  
  <!-- Include jars in the project library directory -->
  
  <fileset dir="${lib.dir}">
  
  <include name="*.jar"/>
  
  </fileset>
  
  </path>
  
  <target name="db" description="Runs HSQLDB database management UIagainst the database file--use when application is not running">
  
  <java classname="org.hsqldb.util.DatabaseManager"
  
  fork="yes">
  
  <classpath refid="project.class.path"/>
  
  <arg value="-driver"/>
  
  <arg value="org.hsqldb.jdbcDriver"/>
  
  <arg value="-url"/>
  
  <arg value="jdbc:hsqldb:${data.dir}/music"/>
  
  <arg value="-user"/>
  
  <arg value="sa"/>
  
  </java>
  
  </target>
  
  <!-- Teach Ant how to use Hibernate's code generation tool -->
  
  <taskdef name="hbm2java"
  
  classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
  
  classpathref="project.class.path"/>
  
  <!-- Generate the java code for all mapping files in our source tree -->
  
  <target name="codegen"
  
  description="Generate Java source from the O/R mapping files">
  
  <hbm2java output="${source.root}">
  
  <fileset dir="${source.root}">
  
  <include name="**/*.hbm.xml"/>
  
  </fileset>
  
  </hbm2java>
  
  </target>
  
  <!-- Create our runtime subdirectories and copy resources into them -->
  
  <target name="prepare" description="Sets up build strUCtures">
  
  <mkdir dir="${class.root}"/>
  
  <!-- Copy our property files and O/R mappings for use at runtime -->
  
  <copy todir="${class.root}" >
  
  <fileset dir="${source.root}" >
  
  <include name="**/*.properties"/>
  
  <include name="**/*.hbm.xml"/>
  
  </fileset>
  
  </copy>
  
  </target>
  
  <!-- Compile the java source of the project -->
  
  <target name="compile" depends="prepare"
  
  description="Compiles all Java classes">
  
  <javac srcdir="${source.root}"
  
  destdir="${class.root}"
  
  debug="on"
  
  optimize="off"
  
  deprecation="on">
  
  <classpath refid="project.class.path"/>
  
  </javac>
  
  </target>
  
  <!-- Generate the schemas for all mapping files in our class tree -->
  
  <target name="schema" depends="compile"
  
  description="Generate DB schema from the O/R mapping files">
  
  <!-- Teach Ant how to use Hibernate's schema generation tool -->
  
  <taskdef name="schemaeXPort"
  
  classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
  
  classpathref="project.class.path"/>
  
  <schemaexport properties="${class.root}/hibernate.properties"
  
  quiet="no" text="no" drop="no">
  
  <fileset dir="${class.root}">
  
  <include name="**/*.hbm.xml"/>
  
  </fileset>
  
  </schemaexport>
  
  </target>
  
  </project>
  
  在3中,构建脚本为:
  
  <?xml version="1.0" encoding="GBK"?>
  
  <project name="Hibernate" default="anthbm2java" basedir=".">
  
  <property name="src.dir" value="./src" />
  
  <property name="class.dir" value="./bin" />
  
  <property name="lib.dir" value="D:/eclipse/plugins/org.hibernate.eclipse_3.0.0.alpha4/lib" />
  
  <path id="project.class.path">
  
  <fileset dir="${lib.dir}">
  
  <include name="*.jar"/>
  
  </fileset>
  
  <pathelement location="${class.dir}" />
  
  </path>
  
  <path id="tasks.classpath">
  
  <fileset dir="${lib.dir}">
  
  <include name="*.jar"/>
  
  </fileset>
  
  <pathelement location="${class.dir}" />
  
  </path>
  
  <target name="anthbm2java">
  
  <taskdef name="hibernatetool"
  
  classname="org.hibernate.tool.ant.HibernateToolTask"
  
  classpathref="tasks.classpath"/>
  
  <hibernatetool destdir="${class.dir}">
  
  <configuration configurationfile="hibernate.cfg.xml" >
  
  <fileset dir="${src.dir}">
  
  <include name="**/*.hbm.xml" />
  
  </fileset>
  
  </configuration>
  
  <hbm2ddl export="false" console="false" create="true" update="false" drop="false" outputfilename="broad.sql" delimeter=";"/>
  
  其中的delimeter属性在Hibernate-Tool 3 A5版本中不支持.
  
  <hbm2java generics="true" ejb3="false"/>
  
  <cfg2hbm/>
  
  <hbm2doc/>
  
  <!--
  
  <cfg2cfgXml/>
  
  这个任务在Hibernate-Tool 3 A5版本中不支持.  -->
  
  </hibernatetool>
  
  </target>
  
  </project> Hibernate3构建脚本的变化
  
  这个脚本在Eclipse中检验过.
  
  通过这个脚本,执行了很多Hibernate辅助工具的功能,方便了开发.
上一篇:怎样利用Hibernate开发Blog实例分析 人气:517
下一篇:用Struts实现模板 人气:735
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐