Package jodd.jtx.data

Source Code of jodd.jtx.data.WorkSession

// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.jtx.data;

import jodd.exception.UncheckedException;

/**
* Transactional resource, encapsulates working session.
*/
public class WorkSession {

  static String persistedValue = "The big bang theory";

  public static String getPersistedValue() {
    return persistedValue;
  }

  public WorkSession() {
  }

  public WorkSession(int txno) {
    this.txno = txno;
  }

  String sessionValue;
  boolean readOnly;
  int txno;

  public void writeValue(String value) {
    if (txno == 0) {  // no transaction
      persistedValue = value;
      return;
    }
    // under transaction
    if (readOnly == true) {
      throw new UncheckedException();
    }
    sessionValue = "[" + txno + "] " + value;
  }

  public String readValue() {
    if (sessionValue != null) {
      return sessionValue;
    }
    return persistedValue;
  }

  // aka commit
  public void done() {
    if (sessionValue != null) {
      persistedValue = sessionValue;
    }
    sessionValue = null;
  }

  // aka rollback
  public void back() {
    sessionValue = null;
  }
}
TOP

Related Classes of jodd.jtx.data.WorkSession

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.