[ http://issues.apache.org/jira/browse/OJB-16?page=comments#action_62746 ] Vadim Gritsenko commented on OJB-16: ------------------------------------
Ok, that one is easy. > Ok, but how do the procedures get chosen? As you can see, for retrieving objects by their identity always select-by-pk procedure is used. Collections are always retrieved using select-by-fk procedure. References are converted in the ObjectReferenceBroker into the Identity queries, so again, select-by-pk is used. select-by-pk is implemented in SqlGeneratorDefaultImpl.getPreparedSelectByPkStatement - that's where query by identity ends up. select-by-fk is implemented using new Query class, constructed in QueryReferenceBroker.getFKQuery1toN and converted to procedure call in the SqlGeneratorDefaultImpl.getPreparedSelectStatement. > IMO it is unclear which one is used when I retrieve objects by a > simple query, What is a simple query? If it's query by identity, then select-by-pk is used. If it's query by example, select-by-fk is used. If it's query by SQL, then it depends on your SQL (I use stored procedures). If neither of those (like query by criteria), then behaviour as it is now (select statement). > or which one is used for retrieving the collection > of B's within A. select-by-fk is always used in this case, as you need to select instances of B using its foreign key field aId. > And if the by-fk procedure is used for the > collection, where do the values come from ? If you mean where B.aId is coming from: that what QueryReferenceBroker.getFKQuery1toN is for, and it is invoked from getFKQuery, it creates query using passed to it A object instance. Regards, Vadim > Support stored procedures in select by pk statement > --------------------------------------------------- > > Key: OJB-16 > URL: http://issues.apache.org/jira/browse/OJB-16 > Project: OJB > Type: New Feature > Components: PB-API > Versions: 1.0.x CVS > Reporter: Vadim Gritsenko > Assignee: Thomas Dudziak > Attachments: QueryByCriteriaBase.java, QueryByFKCriteria.java, > SelectByFKProcedureDescriptor.java, SelectByPKProcedureDescriptor.java, > SqlProcedureFKStatement.java, db-ojb-patch.diff, db-ojb-selectbypk.diff, > xdoclet.diff > > This patch adds support for retrieving objects by primary keys through call > to stored procedure instead of using select statement. > To activate the feature, add xdoclet tag to the class: > /** > * @ojb.class table="MYBEAN" > * @ojb.selectbypk-procedure name="FIND_MYBEAN_BYID" > */ > public class MyBean { > /** > * @ojb.field primarykey="true" > */ > Integer id; > } > And then, create stored procedure: > CREATE OR REPLACE PACKAGE TYPES AS > TYPE CURSORTYPE IS REF CURSOR; > END TYPES; > / > CREATE OR REPLACE FUNCTION FIND_MYBEAN_BYID (ANID IN MYBEAN.ID%TYPE) > RETURN TYPES.CURSORTYPE AS > RESULT TYPES.CURSORTYPE; > BEGIN > OPEN RESULT FOR SELECT * FROM MYBEAN WHERE ID = ANID; > RETURN RESULT; > END; > / > Patch is made against OJB_1_0_RELEASE branch. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
