Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 329089

Summary: PERF: EJBQueryImpl.setParamenterInternal() move indexOf check inside non-native block
Product: z_Archived Reporter: Michael OBrien <michael.f.obrien>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: eclipselink.orm-inbox, michael.f.obrien
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
URL: https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8492
Whiteboard:
Bug Depends on:    
Bug Blocks: 325167    
Attachments:
Description Flags
329989 Performance fix for EJBQueryImpl.setParameterInternal() none

Description Michael OBrien CLA 2010-10-29 14:33:57 EDT
>int index = query.getArguments().indexOf(name);
>should be moved to a smaller scope in
    protected void setParameterInternal(String name, Object value, boolean isIndex) {
        DatabaseQuery query = getDatabaseQueryInternal();
>        int index = query.getArguments().indexOf(name);
        if (query.getQueryMechanism().isJPQLCallQueryMechanism()) { // only non native queries
            if (index == -1) {
                if (isIndex) {
                    throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-argument-index", new Object[] { name, query.getEJBQLString() }));
                } else {
                    throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-argument-name", new Object[] { name, query.getEJBQLString() }));
                }
            }
            Class type = query.getArgumentTypes().get(index);
            if (!isValidActualParameter(value, type)) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-incorrect-parameter-type", new Object[] { name, value.getClass(), query.getArgumentTypes().get(index), query.getEJBQLString() }));
            }
        }
        this.parameterValues.put(name, value);
    }

>should be
    protected void setParameterInternal(String name, Object value, boolean isIndex) {
        DatabaseQuery query = getDatabaseQueryInternal();
        if (query.getQueryMechanism().isJPQLCallQueryMechanism()) { // only non native queries
>            int index = query.getArguments().indexOf(name);
            if (index == -1) {
                if (isIndex) {
                    throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-argument-index", new Object[] { name, query.getEJBQLString() }));
                } else {
                    throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-argument-name", new Object[] { name, query.getEJBQLString() }));
                }
            }
            Class type = query.getArgumentTypes().get(index);
            if (!isValidActualParameter(value, type)) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-incorrect-parameter-type", new Object[] { name, value.getClass(), query.getArgumentTypes().get(index), query.getEJBQLString() }));
            }
        }
        this.parameterValues.put(name, value);
    }
Comment 1 Michael OBrien CLA 2010-10-29 14:38:04 EDT
Created attachment 182073 [details]
329989 Performance fix for EJBQueryImpl.setParameterInternal()
Comment 2 Michael OBrien CLA 2010-11-12 11:48:38 EST
>scope reduction in SVN TXN # 8494
https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8494
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:19:29 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink