Problems with Handles: When the same document is not the same

Disclaimer: This will work in Java, SSJS and Lotus Script.

When opening the same document from the same database in different instances, and then recycle one of them, the other documents will be recycled too, because the handle to the underlying C object are the same.

This SSJS example…

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:label id="labelDemo">
        <xp:this.value>
            <![CDATA[#{javascript:
                var dbCur:NotesDatabase = session.getCurrentDatabase();
                var dbOther:NotesDatabase =  session.getCurrentDatabase();

                var docCur:NotesDocument = dbCur.getDocumentByUNID( "E5CA138B7F5A21E5C1257C190068DBA9" );
                var docOther:NotesDocument = dbOther.getDocumentByUNID( "E5CA138B7F5A21E5C1257C190068DBA9" );

                docCur.recycle();
                return docOther.getUniversalID();
            }]]>
        </xp:this.value>
    </xp:label>

</xp:view>

… fails, because docOther is recycled too.

But if you open the database dbOther after initializing the database object, the handles are not the same. Then, the recycling of the document won’t affect the other instance of the same object:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

    <xp:label id="labelDemo">
        <xp:this.value>
            <![CDATA[#{javascript:
                var dbCur:NotesDatabase = session.getCurrentDatabase();
                var dbOther:NotesDatabase = session.getDatabase( "", "" );
                dbOther.openByReplicaID( dbCur.getServer(), dbCur.getReplicaID() );

                var docCur:NotesDocument = dbCur.getDocumentByUNID( "E5CA138B7F5A21E5C1257C190068DBA9" );
                var docOther:NotesDocument = dbOther.getDocumentByUNID( "E5CA138B7F5A21E5C1257C190068DBA9" );

                docCur.recycle();
                return docOther.getUniversalID();
            }]]>
        </xp:this.value>
    </xp:label>

</xp:view>

In Lotus Script, you can fall into the trap when doing something like this:

Dim session As New NotesSession
Dim dbCur As NotesDatabase
Dim dcCur As NotesDocumentCollection
Dim dbOther As NotesDatabase
Dim docOther As NotesDocument

' open current database & create a document collection
Set dbCur = session.Currentdatabase
Set dcCur = dbCur.CreatedocumentCollection()

' open the current database again  
Set dbOther = New NotesDatabase( "","" )
dbOther.Open dbCur.Server, dbCur.Filepath

' get a document...
Set docOther = dbOther.Alldocuments.Getfirstdocument()

' ... and add it to the collection
dcCur.Adddocument docOther

This will result in a „Document is from a different database“ error:

Dieser Beitrag wurde unter Java, Java Script, Lotus Script abgelegt und mit , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert