Xpages - Java库 - NotesFactory.CreateSession中的错误

时间:2014-07-31 14:27:08

标签: xpages

首先,某些服务器尚不支持扩展库。我想比较db的所有副本中的文档计数。我想在网上显示相同内容。所以我循环遍历catalog.nsf条目。这是代码。问题是,它无法创建会话。这是代码:

package com.apse.replication;
import java.util.*;
import lotus.domino.*;

/**
 * @author Arun Agnihotri
 *
 */
@SuppressWarnings("unchecked")
public class ReplicationCountMismatches
{
    Session s = null;
    Database catDb = null;
    View catView = null;
    Document catDoc = null;
    DocumentCollection catCol = null;
    Vector v;
    String key;

    //hashmap object to hold the database replica id as key and document count as value
    Hashtable<String, Integer> dbTable = new Hashtable<String, Integer>();

    //array to hold server names
    String serverNames[] = {"Server1","Serevr2","Server3"};

    public DocumentCollection GetMismatchedReplicas(){

    //we'll loop through catalog database of every server and update the hashmap
    try{

        for (int i=0;i<serverNames.length;i++){
            s = NotesFactory.createSession(); //this is WHERE I RECEIVE ERROR
            catDb = s.getDatabase(serverNames[i], "catalog.nsf");
            catView = catDb.getView("Applications\\By Title");
            catDoc = catView.getFirstDocument();

            while(catDoc!=null){
                v = s.evaluate("@Text(ReplicaID;\"*\")", catDoc);
                key=v.firstElement().toString();
                if (i==0){
                    //first catalog being scanned.. put all key-value pairs in HashTable
                    dbTable.put(key, catDoc.getItemValueInteger("DbNumDocuments"));
                }
                else{
                    if (!dbTable.containsKey(key)){
                        dbTable.put(key, catDoc.getItemValueInteger("DbNumDocuments"));
                    }
                    else{
                        if ((Integer) dbTable.get(key) != catDoc.getItemValueInteger("DbNumDocuments")){
                            catCol.addDocument(catDoc); 
                        }
                    }
                }
                catDoc = catView.getNextDocument(catDoc);
            }
        }
    }
    catch(Exception e){
        e.printStackTrace();
    }
    return catCol;
    }
}

1 个答案:

答案 0 :(得分:1)

当您的Java代码在XPages上下文中运行时,您应该使用Jsf会话。

import com.ibm.xsp.extlib.util.ExtLibUtil;
...
Session s = ExtLibUtil.getCurrentSession();

如果您的代码将被执行的服务器没有ExtLibUtil,您可以创建自己的JsfUtil库,如here所示。