public static void main(String[] args)
      throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Company com = new Company();

    com.setName("");
    com.getName();

    // simple
    BeanUtils.setProperty(com, "name", "Jack");
    BeanUtils.getProperty(com, "name");

    // indexed
    BeanUtils.setProperty(com, "product[1]", "NOTES SERVER");
    BeanUtils.getProperty(com, "product[1]");

    // mapped
    HashMap am = new HashMap();
    am.put("1", "10010");
    am.put("2", "10010");
    BeanUtils.setProperty(com, "telephone", am);
    BeanUtils.getProperty(com, "telephone(2)");

    // combined
    BeanUtils.getProperty(com, "employee[1].name");

    // copyProperty
    Company com2 = new Company();
    BeanUtils.copyProperties(com2, com);

    // converter
    BeanUtils.setProperty(com, "date", new Date());

    BeanUtils.setProperty(com, "date", "2013-10-01");

    ConvertUtils.register(
        new Converter() {

          public <T> T convert(Class<T> type, Object value) {
            // TODO Auto-generated method stub
            return null;
          }
        },
        Date.class);

    // DynamicBean
    LazyDynaMap dynaBean = new LazyDynaMap();

    dynaBean.set("foo", "bar");
    dynaBean.set("customer", "title", "Rose");
    dynaBean.set("address", 0, "address1");
    System.out.println(dynaBean.get("address", 0));
    Map map = dynaBean.getMap();
    System.out.println(map.toString());

    // returnNull
    dynaBean.setReturnNull(true);

    // Restricted
    dynaBean.setRestricted(true);
  }
Beispiel #2
0
  @Test
  public void testUpdate() {

    Company cp =
        em.createNamedQuery("Company.findByName", Company.class)
            .setParameter("name", "Windy")
            .getSingleResult();
    assertNotNull(cp.getId());

    String originalName = cp.getName();
    String newName = "Chicago Beverage";
    tx.begin();
    cp.setName(newName);
    tx.commit();

    assertNotEquals(originalName, cp.getName());
    assertTrue(newName.equals(cp.getName()));

    tx.begin();
    cp.setName(originalName);
    tx.commit();
  }
 private void publishPrices() {
   String mesg = "Prices " + _day + ":\n";
   for (Company company : _companies.values())
     mesg += company.getName() + " " + company.getPrice() + "\n";
   _stockExchangeStompClient.send("/topic/Prices", mesg);
 }
Beispiel #4
0
 @Override
 public String getName() {
   return String.format("%s working for %s", Employee.super.getName(), Company.super.getName());
 }