Hello!Sorry for my English ![]()
I am beginer and I don’t know how to get access to local database.
I wrote two classes:
-
JavaAgent extend AgentBase with NotesMain function. From this level I have acces to my database, except this I can’t read all records from my ViewEntryCollection vec = view.getAllEntries(); (only 9000 - my database have 13000).
-
MyWindow which is interface to my Agent.
From this level I have’t acces to database - please help!!!
This is my code:
import lotus.domino.*;
import java.util.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.awt.*;
import java.awt.event.*;
public class JavaAgent extends AgentBase {
String myString=“”;
MyWindow myWindow;
public void NotesMain() {
try {
lotus.domino.Session session = getSession();
AgentContext agentContext = session.getAgentContext();
lotus.domino.Database db = agentContext.getCurrentDatabase();
Document doc = agentContext.getDocumentContext();
if(doc!=null)//sprawdzenie czy pobrano dokument
{
myString = doc.getFirstItem("e_mail").getText();
}
else System.out.println("doc is null");
} catch(Exception e) {e.printStackTrace();}
myWindow = new MyWindow(this,myString);
myWindow.setSize(500,500);
myWindow.setVisible(true);
}
}//end class JavaAgent
class MyWindow extends Frame implements WindowListener,ActionListener
{
Button sendToPerson;
Button sendToAll;
JavaAgent agent;
MyWindow(JavaAgent agent,String meil)
{
super("Mailing");
this.agent=agent;
addWindowListener(this);
setLayout(new BorderLayout());
sendToPerson = new Button("Send to person");
sendToPerson.addActionListener(this);
add(BorderLayout.WEST, sendToPerson);
sendToAll = new Button("Send to all");
sendToAll.addActionListener(this);
add(BorderLayout.EAST, sendToAll);
}
public void SendtoPerson()
{
}
public void SendToAll()
{
try {
///// here I have problem
lotus.domino.Session session = agent.getSession();
AgentContext agentContext = session.getAgentContext();
lotus.domino.Database db = agentContext.getCurrentDatabase();
View view = db.getView("MyView");
ViewEntryCollection vec = view.getAllEntries();
System.out.println("\"MyView\" view has " +vec.getCount() + " entries");
ViewEntry entry;
for (int i=1; i< vec.getCount(); i++)
{
try {
entry = vec.getNthEntry(i);
System.out.println(i+" "+entry.getDocument().getItemValueString("e_mail")+"\n");
//here I will send a message, but I have't access to database and field e_mail
//please Help ;)
} catch(Exception en) {}
}
}
catch(Exception e) {e.printStackTrace();}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() instanceof Button)
{
if (e.getSource() == sendToPerson)
{
SendtoPerson();
}
if (e.getSource() == sendToAll)
{
SendToAll();
}
}
}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowClosing(WindowEvent e) {
setVisible(false);
dispose();
}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
}
I have this error:
lotus.domino.NotesException
at lotus.domino.local.NotesBase.CheckObject(NotesBase.java:979)
at lotus.domino.local.Session.getAgentContext(Session.java:1221)
at MyWindow.SendToAll(JavaAgent.java:72)
at MyWindow.actionPerformed(JavaAgent.java:108)
at java.awt.Button.processActionEvent(Button.java:256)
at java.awt.Button.processEvent(Button.java:229)
at java.awt.Component.dispatchEventImpl(Component.java:1812)
at java.awt.Component.dispatchEvent(Component.java:1744)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:79)