Search code examples
androidandroid-sqliterushorm

RushORM store RequestParams


I'm using rushorm for sqlite object serializing and storage. It work pretty cool so far. The problem is that I wan't to store following Request object:

public class Request extends RushObject {

    private String url;
    private RequestParamsStorable params;

    public Request() {}

    public Request(String aUrl, RequestParamsStorable aParams)
    {
        this.url = aUrl;
        this.params = aParams;
    }

    public String getUrl()
    {
        return this.url;
    }

    public RequestParams getParams()
    {
        return this.params;
    }

}

As you can see I need to store RequestParams object. In order to store it, as I obviously cannot make it to extend RushObject I made a subclass and made it to implement Rush as per docs instructions:

public class RequestParamsStorable extends RequestParams implements Rush {

    public RequestParamsStorable() {}

    @Override
    public void save() { RushCore.getInstance().save(this); }
    @Override
    public void save(RushCallback callback) { RushCore.getInstance().save(this, callback); }
    @Override
    public void delete() { RushCore.getInstance().delete(this); }
    @Override
    public void delete(RushCallback callback) { RushCore.getInstance().delete(this, callback); }
    @Override
    public String getId() { return RushCore.getInstance().getId(this); }
}

It didn't throw any errors and calling save() on Request object went smoothly. When I ask for stored objects like that:

    List<Request> remainingsInDB = new RushSearch().find(Request.class);

I indeed receive stored Request objects, with proper url, however RequestParamsStorable is empty(""). I checked and when I save them, they definetely had values, and are not empty.

So the question is where I'm wrong?

Regards,


Solution

  • If your parent class RequestParams contains fields declared as final, they will not be restored.

    As reference you can see the RushORM source code

    ReflectionClassLoader.java

        for (Field field : fields) {
            field.setAccessible(true);
            if (!annotationCache.get(clazz).getFieldToIgnore().contains(field.getName())) {
                if (!loadJoinField(object, rushColumns, annotationCache, field, joins, joinTables)) {
                    if(rushColumns.supportsField(field)) {
                        String value = values.get(counter);
                        if(value != null && !value.equals("null")) {
                            rushColumns.setField(object, field, value);
                        }
                        counter++;
                    }
                }
            }
        }
    

    You should either remove final modifier of the fields or create wrapper object which will be stored in the db and then restore RequestParams from it