英特內軟體股份有限公司


jcx.jform
Class hdao

java.lang.Object
  |
  +--jcx.jform.hdao

public abstract class hdao
extends java.lang.Object

Dmaker dao 物件 super class. 此類別 hdao 為物件化存取 DB Prootype.


	使用方法:
  1.Database first
     使用 DMaker 工具建立較為方便快速
  2.Code first
     自行手動建立 Java 程式 extends jcx.jform.hdao
     table 為 create table TABLE1 (FIELD1 int,FIELD2 varchar(20),primary key(FIELD1));
     範例如下
  package dao;
  import java.io.*;
  import java.util.*;
  import java.math.*;
  import jcx.util.*;
  import jcx.db.talk;
  
  public class myDAO extends jcx.jform.hdao{
  
  	public myDAO(talk t){
  		super(t);
    	}
  	public String configTable(){
  		return "TABLE1";
  	}
  
  	public String[] configKeys(){
  		return new String[]{"FIELD1"};
  	}
  
  	public String[] configFields(){
  		//return null means auto probe;
  		return null;
  	}
  
  	private int FIELD1;
  	private String FIELD2;
  
  	public myDAO setFIELD1(int FIELD1){
  		this.FIELD1 = FIELD1;
  		return this;
  	}
  
  	public int getFIELD1(){
  		return FIELD1;
  	}
  
  	public myDAO setFIELD2(String setFIELD2){
  		this.FIELD2 = FIELD2;
  		return this;
  	}
  
  	public String getFIELD2(){
  		return FIELD2;
  	}
  	public static void main(String[] args) throws Throwable{
  		//Enter your code here...
  
  		myDAO a1=new myDAO(jcx.db.talk.getTalk("test2.dat","a"));
  
  		// insert sample
  		a1.setFIELD1(1).setFIELD2("ROW1").insert();
  
  		a1.reset();
  
  		// query sample
  		a1.setFIELD1(1).query().next();
  
  		// fast query by key
  		a1.find(1).first();
  
  		if(a1.row!=-1){
  			System.out.println("-- FIELD1="+a1.getFIELD1()+" FIELD2="+a1.getFIELD2());
  		} else {
  			System.out.println("-- record not found!");
  		}
  
  		// update sample
  		a1.setFIELD2("new value");
  		a1.update();
  
  		//delete sample
  		a1.delete();
  
  		//transaction begin , commit and rollback;
  		a1.begin();
  		a1.setFIELD2(" value  to commit");
  		a1.update();
  		a1.commit();
  
  		a1.begin();
  		a1.setFIELD2(" value  to rollback");
  		a1.update();
  		a1.rollback();
  
  	}
  }
     
   有關未 commit transaction 處理
   程式執行 begin() 開始進入 transaction 後, database 將會開始鎖定您所異動的資料,
   如果您在程式的最後忘了做 commit() or rollback(), 在一般狀況下會導致 Server 非常嚴重的後果
   database 將會一直鎖住該筆資料或table,甚至可能必須重啟 AP Server來強迫 database rollback,
   因此請盡量做好 commit();
	
	DMaker Server 中執行結束的程式如果有遺忘的 transaction 未 commit , 預設會自動 rollback
   如果希望改變行為模式為 auto commit,請更改 dmaker/db.cfg 加入一行 
     forget_commit=commit
   如果希望改變行為模式為 auto rollback 且在 server log 印出訊息,請更改 dmaker/db.cfg 加入一行 
     forget_commit=exception
     


Field Summary
 int row
          查詢後指標 從1開始 .
 
Constructor Summary
hdao(talk t)
          建構子,請傳入 talk 物件
 
Method Summary
protected  void addIdentity(java.lang.String field)
          指定Identity 欄位.
 void begin()
          begin transaction.
 void commit()
          commit transaction.
abstract  java.lang.String[] configFields()
          取得table的fields,可以return null; 讓系統自動判斷,也可以自行定義.
abstract  java.lang.String[] configKeys()
          取得table的key.
 hdao configOrder(java.lang.String order)
          指定查詢時的 order by .
abstract  java.lang.String configTable()
          取得 資料庫對應的 tablename.
 int delete()
          執行 delete.
 hdao find(java.lang.Object[] values)
          執行快速查詢功能,傳入 key 即可.
 hdao first()
          查詢後移動指標至第一筆資料.
 boolean hasNext()
          查詢後是否有下一筆資料.
 int insert()
          執行 insert.
 hdao last()
          查詢後移動指標至最後一筆資料.
 hdao next()
          查詢後移動指標至下一筆資料.
 hdao query()
          執行查詢功能.
 hdao query(java.lang.String where, java.lang.Object[] values)
          執行查詢功能,傳入 where 即可.
 hdao reset()
          Reset 查詢.
 void rollback()
          rollback transaction.
 int update()
          執行 update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

row

public int row
查詢後指標 從1開始 . -1 表示查無資料 0 表示查詢後有資料,但尚未執行 next()
Constructor Detail

hdao

public hdao(talk t)
建構子,請傳入 talk 物件
Method Detail

configTable

public abstract java.lang.String configTable()
取得 資料庫對應的 tablename.
Returns:
String .

configKeys

public abstract java.lang.String[] configKeys()
取得table的key.
Returns:
String[] .

configFields

public abstract java.lang.String[] configFields()
取得table的fields,可以return null; 讓系統自動判斷,也可以自行定義.
Returns:
String[] .

addIdentity

protected void addIdentity(java.lang.String field)
指定Identity 欄位.
Parameters:
field - 欄位名稱.
Returns:
void.

query

public hdao query()
           throws java.lang.Throwable
執行查詢功能.
Returns:
this.

configOrder

public hdao configOrder(java.lang.String order)
指定查詢時的 order by .
Parameters:
order - by .
Returns:
this.

find

public hdao find(java.lang.Object[] values)
          throws java.lang.Throwable
執行快速查詢功能,傳入 key 即可.
Parameters:
keys - .
Returns:
this.

query

public hdao query(java.lang.String where,
                  java.lang.Object[] values)
           throws java.lang.Throwable
執行查詢功能,傳入 where 即可.
  exam.
  query("where FIELD1=? and FIELD2=?",1,"abc");

  
Parameters:
where - .
parameters - .
Returns:
this.

hasNext

public boolean hasNext()
查詢後是否有下一筆資料.
Returns:
boolean.

next

public hdao next()
          throws java.lang.Throwable
查詢後移動指標至下一筆資料.
Returns:
this.

first

public hdao first()
           throws java.lang.Throwable
查詢後移動指標至第一筆資料.
Returns:
this.

last

public hdao last()
          throws java.lang.Throwable
查詢後移動指標至最後一筆資料.
Returns:
this.

reset

public hdao reset()
           throws java.lang.Throwable
Reset 查詢.
Returns:
this.

update

public int update()
           throws java.lang.Throwable
執行 update.
Returns:
int 異動筆數.

insert

public int insert()
           throws java.lang.Throwable
執行 insert.
Returns:
int 異動筆數.

delete

public int delete()
           throws java.lang.Throwable
執行 delete.
Returns:
int 異動筆數.

begin

public void begin()
           throws java.sql.SQLException,
                  java.lang.ClassNotFoundException
begin transaction.
Returns:
void.

commit

public void commit()
            throws java.sql.SQLException
commit transaction.
Returns:
void.

rollback

public void rollback()
              throws java.sql.SQLException
rollback transaction.
Returns:
void.

英特內軟體股份有限公司