1 14 package org.compiere.model; 15 16 import java.net.*; 17 import java.sql.*; 18 import java.util.*; 19 20 import org.compiere.util.*; 21 22 29 public class MSession extends X_AD_Session 30 { 31 36 public static MSession getDefault (Properties ctx) 37 { 38 if (s_session == null) 39 { 40 s_session = new MSession (ctx); 41 s_session.save(); 42 } 43 return s_session; 44 } 46 50 public static MSession getDefault () 51 { 52 return s_session; 53 } 55 56 57 private static MSession s_session = null; 58 59 60 61 66 public MSession (Properties ctx, int AD_Session_ID) 67 { 68 super(ctx, AD_Session_ID); 69 if (AD_Session_ID == 0) 70 { 71 setProcessed (false); 72 } 73 } 75 80 public MSession(Properties ctx, ResultSet rs) 81 { 82 super(ctx, rs); 83 } 85 90 public MSession (Properties ctx, String Remote_Addr, String Remote_Host, String WebSession) 91 { 92 this (ctx, 0); 93 if (Remote_Addr != null) 94 setRemote_Addr(Remote_Addr); 95 if (Remote_Host != null) 96 setRemote_Host(Remote_Host); 97 if (WebSession != null) 98 setWebSession(WebSession); 99 } 101 105 public MSession (Properties ctx) 106 { 107 this (ctx, 0); 108 try 109 { 110 InetAddress lh = InetAddress.getLocalHost(); 111 setRemote_Addr(lh.getHostAddress()); 112 setRemote_Host(lh.getHostName()); 113 } 114 catch (UnknownHostException e) 115 { 116 log.error("MSession - No Local Host", e); 117 } 118 } 120 124 public String toString() 125 { 126 StringBuffer sb = new StringBuffer ("MSession[") 127 .append(getAD_Session_ID()) 128 .append(",AD_User_ID=").append(getCreatedBy()) 129 .append(",").append(getCreated()) 130 .append(",Remote=").append(getRemote_Addr()); 131 String s = getRemote_Host(); 132 if (s != null && s.length() > 0) 133 sb.append(",").append(s); 134 sb.append("]"); 135 return sb.toString(); 136 } 138 141 public void logout() 142 { 143 setProcessed(true); 144 save(); 145 log.info("logout - " + TimeUtil.formatElapsed(getCreated(), getUpdated())); 146 } 148 149 158 public MChangeLog changeLog (int AD_Table_ID, int AD_Column_ID, int Record_ID, 159 String OldValue, String NewValue) 160 { 161 if (!MChangeLog.isLogged(AD_Table_ID)) 162 return null; 163 MChangeLog cl = new MChangeLog(getCtx(), getAD_Session_ID(), 165 AD_Table_ID, AD_Column_ID, Record_ID, OldValue, NewValue); 166 cl.save(); 167 return cl; 168 } 170 } 172 | Popular Tags |