Cursor.count( ) leaves open cursors?

Hi, I am seeing a weird scenario inside a JUnit test -- they symptom is if I call cursor.count( ); in the code, and then close everything properly (I think), when I call close( ) on the environment, it throws a DB exception and claims there are cursors still open. If I comment out the call to cursor.count( ); this exception goes away.
Example inside JUnit test:
EntityIndex<Long, FaceEdge> subIndex = da.faceEdgeByEdgeId.subIndex(12L);
assertFalse(cursor.count( ) == 0);
try {
   for (FaceEdge fe : cursor) {
       assertTrue(fe.getEdgeId( ) == 12L);
   } finally {
       cursor.close( );
}The JUnit tearDown looks like this:
super.tearDown( );
myDbEnv.close( );...and myDbEnv.close( ) looks like this:
if (store != null) {
   try {
       store.close( );
   } catch(DatabaseException dbe) {
      etc.
if(myEnv != null) {
   try {
       myEnv.close( );
   } catch(DatabaseException dbe) {
      // this gets caught and says there are cursors still open
}The comment above is where the exception is caught. I use no other cursors anywhere, and if I comment out the line:
assertFalse(cursors.count( ) == 0);..in the JUnit test, the exception goes away.

Hello,
EntityCursor<FaceEdge> cursor = subIndex.entities();
assertFalse(cursor.count( ) == 0);I think the problem is that you're calling EntityCursor.count for an uninitalized cursor. The cursor must be advanced to the first entity before calling count() is allowed. In this situation a DatabaseException will be thrown with an "uninitialized cursor" message.
Probably what is happening in your JUnit test is that the exception is thrown but your tearDown method still executes, or perhaps you have a finally block, and you're trying to close the EntityStore or the Environment. If you try to close the store or the environment with cursors left open, you'll get an exception telling you to close the cursors. Because of this second exception, you don't see the first exception about the cursor being uninitialized.
I see this problem a lot in my own JUnit tests. :-) What I do is, in the tearDown method I put the calls to close the store and the environnment in a try/catch block. If an exception occurs, I print it, but I don't rethrow it. This allows the original exception (the one thrown by EntityCursor.count in your case) to be reported by JUnit. For example:
public void tearDown() {
    if (store != null) {
        try {
            store.close();
        } catch (Throwable e) {
            System.out.println("During tearDown: " + e);
        store = null;
    if (env != null) {
        try {
            env.close();
        } catch (Throwable e) {
            System.out.println("During tearDown: " + e);
        env = null;
}Mark

Similar Messages

  • Viewer leaving open cursors in Oracle

    We are using the JRC to display reports in our software. We are running jboss-4.2.0 as our application server. The backend could be either SQL Server or Oracle. For Oracle we are using the oracle.jdbc.driver.OracleDriver driver. The reports are set up using a JDBC (JNDI) connection. Generally we have it working ok but in Oracle the JRC is leaving open cursors leading to  ORA-01000: MAXIMUM OPEN CURSORS EXCEEDED. I have found that a new cursor is opened when the data source is changed in the following code snippet
    Iterator tableIT = tableNames.iterator();
    while (tableIT.hasNext()) {
      ITable oldTable = (ITable)tableIT.next();
      ITable table = (ITable) ((IClone)oldTable).clone(true);
      table.setQualifiedName(table.getName());
      clientDoc.getDatabaseController().setTableLocation(oldTable, table);
    When we hit the last line in this loop, a new cursor is opened in Oracle so if a report has 10 tables, I get 10 cursors opened. I know that I need to close the cursors somehow but nothing I do seems to make a difference. After my processHttpRequest call to the viewer I added:
    crystalReportPageViewer.getReportSource().dispose();
    clientDoc.getReportSource().dispose();
    The code definately executes but the the number of open cursors in Oracle does not change. I am at a loss.

    A couple more things to think about then.
    1.  When you go through your loop to set your table location, you are using the clone method to create a new table and then pass that table to the report.  Cloning tables is no longer necessary with the JRC.  We do know that a fix was provided for the JRC SDK, however this fix would probably not have been applied to the clone method since it has been deprecated.
    I have attached a sample that shows the new methodology for setting table location; very similar, just not using clone anymore.
    2.  When you want to destroy any connections that the ReportClientDocument has made, you will need to call .close() on this object.  This can be done in conjunction with the viewer.dispose().  One thing to note is that if you call the .close() method, it will need to be done as the user is closing the browser, or you will not have access to your report object when you have it open in the HTML Viewer.

  • Keeping track of count of open cursors

    Is there a way to ask the API for a list of open cursors (or at least a count of) ?

    Hi Linda,
    Again, thanks for the reply.
    Yes, I wanted to use it to manage cursors while closing a database. At the moment I maintain a count of open cursors myself, I do this so that I can manage the close database process.
    I do this if I want to close the database:
    1. Prevent new cursors from being opened (reject all db updates & queries)
    2. Wait till open cursor count is zero
    3. close db
    However, it does mean having to wrap every query/update method in such a way that I can maintain the cursor count. I was setting up a few new databases and was just wondering if i'd missed something in the API to do this for me.
    Thanks,
    Joel
    Edited by: JoelH on 17-Dec-2009 08:57

  • Total count of open invoices

    Hi,
    I want to get the total count of open invoices and paid invoices and total amount for a give list of vendors between a date range. Could anyone tell me what tables I should use to get the data?
    Thanks

    Hi,
    two vendor tables BSIK (for open items) and BSAK (for vendor cleared items) will serve the purpose for using them in you program.
    regards,
    chaitanya

  • Getting fast PDF page count (without opening file)?

    I’ve got a menu with about 100 PDFs and for various
    reasons I’d like to display the page count for each. I could
    enter the page count by hand but that becomes a maintenance
    nightmare as the PDFs are updated and someone (myself included)
    will forget to update the count. Opening each PDF in an xtra to get
    the page count would be too slow for 100 documents . I’ve
    found a dll that claims to parse the PDF header and quickly count
    PDF pages which might work (we’re already using dllBinder for
    MAPI access) although I haven’t started experimenting with
    it. Has anyone tried something similar? Can I parse the header with
    lingo/Buddy API and avoid working with the dll black box?

    I would take an approach in between the extremes you listed.
    Consider
    this. Make a list of all the documents, and make an automated
    process
    using Impressario or something to get the total pages in all
    100
    documents. Save this list. It will take a bit to open and
    close all
    the docs, but it only need to be done once. From then on,
    compare to
    the saved list. Whenever a doc gets changed use your
    automated
    Impressario process to update the list.
    If the DLL route doesn't pan out, then that is how I would go
    about it.
    You;d still need to remember to update your list after every
    change,
    but at least it is an automatic process.

  • How can I stop my Air from moving my programs that I leave open to other windows where I didn't leave them?

    How can I stop my Air from moving my programs that I leave open to other windows where I didn't leave them?

    Try toggling this preference (circled):

  • Mac user leaves open temp files, dsstore fil on Windows 2003 server network

    Our Mac user (Tiger - 10.4.8) leaves temporary open files and ds store files in the folders wherever he accesses an office file. He doesn't see them when he reopens the folder, but the Windows PC users see his 'footprints' everywhere. Is there a setting or update for his ibook?

    I have not tried this myself, but here's an article on how to disable this.
    http://docs.info.apple.com/article.html?artnum=301711

  • 919: Column count replaces query count when opening table/view/etc tab

    I don't know whether this is intentional or not, but I have just noticed that opening a table or view tab from the connection pane replaces the existing query count message with the query count from the column query. For example, opening a table tab for a table with 14 columns sets the query count message to "All Rows Fetched: 14".
    This is not a big issue, but adds to the aggravation of only having the latest query count message, rather than one for each SQL Worksheet.
    Is it possible to find somewhere on the SQL Worksheet that we can put it's query count message (for example to the right of the execution time)?

    I am happy for querying the columns of a table/view/etc to display the fetch count of the columns, although I am rarely interested in how many columns there are in a table/view/etc.
    However, I already find it frustrating that the query count is only for the last fetch - it can be very useful having the query count for last fetch per SQL Worksheet. Having the last fetch overwritten by opening a table tab only makes it more frustrating.

  • Close front panel but leave open block diagram

    Is there a way to do this? I would like to have my block diagrams of a few subvi's open but front panels closed so my task bar isn't so cluttered. It's not a big deal, I was just curious
    CLA, LabVIEW Versions 2010-2013

    Chris_VH wrote:
    No current way unfortunately.
    A colleague and I actually just put in a product suggestion for this yesterday.
    So if they fix this do I give you or them credit for the solution?
    CLA, LabVIEW Versions 2010-2013

  • HELP!! Black screen on my MacBook Pro after leaving open and on for over 8 hours.

    Hi everyone,
    This is the first time I'm using the discussion board as I haven't had any problems with my MacBook Pro since I bought it in November 2010. However, yesterday, I left my laptop on and open for over 8 hours without realising. When I came back to my laptop it had a black screen that just wouldn't go away. I pressed all the buttons on my keypad to wake it up but this didn't work. The caps lock key lights up when pressed and the volume button makes the clicky noise when turned up and down but the screen is still black. I have tried turning the laptop on/off using the power button several times. When it starts up it makes the usual sounds and I can hear that it is on but the screen is still black.
    I do not use my laptop for anything complicated. I really only use it to browse the web. I hope someone can help me. I have tried to make an appointment with the Genius Bar but there are no available appointments at my local one. I'm not a mac expert and don't understand technical words so please speak in layman terms otherwise I won't understand. Any help would be greatly appreciated. Many thanks

    If you've a 15" version, maybe...
    Mid-2010 15" MacBook Pros - the bad NVIDIA GPU
    If you're having frequent kernel panics with your 15" mid-2010, or intermittent screen problems, the problem is, more than likely, the faulty NVIDIA GPU found in a number of those machines.
    Here's just a sample of a kernel panic log that points to the faulty NVIDIA card:
    Kernel Extensions in backtrace (with dependencies):
             com.apple.GeForce(6.4.0)@0x82ac4000->0x82b7afff
                dependency: com.apple.NVDAResman(6.4.0)@0x834a0000
                dependency: com.apple.iokit.IONDRVSupport(2.2.1)@0x82fd3000
                dependency: com.apple.iokit.IOPCIFamily(2.6.5)@0x7a802000
                dependency: com.apple.iokit.IOGraphicsFamily(2.2.1)@0x8301b000
             com.apple.nvidia.nv50hal(6.4.0)@0x83c05000->0x84019fff
                dependency: com.apple.NVDAResman(6.4.0)@0x834a0000
             com.apple.NVDAResman(6.4.0)@0x834a0000->0x8378dfff
                dependency: com.apple.iokit.IOPCIFamily(2.6.5)@0x7a802000
                dependency: com.apple.iokit.IONDRVSupport(2.2.1)@0x82fd3000
                dependency: com.apple.iokit.IOGraphicsFamily(2.2.1)@0x8301b000
    Here's the "official" Apple take on the issue - but the very real kernel panics need not be preceded by 'Intermittent black screen or loss of video'... in fact, you might not experience any video problems at all. Although video problems can certainly be a portent of things to come…
    So what can you do? Print out a copy of your kernel panic and a copy of the Knowledge Base article and take them, along with your machine, to your local Apple Store or an Apple Authorized Service Provider. They should be more than willing to install a new logic board at no cost. I have no idea why this faulty GPU is making the headline here on the MacBook Pro forum so often now - could it be because Mountain Lion is just bringing the issue to a head more readily? I don't know - I only know that we're seeing more and more of these kernel panics of late.
    Good luck,
    Clinton

  • Audit View Count (By opening, by Running,By Clicking a link)

    Hi, Running the query below and need to know if this one would give the exact count of any report viewed by running manually the report or view from instance or view by clicking a viewer link sent via email.
    Any help or ideas appreciated. I'm assuming this is the same for XIR2 and XI 3.1
    Thanks,
    SELECT
    top 1000
    AUDIT_EVENT.Start_Timestamp,
      AUDIT_EVENT.Event_ID,
      AUDIT_EVENT.Event_Type_ID,
      EVENT_TYPE.Event_Type_Description,
      DERIVED_OBJECT_NAME.Detail_Text,
      AUDIT_EVENT.User_Name
    FROM
      AUDIT_EVENT,
      EVENT_TYPE,
      (   select
         AUDIT_EVENT.Server_CUID, AUDIT_EVENT.Event_ID,  cast(AUDIT_DETAIL.Detail_Text as nvarchar(128)) as Detail_Text
              from AUDIT_EVENT, AUDIT_DETAIL
         where
         (AUDIT_EVENT.Server_CUID = AUDIT_DETAIL.Server_CUID) and
         (AUDIT_EVENT.Event_ID = AUDIT_DETAIL.Event_ID) and
         (AUDIT_DETAIL.Detail_Type_ID = 3)
      )  DERIVED_OBJECT_NAME
    WHERE
      ( AUDIT_EVENT.Event_Type_ID=EVENT_TYPE.Event_Type_ID  )
      AND  ( AUDIT_EVENT.Event_ID=DERIVED_OBJECT_NAME.Event_ID and AUDIT_EVENT.Server_CUID=DERIVED_OBJECT_NAME.Server_CUID  )
      AND    AUDIT_EVENT.Event_Type_ID  In  ( 131073,131074,196609,196610 ,65537 )

    I doubt that Auditing is same in R2 and 3.1. Client tool activity added from 3.
    From Xi 3 onwards, I think it shouldn't matter how you access the report. It should capture all the events.
    If you have Auditor configured, it comes with some standard reports. You can edit either "Least Accessed reports" or "Most Accessed Reports" and remove the Ranking from the reports. You'll get all reports statistics.
    Note: Refresh events are not captured in case of Crystal Reports.

  • Adobe flash error when opening a file is closed and leaves open the file

    the problem is this I try to open a file FlippingBook Publication and try to open it immediately closes and says there are problems with adobe flash player 10.1 r102 you uninstall and reinstall the latest version adobe the problem continues, anyone know how to fix it?

    adobe flash player 10.1 r102
    Is there a specific reason you're using a five-year-old Flash Player version?

  • How to find total count of records in a cursor

    Aassume below is the cursor i defined
    cursor c1 is select * from emp;
    now, i want to find the total count of records in this cursor using an existing function etc., using one line statement.
    FYI: c1%rowcount is always giving 0, so i cant rely on this.
    Any thoughts, please share.
    Thanks in advance.

    I am just showing this to show how to get the rowcount along with the cursor, if the program has so much gap of between verifying the count(*) and opening the cursor.
    Justin actually covered this, he said, oracle has to spend some resources to build this functionality. As it is not most often required, it does not makes much sence to see it as a built-in feature. However, if we must see the rowcount when we open the cursor, here is a way, but it is little bit expensive.
    SQL> create table emp_crap as select * from emp where 1 = 2;
    Table created.
    SQL> declare
      2   v_cnt     number := 0;
      3   zero_rows         exception;
      4  begin
      5    for rec in (select * from (select rownum rn, e.ename from emp_crap e) order by 1 desc)
      6     loop
      7        if v_cnt = 0 then
      8           v_cnt := rec.rn;
      9        end if;
    10     end loop;
    11     if v_cnt = 0 then
    12        raise zero_rows;
    13     end if;
    14   exception
    15    when zero_rows then
    16      dbms_output.put_line('No rows');
    17   end;
    18  /
    No rows
    PL/SQL procedure successfully completed.
    -- Now, let us use the table, which has the data
    SQL> declare
      2   v_cnt     number := 0;
      3   zero_rows         exception;
      4  begin
      5    for rec in (select * from
      6          (select rownum rn, e.ename from emp e)
      7          order by 1 desc)
      8     loop
      9        if v_cnt = 0 then
    10           v_cnt := rec.rn;
    11           dbms_output.put_line(v_cnt);
    12        end if;
    13     end loop;
    14     if v_cnt = 0 then
    15        raise zero_rows;
    16     end if;
    17   exception
    18    when zero_rows then
    19      dbms_output.put_line('No rows');
    20   end;
    21  /
    14
    PL/SQL procedure successfully completed.Thx,
    Sri

  • Ref Cursors in a stored Procedure

    Can some help me with an answer to the below question.
    How many ref cursors can be declared in a stored procedure in oracle?
    Thanks

    user533016 wrote:
    You are right. Keeping so many cursors open is not good at all. But i was doing this to see where it breaks and is there something that definitely controls the number of refcursors in allowed a PL/SQL block.As Karthick already mentioned you have the OPEN_CURSORS parameter which defines how many open cursors you may have in any one session.
    However, this doesn't just apply to Ref Cursors. If you open explicitly defined cursors then this will also count towards that, as well as issuing select statements as they are implicit cursors... e.g.
    declare
      cursor c1 is
        select * from emp;
      cursor c2 is
        select * from dept;
      v_c1 c1%ROWTYPE;
      v_c2 c2%ROWTYPE;
      v_cnt number;
    begin
      open c1; -- now we have 1 open cursors
      loop
        fetch c1 into v_c1;
        exit when c1%notfound;
        open c2;  -- now we have 2 open cursors
        loop
          fetch c2 into v_c2;
          exit when c2%notfound;
          select count(*)  -- this counts as opening cursor number 3.
          into v_cnt
          from payroll;
          -- after the select statement the implicit cursor is automatically closed, so now we have 2 open again
        end loop;
        close c2; -- after this we just have 1 more open
      end loop;
      close c1; -- after this we have no open cursors
    end;

  • Using Same Cursor Variable

    Hi,
    I have declared a cursor as:
    TYPE T1_CUR IS REF CURSOR;
    T1_REC T1_CUR;
    I want to use the same Cursor variable at multiple places in my PL/SQL procedure by issuing OPEN, FETCH statements.
    Will the file pointer be set at the beginning each time I OPEN it with a SQL statement?
    Thanks

    We can OPEN a ref cursor many times, but we can only FETCH its contents once...
    SQL> DECLARE
      2     TYPE RCTyp IS REF CURSOR;
      3     TYPE T1List IS TABLE OF t1.col1%TYPE;
      4     TYPE T2List IS TABLE OF t2.col1%TYPE;
      5     t_cur RCTyp;
      6     t1s  T1List;
      7     t2s   T2List;
      8  BEGIN
      9      OPEN t_cur FOR SELECT col1 FROM t1;
    10      FETCH t_cur BULK COLLECT INTO t1s;
    11      dbms_output.put_line('#1='||to_char(t1s.COUNT));
    12      OPEN t_cur FOR SELECT col1 FROM t2;
    13      FETCH t_cur BULK COLLECT INTO t2s;
    14      dbms_output.put_line('#2='||to_char(t2s.COUNT));
    15      FETCH t_cur BULK COLLECT INTO t2s;
    16      dbms_output.put_line('#3='||to_char(t2s.COUNT));
    17  END;
    18  /
    #1=9
    #2=3
    #3=0
    PL/SQL procedure successfully completed.
    SQL> Cheers, APC

Maybe you are looking for

  • Required variable logic in BI 7.0

    we have two characters (posting _date & Netdue date )required the variables with one entry for the posting date,then it takes the same value for netduedate also.(aging buckets reports (AR).) please let me know ur suggestions

  • Subscription not being renewed despite payment bei...

    Hi all. One of my subscriptions has not been renewed. It clearly states that it should be renewed on the 17th, payment was taken on the 15th and it is now the 18th with no subcription renewal. I have attached an image which displays this. I have lost

  • 11g Read-Only repository on Linux

    Hi Currrenty I am struggling with a Read-Only issues on a new install of OBIEE 11g. I have install OBIEE11g on a Linux box and also on a windows server just to use the Repository Administation tool. I then created an ODBC DSN on the windows server to

  • Is plan driven procurement possible in classic scenario

    hai , is classic scenario possible in plan driven procurement? if possible anyone give me the steps required to do it. thanks and best regards, n.chakradhar

  • T500 display adapter problem on Windows Server 2008

    Hello, I recently got T500 and if I understand this correctly, it comes with two display adapters, - ATI Mobility HD Radeon 3650 - Intel Mobility 4 Series Express Chipset Family. I installed Windows Server 2008. Now my problem is that I can't install