Creating Named Query: from OracleCallableStatement

We have a great many PL/SQL Procs in an existing legacy system that return PL/SQL Boolean, that we wish to call from toplink.
Ideally we would like to create Toplink Nameded queries that wrap the SQL call statements.
Does anyone know if its possible to convert a call like the following into a Toplink named query?
String domain = "COST CENTRE";
String value = "OP";
OracleCallableStatement xcall = (OracleCallableStatement) con.prepareCall(
"BEGIN ? := SYS.SQLJUTL.bool2int(is_valid_value(?, ?)); END;");
xcall.registerOutParameter( 1, OracleTypes.INTEGER);
xcall.setString(2,domain);
xcall.setString(3,value);
xcall.execute();
System.out.println ("Status = " + xcall.getInt(1));
FUNCTION is_valid_value(
p_rv_domain IN CG_REF_CODES.RV_DOMAIN%TYPE,
p_rv_low_value IN CG_REF_CODES.RV_LOW_VALUE%TYPE
RETURN BOOLEAN
IS
Many thanks,
Lee.

You can define Stored Procedure calls in TopLink through the StoredProcedureCall class. StoredProcedureCall allows you to define output parameters to access return values.
Example:
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("is_valid_value");
call.addNamedArgumentValue("DOMAIN", domain);
call.addNamedArgumentValue("VALUE", value);
call.addNamedOutputArgument("RESULT", "RESULT", Integer.class);
List results = session.executeSelectingCall(call);
boolean value = ((Integer) ((Map) results.get(0)).get("RESULT")).intValue() == 0;
However what you seem to be accessing is a stored function, not a procedure. To access a stored function from TopLink you must use an SQLCall and select the return value through the DUAL table.
Example:
SQLCall call = new SQLCall("Select SYS.SQLJUTL.bool2int(is_valid_value(" + domain + ", " + value + ")) from dual");
List results = session.executeSelectingCall(call);

Similar Messages

  • Create Named Query with no descriptor?

    I have a very simple query(see below). I'd like to use it as a named query instead of recreating it everytime. I wonder if there is a way I can add it to somewhere without using a descriptor so that I can retrevie it from the session.
    Thanks,
    Wei
    ValueReadQuery query = new ValueReadQuery();
    query.setSQLString("SELECT SYSDATE FROM DUAL");
    Object obj = (Object) session.executeQuery(query);

    There is an "addQuery(DatabaseQuery q)" on the Session interface that should do the trick. So create your session, and then do:
    ValueReadQuery query = new ValueReadQuery();
    query.setSQLString("SELECT SYSDATE FROM DUAL");
    session.addQuery("getDate", query);
    Then later you should be able to:
    session.executeQuery("getDate");
    - Don

  • Creating a query from a DSO to group into categories

    I have a DSO with data like this:
    Transaction No /    Customer
    1 /                        1
    2 /                        1
    3 /                        1
    4 /                        2
    5 /                        2
    6 /                        3
    (i.e. a list of transactions with a customer ID assigned)
    I want to create a query that looks like this:
    Group /                             Customer Count
    Two or less transactions /     2
    Three or more transactions / 1
    (i.e. two buckets, one count of how many customers have 2 or less transactions, one count of how many have three or more transactions)
    Can someone give me an idea of how this could be performed?  Can I do it with just one query, or do I need to load the data from the DSO into a new DSO with data agregated for customers somehow?
    Any suggestions would be greatly appreciated.

    Hello SAP BI Learner,
    Thanks for your suggest.  I've tried this query a little more and found it quite difficult to work out.  I'm not sure exactly what you mean by your answer, but I appreciate you input.

  • Named query problem, [TOPLINK-6008] error

    I created a simple table in database (one column, two rows). I created java class and Data Control and dragged the Data Control onto JSP page. Data were shown ok. Then I tried to create named query (simple SELECT MyCol FROM FROM MyTable). This time the new Data Control on JSP didn't work (no data shown). So I tried this scriptlet on jsp:
    <%
    String sDC = "MyDataControl";
    DCDataControl dc = HttpBindingContext.getContext(request).findDataControl(sDC);
    ClientSession cs = ((ToplinkDataControl)dc).getClientSession();
    Vector all = (Vector)cs.executeQuery("MyNamedQuery",mypackage.MyTable.class);
    %>
    Last row causes error
    Exception [TOPLINK-6008] (OracleAS TopLink - 10g (9.0.4) (Build 031126)): oracle.toplink.exceptions.QueryException
    Description: Missing descriptor for [mypackage.MyTable] for query named [MyNamedQuery].
         at oracle.toplink.exceptions.QueryException.descriptorIsMissingForNamedQuery(QueryException.java:282)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:878)
         at dataPage.jspService(dataPage.jsp:26)
    Does anybody have an idea why the jsp page with Data Control based on named query is empty and why above scriptlet causes that error ? Thanks.

    This solution only applies to earlier version of JDeveloper. In 10.1.3 the TopLink metadata (XML deployment descriptor) is automatically generated during the build/make process as required. In earlier version this is a required step after any change is made to the mappings .
    Doug

  • Which one should we go for Named Query or Redirect Query???

    Hi all,
    We are in the process of implementing top-links in our project so we are working with different queries of top-links. We have made most of them many of the queries are clear in their concept and implementation. It was a very nice experience working for now. but i have some un-answered questions like
    ---- what is the difference between Redirect query and Named query (Both seems to be the same... to me). we got output using Redirect query but i am totally confused because in documentation it gave that redirect query is used in situation where query is complex and named query cannot be used for it.But i personally feel some things about redirect query .....
    -- Query implementation is itself complex and confusing .
    -- What operations can we do in the static method where we are redirecting the query.
    -- Almost of all the methods in the 'ClassDescriptor ' are deprecated...
    -- Not Much Implementation code is available in Top-link docs nor On-line.
    That's why i am not able to decide which query i must use for a complex query i would prefer named query from myself because of its simplicity and straight forwardness.
    Can any one clear my questions.....
    Many questions in days to come........
    Thanks in Advance
    Adil

    no reply ..... :-)

  • Error Query from Multiprovider

    Hi,
    We are creating a Query from a Multiprovider. This Multiprovider was made using one infocube and one ODS. When we run the Query the data from ODS are not being displayed. If  the Query contains only characteristics from ODS, the Query display data.
    If  the Query contains only characteristics from Infocube, the Query display data. But when the Query contains characteristics from both InfoProviders the data  are not being displayed.
    The following example tries explain better the issue.
    There're 2 infoproviders infocube X and ODS Y we want to report as combined.
    Both of them have order number 0DOC_NUM and order item 00RD_ITEM in common.
    Cube A keeps order item based key figures: S Keyfigure &
    D Keyfigure.
    ODS B has detail order item based characteristics Char1 & Char2, which don't exist in cube A.
    Cube A
    Order Number___Order Item____S Keyfigure___D Keyfigure
    100_______________10____________25___________23______
    100_______________20____________45___________40______
    100_______________30____________30___________30______
    ODS B
    Order Number____Order Item_____Char1________Char2
    100_______________10____________SSS_________Blue______
    100_______________20____________TTT_________Blue______
    100_______________30____________SSS_________Black____
    We want the query to display the way below:
    Order Number_Order Item__Char1___Char2____S KF___D KF
    100____________10________SSS____Blue_____25______23
    100____________20________TTT____Blue_____45______40
    100____________30________SSS____Black____30______30
    But when we combine these two in a multiprovider, query result doesn't list the data from ODS.
    Can you help us with this?
    Thanks..

    That means the multi provider is not making any union, because the chars in the cube and that in the ODS are disjoint. Try if you can acheive this with an infoset and I doubt you cant.
    Altervatively, you can make the report via the same cube if you have a logic for combining the chars in the cube with that in the ODS and update the cube with that char in the ODS. You need to revisit the data model and design.
    Ravi Thothadri

  • Query from multiple queries

    Hi Experts
    Is it possible to create a query from multiple queries? if yes, how can I do it?
    Thanks
    Hachim

    Hi Hachim EL ALAMI  ,
    I am giving you some insight to do this but I am not sure whether we can acheive this or not.
    Assigning a query to another InfoSet (Enhanced copy functions) -> Maybe this can to some extent give you the idea.
    The standard copy functions of transactions SQ01 and SQ02 were extended by report RSAQCOPY.For example, you can copy an InfoSet including all dependent queries or copy a query into another InfoSet.For further information see note 324393. By doing so we can make a fresh query from already existing queries.
    General link to SAP Query..
    http://help.sap.com/saphelp_nw04/helpdata/en/7f/af0c36932211d194f60000e82de14a/frameset.htm
    http://www.saptechies.com/sap-query/
    Regards,
    Vvieks
    Note : This is not the detailed answer for your query

  • Query from query?

    Hello gurus,
    I had a request for a report that seem to be easy to implement in ABAP and I am not sure that it is also easy in the Query Designer, but as I am quite new in SAP BW reporting I am surely mistaken.
    So assuming I have a Purchase Order items ODS with the following data:
    - PO number
    - PO item
    - PO date
    - material group
    - [counter]
    ... I want to have a report that presents the following data for a given period:
    - material group
    - number of purchase oprders (not po items!)
    If it was possible to create a query from a query, it would be easy. Is it easy anyway?
    Cheers,
    Michal

    Michal,
    One way is to see update a new counter on the posibility of PO Number 1st record as 1 and Other line items as 0. and use this counter in the reports..
    Option 2: Not sure that this will work..
    1. Create a new Formula/selection on Count and in the properties..select 'caliculate result as first value..'
    regards,
    Hari

  • How to create olap cube using Named Query Table in Data source View

     I Create on OLAP Cube using Existing Tables Its Working Fine But When i Use Named Query Table with RelationShip To other Named query Table  It Not Working .So give me some deep Clarification On Olap Cube for Better Understanding
    Thanks

    Hi Pawan,
    What do you mean "It Not Working"? As Kamath said, please post the detail error message, so that we can make further analysis.
    In the Data Source View of a CUBE, we can define a named query. In a named query, you can specify an SQL expression to select rows and columns returned from one or more tables in one or more data sources. A named query is like any other table in a data source
    view (DSV) with rows and relationships, except that the named query is based on an expression.
    Reference:Define Named Queries in a Data Source View (Analysis Services)
    Regards,
    Charlie Liao
    TechNet Community Support

  • ERROR: Cannot create authcontext with null org-Naming query failed  code:21

    I use OpenSSO Enterprise 8.0 Update 1 Patch1 Build 6.1(2009-June-9 12:56)
    I try to evaluate the Apache 2.2 web agent.
    It's been installed without errors, and both the OpenSSO and Apache server restarted.
    The agent profile's been created. Also, I use the default (OpenDS) configuration repository
    for OpenSSO, but an external (DSEE) user data directory.
    I think I did all the required steps with regards to both directories, since I don't see any error
    in the LDAP logs, each entry seems to be found as expected, the BIND operations are all
    successfull.
    Also, I use a sub-realm rather than the default top realm, and thus, I've modified the agent configuration
    (in the agent profile) so that the login URL is now ... /UI/Login?realm=myrealm
    When I try to access the Apache homepage, I get an error 500. The most recent OpenSSO server log file
    (...../opensso/debug/Authentication) contains the following message:
    ERROR: Cannot create authcontext with null org
    The most recent agent log file (....../apache22_agent/Agent_001/logs/debug/amAgent) has the following error:
    2009-07-07 17:08:11.992 Error 10513:80149a50 PolicyEngine: am_policy_evaluate: InternalException in Service::update_policy with error message:Naming query failed. and code:21
    I don't know what else I can do to debug this problem and find a solution. Any idea ?

    Thank you Shubba,
    With all available log details enabled, I now have the following messages on the agent side:
    2009-07-09 10:14:51.731MaxDebug 5613:80149a50 all: No value specified for key com.sun.identity.agents.config.profile.attribute.mapping, using default value .
    2009-07-09 10:14:51.731 Debug 5613:80149a50 NamingService: BaseService::doRequest(): Using server: http://portable.antibes.net:8080/opensso/namingservice.
    2009-07-09 10:14:51.731MaxDebug 5613:80149a50 NamingService:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <RequestSet vers="1.0" svcid="com.iplanet.am.naming" reqid="10">
    <Request><![CDATA[                                                                                                                      
      <NamingRequest vers="3.0" reqid="2" sessid=""AQIC5wM2LY4SfcyaGFgc5h9Y7/kpf4f//ml82oVfNlbWxQE=@AAJTSQACMDE=#"">                             <GetNamingProfile>                                                                                                                         </GetNamingProfile>                                                                                                                        </NamingRequest>]]> </Request>
    </RequestSet>
    2009-07-09 10:14:51.712MaxDebug 5613:80149a50 NamingService: BaseService::sendRequest Request line: POST /opensso/namingservice HTTP/1.0
    2009-07-09 10:14:51.712 Debug 5613:80149a50 NamingService: BaseService::sendRequest Cookie and Headers =Host: portable.antibes.net
    2009-07-09 10:14:51.712 Debug 5613:80149a50 NamingService: BaseService::sendRequest Content-Length =Content-Length: 334
    2009-07-09 10:14:51.712 Debug 5613:80149a50 NamingService: BaseService::sendRequest Header Suffix =Accept: text/xml
    Content-Type: text/xml; charset=UTF-8
    2009-07-09 10:14:51.712MaxDebug 5613:80149a50 NamingService: BaseService::sendRequest(): Total chunks: 7.
    2009-07-09 10:14:51.712MaxDebug 5613:80149a50 NamingService: BaseService::sendRequest(): Sent 7 chunks.
    2009-07-09 10:14:51.728 Debug 5613:80149a50 NamingService: HTTP Status = 500 (Internal Server Error)
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: Http::Response::readAndParse(): Reading headers.
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: Server: Apache-Coyote/1.1
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: Content-Type: text/html;charset=utf-8
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: Date: Thu, 09 Jul 2009 08:14:51 GMT
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: Connection: close
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: Http::Response::readAndParse(): Reading body content of length: 13830487939496281954
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 all: Connection::waitForReply(): returns with status success.
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: Http::Response::readAndParse(): Completed processing the response with status: success
    2009-07-09 10:14:51.729MaxDebug 5613:80149a50 NamingService: <html><head><title>Apache Tomcat/6.0.18 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>javax.servlet.ServletException: AMSetupFilter.doFilter
    com.sun.identity.setup.AMSetupFilter.doFilter(AMSetupFilter.java:117)
    </pre></p><p><b>root cause</b> <pre>java.lang.NullPointerException
    com.iplanet.services.naming.service.NamingService.processRequest(NamingService.java:361)
    com.iplanet.services.naming.service.NamingService.process(NamingService.java:352)
    com.iplanet.services.comm.server.PLLRequestServlet.handleRequest(PLLRequestServlet.java:180)
    com.iplanet.services.comm.server.PLLRequestServlet.doPost(PLLRequestServlet.java:134)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    com.sun.identity.setup.AMSetupFilter.doFilter(AMSetupFilter.java:91)
    </pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.18</h3></body></html>
    2009-07-09 10:14:51.729 Warning 5613:80149a50 NamingService: BaseService::doHttpPost() failed, HTTP error = 500
    2009-07-09 10:14:51.729 Debug 5613:80149a50 NamingService: NamingService()::getProfile() returning with error code HTTP error.
    2009-07-09 10:14:51.729 Error 5613:80149a50 PolicyEngine: am_policy_evaluate: InternalException in Service::update_policy with error message:Naming query failed. and code:21
    In my Tomcat server (OpenSSO server web container), I have the following errors:
    Jul 9, 2009 10:12:35 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 22746 ms
    [Fatal Error] :2:46: Element type "NamingRequest" must be followed by either attribute specifications, ">" or "/>".
    java.lang.NullPointerException
    at com.iplanet.services.naming.service.NamingService.processRequest(NamingService.java:361)
    at com.iplanet.services.naming.service.NamingService.process(NamingService.java:352)
    at com.iplanet.services.comm.server.PLLRequestServlet.handleRequest(PLLRequestServlet.java:180)
    at ...
    It seems like the problem comes from the couple of closing square brackets in the NamingRequest tag:
    </NamingRequest>]]>
    I don't know where it comes from, so if you've an idea I'd enjoy .
    Cheers,

  • Treat objects from named query as new ones

    Hello,
    I use TopLink 11.1.1.1.0 and I need to do following. I want to read object from database with named query and let TopLink treat them like new object created in java. Is it possible? Obejcts are in one table but the named query computes them with select from several different tables, so this obejcts are not present in the table.
    Why I need it? It is import of data from one module of our application to another. Previously it was done in java. About 500 000 objects were read in one module just to convert into 20 000 objects in another module. If database does this conversion (named query with grouping which reads the 20 000 objects) it is much faster and take much less memory.
    What I can do is to create new class with the same fields query this objects and then copy them to object I need. But I don't like creating new class just for this.
    Thank for any help
    Frank

    Thanks for help I solved it different way eventually. I made a stored procedure which inserts data to the table of SOURCE_ITEMS. First I call stored procedure, then I load all new created SOURCE_ITEMS with ReadAllQuery (I have business parameters by which to select them) and make post processing in java with them. I used StoredProcedureCall in TopLink so if exception occurs and transaction rollbacks, stored procedure will rollback as well (I tried it, works for sure:).
    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName(SQL_IMPORT_CALL);
    call.addNamedArgumentValue(SQL_IMPORT_PARAM_1, getId());
    call.addNamedArgumentValue(SQL_IMPORT_PARAM_2, getXXX().getId());
    call.addNamedArgumentValue(SQL_IMPORT_PARAM_3, getYYY.getId());
    call.addNamedArgumentValue(SQL_IMPORT_PARAM_4, getZZZ());
    DataModifyQuery query = new DataModifyQuery();
    query.setCall(call);
    query.setShouldBindAllParameters(true);
    // insert of imported SOURCE_ITEMS
    ctx.executeQuery(query);
    Thanks Chris and hope this will help to somebody else as well..
    Frank
    Edited by: user604333 on Nov 17, 2010 12:20 PM
    Edited by: user604333 on Nov 17, 2010 12:20 PM
    Edited by: user604333 on Nov 17, 2010 12:20 PM

  • Creating a Java named query?

    Hi,
    From the application developers manual; is it implied that named queries can be created using the Oracle Toplink API in Java; i.e out of the workbench but I have not been able to find any references to this elsewhere. Does anyone have any information on this? i.e creating the named query in Java code and then adding it to the project deployment.
    In addition, is it possible to have it such that if a named query expects 4 arguments; the Java code is written to check if there are any null values passed in, and if the values are null those columns wlil be removed from the query.

    There are really two types of queries that apply.
    Named queries being those queries defined in Java code at application start up that take a fixed number and types of parameters. These queries are typically added using descriptor after-load methods. In the MW you select the static after-load method where you wish to define your queries. As of TopLink 9.0.4 it is possible to define your named queries with arguments directly in the MW without an after-load method.
    Redirect queries are queries where TopLink invokes your method at runtime to execute the query. This approach allows for your code to selectively build the where clause based upon the arguments passed in.
    Some links into the docs that may be of interest:
    after-load: http://download-west.oracle.com/docs/cd/B10464_01/web.904/b10316/dscriptr.htm#1014978
    Using named queries: http://download-west.oracle.com/docs/cd/B10464_01/web.904/b10313/queries.htm#1146839
    Redirect queries: http://download-west.oracle.com/docs/cd/B10464_01/web.904/b10313/queries.htm#1141580
    Doug

  • Creating a table from a query

    I am trying to create a table from the results of a query. With other products, I could issue the following SQL statement to achieve my goal but this doesn't work with Oracle.
    select MyTable.* into NewTable from MyTable where MAPID < 1000
    What am I missing?

    Try this way :
    create table NewTable as
    select * from MyTable where MAPID < 1000;

  • Toplink Named Query - Creating the Expression

    In JDeveloper, I have this scenario.
    I’ve created a:
    Name.java – private String name;
    Managed Bean – Name - id, Class - paperless.Name, Scope - session
    Toplink Named Query --> findUserProfile
    Type --> ReadObjectQuery
    In the format tab, I’m using “Expression” and it is “1. pp_Username EQUAL “#{id.name}”
    I’m trying to do a query on pp_Username where pp_Username equals the login name that I have stored in the session (id.name). I can only assume that I have my express written incorrectly. When I run it, I just get nothing. Any ideas?

    Go to your toplink map in the application navigator, select the descriptor in the structure pane and then click on the "Queries" tab in the editor pane. You should be able to configure your named query there.
    Hope this helps.
    Anuj

  • WebI:Creating a minus query from data providers not using the same universe

    Hi there. A client of ours wishes to use Combined Query on multiple universes in the same WebI report. So far, I have heard it is not feasible in WebI. I know it is possible in DeskI. Even the sub-query option is limited to just one universe in WebI. So, I am stuck.
    Is there a workaround to creating a minus query from data providers not using the same universe in WebI?

    Hello Amit,
    what are the Datasources ? Usually when you create a Sub Query you can choose a seperate Universe.
    Maybe if you only see one Universe you only have the rights for this Universe ?!.
    Regards
    -Seb.

Maybe you are looking for