GWT Editor: select calls twice before update

106 views
Skip to first unread message

John99

unread,
Dec 11, 2011, 5:29:52 AM12/11/11
to google-we...@googlegroups.com

During update the entity with Editor framework select from db calls twice. May be it's not a problem but a feature of Editor framework?

Here is a code snippet:

public class UserActivity extends BasicActivity<UserActivity.Display> {

...

interface Driver extends RequestFactoryEditorDriver<UserProxy, UserPanel> {
}

private UserProxy user;

private Driver driver;

@Inject
private Provider<UserRequestContext> userContextProvider;

...

@Inject
public UserActivity(EventBus eventBus, Display display, PlaceController placeController, WmsRequestFactory requestFactory) {

    super(display, eventBus, placeController);

    driver = GWT.create(Driver.class);
    driver.initialize(requestFactory, (UserPanel) display);

}

...

@Override
protected void onBind() {

    UserRequestContext userRequestContext = userContextProvider.get();

    userRequestContext.updateUser(user);

    driver.edit(user, userRequestContext);

    registerHandler(display.getSaveButton().addClickHandler(
            new ClickHandler() {
                public void onClick(ClickEvent event) {

                    RequestContext context = driver.flush();

                    // Check for errors
                    if (driver.hasErrors()) {
                        display.getStatus().setHTML(
                                "<b>Errors detected locally</b>");
                        return;
                    }

                    // Send the request
                    context.fire();

                }
            }));

   ...

Hibernate output after save button clicked:

 [INFO] Hibernate: select user0_.ID as ID1_0_, user0_.CREATED as CREATED1_0_, user0_.MODIFIED as MODIFIED1_0_, user0_.version as version1_0_, user0_.BIRTH_DATE
as BIRTH5_1_0_, user0_.EMAIL as EMAIL1_0_, user0_.FIRST_NAME as FIRST7_1_0_, user0_.LAST_NAME as LAST8_1_0_, user0_.LOGIN as LOGIN1_0_, user0_.PASSWORD as PASS
WORD1_0_ from USER user0_ where user0_.ID=?

[INFO] Hibernate: select user0_.ID as ID1_0_, user0_.CREATED as CREATED1_0_, user0_.MODIFIED as MODIFIED1_0_, user0_.version as version1_0_, user0_.BIRTH_DATE
as BIRTH5_1_0_, user0_.EMAIL as EMAIL1_0_, user0_.FIRST_NAME as FIRST7_1_0_, user0_.LAST_NAME as LAST8_1_0_, user0_.LOGIN as LOGIN1_0_, user0_.PASSWORD as PASS
WORD1_0_ from USER user0_ where user0_.ID=?

[INFO] Hibernate: update USER set MODIFIED=?, version=?, BIRTH_DATE=?, EMAIL=?, FIRST_NAME=?, LAST_NAME=?, LOGIN=?, PASSWORD=? where ID=? and version=?

Is it normal?

Thomas Broyer

unread,
Dec 11, 2011, 10:52:32 AM12/11/11
to google-we...@googlegroups.com
First, this has nothing to do with the Editor framework, but with RequestFactory.

If you're not using a Locator, or you're not overriding the isLive() method of your Locator, then this is the expected behavior: this is how RequestFactory determines whether an entity is still "alive" before sending the response to the client. If it's not, then it'll tell the client that the entity has been deleted (dispatch an EntityProxyChange event on the EventBus with a WriteOperation.DELETED). The default implementation of isLive(entity) is "find(entity.get()) != null", and this is also what happens in the absence of a Locator for an entity (the difference is that with a Locator you can override isLive() to change the default implementation with, e.g., a more optimized one).

Jesse Hutton

unread,
Dec 13, 2011, 10:00:06 AM12/13/11
to google-we...@googlegroups.com
To add to what Thomas said, if you use EntityManager#find(Class<T> entityClass, Object primaryKey), and the entity already exists in the current persistence context, your JPA implementation will not hit the db again (check the javadoc in javax.persistence.EntityManager). So, if you then use request scoped (or larger) entity managers, you will not see additional db hits when the default implementation of isLive() is called. However, if you create a JPAQL or HQL query in your Locator#find() method (and you don't override isLive() to do something else), it will hit the db again for each entity being serialized and sent to the client.

Jesse

On Sun, Dec 11, 2011 at 10:52 AM, Thomas Broyer <t.br...@gmail.com> wrote:
First, this has nothing to do with the Editor framework, but with RequestFactory.

If you're not using a Locator, or you're not overriding the isLive() method of your Locator, then this is the expected behavior: this is how RequestFactory determines whether an entity is still "alive" before sending the response to the client. If it's not, then it'll tell the client that the entity has been deleted (dispatch an EntityProxyChange event on the EventBus with a WriteOperation.DELETED). The default implementation of isLive(entity) is "find(entity.get()) != null", and this is also what happens in the absence of a Locator for an entity (the difference is that with a Locator you can override isLive() to change the default implementation with, e.g., a more optimized one).

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/vV1wYZ6n9EUJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages