Keyword Caching Bean


package com.xpagedeveloper;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Vector;
import javax.faces.context.FacesContext;

import lotus.domino.Database;
import lotus.domino.Document;

import lotus.domino.NotesException;
import lotus.domino.View;

import java.util.concurrent.ConcurrentHashMap;
import com.ibm.xsp.model.domino.DominoUtils;

public class FormHelper2 implements Serializable {
 
    private static final long serialVersionUID = 2L;
    
    private ConcurrentHashMap <String,Vector> Cache=null;
    
    public FormHelper2 (){
    	this.Cache=new ConcurrentHashMap();
    }
	
 @SuppressWarnings("unchecked")
public Vector <String> getKeyword(String Name){
	
	 Vector keyword= new Vector();
	 try {
		 
	if(this.Cache.containsKey(Name)){
		return this.Cache.get(Name);
	}else{
	 Database db=DominoUtils.getCurrentDatabase();
	 View view = db.getView("byKeyword");
	
	 Document Doc=view.getDocumentByKey(Name,true);
	 if(Doc!=null){
	 keyword=Doc.getItemValue("Data");
	 }
	 Doc.recycle();Doc=null;
	 view.recycle();view=null;
	 db.recycle();db=null;
	 
	 Cache.put(Name, keyword);
	}
	 } catch (NotesException e) {
	
		 System.out.println("Error1");
		}
	 
	 return keyword;
	 
 } 
 public String getKeywordString(String Name,String Separator){
	 String Data="";
	 try{
	 Vector <String> keyword=getKeyword(Name);
	 if(!keyword.isEmpty()){
		 Iterator <String> i=keyword.iterator();
		 
		 while(i.hasNext()) {
		          String entry = i.next();
		          if("".equals(Data)){
		        	  Data=entry;
		          }else{
		        	  Data=Data+Separator;
		        	  Data=Data+entry;
		          }
		  }
	 }

 }catch(Exception e){
	 System.out.println("Error 2");
 }
	 return Data; 
 }
 public void recacheKeyword(String Name){
	 if(this.Cache.containsKey(Name)){
		 this.Cache.remove(Name);
	 }
 }
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...