コード例 #1
0
 public void updateBeneficiaries(Account account) {
   String sql = "update T_ACCOUNT_BENEFICIARY SET SAVINGS = ? where ACCOUNT_ID = ? and NAME = ?";
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = dataSource.getConnection();
     ps = conn.prepareStatement(sql);
     for (Beneficiary beneficiary : account.getBeneficiaries()) {
       ps.setBigDecimal(1, beneficiary.getSavings().asBigDecimal());
       ps.setLong(2, account.getEntityId());
       ps.setString(3, beneficiary.getName());
       ps.executeUpdate();
     }
   } catch (SQLException e) {
     throw new RuntimeException("SQL exception occurred updating beneficiary savings", e);
   } finally {
     if (ps != null) {
       try {
         // Close to prevent database cursor exhaustion
         ps.close();
       } catch (SQLException ex) {
       }
     }
     if (conn != null) {
       try {
         // Close to prevent database connection exhaustion
         conn.close();
       } catch (SQLException ex) {
       }
     }
   }
 }
コード例 #2
0
  public void testEnumInEmbeddedId() {
    EntityManager em = emf.createEntityManager();
    Beneficiary b = new Beneficiary();
    b.setId("b8");
    List<BeneContact> contacts = new ArrayList<BeneContact>();
    BeneContact c = new BeneContact();
    c.setEmail("email8");
    BeneContactId id = new BeneContactId();
    id.setContactType(BeneContactId.ContactType.HOME);
    c.setBeneficiary(b);

    c.setId(id);
    em.persist(c);
    contacts.add(c);
    b.setContacts(contacts);
    em.persist(b);
    em.getTransaction().begin();
    em.flush();
    em.getTransaction().commit();
    em.clear();
    BeneContactId id1 = c.getId();
    BeneContact c1 = em.find(BeneContact.class, id1);
    assertEquals("email8", c1.getEmail());
    em.close();
  }
コード例 #3
0
ファイル: Account.java プロジェクト: ElliottKW/corespring
 /**
  * Returns a single account beneficiary. Callers should not attempt to hold on or modify the
  * returned object. This method should only be used transitively; for example, called to
  * facilitate reporting or testing.
  *
  * @param name the name of the beneficiary e.g "Annabelle"
  * @return the beneficiary object
  */
 public Beneficiary getBeneficiary(String name) {
   for (Beneficiary b : beneficiaries) {
     if (b.getName().equals(name)) {
       return b;
     }
   }
   throw new IllegalArgumentException("No such beneficiary with name '" + name + "'");
 }
コード例 #4
0
ファイル: Account.java プロジェクト: ElliottKW/corespring
 /**
  * Validation check that returns true only if the total beneficiary allocation adds up to 100%.
  */
 @Transient
 public boolean isValid() {
   Percentage totalPercentage = Percentage.zero();
   for (Beneficiary b : beneficiaries) {
     try {
       totalPercentage = totalPercentage.add(b.getAllocationPercentage());
     } catch (IllegalArgumentException e) {
       // total would have been over 100% - return invalid
       return false;
     }
   }
   if (totalPercentage.equals(Percentage.oneHundred())) {
     return true;
   } else {
     return false;
   }
 }
コード例 #5
0
    @Override
    public IdentificationDocument build() {
      IdentificationDocument document = new IdentificationDocument();
      document.setHolderFIO(holderFIO);
      document.setIssueDate(issueDate);
      document.setIssuingAuthority(issuingAuthority);
      document.setName(name);
      document.setNumber(number);
      document.setSerial(serial);
      document.setValid(valid);
      if (holder != null) {
        holder.addIdentificationDocument(document);
      }

      return document;
    }
コード例 #6
0
ファイル: Account.java プロジェクト: ElliottKW/corespring
 /**
  * Distribute the contribution amount among this account's beneficiaries.
  *
  * @param amount the total contribution amount
  * @return the individual beneficiary distributions
  */
 private Set<Distribution> distribute(MonetaryAmount amount) {
   Set<Distribution> distributions = new HashSet<Distribution>(beneficiaries.size());
   for (Beneficiary beneficiary : beneficiaries) {
     MonetaryAmount distributionAmount = amount.multiplyBy(beneficiary.getAllocationPercentage());
     beneficiary.credit(distributionAmount);
     Distribution distribution =
         new Distribution(
             beneficiary.getName(),
             distributionAmount,
             beneficiary.getAllocationPercentage(),
             beneficiary.getSavings());
     distributions.add(distribution);
   }
   return distributions;
 }
コード例 #7
0
  public void testFindByCreditCard() {
    Account account = repository.findByCreditCard("1234123412341234");
    // assert the returned account contains what you expect given the state of the database
    // and the Account Hibernate mapping configuration
    assertNotNull("account should never be null", account);
    assertEquals("wrong entity id", Long.valueOf(0), account.getEntityId());
    assertEquals("wrong account number", "123456789", account.getNumber());
    assertEquals("wrong name", "Keith and Keri Donald", account.getName());
    assertEquals("wrong beneficiary collection size", 2, account.getBeneficiaries().size());

    Beneficiary b1 = account.getBeneficiary("Annabelle");
    assertNotNull("Annabelle should be a beneficiary", b1);
    assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b1.getSavings());
    assertEquals(
        "wrong allocation percentage", Percentage.valueOf("50%"), b1.getAllocationPercentage());

    Beneficiary b2 = account.getBeneficiary("Corgan");
    assertNotNull("Corgan should be a beneficiary", b2);
    assertEquals("wrong savings", MonetaryAmount.valueOf("0.00"), b2.getSavings());
    assertEquals(
        "wrong allocation percentage", Percentage.valueOf("50%"), b2.getAllocationPercentage());
  }