RequestFactoryEditorDriver不保存完整的图表,即使“with()”叫做。循环引用是一个问题吗? [英] RequestFactoryEditorDriver doesn't save full graph even though "with()" is called. Is circular reference an issue?

查看:132
本文介绍了RequestFactoryEditorDriver不保存完整的图表,即使“with()”叫做。循环引用是一个问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我从SimpleBeanEditorDriver切换到RequestFactoryEditorDriver,我的代码不再保存完整的图表,即使<$ c调用$()方法。但它正确地在构造函数中加载完整的图。



它可能是由OrganizationProxy和PersonProxy之间的循环引用引起的吗?我不知道还有什么想法:(尽管它与SimpleBeanEditorDriver一起工作。



以下是我的客户端代码。请告诉我是否需要添加代理源到这个问题(或者你可以看到他们 这里

  public class NewOrderView extends Composite 
{
interface Binder extends UiBinder< Widget,NewOrderView> {}
private static Binder uiBinder = GWT.create(Binder.class);

接口Driver扩展了RequestFactoryEditorDriver< OrganizationProxy,OrganizationEditor> {}
Driver driver = GWT.create(Driver.class);

@UiField
按钮保存;

@UiField
OrganizationEditor orgEditor;

AdminRequestFactory requestFactory;
AdminRequestFactory.OrderRequestContext requestContext;

OrganizationPr氧组织;

public NewOrderView()
{
initWidget(uiBinder.createAndBindUi(this));

requestFactory = createFactory();
requestContext = requestFactory.contextOrder();
driver.initialize(requestFactory,orgEditor);

String [] paths = driver.getPaths();
createFactory()。contextOrder()。findOrganizationById(1).with(paths).fire(new Receiver< OrganizationProxy>()
{
@Override
public void onSuccess OrganizationProxy响应)
{
if(response == null)
{
organization = requestContext.create(OrganizationProxy.class);
organization.setContactPerson(requestContext.create (PersonProxy.class));
} else
organization = requestContext.edit(response);

driver.edit(organization,requestContext);
}

@Override
public void onFailure(ServerFailure error)
{
createConfirmationDialogBox(error.getMessage())。center();
}
});
}

private static AdminRequestFactory createFactory()
{
AdminRequestFactory factory = GWT.create(AdminRequestFactory.class);
factory.initialize(new SimpleEventBus());
退货工厂;
}

@UiHandler(save)
void buttonClick(ClickEvent e)
{
e.stopPropagation();
save.setEnabled(false);

尝试
{
AdminRequestFactory.OrderRequestContext ctx =(AdminRequestFactory.OrderRequestContext)driver.flush();
if(!driver.hasErrors())
{
//相互链接
PersonProxy contactPerson = organization.getContactPerson();
contactPerson.setOrganization(organization);

String [] paths = driver.getPaths();
ctx.saveOrganization(organization).with(paths).fire(new Receiver< Void>()
{
@Override
public void onSuccess(Void arg0)
{
createConfirmationDialogBox(Saved!).center();
}

@Override
public void onFailure(ServerFailure error)
{
createConfirmationDialogBox(error.getMessage()).center();
}
});
}
} finally
{
save.setEnabled(true);




花了我一些时间才意识到问题是Person实体的组合 id



下面是代码片段 PojoLocator 用于我的代理实体

  public class PojoLocator扩展Locator< DatastoreObject,Long> 
{
@Override
public DatastoreObject find(Class< ;? extends DatastoreObject> clazz,Long id)
{
}

@Override
public Long getId(DatastoreObject domainObject)


$ b code $ $ b

为了从DataStore获取子实体,您需要拥有一个父类的id。为了达到这个目的,我将Locator<>的ID class转换为表示Objectify的Key<>类的文本形式的字符串。

以下是现在的样子:

  public class PojoLocator扩展Locator< DatastoreObject,String> 
{
@Override
public DatastoreObject find(Class< ;? extends DatastoreObject> clazz,String id)
{
Key< DatastoreObject> key = Key.create(id);
return ofy.load(key);

$ b @Override
public String getId(DatastoreObject domainObject)
{
if(domainObject.getId()!= null)
{
Key< DatastoreObject> key = ofy.fact()。getKey(domainObject);
return key.getString();
} else
返回null;






$ b请注意你的实现可能会略有不同, m使用Objectify4。


Could you guys please help me find where I made a mistake ?

I switched from SimpleBeanEditorDriver to RequestFactoryEditorDriver and my code no longer saves full graph even though with() method is called. But it correctly loads full graph in the constructor.

Could it be caused by circular reference between OrganizationProxy and PersonProxy ? I don't know what else to think :( It worked with SimpleBeanEditorDriver though.

Below is my client code. Let me know if you want me to add sources of proxies to this question (or you can see them here).

public class NewOrderView extends Composite
{
    interface Binder extends UiBinder<Widget, NewOrderView> {}
    private static Binder uiBinder = GWT.create(Binder.class);

    interface Driver extends RequestFactoryEditorDriver<OrganizationProxy, OrganizationEditor> {}
    Driver driver = GWT.create(Driver.class);

    @UiField
    Button save;

    @UiField
    OrganizationEditor orgEditor;

    AdminRequestFactory requestFactory;
    AdminRequestFactory.OrderRequestContext requestContext;

    OrganizationProxy organization;

    public NewOrderView()
    {
        initWidget(uiBinder.createAndBindUi(this));

        requestFactory = createFactory();
        requestContext = requestFactory.contextOrder();
        driver.initialize(requestFactory, orgEditor);

        String[] paths = driver.getPaths();
        createFactory().contextOrder().findOrganizationById(1).with(paths).fire(new Receiver<OrganizationProxy>()
        {
            @Override
            public void onSuccess(OrganizationProxy response)
            {
                if (response == null)
                {
                    organization = requestContext.create(OrganizationProxy.class);
                    organization.setContactPerson(requestContext.create(PersonProxy.class));
                } else
                    organization = requestContext.edit(response);

                driver.edit(organization, requestContext);
            }

            @Override
            public void onFailure(ServerFailure error)
            {
                createConfirmationDialogBox(error.getMessage()).center();
            }
        });
    }

    private static AdminRequestFactory createFactory()
    {
        AdminRequestFactory factory = GWT.create(AdminRequestFactory.class);
        factory.initialize(new SimpleEventBus());
        return factory;
    }

    @UiHandler("save")
    void buttonClick(ClickEvent e)
    {
        e.stopPropagation();
        save.setEnabled(false);

        try
        {
            AdminRequestFactory.OrderRequestContext ctx = (AdminRequestFactory.OrderRequestContext) driver.flush();
            if (!driver.hasErrors())
            {
                // Link to each other
                PersonProxy contactPerson = organization.getContactPerson();
                contactPerson.setOrganization(organization);

                String[] paths = driver.getPaths();
                ctx.saveOrganization(organization).with(paths).fire(new Receiver<Void>()
                {
                    @Override
                    public void onSuccess(Void arg0)
                    {
                        createConfirmationDialogBox("Saved!").center();
                    }

                    @Override
                    public void onFailure(ServerFailure error)
                    {
                        createConfirmationDialogBox(error.getMessage()).center();
                    }
                });
            }
        } finally
        {
            save.setEnabled(true);
        }
    }
}

解决方案

It took me some time to realize that the problem was the composite id of Person entity.

Below is the code snippet of PojoLocator that is used by my proxy entities.

public class PojoLocator extends Locator<DatastoreObject, Long>
{
    @Override
    public DatastoreObject find(Class<? extends DatastoreObject> clazz, Long id)
    {
    }

    @Override
    public Long getId(DatastoreObject domainObject)
    {
    }
}

In order to fetch child entity from DataStore you need to have id of a parent class. In order to achieve that I switched "ID class" for Locator<> to String which represents textual form of Objectify's Key<> class.

Here is how to looks now:

public class PojoLocator extends Locator<DatastoreObject, String>
{
    @Override
    public DatastoreObject find(Class<? extends DatastoreObject> clazz, String id)
    {
        Key<DatastoreObject> key = Key.create(id);
        return ofy.load(key);
    }

    @Override
    public String getId(DatastoreObject domainObject)
    {
        if (domainObject.getId() != null)
        {
            Key<DatastoreObject> key = ofy.fact().getKey(domainObject);
            return key.getString();
        } else
            return null;
    }
}

Please note that your implementation may slightly differ because I'm using Objectify4.

这篇关于RequestFactoryEditorDriver不保存完整的图表,即使“with()”叫做。循环引用是一个问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆