only returns specified fields (translated query) in an activerecord

20 views
Skip to first unread message

stark

unread,
Aug 17, 2012, 5:34:45 PM8/17/12
to scooter-...@googlegroups.com
Hello John,

Wazzzzuuuppppp....

Just would like to ask,

If i have only one activerecord class which represents an 'Employee' and it has like 100 columns,

is it possible to specify the fields that I only want when i am getting records ("getRecords()")? and say i only want 10 fields of those returned?

It's like the one of the options for the "Belongs-To Association" which is the 'columns'/'ex_columns' option but only applies for this particular ActiveRecord class?

Because what I am seeing also in the logs ('JdbcStatementProcessor'), is that it is specifying all fields (*) in the select query, and I find it too slow. 

How can I resolve this? How can we specify columns and exclude columns ?


i LoVe ScoOteR!


Many Thanks!

John Chen

unread,
Aug 18, 2012, 1:35:08 AM8/18/12
to scooter-...@googlegroups.com
Stark,

Good question. There are a few option constants for you to use. Unfortunately this feature is not in QueryBuilder, but you can indirectly use it with TableGateway class:

TableGateway tg = ActiveRecordUtil.getGateway(Employee.class);
List<Employee> employees = tg.findAll(String conditionsSQL, Map<String, Object> conditionsSQLData, String options);

In the options string or map, you can use one of the following options:
Use "columns" option (ActiveRecordConstants.key_columns)
Use "ex_columns" option (ActiveRecordConstants.key_ex_columns)
Use "finder_sql" option (ActiveRecordConstants.key_finder_sql)
See JavaDoc of ActiveRecordConstants class for the above options.

Here is an example:
List<Employee> employees = tg.findAll(null, null, "columns: id, first_name, last_name, salary; order_by: first_name, salary DESC");

The employee instance in the returned employees list should only have values for columns id, first_name, last_name, and salary. Employee's manager ID column is ignored.

Hope this works.

John

stark

unread,
Aug 18, 2012, 3:59:09 AM8/18/12
to scooter-...@googlegroups.com

Yo John,

It's working with the tableGateway, tested it with page, limit, sort and it's working. I was afraid that it wont work with 'page', limit, etc with the tableGateway.. pardon my laziness. ^^

Hope that you can integrate it with the QueryBuilder, I really think this one's really essential, or perhaps also part of the activeRecord class, but the one in the querybuilder will be more convenient.

Let me know if you have plans in implmenting it, I will test it ASAP.

Btw, have you ever used ala scooter with a portlet app (db layer or view or any part of scooter) ? just dreaming of just using some parts.


Many Thanks!!!

Woooohoooooo! happy with scooter!
Reply all
Reply to author
Forward
0 new messages