1 16 package dlog4j.formbean; 17 18 import java.io.Serializable ; 19 import java.sql.SQLException ; 20 import java.text.DateFormat ; 21 import java.text.SimpleDateFormat ; 22 import java.util.Date ; 23 24 import javax.servlet.ServletContext ; 25 26 import web.struts.ActionFormExtend; 27 28 import net.sf.hibernate.HibernateException; 29 import net.sf.hibernate.Session; 30 import net.sf.hibernate.SessionFactory; 31 32 38 public abstract class DlogActionForm extends ActionFormExtend implements Serializable { 39 40 public final static DateFormat df1 = new SimpleDateFormat ("yyyy-M-d H:mm:ss"); 41 public final static DateFormat df2 = new SimpleDateFormat ("yyyy-M-d"); 42 public final static DateFormat df3 = new SimpleDateFormat ("H:mm:ss"); 43 44 protected boolean isToday(Date date){ 45 return df2.format(new Date ()).equals(df2.format(date)); 46 } 47 51 protected Session getSession() throws SQLException { 52 ServletContext context = servlet.getServletContext(); 53 SessionFactory sessions = (SessionFactory)context.getAttribute(dlog4j.Globals.HIBERNATE_SESSIONS_KEY); 54 return sessions.openSession(getConnection()); 55 } 56 62 protected void commitSession(Session session, boolean close) throws SQLException , HibernateException{ 63 session.flush(); 64 session.connection().commit(); 65 if(close) 66 session.close(); 67 } 68 74 protected void closeSession(Session session) throws SQLException ,HibernateException{ 75 session.connection().close(); 76 session.close(); 77 } 78 79 public static void main(String [] args) { 80 System.out.println(df1.format(new Date ())); 81 System.out.println(df2.format(new Date ())); 82 System.out.println(df3.format(new Date ())); 83 } 84 85 } 86 | Popular Tags |