예제 #1
0
 public static void withMap(String companyId) {
   Company company = Company.findById(companyId);
   Project project = new Project();
   project.companies = new HashMap();
   project.companies.put(company.name, company);
   project.create();
   render("@show", project);
 }
  /**
   * This uses a native query because you can't use the DATE() function in MySQL in a JPA query
   *
   * @param start startDate
   * @param end endDate end date ( uses the whole day via DateUtil.getNextDay() )
   * @param c Company
   * @param campaign Campaign (optional)
   * @param device Device (optional)
   * @return
   */
  @Override
  public List<BluetoothFileSendSummary> getBluetoothFileSendSummaryFromBluetoothSend(
      Date start, Date end, Company company, Campaign campaign, Device device) {

    int count = 4;
    HashMap<Integer, Object> parameters = new HashMap<Integer, Object>();

    String query =
        "SELECT DATE(event_date), file, count(*) "
            + "FROM bluetooth_send "
            + "WHERE send_status = 1 "
            + "AND company_id = ?1 "
            + "AND event_date BETWEEN ?2 AND ?3 ";
    if (campaign != null) {
      query += "AND campaign_id = ?" + count + " ";
      parameters.put(count, campaign.getId());
      count++;
    }
    if (device != null) {
      query += "AND device_id = ?" + count + " ";
      parameters.put(count, device.getId());
      count++;
    }

    query += "GROUP BY file, DATE(event_date) ORDER BY DATE(event_date)";

    Query q = em.createNativeQuery(query);
    q.setParameter(1, company.getId());
    q.setParameter(2, start);
    q.setParameter(3, DateUtil.getNextDay(end));

    for (Map.Entry<Integer, Object> entry : parameters.entrySet()) {
      Integer position = entry.getKey();
      Object param = entry.getValue();
      q.setParameter(position, param);
    }

    List<BluetoothFileSendSummary> results = new ArrayList<BluetoothFileSendSummary>();

    List<Object[]> result = q.getResultList();
    for (Object[] object : result) {
      Date eventDate = (Date) object[0];
      String file = (String) object[1];
      Long sendCount = (Long) object[2];

      BluetoothFileSendSummary item = new BluetoothFileSendSummary();
      item.setEventDate(eventDate);
      item.setFile(file);
      item.setSendCount(sendCount);
      item.setCompany(company);
      item.setCampaign(campaign);
      item.setDevice(device);

      results.add(item);
    }
    return results;
  }
  public void populate(DatabaseSession session) {
    PopulationManager manager = PopulationManager.getDefaultManager();

    Cat cat = Cat.example1();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample1");

    Dog dog = Dog.example1();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample1");

    cat = Cat.example2();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample2");

    dog = Dog.example2();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample2");

    cat = Cat.example3();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample3");

    dog = Dog.example3();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample3");

    Company company = Company.example1();
    session.writeObject(company);
    manager.registerObject(company, "example1");

    manager.registerObject(((Vector) company.getVehicles().getValue()).firstElement(), "example1");

    company = Company.example2();
    session.writeObject(company);
    manager.registerObject(company, "example2");

    company = Company.example3();
    session.writeObject(company);
    manager.registerObject(company, "example3");

    Person person = Person.example1();
    session.writeObject(person);
    manager.registerObject(person, "example1");

    // populate the data for duplicate field testing
    session.writeObject(A_King2.exp1());
    session.writeObject(A_King2.exp2());
    session.writeObject(A_1_King2.exp3());
    session.writeObject(A_2_King2.exp4());
    session.writeObject(A_2_1_King2.exp5());

    UnitOfWork unitOfWork = session.acquireUnitOfWork();
    person = Person.example2();
    unitOfWork.registerObject(person);
    unitOfWork.commit();
    manager.registerObject(person, "example2");
    manager.registerObject(person.bestFriend, "example5");
    manager.registerObject(person.representitive, "example4");

    person = Person.example3();
    session.writeObject(person);
    manager.registerObject(person, "example3");

    Computer computer = Computer.example1();
    session.writeObject(computer);
    manager.registerObject(computer, "example1");

    computer = Computer.example2();
    session.writeObject(computer);
    manager.registerObject(computer, "example2");

    computer = Computer.example3();
    session.writeObject(computer);
    manager.registerObject(computer, "example3");

    computer = Computer.example4();
    session.writeObject(computer);
    manager.registerObject(computer, "example4");

    computer = Computer.example5();
    session.writeObject(computer);
    manager.registerObject(computer, "example5");

    JavaProgrammer JP = JavaProgrammer.example1();
    session.writeObject(JP);
    manager.registerObject(JP, "example1");

    JP = JavaProgrammer.example2();
    session.writeObject(JP);
    manager.registerObject(JP, "example2");

    // Added to test bug 3019934.
    unitOfWork = session.acquireUnitOfWork();
    Alligator alligator = new Alligator();
    alligator.setFavoriteSwamp("Florida");
    alligator.setLatestVictim(JavaProgrammer.steve());
    unitOfWork.registerObject(alligator);
    manager.registerObject(alligator, "example1");
    unitOfWork.commit();

    // Added to test bug 6111278

    unitOfWork = session.acquireUnitOfWork();
    Entomologist bugguy = new Entomologist();
    bugguy.setId((int) System.currentTimeMillis());
    bugguy.setName("Gary");
    bugguy = (Entomologist) unitOfWork.registerObject(bugguy);
    Insect insect = new GrassHopper();
    insect.setIn_numberOfLegs(4);
    insect.setEntomologist(bugguy);
    bugguy.getInsectCollection().add(insect);
    unitOfWork.commit();
  }
예제 #4
0
 public static void createCompany(Company company) {
   company.create();
   render(company);
 }