Hi everyone,

I am working on an GWT generator project that enables objects to be
persisted on the client side html5 database (or Google Gears db). The
generator is a wrapper of a JavaScript library that provides the
actual object persistence functionality. If you have need to persist
objects on the browser database, you are welcome to visit the project
site for more details.

http://github.com/dennisjzh/gwt-html5-persistence

The sample code below demonstrates how to persist objects to the
browser database. The sample creates five task objects, persists them,
and then retrieves the ones that are marked as done. No SQL statement
is used in the code.

final Entity<Task> taskEntity = GWT.create(Task.class);
final Entity<Tag> tagEntity = GWT.create(Tag.class);
final Entity<Category> categoryEntity = GWT.create(Category.class);

Persistence.schemaSync(new Callback() {
    public void onSuccess() {
        final Category c = categoryEntity.newInstance();
        c.setName("Main");
        final Tag tag = tagEntity.newInstance();
        tag.setName("Urgent");
        for (int i = 0; i < 5; i++) {
            Task t = taskEntity.newInstance();
            t.setName("Task" + Integer.toString(i));
            t.setDescription("Task No #" + Integer.toString(i));
            t.setDone(i % 2 == 0);
            t.setCategory(c);
            t.getTags().add(tag);
        }

        Persistence.flush(new Callback() {
            public void onSuccess() {
                Collection<Task> allTasks =
c.getTasks().filter("Done", "==", true);
                allTasks.list(new CollectionCallback<Task>() {
                    public void onSuccess(Task[] results) {
                        for (Task task : results) {
                            RootPanel.get("taskNameContainer").add(new
Label(task.getName()));
                        }
                    }
                });
                Persistence.reset();
            }
        });
    }
});

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to