Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Param.java

Go to the documentation of this file.
00001 package cedar.jetweb.model.parameters;
00002 
00003 import cedar.jetweb.JetWebException;
00004 import cedar.jetweb.db.DBParamManager;
00005 
00007 
00008 public class Param <T>{
00009 
00010     private Integer id_ = -1;
00011     private String name_ = "";
00012     private T value_;
00013 
00014     public Param(){
00015 
00016     }
00017 
00018     public Param(Integer id){
00019     id_ = id;
00020     }
00021 
00022     public Param(String name){
00023     name_ = name;
00024     }
00025 
00026     public Integer getParamId(){
00027     return id_;
00028     }
00029 
00030     public Param setParamId(Integer id){
00031     id_ = id;
00032     return this;
00033     }
00034 
00035     public String getName(){
00036     if(name_.equals("") && id_>0){
00037         try{
00038         retrieve();
00039         }catch(JetWebException err){
00040         System.out.println
00041             ("Unable to retrieve Parameter " + id_ +
00042              " name from database");
00043         System.out.println(err.getMessage());
00044         err.printStackTrace();
00045         }
00046     }
00047     return name_;
00048     }
00049 
00050     public Param setName(String name){
00051     name_ = name;
00052     return this;
00053     }
00054 
00055     public Param setValue(T value){
00056     value_ = value;
00057     return this;
00058     };
00059 
00060     public T getValue(){
00061     if(value_==null && id_>0){
00062         try{
00063         retrieve();
00064         }catch(JetWebException err){
00065         System.out.println
00066             ("Unable to retrieve Parameter " + id_ +
00067              " value from database");
00068         System.out.println(err.getMessage());
00069         err.printStackTrace();
00070         }
00071     }
00072     return value_;
00073     };
00074 
00075     public boolean equals(Param<T> param){
00076     
00077     return param.getName().equals(getName()) && 
00078         param.getParamId()== getParamId();
00079     }
00080 
00087     public boolean  store()
00088     throws JetWebException{
00089 
00090     Integer id = DBParamManager.matchId(this);
00091     if(id >0){
00092         id_ = id;
00093         return false;
00094     }
00095 
00096     DBParamManager.toDB(this);
00097 
00098     return true;
00099     }
00100 
00107     public boolean retrieve()
00108     throws JetWebException{
00109 
00110     boolean success = false;
00111 
00112     if(id_>0){
00113         success = DBParamManager.selectById(this);
00114         if(success) return success;
00115     }
00116 
00117     Integer id = DBParamManager.matchId(this);
00118 
00119     if(id>0){
00120         id_ = id;
00121         success = true;
00122     }
00123 
00124     return success;
00125     }
00126 }

Generated Wed Jan 17 09:14:27 GMT 2007