01: /*
02: * Copyright (c) 2006 Your Corporation. All Rights Reserved.
03: */
04:
05: package com.technoetic.xplanner.upgrade;
06:
07: import net.sf.hibernate.HibernateException;
08: import net.sf.hibernate.Session;
09:
10: import com.technoetic.xplanner.XPlannerProperties;
11: import com.technoetic.xplanner.db.hibernate.GlobalSessionFactory;
12: import com.technoetic.xplanner.db.hibernate.HibernateHelper;
13: import com.technoetic.xplanner.db.hibernate.ThreadSession;
14:
15: import org.apache.log4j.Logger;
16:
17: public abstract class ExternalTool {
18: XPlannerProperties properties = new XPlannerProperties();
19:
20: public static boolean isCaseSensitive = false;
21: public static boolean readCaseSensitiveValueFromProperties = true;
22: public static boolean printLog = true;
23: private static final Logger LOG = Logger
24: .getLogger(ExternalTool.class);
25: protected Session session;
26:
27: protected void setUp() throws HibernateException {
28: HibernateHelper.initializeHibernate();
29: session = GlobalSessionFactory.get().openSession();
30: ThreadSession.set(session);
31: }
32:
33: protected void tearDown() {
34: try {
35: if (session != null && session.isOpen())
36: session.close();
37: } catch (HibernateException e) {
38: LOG.error("Exception closing session", e);
39: }
40: }
41:
42: public void run() {
43: try {
44: setUp();
45: doRun();
46: } catch (Exception e) {
47: LOG.error("Exception has been thrown", e);
48: } finally {
49: tearDown();
50: }
51:
52: }
53:
54: protected abstract void doRun() throws Exception;
55:
56: }
|