Bug 334357 - PERF: TransformationMapping - DatabaseField.getIndex is always -1 in default use
Summary: PERF: TransformationMapping - DatabaseField.getIndex is always -1 in default use
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2011-01-14 04:23 EST by Martin JANDA CLA
Modified: 2022-06-09 10:05 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin JANDA CLA 2011-01-14 04:23:13 EST
Build Identifier: 2.2 revision 8831 - 01/14/2011 03:10 AM

When defining "AttributeTransformer"/"Method attribute transformer" access to field value is through record.get(<field_name>).

<field_name> can be DatabaseRecord or String (-this is used usually)

record.get(<String_field_name>) - created "lookup DatabaseField" with index=-1
it means that AbstractRecord must search every time for proper field index 'Vector.indexOf'

--- Sample transformer

public class TimeTransformer extends AttributeTransformerAdapter {
@Override
    public Object buildAttributeValue(final Record record, final Object object, final Session session) {
        Long actionS = (Long) record.get("ACTION_S"); // new 'lookup' DatabaseField is created with index -1 - forces call AbstractRecord.fields.indexOf

        Long actionF = (Long) record.get("ACTION_F"); // reused previous 'lookup' database field index again set to -1 - forces call AbstractRecord.fields.indexOf
}
}

There is called AbstractRecord.fields.indexOf for every row and every field accessed in in 'buildAttributeValue' -> no optimalisation, Vector.indexOf has O(n)

--- Expected behaviour
fields.indexOf should be called only once/query no for every row*every_field
 
--- Possible workaround - not sure it its correct - don't know if index of DatabaseField can change between different queries
cache locally and reuse DatabaseField in AttributeTransformerAdapter
  - not possible for method attribute transformer


Reproducible: Always
Comment 1 Tom Ware CLA 2011-02-03 09:50:16 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 2 James Sutherland CLA 2011-05-17 11:06:26 EDT
Calling record.get(String) only has the String so no index, so it will be O(n).
This is expected.  Can't see any way to get an index when using String lookup.
The lookup field will get the index, but this will only help if you only lookup by one field name.

If you wish to use an index, you need to cache your DatabaseField.

DatabaseField field; // declare as variable in transformer or static in class if using method access

record.get(field); // this will assign the index on the first call, so be O(1).

Suggesting this be closed.
Comment 3 Martin JANDA CLA 2011-05-24 11:56:52 EDT
I can't recommend your suggested workaround to cache DatabaseField.

There is no warranty that cached index will be always correct.

You can execute full query followed by partial query and then the cached index will be invalid. I'm not 100% sure that EclipseLink has fallback when index is set to wrong field.

Please, if you can please let this issue open for Future as Target Milestone.
Comment 4 Peter Krogh CLA 2011-06-20 13:59:54 EDT
moving to future as part of 2.3 bug scrub.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:05:17 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink