2005年07月18日

    It seems that i will finish the framework in this week.In this framework i use hibernate ,spring ,struts,jfreechart,itext,etc.After this framework ,It’s true that i will be very well up in these technologies. 

  And the next plan is to research the web search enginer of nutch.The target is add the additional plugin into nutch .

  For catching some good chance in the future, it is necessary to master  EJB3,JMS,UML.RUP,etc.Also I must have fluent English.

   In these which I will be improved,The English is need to take many time and have enough patience.

   Of cource ,I can’t egnore the chance in this company . It is the base of  development  that i finished the work with flying colors.

  

2005年07月08日

Hibernate的继承映射包含了三种不同的策略:

  1. 每簇类使用一个表;
  2. 每个子类一个表;
  3. 每个具体内一个表(有限制)。

假设我们有四个类Animal,Dog,Cat,其代码如下:
文件名:Animal.java

class Animal {
    
private String identifier;
    
private String name;
    
private String category;
    
// setter and getter
}


文件名:Dog.java

class Dog extends Animal {
    
private String 
    
// setter and getter
}


文件名:Cat.java

class Cat extends Animal {
    
private String 
    
// setter and getter
}


  • 每簇类使用一个表

       使用每簇类使用一个表的策略时,有一个限制就时子类不能有NOT NULL,映射文件为:
       文件名:Animal.hbm.xml

       <class name="Animal" table="TB_ANIMAL">
          
<id name="identifier" type="string" column="IDENTIFIER">
             
<generator class="uuid.hex"/>
          
</id>
          
<discriminator column="ANIMAL_TYPE" type="string"/>
          
<property name="name" column="NAME" type="string"/>
          
          
<subclass name="Dog" discriminator-value="DOG">
             
          
</subclass>
          
<subclass name="Cat" discriminator-value="CAT">
             
          
</subclass>
       
</class>


  • 每个子类一个表

       使用每个子类一个表的策略时,可以使用一个映射文件实现,也可以分成多个映射文件来实现。每个子类一个映射文件的情况:
       文件名:Animal.hbm.xml

       <class name="Animal" table="ANIMAL">
          
<id name="identifier" column="IDENTIFIER" type="string">
             
<generator class="uuid.hex"/>
          
</id>
          
<property >
       
</class>
       文件名:Dog.hbm.xml
       
<joined-subclass name="Dog" table="DOG" extends="Animal">
          
<key column="DOG_ID"/>
          
       
</joined-subclass>
       文件名:Cat.hbm.xml
       
<joined-subclass name="Cat" table="CAT" extends="Cat">
          
<key column="CAT_ID"/>
          
       
</joined-subclass>


       每个子类一个表的策略实际上一种one-to-one的映射。

  • 每个具体内一个表(有限制)

       使用每个具体内一个表(有限制)策略时,每一个子类的映射文件将要包含所有父类中的属性,映射文件:
       文件名:Dog.hbm.xml

       <class name="Dog" table="DOG">
          
<id name="identifier" column="IDENTIFIER" type="string">
             
<generator class="uuid.hex"/>
          
</id>
          
<property name="name" column="NAME" type="string"/>
          
       
</class>
       文件名:Cat.hbm.xml
       
<class name="Cat" table="CAT">
          
<id name="identifier" column="IDENTIFIER" type="string">
             
<generator class="uuid.hex"/>
          
</id>
          
<property name="name" column="NAME" type="string"/>
          
       
</class>


第二个例子

新建一个类,包名:javamxj.inheritance.two,类名:Animal。然后在生成的代码中添加变量,再利用“生成 Getter 和 Setter”,具体方式同《Eclipse快速上手Hibernate–1. 入门实例 》文章中的编辑User.java的方式一样。

·  这个类是父类,只是生成一个简单的表。

Vehicle.java

/*
 * Hibernate - 继承映射(每个子类一个表)
 * 创建日期 2005-4-9
 * @author javamxj(分享java快乐)
 * @link  Blog: htpp://javamxj.mblogger.cn  
 *              htpp://blog.csdn.net/javamxj/ 
 */
package javamxj.inheritance.two;

/**
 * @hibernate.class
 */
public class Vehicle {
	private Long id;

	private String name;

	/**
	 * @hibernate.id 
	 *   column="ID" 
	 *   generator-class="hilo" 
	 *   unsaved-value="null"
	 */
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @hibernate.property 
	 *   length = "24"
	 */
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
 
·  子类Car.java
Car.java
package javamxj.inheritance.two;

/**
 * @hibernate.joined-subclass
 * @hibernate.joined-subclass-key 
 *   column="id"
 */
public class Car extends Vehicle {
	private String seat;

	/**
	 * @hibernate.property 
	 *   column = "载客" 
	 *   length = "24"
	 */
	public String getSeat() {
		return seat;
	}

	public void setSeat(String seat) {
		this.seat = seat;
	}
}

 
·  子类Truck.java
Truck.java
package javamxj.inheritance.two;

/**
 * @hibernate.joined-subclass
 * @hibernate.joined-subclass-key 
 *   column="id"
 */
public class Truck extends Vehicle {
	private String load;

	/**
	 * @hibernate.property 
	 *   column = "载重" 
	 *   length = "24"
	 */
	public String getLoad() {
		return load;
	}

	public void setLoad(String load) {
		this.load = load;
	}
}

· 这两个子类都很简单,注意添加的hibernate.joined-subclass的标记。
 
· 好了,这时整个项目的结构如下:
 
 
3. 运行任务
 
·  双击“generate-hbm”任务,会发现在包中多了一个Vehicle.hbm.xml文件。如果没有,按F5键刷新一下(这里建议打开Eclipse的“首选项”对话框,在“工作台”中勾选“自动刷新工作空间”和“在构建之前自动保存”这两项,这样以后不用每次都刷新了)。

Vehicle.hbm.xml

<?xml version="1.0" encoding="GBK"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
    <class
        name="javamxj.inheritance.two.Vehicle"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >

        <id
            name="id"
            column="ID"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="hilo">
              <!--  
                  To add non XDoclet generator parameters, create a file named 
                  hibernate-generator-params-Vehicle.xml 
                  containing the additional parameters and place it in your merge dir. 
              -->
            </generator>
        </id>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="name"
            length="24"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Vehicle.xml
            containing the additional properties and place it in your merge dir.
        -->

        <joined-subclass
            name="javamxj.inheritance.two.Truck"
            dynamic-update="false"
            dynamic-insert="false"
        >
        <key
            column="id"
        />
        <property
            name="load"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="载重"
            length="24"
        />

        </joined-subclass>
        <joined-subclass
            name="javamxj.inheritance.two.Car"
            dynamic-update="false"
            dynamic-insert="false"
        >
        <key
            column="id"
        />
        <property
            name="seat"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="载客"
            length="24"
        />

        </joined-subclass>

    </class>

</hibernate-mapping>
· 重点是看看“joined-subclass”标签。
 
· 同时在hibernate.cfg.xml文件中会自动添加一个映射文件信息:
<mapping resource="javamxj/inheritance/two/Vehicle.hbm.xml"/>
 
 
·  先运行MySQL,然后双击“schemaexport”任务,在项目根目录下,会更新“schema-export.sql”文件。
打开这个文件,会发现添加了以下一些语句。
create table Car (
   id bigint not null,
   载客 varchar(24),
   primary key (id)
)
create table Truck (
   id bigint not null,
   载重 varchar(24),
   primary key (id)
)
create table Vehicle (
   ID bigint not null,
   name varchar(24),
   primary key (ID)
)
 
·  切换到数据库中,会发现已经自动产生了数据表Car、Truck、Vehicle。
 
· 将数据表与映射文件Vehicle.hbm.xml对照看看,可以更好的理解每个子类一个表的策略。
 
 
4. 测试程序
 
·  好了,在包javamxj.inheritance.two下新建一个Demo.java类,很简单,前半部分是添加数据,后半部分是简单的测试。

Demo.java

/*
 * Hibernate - 继承映射(每个子类一个表)
 * 创建日期 2005-4-9
 * @author javamxj(分享java快乐)
 * @link  Blog: htpp://javamxj.mblogger.cn  
 *              htpp://blog.csdn.net/javamxj/ 
 */
package javamxj.inheritance.two;

import java.util.Iterator;
import java.util.List;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;

public class Demo {

	public static void main(String[] args) {
		try {
			new Demo();
		} catch (HibernateException he) {
			he.printStackTrace();
		}
	}

	public Demo() throws HibernateException {		

		SessionFactory sf = new Configuration().configure()
				.buildSessionFactory();

		Session sess = sf.openSession();
		Transaction tx = null;
		try {
			tx = sess.beginTransaction();

			Car car = new Car();
			car.setName("奇瑞QQ");
			car.setSeat("4人");
			sess.save(car);

			Truck truck = new Truck();
			truck.setName("一汽解放");
			truck.setLoad("10吨");
			sess.save(truck);

			tx.commit();
		} catch (HibernateException e) {
			if (tx != null)
				tx.rollback();
			throw e;
		} finally {
			sess.close();
		}

		sess = sf.openSession();
		tx = null;
		try {
			tx = sess.beginTransaction();

			List pets = sess.find("from " + Vehicle.class.getName());

			for (Iterator it = pets.iterator(); it.hasNext();) {
				Vehicle vehicle = (Vehicle) it.next();
				System.out.println("车型 " + vehicle.getName()
						+ " its class is: " + vehicle.getClass().getName());
			}

			tx.commit();
		} catch (HibernateException e) {
			if (tx != null)
				tx.rollback();
			throw e;
		} finally {
			sess.close();
		}
	}
}
 
·  运行这个类,控制台输出如下:
 
·  同时,数据表中生成如下数据:
 
 
 
 


2005年07月06日

  

     现在工作任务比较轻松,打算整理出自己的framework,沿用spring的设计思想,正好前一个阶段做了一个不大的系统,打算全新改造这个系统,在改造系统的各个层面后,创建以后利用的成熟api包。然后整理出一套framework。

  refactor = my framework! 

   
   目标:整理出具有实际应用价值的成熟开发框架

   周期:三周左右

   结果:在本机上全部修改完毕,测试无误,在迁移到服务器上

framework 具体思路如下:

   1、整体改造采用ioc+aop模式,延续spring的设计思想。并在一些地方采用spring的成熟方案。

   2、用户登陆验证及网页安全验证采用jass思想,结合filter、session listen等技术,编写出一个跨application   server的包
 
   3、采用自制tag编写界面架构

   4、数据层采用hibernate+dao模式
  
   5、报表采用成熟的报表工具jsper report、 ireport、style report等一种,图形还是采用jfreechart。

  

   国内对于各种workflow产品研究最多的当数银狐999了,以下是他的blog和个人网站:

  http://blog.csdn.net/james999/archive/2004/10/29/158653.aspx

  http://blog.csdn.net/james999/archive/2004/10/29/158653.aspx

 在银狐999的网站和blog里面有大量的资料,个人觉得如果把他写的东西全部理解,可以成为workflow的高人了。估计有些workflow产品虽然银狐999在文章写过,估计他本人可能都没有研究透,不然太厉害了,现在workflow的产品太多,而且很多workflow实现的机制都不相同。

  开始我选择了jbpm,选择这个产品的原因.是因为我原来在一个公司工作的时候,不小心接受了bea的bpm培训。不过汗颜的是,当时对工作流的了解不够,同时培训又太乏味,没有对workflow重视起来。

        jbmp被jboss拉过去之后,产品在设计方面对jboss也捆绑的比较深,失去了java和open source的本质精神“run any platform”.真是拿人钱财,替人创利。本人深表理解,但同时对于jbmp的研究兴趣大减

        随后看起了osworkflow,据说此君在国内被用的很广,相对jbmp,osworkflow国内的研究资料相对多一些,加上osworkflow比较简单,看起来也比较省事,容易理解。但让我失望的是,osworkflow没有自带一个图形化编辑器,它带了一个简单丑陋的gui application,如果要用osworkflow的话,还要自己要写一个图形编辑器.

     随后找到了一个workflow图形化编辑器,令我兴奋,不过它遵守WfMC 规范,支持XPDL,对比WfMC和XPDL,osworkflow只能算作山外野汉,所以对于它和osworkflow的融合只能放弃。

 

osworkflow有一个被翻译成中文的指南:

http://wiki.opensymphony.com/pages/viewpage.action?pageId=2481

当然最多的资料还是它的官方网站

http://www.opensymphony.com/osworkflow/

2005年07月04日

    On last Friday ,the company had a "hammer online" match.And the many foods were  on a  big table which was in the  room of match. the match was very funny and stinging.It give me a very good feeling.

  By the way ,I had be in a compay like this which is easiest and comfortable.And I work hard than before because I treasure these such as what I said .

   After enjoy the happy time,I make a plan for this week.My main task is masterying the search engineer of Lucene, and try to write the edition search system on any platform.

 On the last weekend ,the company takes us to go skee which is in the room.The sport is very strange ,tired,funny.It can break out of hard work and strenuous rhythm.