[ http://issues.apache.org/jira/browse/OJB-16?page=comments#action_62722 ]
Vadim Gritsenko commented on OJB-16:
------------------------------------
> Could you perhaps post a complete sample with source xdoclet tags or
> repository.xml that uses both variants, e.g. perhaps even something
> that runs, because I don't yet understand how you would use the by-fk
> variant (the by-pk is clear as it matches the current way OJB retrieves
> collections/references).
Most certainly. I'll attach complete patch including both by-pk and by-fk
variants. Problem is, by-fk implementation, I'm afraid, will not get accepted
as-is, and will need some refactorings. But it sure works and you can see the
code.
Here is simple example:
/**
* @ojb.class
* @ojb.selectbypk-procedure name="FIND_A_BYID"
* @ojb.selectbyfk-procedure name="FIND_A"
*/
public class A {
/**
* @ojb.field primarykey="true"
* autoincrement="ojb"
* sequence-name="a_seq"
*/
public Integer id;
/**
* @ojb.field
*/
public String name;
/**
* @ojb.collection element-class-ref="B"
* foreignkey="aId"
*/
public Collection b;
}
/**
* @ojb.class
* @ojb.selectbypk-procedure name="FIND_B_BYID"
* @ojb.selectbyfk-procedure name="FIND_B"
*/
public class B {
/**
* @ojb.field primarykey="true"
* autoincrement="ojb"
* sequence-name="b_seq"
*/
public Integer id;
/**
* @ojb.field
*/
public Integer aId;
/**
* @ojb.reference foreignkey="aId"
*/
public A a;
/**
* @ojb.field
*/
public String value;
}
CREATE FUNCTION FIND_A_BYID (A_ID IN NUMBER)
RETURN TYPES.CURSORTYPE AS
RESULT TYPES.CURSORTYPE;
BEGIN
OPEN RESULT FOR SELECT ID, NAME FROM A WHERE ID = A_ID;
RETURN RESULT;
END;
/
CREATE FUNCTION FIND_A (A_ID IN NUMBER, A_NAME IN VARCHAR)
RETURN TYPES.CURSORTYPE AS
RESULT TYPES.CURSORTYPE;
BEGIN
OPEN RESULT FOR SELECT ID, NAME FROM A WHERE
(A_ID IS NULL OR A_ID = ID) AND (A_NAME IS NULL OR A_NAME = NAME);
RETURN RESULT;
END;
/
CREATE FUNCTION FIND_B_BYID (A_ID IN NUMBER)
RETURN TYPES.CURSORTYPE AS
RESULT TYPES.CURSORTYPE;
BEGIN
OPEN RESULT FOR SELECT ID, AID, VALUE FROM B WHERE ID = A_ID;
RETURN RESULT;
END;
/
CREATE FUNCTION FIND_B (A_ID IN NUMBER, A_AID IN NUMBER, A_VALUE IN VARCHAR)
RETURN TYPES.CURSORTYPE AS
RESULT TYPES.CURSORTYPE;
BEGIN
OPEN RESULT FOR SELECT ID, AID, VALUE FROM B WHERE
(A_ID IS NULL OR A_ID = ID) AND
(A_AID IS NULL OR A_AID = AID) AND
(A_VALUE IS NULL OR A_VALUE = VALUE);
RETURN RESULT;
END;
/
> 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]