麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

源代碼分享——進化中Hibernate3腳本

2019-11-18 12:56:41
字體:
來源:轉載
供稿:網友

  在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輔助工具的功能,方便了開發.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 狠狠婷婷综合久久久久久妖精 | 午夜精品久久久久久毛片 | 精品少妇v888av | 黄色片网站在线免费观看 | 国产精品久久久久久久四虎电影 | 亚洲射逼| 欧美日韩高清在线观看 | 99在线热播精品免费 | 欧美日韩在线播放 | fc2国产成人免费视频 | 91久久极品少妇韩国 | 一区免费| 久久国产91 | 91九色蝌蚪国产 | 大奶一级片 | 在线观看国产一区二区三区 | 亚洲成人欧美在线 | 天天透天天狠天天爱综合97 | 久久毛片免费 | 1314av| 91成人一区| 久久久久久久久日本理论电影 | 最新欧美精品一区二区三区 | 欧美成人理论片乱 | 99日韩精品视频 | 思思久而久而蕉人 | 久久久久久久久久91 | 久久精品一级 | 美女露100%无遮挡 | 草人人 | 久久吊| av噜噜噜噜 | 羞羞电影网 | 亚洲va国产va| 老女人碰碰在线碰碰视频 | 日韩视频一区二区在线观看 | 欧美a∨一区二区三区久久黄 | 中文字幕视频在线播放 | 电影91 | 亚洲视频综合网 | 欧美精品欧美 |