1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.math.*; 19 20 import org.compiere.util.DB; 21 22 28 public class MPInstance extends X_AD_PInstance 29 { 30 35 public MPInstance (Properties ctx, int AD_PInstance_ID) 36 { 37 super (ctx, AD_PInstance_ID); 38 if (AD_PInstance_ID == 0) 39 { 40 setAD_Process_ID (0); 41 setRecord_ID (0); 42 setIsProcessing (false); 43 } 44 } 46 51 public MPInstance (Properties ctx, ResultSet rs) 52 { 53 super (ctx, rs); 54 } 56 61 public MPInstance (MProcess process, int Record_ID) 62 { 63 super (process.getCtx(), 0); 64 setAD_Process_ID (process.getAD_Process_ID()); 65 setRecord_ID (Record_ID); 66 setIsProcessing (false); 67 save(); MProcess_Para[] para = process.getParameter(); 70 for (int i = 0; i < para.length; i++) 71 { 72 MPInstance_Para pip = new MPInstance_Para (process.getCtx(), getAD_PInstance_ID(), para[i].getSeqNo()); 73 pip.setParameterName(para[i].getColumnName()); 74 pip.setInfo(para[i].getName()); 75 pip.save(); 76 } 77 } 79 protected POInfo initPO (Properties ctx) 80 { 81 int AD_Table_ID = 282; 82 POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID); 83 return poi; 84 } 85 86 87 private MPInstance_Para[] m_parameters = null; 88 89 93 public MPInstance_Para[] getParameter() 94 { 95 if (m_parameters != null) 96 return m_parameters; 97 ArrayList list = new ArrayList(); 98 String sql = "SELECT * FROM AD_PInstance_Para WHERE AD_PInstance_ID=?"; 100 PreparedStatement pstmt = null; 101 try 102 { 103 pstmt = DB.prepareStatement(sql); 104 pstmt.setInt(1, getAD_Process_ID()); 105 ResultSet rs = pstmt.executeQuery(); 106 while (rs.next()) 107 { 108 list.add(new MPInstance_Para(getCtx(), rs)); 109 } 110 rs.close(); 111 pstmt.close(); 112 pstmt = null; 113 } 114 catch (Exception e) 115 { 116 log.error("getParameter", e); 117 } 118 finally 119 { 120 try 121 { 122 if (pstmt != null) 123 pstmt.close (); 124 } 125 catch (Exception e) 126 {} 127 pstmt = null; 128 } 129 m_parameters = new MPInstance_Para[list.size()]; 131 list.toArray(m_parameters); 132 return m_parameters; 133 } 135 136 137 138 private ArrayList m_log = new ArrayList(); 139 140 144 public MPInstance_Log[] getLog() 145 { 146 m_log.clear(); 148 String sql = "SELECT * FROM AD_PInstance_Log WHERE AD_PInstance_ID=? ORDER BY Log_ID"; 149 PreparedStatement pstmt = null; 150 try 151 { 152 pstmt = DB.prepareStatement(sql); 153 pstmt.setInt(1, getAD_PInstance_ID()); 154 ResultSet rs = pstmt.executeQuery(); 155 while (rs.next()) 156 { 157 m_log.add(new MPInstance_Log(rs)); 158 } 159 rs.close(); 160 pstmt.close(); 161 pstmt = null; 162 } 163 catch (Exception e) 164 { 165 log.error("getLog", e); 166 } 167 finally 168 { 169 try 170 { 171 if (pstmt != null) 172 pstmt.close (); 173 } 174 catch (Exception e) 175 {} 176 pstmt = null; 177 } 178 179 MPInstance_Log[] retValue = new MPInstance_Log[m_log.size()]; 180 m_log.toArray(retValue); 181 return retValue; 182 } 184 190 public void addLog (Timestamp P_Date, int P_ID, BigDecimal P_Number, String P_Msg) 191 { 192 MPInstance_Log logEntry = new MPInstance_Log (getAD_PInstance_ID(), m_log.size()+1, 193 P_Date, P_ID, P_Number, P_Msg); 194 m_log.add(logEntry); 195 } 199 200 201 202 206 public boolean save () 207 { 208 log.debug ("save"); 209 return super.save (); 210 } 212 public String toString () 213 { 214 StringBuffer sb = new StringBuffer ("MPInstance[") 215 .append (getID()) 216 .append(",OK=").append(isOK()); 217 String msg = getErrorMsg(); 218 if (msg != null && msg.length() > 0) 219 sb.append(msg); 220 sb.append ("]"); 221 return sb.toString (); 222 } 224 public void log() 225 { 226 log.info(toString()); 227 MPInstance_Log[] pil = getLog(); 228 for (int i = 0; i < pil.length; i++) 229 log.info(pil[i]); 230 } 232 public void setRecord_ID (int Record_ID) 233 { 234 setValue ("Record_ID", new Integer (Record_ID)); 235 } 236 237 public int getRecord_ID () 238 { 239 Integer ii = (Integer )getValue ("Record_ID"); 240 if (ii == null) 241 return 0; 242 return ii.intValue (); 243 } 244 245 public void setIsProcessing (boolean IsProcessing) 246 { 247 setValue ("IsProcessing", new Boolean (IsProcessing)); 248 } 249 250 public boolean isProcessing () 251 { 252 Boolean bb = (Boolean )getValue ("IsProcessing"); 253 if (bb != null) 254 return bb.booleanValue (); 255 return false; 256 } 257 258 public void setAD_User_ID (int AD_User_ID) 259 { 260 setValue ("AD_User_ID", new Integer (AD_User_ID)); 261 } 262 263 public int getAD_User_ID () 264 { 265 Integer ii = (Integer )getValue ("AD_User_ID"); 266 if (ii == null) 267 return 0; 268 return ii.intValue (); 269 } 270 271 public void setErrorMsg (String Errormsg) 272 { 273 setValue ("ErrorMsg", Errormsg); 274 } 275 276 public String getErrorMsg () 277 { 278 return (String )getValue ("ErrorMsg"); 279 } 280 281 public void setResult (int Result) 282 { 283 setValue ("Result", new Integer (Result)); 284 } 285 286 public static final int RESULT_OK = 1; 287 public static final int RESULT_ERROR = 0; 288 289 public int getResult () 290 { 291 Integer ii = (Integer )getValue ("Result"); 292 if (ii == null) 293 return 0; 294 return ii.intValue (); 295 } 296 297 public boolean isOK() 298 { 299 return getResult() == RESULT_OK; 300 } 301 302 public void setAD_Process_ID (int AD_Process_ID) 303 { 304 setValue ("AD_Process_ID", new Integer (AD_Process_ID)); 305 } 306 307 public int getAD_Process_ID () 308 { 309 Integer ii = (Integer )getValue ("AD_Process_ID"); 310 if (ii == null) 311 return 0; 312 return ii.intValue (); 313 } 314 315 void setAD_PInstance_ID (int AD_PInstance_ID) 316 { 317 setValueNoCheck ("AD_PInstance_ID", new Integer (AD_PInstance_ID)); 318 } 319 320 public int getAD_PInstance_ID () 321 { 322 Integer ii = (Integer )getValue ("AD_PInstance_ID"); 323 if (ii == null) 324 return 0; 325 return ii.intValue (); 326 } 327 328 } | Popular Tags |