Beispiel #1
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;
    }
  }