@Override
 public void destroy() {
   entityManagerFactory.close();
   entityManagerFactory = null;
   threadLocal = null;
   Logger.debug("%s destroyed.", PersistenceManagerImpl.class.getName());
 }
示例#2
0
 @Override
 public Object resolve(
     MethodAction action,
     RouteType routeType,
     HttpServletRequest req,
     HttpServletResponse resp,
     Map<String, String> pathVars)
     throws ActionException {
   Object controller = getOrCreateController(action);
   Map<Annotation, ActionInterceptor<Annotation>> interceptors = action.interceptors();
   Object result = null;
   Exception exception = null;
   try {
     result = beforeInterceptors(interceptors, req, resp);
     List<?> arguments = bindArguments(action, req, resp, pathVars);
     result = result != null ? result : action.invoke(controller, arguments);
     result = afterInterceptors(result, interceptors, req, resp);
   } catch (InvocationTargetException e) {
     // we need to unwrap InvocationTargetExceptions to get at the real exception
     exception = Cast.as(e.getTargetException(), Exception.class);
     if (exception == null) {
       throw new BaseException(e);
     }
   } catch (Exception e) {
     exception = e;
   }
   if (exception != null) {
     result = exceptionInterceptors(interceptors, req, resp, exception);
     if (result == null) {
       throw new ActionException(exception, "Failed in %s: %s", action, exception.getMessage());
     }
   }
   Logger.debug("%s -> %s resolved", req.getRequestURI(), action);
   return result;
 }
 /**
  * Only call this if you plan on managing the whole EntityManagerFactory lifecycle yourself.
  * Regular thundr apps should have no need to create these themselves and should simply declare an
  * injection dependency on EntityManagerHelper. If you do choose to manage this yourself be sure
  * to call <code>#destroy()</code> to ensure all resources are properly cleaned up.
  *
  * @param persistenceUnit the name of a persistence unit to initialize the EntityManagerFactory
  *     with
  */
 public PersistenceManagerImpl(String persistenceUnit) {
   String className = PersistenceManagerImpl.class.getName();
   try {
     entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnit);
     threadLocal = new ThreadLocal<EntityManager>();
     Logger.debug("%s initialized.", className);
   } catch (Exception e) {
     Logger.error("Initialization of %s failed: %s", className, e.getMessage());
     throw new JpaException(e, "Initialization of %s failed.", className);
   }
 }