Beispiel #1
0
  /* update title string */
  public static void updateAccountString(
      Account account, String stringID, String description, String singular, String plural)
      throws DBException {

    /* valid account? */
    if (account == null) {
      throw new DBException("Account not specified.");
    }

    /* delete? */
    // delete if both singular/plural values are empty/null
    if (((singular == null) || singular.equals("")) && ((plural == null) || plural.equals(""))) {
      String acctID = account.getAccountID();
      AccountString.Key key = new AccountString.Key(acctID, stringID);
      key.delete(true); // also delete dependencies (if any)
      return;
    }

    /* get/create AccountString */
    AccountString str = AccountString.getAccountString(account, stringID);
    if (str == null) {
      str = AccountString.getAccountString(account, stringID, true);
    }

    /* insert/update */
    str.setDescription(description);
    str.setSingularTitle(singular);
    str.setPluralTitle((plural != null) ? plural : singular);
    str.save();
  }
Beispiel #2
0
  /* Return specified StatusCode, create if specified */
  private static StatusCode _getStatusCode(
      String accountID, Account account, String deviceID, int code, boolean createOK)
      throws DBException {
    // does not return null if 'createOK' is true

    /* account-id specified? */
    if (StringTools.isBlank(accountID)) {
      if (account == null) {
        throw new DBException("Account not specified.");
      } else {
        accountID = account.getAccountID();
      }
    } else if ((account != null) && !account.getAccountID().equals(accountID)) {
      throw new DBException("Account does not match specified AccountID.");
    }

    /* device-id specified? */
    if (StringTools.isBlank(deviceID)) {
      // throw new DBException("Device-ID not specified.");
      deviceID = ALL_DEVICES;
    }

    /* get/create entity */
    StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, code);
    if (scKey.exists()) { // may throw DBException
      StatusCode sc = scKey.getDBRecord(true);
      if (account != null) {
        sc.setAccount(account);
      }
      return sc;
    } else if (createOK) {
      StatusCode sc = scKey.getDBRecord();
      if (account != null) {
        sc.setAccount(account);
      }
      sc.setCreationDefaultValues();
      return sc; // not yet saved!
    } else {
      // record doesn't exist, and caller doesn't want us to create it
      return null;
    }
  }
Beispiel #3
0
 /* get string */
 public static AccountString getAccountString(Account account, String strID) throws DBException {
   if ((account != null) && (strID != null)) {
     String acctID = account.getAccountID();
     AccountString.Key key = new AccountString.Key(acctID, strID);
     if (key.exists()) {
       AccountString str = key.getDBRecord(true);
       str.setAccount(account);
       return str;
     } else {
       // AccountString does not exist
       return null;
     }
   } else {
     return null; // just say it doesn't exist
   }
 }
Beispiel #4
0
  // Note: does NOT return null
  public static AccountString getAccountString(Account account, String strID, boolean create)
      throws DBException {

    /* account-id specified? */
    if (account == null) {
      throw new DBNotFoundException("Account not specified.");
    }
    String acctID = account.getAccountID();

    /* string-id specified? */
    if ((strID == null) || strID.equals("")) {
      throw new DBNotFoundException("String-ID not specified for account: " + acctID);
    }

    /* get/create */
    AccountString str = null;
    AccountString.Key strKey = new AccountString.Key(acctID, strID);
    if (!strKey.exists()) {
      if (create) {
        str = strKey.getDBRecord();
        str.setAccount(account);
        str.setCreationDefaultValues();
        return str; // not yet saved!
      } else {
        throw new DBNotFoundException("String-ID does not exists: " + strKey);
      }
    } else if (create) {
      // we've been asked to create the AccountString, and it already exists
      throw new DBAlreadyExistsException("String-ID already exists '" + strKey + "'");
    } else {
      str = AccountString.getAccountString(account, strID);
      if (str == null) {
        throw new DBException("Unable to read existing String-ID: " + strKey);
      }
      return str;
    }
  }