?? dbtool.java~310~
字號:
wg.words.remove(ew.word);
wg.store();
//刪除EnWord本身
deleteOne(EN_WORD_DB,rsId);
return rsId;
}
catch(Exception e){
e.printStackTrace();
return -1;
}
}
/**
* 刪除單個CnWord方法,該方法的執行過程如下:<br>
* 1.刪除EnWord中關聯<br>
* 2.刪除CnGroup中的關聯<br>
* 3.刪除CnWord本身
* @param rsId int 失?。?1,成功:正整數
*/
public int delCnWord(int rsId){
try{
//構建CnWord對象
CnWord cw=new CnWord(rsId);
//刪除該CnWord與EnWord的關聯
if(cw.enRSId.size()>0){
Vector ens=cw.enRSId;
EnWord ew=null;
int index=0;
for(int n=ens.size()-1;n>=0;n--){
ew=new EnWord(Integer.parseInt((String)ens.elementAt(n)));
index=ew.cnRSId.indexOf(rsId+"");
ew.cnAdj.removeElementAt(index);
ew.cnRSId.removeElementAt(index);
ew.store();
}
}
//刪除該CnWord與CnGroup的關聯
WordGroup wg=new WordGroup(cw.word);
wg.words.remove(cw.word);
wg.store();
//刪除EnWord本身
deleteOne(CN_WORD_DB,rsId);
return rsId;
}
catch(Exception e){
e.printStackTrace();
return -1;
}
}
/**
* 返回中文詞語或英文單詞RMS數據庫中下一條記錄的id編號
* @param en boolean 英文true,中文false
* @return int
*/
public int getNextId(boolean en){
RecordStore rs=null;
int nextId=-1;
try{
if (en) {
rs = openRS(EN_WORD_GROUP_DB);
nextId = rs.getNextRecordID();
rs.closeRecordStore();
} else {
rs = openRS(CN_WORD_GROUP_DB);
nextId = rs.getNextRecordID();
rs.closeRecordStore();
}
}
catch(Exception e){e.printStackTrace();}
return nextId;
}
/**
* 重新初始化CnGroupDB庫,主要是創建占位Record,該方法采用先刪除原有庫,然后在重新
* 創建庫并插入記錄.
*/
public void initCnGroupDB(byte[]bt){
try {
RecordStore rs = openRS(CN_WORD_GROUP_DB);
rs.closeRecordStore();
rs.deleteRecordStore(CN_WORD_GROUP_DB);
rs=openRS(CN_WORD_GROUP_DB);
for(int i=0;i<1000;i++){
int res=rs.addRecord(bt,0,bt.length);
}
rs.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
}
/**
* 重新初始化EnGroup庫,主要是創建占位Record,該方法采用先刪除原有庫,然后在重新
* 創建庫并插入記錄.
*/
public void initEnGroupDB(byte[]bt){
try {
RecordStore rs = openRS(EN_WORD_GROUP_DB);
rs.closeRecordStore();
rs.deleteRecordStore(EN_WORD_GROUP_DB);
rs=openRS(EN_WORD_GROUP_DB);
byte[]t=new byte[0];
for(int i=0;i<676;i++){
int res=rs.addRecord(bt,0,bt.length);
System.out.println(i+"="+res);
}
rs.closeRecordStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
}
/**
* 數據庫占位初始化,由于需要校長時間,所以采用了啟用新線程的方法,后臺執行數據庫的初始化,
* 前臺顯示請等待...頁面
*/
public void run() {
RecordStore rs=null;
try{
ByteArrayOutputStream bos=new ByteArrayOutputStream();
DataOutputStream dos=new DataOutputStream(bos);
dos.writeInt(0);
byte[]bt=bos.toByteArray();
dos.close();
bos.close();
if (cnFirstId < 0) {
initCnGroupDB(bt);
cnFirstId=getNextId(false)-1000;
}
if (enFirstId < 0) {
initEnGroupDB(bt);
enFirstId=getNextId(true)-676;
}
}
catch(Exception e){e.printStackTrace();}
Navigator.show();
}
/**
* 返回生詞庫中的Id集合
* @return Vector
*/
public Vector getSenIds(){
Vector result = new Vector();
try{
RecordStore rs = this.openRS(DbTool.STRANGE_WORD);
RecordEnumeration re = rs.enumerateRecords(null, null, false);
while (re.hasNextElement()) {
byte[] bs = re.nextRecord();
ByteArrayInputStream bis = new ByteArrayInputStream(bs);
DataInputStream dis = new DataInputStream(bis);
result.addElement("" + dis.readInt());
dis.close();
bis.close();
}
rs.closeRecordStore();
}
catch(Exception e){
e.printStackTrace();
}
return result;
}
/**
* 強行刪除該程序下的所有RMS
*/
public void deleteAll(){
try {
RecordStore rs = openRS(CN_WORD_GROUP_DB);
rs.closeRecordStore();
try{
rs.deleteRecordStore(CN_WORD_GROUP_DB);
}catch(Exception e){System.out.println("STRANGE_WORD not equals!");}
try{
rs.deleteRecordStore(EN_WORD_GROUP_DB);
}catch(Exception e){System.out.println("STRANGE_WORD not equals!");}
try{
rs.deleteRecordStore(CN_WORD_DB);
}catch(Exception e){System.out.println("STRANGE_WORD not equals!");}
try{
rs.deleteRecordStore(EN_WORD_DB);
}catch(Exception e){System.out.println("STRANGE_WORD not equals!");}
try{
rs.deleteRecordStore(STRANGE_WORD);
}catch(Exception e){System.out.println("STRANGE_WORD not equals!");}
try{
rs.deleteRecordStore(SYSTEM_DB);
}catch(Exception e){System.out.println("SYSTEM_DB not equals!");}
System.out.println("delete is ok..");
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
}
/**
* 刪除記錄倉庫中的單條記錄
* @param rsName String
* @param rsid int
*/
public void deleteOne(String rsName,int rsid){
try{
RecordStore rs=openRS(rsName);
rs.deleteRecord(rsid);
rs.closeRecordStore();
}
catch(Exception e){
e.printStackTrace();
}
}
/* 以下是測試方法?。?
public void selectAll(){
try{
RecordStore rs=openRS(EN_WORD_DB);
queryRS(rs,1);
rs.closeRecordStore();
System.out.println("E is end ....");
RecordStore rs1=openRS(CN_WORD_DB);
queryRS(rs1,2);
rs1.closeRecordStore();
System.out.println("C is end ....");
RecordStore rs2=openRS(EN_WORD_GROUP_DB);
queryRS(rs2,-1);
rs2.closeRecordStore();
System.out.println("EG is end ....");
RecordStore rs3=openRS(CN_WORD_GROUP_DB);
queryRS(rs3,0);
rs3.closeRecordStore();
System.out.println("CG is end ....");
}
catch(Exception e){
e.printStackTrace();
}
}
private void queryRS(RecordStore rs,int type) throws
InvalidRecordIDException, RecordStoreNotOpenException,
RecordStoreException {
RecordEnumeration re=rs.enumerateRecords(null,null,false);
int id=-1;
for(int i=0;i<re.numRecords();i++){
id=re.nextRecordId();
System.out.println("_"+id);
if(type==0){
WordGroup cwg=new WordGroup(CN_WORD_GROUP_DB,id);
if(cwg.words.size()>0){
System.out.println(cwg.rsId + "CG_.." + cwg.words);
}
}
else if(type==-1){
WordGroup ewg=new WordGroup(EN_WORD_GROUP_DB,id);
if(ewg.words.size()>0){
System.out.println(ewg.rsId + "EG_.." + ewg.words);
}
}
else if(type==1){//en
EnWord ew=new EnWord(id);
System.out.println(ew.rsId+"E_.w."+ew.word);
System.out.println(ew.rsId+"E_.adj."+ew.cnAdj);
System.out.println(ew.rsId+"E_.cid."+ew.cnRSId);
}
else{
CnWord cw=new CnWord(id);
System.out.println(cw.rsId+"C_.w."+cw.word);
System.out.println(cw.rsId+"C_.eid."+cw.enRSId);
}
}
}
*/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -