<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    kapok

    垃圾桶,嘿嘿,我藏的這么深你們還能找到啊,真牛!

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      455 隨筆 :: 0 文章 :: 76 評論 :: 0 Trackbacks

    http://blog.ideoplex.com/software/2003/12/11.html

    Adding a Hibern8IDE browser to your Hibernate Project

    The Hibern8 IDE is a quick'n'dirty interactive Hibernate Query Language (HQL) tool. And while it's not really an IDE, it's a pretty slick way of viewing the contents of your persistent Hibernate data store. There are basically two ways of opening up your data store with Hibern8IDE: you can interactively add hibernate properties and configuration files or you can programmatically start Hibern8IDE with a hibenate configuration object. Since I hate to constantly repeat myself, I opted for the programmatic option.

    If you've been following my series on Hibernate, then you know that I've been keeping all my configuration files in the cfg directory tree. So I decided to simply traverse the cfg directory tree, adding all .hbm.xml files to a configuration object before passing the configuration object on to Hibern8IDE. And since traversing a directory is a pretty common operation, I decided to implement a general solution consisting of a simple TreeWalker class and a TreeAction interface.

    14 May 04: Max Andersen from the Hibernate team comments that the load order of .hbm.xml files is important when a subclass or joined-subclass is defined in a separate file from the parent. If the parent is defined in parent.hbm.xml and the child is defined in child.hbm.xml, then parent.hbm.xml must be loaded before child.hbm.xml.

    package util; 

    public interface TreeAction { public void handle( java.io.File f ); }
    package util;

    import java.io.File;

    public class TreeWalker {

    public void walk ( TreeAction actor, File root ) { if ( root.exists() ) { if ( root.isDirectory() ) { File[] files = root.listFiles();

    for ( int i=0 ; i<files.length ; ++i ) { if ( files[i].isDirectory() ) { this.walk( actor, files[i] ); } else if ( files[i].isFile() ) { actor.handle( files[i] ); } } } else if ( root.isFile() ) { actor.handle( root ); } } } }

    The top level Ide class treats each command line argument as a configuration root directory It contains a static inner class Action implementing TreeAction that adds each .hbm.xml file to the hibernate configuration. And we hand the configuration object to Hibern8IDE once all the configuration directories have been traversed.

    Note that static inner class Action has to catch the hibernate MappingException to match the TreeAction interface. After catching the MappingException, we use it to create a RuntimeException. This trick of wrapping checked exceptions in a RuntimeException comes courtesy of Tim Bray. This is an appropriate response because our only other choice is to ignore it entirely.

    import java.io.File;

    import net.sf.hibernate.cfg.Configuration; import net.sf.hibernate.MappingException; import net.sf.hibernate.HibernateException;

    import net.sf.hibern8ide.Hibern8IDE;

    import util.*;

    public class Ide {

    static class Action implements TreeAction { private Configuration config;

    public Action ( Configuration aConfig ) { config = aConfig; }

    public void handle ( File f ) { String name = f.toString(); if ( name.endsWith( ".hbm.xml" ) ) { try { config.addFile( f ); } catch ( MappingException e ) { throw new RuntimeException( e ); } } } }

    public static void main ( String[] args ) throws MappingException, HibernateException { Configuration cfg = new Configuration(); Action actor = new Action( cfg ); TreeWalker walker = new TreeWalker();

    for ( int i=0 ; i<args.length ; ++i ) { File f = new File( args[i] ); walker.walk( actor,f ); }

    Hibern8IDE.startWith( cfg ); } }

    Finally, we add a new ide action to our build file (other minor buildfile changes not shown here). The single command line argument references our configuration directory.

      ...
      <target name="ide" depends="compile,setup-run">
        <java classname="Ide"
              fork="true">
          <classpath refid="classpath.ide" />
          <arg value="${cfg-dir}" />
          <sysproperty key="log4j.configuration" value="${LOG4J_OUT}" />
        </java>
      </target>
      ...
    

    Now we can launch the Hibern8IDE query tool by simply typing "ant ide". Here's the source for adding a Hibern8IDE query tool to your Hibernate project..


    Disclaimer: I don't claim to be an expert on hibernate. Please send comments and corrections.

    posted on 2005-05-24 15:49 笨笨 閱讀(422) 評論(0)  編輯  收藏 所屬分類: J2EE 、HibernateAndSpring 、ALL
    主站蜘蛛池模板: 成人午夜免费视频| 又粗又大又硬又爽的免费视频| 国产精品亚洲а∨无码播放麻豆 | 亚洲VA综合VA国产产VA中| 久久不见久久见免费视频7| 一级毛片在线免费视频| 亚洲熟妇少妇任你躁在线观看| 亚洲AV日韩精品久久久久| 亚洲国产成人久久一区WWW| 大学生一级特黄的免费大片视频| 一级毛片不卡片免费观看| 日韩精品无码免费视频| 亚洲av无码日韩av无码网站冲| 亚洲欧洲日产韩国在线| 亚洲AV人无码激艳猛片| 国产亚洲美女精品久久久2020| 免费观看国产小粉嫩喷水| 女人被弄到高潮的免费视频| 成人免费午夜无码视频| 亚洲视频免费观看| 三年片在线观看免费观看大全动漫| 国产精品青草视频免费播放| 黄页网站在线视频免费| 国产产在线精品亚洲AAVV| 亚洲成AV人影片在线观看| 亚洲永久网址在线观看| 亚洲AV综合色区无码二区爱AV| 亚洲精品福利在线观看| 亚洲欧洲日产国产综合网| 水蜜桃亚洲一二三四在线| 久久夜色精品国产嚕嚕亚洲av| 亚洲videos| 亚洲激情黄色小说| 亚洲激情校园春色| 亚洲性69影院在线观看| 亚洲欧洲日产国产最新| 亚洲影视自拍揄拍愉拍| 亚洲熟妇无码八V在线播放| 亚洲精品色播一区二区| 黄色a三级免费看| 无码毛片一区二区三区视频免费播放 |