Exemple #1
0
/** @author <a href="mailto:[email protected]">Khoi NGUYEN</a> */
@PersistenceCapable
public class Menu {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private String date;

  @Persistent private String menu;

  private static final PersistenceManager pmf = PMF.get().getPersistenceManager();

  public Menu(String menu, String date) {
    this.menu = menu;
    this.date = date;
  }

  public void save() {
    PMF.get().getPersistenceManager().makePersistent(this);
  }

  public static Menu getMenu(Date date) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    String strDate = sdf.format(date);
    Query query = pmf.newQuery(Menu.class, "date == '" + strDate + "'");
    List<Menu> menus = (List<Menu>) query.execute();
    if (menus != null && menus.size() > 0) {
      return menus.get(0);
    }
    return null;
  }

  public static String getMenuAsHtml(Date date) {
    Menu menuEntity = getMenu(date);
    String result = "";
    if (menuEntity != null) {
      result = menuEntity.getMenu().replaceAll("\r\n", "<br/>");
    } else {
      result = "Sorry, there is no set Today.";
    }
    return result;
  }

  public String getDate() {
    return date;
  }

  public String getMenu() {
    return menu;
  }
}
Exemple #2
0
 public void save() {
   PMF.get().getPersistenceManager().makePersistent(this);
 }