1 14 package org.compiere.session; 15 16 import java.util.*; 17 import java.sql.*; 18 import javax.sql.*; 19 20 import java.rmi.RemoteException ; 21 import javax.ejb.CreateException ; 22 import javax.ejb.EJBException ; 23 import javax.ejb.FinderException ; 24 import javax.ejb.RemoveException ; 25 import javax.ejb.SessionBean ; 26 import javax.ejb.SessionContext ; 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.naming.NamingException ; 30 import javax.rmi.PortableRemoteObject ; 31 32 import org.apache.log4j.Logger; 33 34 import org.compiere.interfaces.*; 35 36 import org.compiere.Compiere; 37 38 import org.compiere.util.CompiereStatement; 39 import org.compiere.util.CompiereStatementVO; 40 import org.compiere.acct.AcctServer; 41 import org.compiere.model.MWindowVO; 42 import org.compiere.process.*; 43 44 59 public class ServerBean implements SessionBean 60 { 61 62 private SessionContext m_Context; 63 64 private transient Logger log = Logger.getLogger(getClass()); 65 private static int s_no = 0; 67 private int m_no = 0; 68 private int m_windowCount = 0; 70 private int m_postCount = 0; 71 private int m_processCount = 0; 72 private int m_stmt_rowSetCount = 0; 73 private int m_stmt_updateCount = 0; 74 75 86 public MWindowVO getWindowVO (Properties ctx, int WindowNo, int AD_Window_ID, int AD_Menu_ID) 87 throws RemoteException 88 { 89 log.info ("getWindowVO[" + m_no + "] Window=" + AD_Window_ID); 90 MWindowVO vo = MWindowVO.create(ctx, WindowNo, AD_Window_ID, AD_Menu_ID); 92 m_windowCount++; 93 return vo; 94 } 96 97 108 public boolean postImmediate (int AD_Table_ID, int AD_Client_ID, 109 int Record_ID, boolean force) 110 throws RemoteException 111 { 112 log.info ("postImmediate[" + m_no + "] Table=" + AD_Table_ID + ", Record=" + Record_ID); 113 m_postCount++; 114 return AcctServer.postImmediate(AD_Table_ID, AD_Client_ID, Record_ID, force); 115 } 117 118 119 127 public RowSet stmt_getRowSet (CompiereStatementVO info) throws RemoteException 128 { 129 m_stmt_rowSetCount++; 131 CompiereStatement stmt = new CompiereStatement(info); 132 return stmt.remote_getRowSet(); 133 } 135 143 public int stmt_executeUpdate (CompiereStatementVO info) throws RemoteException 144 { 145 log.debug("stmt_executeUpdate[" + m_no + "]"); 146 m_stmt_updateCount++; 147 CompiereStatement stmt = new CompiereStatement(info); 148 return stmt.remote_executeUpdate(); 149 } 151 152 153 165 public boolean process (String className, Properties ctx, String Name, 166 int AD_PInstance_ID, int Record_ID) 167 throws RemoteException 168 { 169 log.info ("process[" + m_no + "] " + AD_PInstance_ID); 170 m_processCount++; 171 172 return false; 173 } 175 184 public ProcessInfo process (Properties ctx, ProcessInfo pi) throws RemoteException 185 { 186 String className = pi.getClassName(); 187 log.debug("process " + className + " - " + pi); 188 m_processCount++; 189 Class clazz = null; 191 try 192 { 193 clazz = Class.forName (className); 194 } 195 catch (ClassNotFoundException ex) 196 { 197 log.warn("process - " + className, ex); 198 pi.setSummary ("ClassNotFound", true); 199 return pi; 200 } 201 SvrProcess process = null; 203 try 204 { 205 process = (SvrProcess)clazz.newInstance (); 206 } 207 catch (Exception ex) 208 { 209 log.warn("process - Instance for " + className, ex); 210 pi.setSummary ("InstanceError", true); 211 return pi; 212 } 213 try 215 { 216 boolean ok = process.startProcess (ctx, pi); 217 pi = process.getProcessInfo(); 218 } 219 catch (Exception ex1) 220 { 221 pi.setSummary ("ProcessError", true); 222 return pi; 223 } 224 return pi; 225 } 227 228 229 234 public String getStatus() 235 { 236 StringBuffer sb = new StringBuffer ("ServerBean["); 237 sb.append(m_no) 238 .append("-Window=").append(m_windowCount) 239 .append(",Post=").append(m_postCount) 240 .append(",Process=").append(m_processCount) 241 .append(",RowSet=").append(m_stmt_rowSetCount) 242 .append(",Update=").append(m_stmt_updateCount) 243 .append("]"); 244 return sb.toString(); 245 } 247 248 252 public String toString() 253 { 254 return getStatus(); 255 } 257 258 259 264 public void ejbCreate() throws CreateException 265 { 266 m_no = ++s_no; 267 log.info ("ejbCreate " + this); 268 try 269 { 270 org.compiere.Compiere.startupServer(new InitialContext ()); 271 } 272 catch (Exception ex) 273 { 274 log.error("ejbCreate", ex); 275 } 277 } 279 280 284 public void setSessionContext (SessionContext aContext) throws EJBException 285 { 286 m_Context = aContext; 287 } 288 289 public void ejbActivate() throws EJBException 290 { 291 if (log == null) 292 log = Logger.getLogger(getClass()); 293 log.debug("ejbActivate " + this); 294 } 295 296 public void ejbPassivate() throws EJBException 297 { 298 log.debug("ejbPassivate " + this); 299 } 300 301 public void ejbRemove() throws EJBException 302 { 303 log.debug("ejbRemove " + this); 304 } 305 306 } | Popular Tags |