示例#1
0
 /** 현재 Thread Context하에서 사용할 TimeCalendar입니다. */
 public static ITimeCalendar getTimeCalendar() {
   ITimeCalendar calendar = Local.get(TIME_CALENDAR_KEY, ITimeCalendar.class);
   if (calendar == null) {
     calendar = TimeCalendar.getDefault();
     Local.put(TIME_CALENDAR_KEY, calendar);
   }
   return calendar;
 }
示例#2
0
  /** 현재 시작된 {@link IUnitOfWork}의 인스턴스 ({@link UnitOfWorkAdapter}를 반환합니다. */
  public static synchronized IUnitOfWork getCurrent() {
    if (!isStarted()) throw new HibernateException(UNIT_OF_WORK_NOT_STARTED);

    if (globalNonThreadSafeUnitOfWork != null) return globalNonThreadSafeUnitOfWork;

    return Local.get(IUnitOfWork.CURRENT_UNIT_OF_WORK_KEY, IUnitOfWork.class);
  }
示例#3
0
  /**
   * Start new unit of work.
   *
   * @param sessionFactory {@link SessionFactory} instance.
   * @param nestingOptions 생성 옵션 {@link UnitOfWorkNestingOptions}
   * @return {@link IUnitOfWork} instance.
   */
  public static synchronized IUnitOfWork start(
      SessionFactory sessionFactory, UnitOfWorkNestingOptions nestingOptions) {
    if (log.isDebugEnabled())
      log.debug(
          "새로운 UnitOfWork를 시작합니다... sessionFactory=[{}], nestingOptions=[{}]",
          sessionFactory,
          nestingOptions);

    if (globalNonThreadSafeUnitOfWork != null) return globalNonThreadSafeUnitOfWork;

    IUnitOfWorkImplementor existing =
        Local.get(IUnitOfWork.CURRENT_UNIT_OF_WORK_KEY, IUnitOfWorkImplementor.class);
    boolean useExisting =
        existing != null
            && nestingOptions == UnitOfWorkNestingOptions.ReturnExistingOrCreateUnitOfWork;

    if (useExisting) {
      if (log.isTraceEnabled())
        log.trace(
            "기존 IUnitOfWork 가 존재하므로, 사용횟수만 증가시키고, 기존 IUnitOfWork 인스턴스를 반환합니다. 사용횟수=[{}]",
            existing.getUsage());

      existing.increseUsage();
      return existing;
    }

    if (log.isTraceEnabled()) log.trace("새로운 IUnitOfWorkFactory 와 IUnitOfWork 를 생성합니다...");

    if (existing != null && sessionFactory == null) {
      sessionFactory = existing.getSession().getSessionFactory();
    } else if (existing == null) {
      sessionFactory = getCurrentSessionFactory();
    }

    setCurrent(getUnitOfWorkFactory().create(sessionFactory, existing));

    if (log.isDebugEnabled())
      log.debug("새로운 IUnitOfWork를 시작했습니다. sessionFactory=[{}]", sessionFactory);

    return getCurrent();
  }
示例#4
0
 public static void setTimeCalendar(ITimeCalendar calendar) {
   Local.put(TIME_CALENDAR_KEY, calendar);
 }
示例#5
0
 /** UnitOfWork 가 이미 시작되었는지 확인한다. */
 public static synchronized boolean isStarted() {
   return globalNonThreadSafeUnitOfWork != null
       || Local.get(IUnitOfWork.CURRENT_UNIT_OF_WORK_KEY) != null;
 }
示例#6
0
  /**
   * Set current unit of work.
   *
   * @param unitOfWork the unit of work
   */
  public static void setCurrent(IUnitOfWork unitOfWork) {
    if (log.isDebugEnabled())
      log.debug("현 Thread Context의 UnitOfWork 인스턴스를 설정합니다. unitOfWork=[{}]", unitOfWork);

    Local.put(IUnitOfWork.CURRENT_UNIT_OF_WORK_KEY, unitOfWork);
  }