/**
   * Build method for a request
   *
   * @param reference
   * @param customer
   * @param goods
   * @param departure
   * @param arrival
   * @param ruleVersion
   * @return
   */
  public static Request build(
      Long id,
      String reference,
      Customer customer,
      Goods goods,
      Destination departure,
      Destination arrival,
      AgreementRuleAud ruleVersion) {
    Request r = new Request();
    r.id = id;
    r.version = 1;
    r.reference = reference;
    r.customer = customer;
    r.goods = goods;
    r.departure = departure;
    r.arrival = arrival;
    r.ruleAud = ruleVersion;
    r.overallStatus = RequestOverallStatus.WAITING_FOR_VALIDATION;
    r.agreementStatus = RequestAgreementStatus.PENDING;
    r.nextAgreementVisaRank = 0;
    r.agreementVisas = new ArrayList<>();

    LocalDateTime date = LocalDateTime.now();
    r.creationDate = date;
    r.updateDate = date;

    String customerUid = customer == null ? null : customer.getUid();
    r.creationUser = customerUid;
    r.updateUser = customerUid;

    r.checkValues();

    return r;
  }
 public void testFinderThrowsNoResult() throws Exception {
   try {
     Customer.findByNumber(66); // 66 doesn't exist
     fail("EntityNotFoundException expected");
   } catch (javax.persistence.NoResultException ex) {
     // All fine
   }
 }
  public static void main(String[] args) throws Exception {
    HashMap map = new HashMap();
    // map.put("hibernate.show_sql", "true");
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("titan", map);
    EntityManager entityManager = factory.createEntityManager();
    entityManager.getTransaction().begin();
    try {
      System.out.println("Initialize DB");
      InitializeDB.initialize(entityManager);
      System.out.println();
      System.out.println();

      System.out.println("Find Bill Burke by named parameter");
      Customer cust = findCustomerByNamedParameter(entityManager, "Bill", "Burke");
      System.out.println("Bill Burke's cust id: " + cust.getId());
      System.out.println();
      System.out.println();

      System.out.println("Find Gavin King by indexed parameter");
      cust = findCustomerByIndexedParameter(entityManager, "Gavin", "King");
      System.out.println("Gavin King's cust id: " + cust.getId());
      System.out.println();
      System.out.println();

      System.out.println("Output all customers via paging");
      List results;
      int first = 0;
      int max = 2;
      do {
        results = getCustomers(entityManager, max, first);
        Iterator it = results.iterator();
        while (it.hasNext()) {
          Customer c = (Customer) it.next();
          System.out.println(c.getFirstName() + " " + c.getLastName());
        }
        entityManager.clear();
        first = first + results.size();
      } while (results.size() > 0);
    } finally {
      entityManager.getTransaction().commit();
      entityManager.close();
      factory.close();
    }
  }
示例#4
0
 /** Set the customer with their current shipping address. */
 public void setCustomerWithShipping(Customer customer) {
   this.customer = customer;
   this.shippingAddress = customer.getShippingAddress();
 }