public void close() {
    // The spec says so, that's why :(
    validateNotClosed();

    sessionFactory.close();
    EntityManagerFactoryRegistry.INSTANCE.removeEntityManagerFactory(
        entityManagerFactoryName, this);
  }
Example #2
0
  /** @param connectionProvider */
  public static void stopConnectionProvider(SessionFactoryImpl sessionFactory) {
    if (sessionFactory == null) {
      return;
    }

    try {
      sessionFactory.close();

    } catch (Exception e) {
      e.printStackTrace();
    }

    ConnectionProvider connectionProvider = sessionFactory.getConnectionProvider();
    if (connectionProvider == null) {
      return;
    }

    Method method = KernelReflect.declaredMethod(connectionProvider.getClass(), "close");
    if (method == null) {
      method = KernelReflect.declaredMethod(connectionProvider.getClass(), "stop");
      if (method == null) {
        method = KernelReflect.declaredMethod(connectionProvider.getClass(), "destory");
      }
    }

    if (method == null) {
      LOGGER.info("stop " + connectionProvider + " failed");

    } else {
      try {
        LOGGER.info("stop " + connectionProvider + " at " + method.getName());
        method.invoke(connectionProvider);

      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    Object ds = KernelObject.declaredGet(connectionProvider, "ds");
    if (ds != null) {
      KernelObject.declaredSend(ds, "close", true);
    }
  }