浏览 2026 次
锁定老帖子 主题:floggy
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-03-27
最后修改:2010-03-30
How to use it ? it is very easy.see below, public static void saveObject() { Person person = new Person(); person.setName("LaoLi"); person.setBirthday("1988/8/8"); person.setGender("man"); person.setPhones("13169563289"); try { int id = PersistableManager.getInstance().save(person); // Editing and saving a previously saved object PersistableManager.getInstance().load(person, id); person.setName("LiLao"); id = PersistableManager.getInstance().save(person); // Deleting a previously saved object PersistableManager.getInstance().load(person, id); PersistableManager.getInstance().delete(person); } catch (FloggyException e) { System.out.println("throw a exception"); e.printStackTrace(); } // Listing all objects ObjectSet persons; try { persons = PersistableManager.getInstance().find(Person.class, null, null); for ( int i = 0 ; i < persons.size() ; i++) { Person person2 = (Person) persons.get(i); System.out.println("name: " + person2.getName()); } } catch (FloggyException e) { e.printStackTrace(); } // Using a filter to find specific objects try { persons = PersistableManager.getInstance().find(Person.class, new MacFilter(), null); for ( int i = 0; i< persons.size(); i++) { Person pers = (Person) persons.get(i); } } catch (FloggyException e) { e.printStackTrace(); } // Sorting persons by their age (younger first) try { persons = PersistableManager.getInstance().find(Person.class, null, new AgeCompator()); } catch (FloggyException e) { e.printStackTrace(); } } } class MacFilter implements Filter{ public boolean matches(Persistable persistable) { Person person = (Person) persistable; return person.getGender() == "M"; } } class AgeCompator implements Comparator{ public int compare(Persistable p1, Persistable p2) { Person per = (Person) p1; Person pers = (Person) p2; if ( per.getBirthday().length() < pers.getBirthday().length()) { return PRECEDES; } if ( per.getBirthday().length() > pers.getBirthday().length()) { return FOLLOWS; } return EQUIVALENT; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |