cqengine icon indicating copy to clipboard operation
cqengine copied to clipboard

No api to create attributes for SQLParser when attributes are defined in a seperate file

Open ldwnt opened this issue 4 years ago • 2 comments

public class RecallItem {
...
    public String getStatus() {
        return status;
    }
...
}

public class CQRecallItem {
...
    public static final Attribute<RecallItem, String> STATUS = new SimpleNullableAttribute<RecallItem, String>("STATUS") {
        public String getValue(RecallItem recallitem, QueryOptions queryOptions) { return recallitem.getStatus(); }
    }
...
}

SQLParser provides an api to register attributes from the pojo class, but not a seperate class:

public static <O> SQLParser<O> forPojoWithAttributes(Class<O> pojoClass, Map<String, ? extends Attribute<O, ?>> attributes)

ldwnt avatar Jun 28 '21 09:06 ldwnt

I don't think it cares which class the attributes are defined in. The attributes just need to read from objects of type pojoClass.

There are other methods in the superclass of SQLParser for registering attributes in different ways.

Does the following work?

SQLParser<RecallItem> parser = SQLParser.forPojo(RecallItem.class);
parser.registerAttribute(CQRecallItem.STATUS);

npgall avatar Jun 28 '21 10:06 npgall

I don't think it cares which class the attributes are defined in. The attributes just need to read from objects of type pojoClass.

There are other methods in the superclass of SQLParser for registering attributes in different ways.

Does the following work?

SQLParser<RecallItem> parser = SQLParser.forPojo(RecallItem.class);
parser.registerAttribute(CQRecallItem.STATUS);

parser.registerAttribute results in failure with sql "select * from collection where status = 'ACTIVE'" and it requires query with upper-case field "STATUS" instead of "status". However parser.forPojoWithAttributes requires query with lower-case field 'status'. Such behavior is confusing. Besides, if RecallItem.status is private this field can't be queried either, which is not documented in the guide.

ldwnt avatar Jun 29 '21 02:06 ldwnt