N-tier with RequestFactory is possible?

191 views
Skip to first unread message

Rafael Dipold

unread,
Jul 25, 2011, 7:15:51 PM7/25/11
to google-we...@googlegroups.com
Hi guys,

The RequestFactory could be used for comunication between logic tier and presentation tier in desktop like JavaFX, to build data-oriented (CRUD) software where I use GAE to data and logic tier?

It's the best choice?

Other question: The GWT 2.4 beta avaliable for download already support polymorphism in RequestContext? Because a get error when add generics type in class declaration!

Kind Regards,

David Chandler

unread,
Jul 26, 2011, 11:32:18 AM7/26/11
to google-we...@googlegroups.com
Hi Rafael, try the 2.4 RC (expected later today) and be sure to see
the updated docs at
http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html.

/dmc

> --
> 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/-/SZjzNp7FHhMJ.
> 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.
>

--
David Chandler
Developer Programs Engineer, GWT+GAE
w: http://code.google.com/
b: http://turbomanage.wordpress.com/
b: http://googlewebtoolkit.blogspot.com/
t: @googledevtools

Rafael Dipold

unread,
Jul 27, 2011, 2:09:21 PM7/27/11
to google-we...@googlegroups.com
Hi David,

Thanks for answer, the RequestContext polymorphic on 2.4 RC works fine now!

And about my first question you could tell me if I did the best choice?

Kind Regards,

Rafael Dipold


Rafael Dipold

unread,
Jul 28, 2011, 1:07:15 AM7/28/11
to google-we...@googlegroups.com
Maybe I spoke too soon about 2.4 RC. I get the error:

   Scanning for additional dependencies: file:/C:/JAVA/workspace/Test/src/com/test/client/Main.java
      Computing all possible rebind results for 'com.test.shared.request.BaseEntityRF'
         Rebinding com.test.shared.request.BaseEntityRF
            Invoking generator com.google.web.bindery.requestfactory.gwt.rebind.RequestFactoryGenerator
               [ERROR] Invalid Request parameterization T extends com.google.web.bindery.requestfactory.shared.BaseProxy
               [ERROR] Unable to create RequestFactoryModel model due to previous errors
   [ERROR] Errors in 'file:/C:/JAVA/workspace/Test/src/com/test/client/Main.java'
      [ERROR] Line 12:  Failed to resolve 'com.test.shared.request.BaseEntityRF' via deferred binding

Everything works fine if I don't use generics in RequestContext class. What I do wrong?

My classes (Proof of Concept Project):

public class Main implements EntryPoint {
    final private EventBus eventBus = new SimpleEventBus();
    private BaseEntityRF rf         = GWT.create(BaseEntityRF.class);
   
    @Override
    public void onModuleLoad() {
        rf.initialize(eventBus);
   
        BaseEntityRequest<BaseEntityProxy> reqBaseEntity = rf.baseRequest();
        BaseEntityProxy baseEntity = reqBaseEntity.create(BaseEntityProxy.class);
    }
}

@ProxyFor(value = BaseEntity.class, locator = BaseEntityLocator.class)

public interface BaseEntityProxy extends EntityProxy {
    EntityProxyId<BaseEntityProxy> stableId();
    Integer getVersion();
}

@Service(value = DAOJPA10.class, locator = DaoServiceLocator.class)
public interface BaseEntityRequest<T extends BaseProxy> extends RequestContext {
    Request<Void> insert(T instance);
    Request<T> update(T instance);
    Request<Void> delete(T instance);
}

public interface BaseEntityRF extends RequestFactory {
    <T extends BaseProxy> BaseEntityRequest<T> baseRequest();
}

Thomas Broyer

unread,
Jul 28, 2011, 12:02:01 PM7/28/11
to google-we...@googlegroups.com
You have to define sub-interfaces of BaseEntityRequest with the "T" type argument bound to a proxy, and then define as many factory methods in BaseEntityRF.
RequestFactory (just like every other GWT generator) works by looking at the code and generating things for types it sees. If you give it BaseEntityRF, it won't "see" in here your FooProxy or BarProxy. They have to be called out explicitly in your code (and by "code", I mean things reachable from BaseEntityRF, looking at the defined methods and their argument and return types, recursively).

The only exception to that rule is GWT-RPC, and this is one the things causing so much harm to developers and users: yes you can use class X as an argument or return type, but you'll pay the price for every single class extending it that is present in the classpath at the time you GWT-compile your code, and the compilation is likely to fail because of non-serializable such types. The same being of course true (and much worse) for interfaces: java.util.List anyone? (one example among the many reported issues: http://code.google.com/p/google-web-toolkit/issues/detail?id=4438 )

Rafael Dipold

unread,
Jul 28, 2011, 1:13:33 PM7/28/11
to google-we...@googlegroups.com
Thanks man!
I thought that I could generalize in such a way that didn't need to create a RequestContext for each entityProxy.
Force of habit that I always have to try generalize it up.

Follows my code up and working properly now:


public class Main implements EntryPoint {
    final private EventBus eventBus = new SimpleEventBus();
    private BaseEntityRF rf         = GWT.create(BaseEntityRF.class);
   
    @Override
    public void onModuleLoad() {
        rf.initialize(eventBus);
   
        CountryRequest reqCountry = rf.countryRequest();
        CountryProxy country      = reqCountry.create(CountryProxy.class);
        country.setCode("FR");
        country.setName("France");
    }
}

@ProxyFor(value = Country.class, locator = BaseEntityLocator.class)
public interface CountryProxy extends BaseEntityProxy {
    String getCode();
    String getName();

    void setCode(String code);
    void setName(String name);

}

@Service(value = DAOJPA10.class, locator = DaoServiceLocator.class)

public interface BaseEntityRequest<T extends BaseProxy> extends RequestContext {
    Request<Void> insert(T instance);
    Request<T> update(T instance);
    Request<Void> delete(T instance);
}

@Service(value = DAOJPA10.class, locator = DaoServiceLocator.class)
public interface CountryRequest extends BaseEntityRequest<CountryProxy> {}


public interface BaseEntityRF extends RequestFactory {
    CountryRequest countryRequest();
}
Reply all
Reply to author
Forward
0 new messages