Examples: Creating, compacting, removing, and replicating a database
- This agent creates a local database named salesdisc.nsf. The database
is not initialized. This database is useful for storing data programmatically
but cannot be used through the workspace.
import lotus.domino.*; public class JavaAgent extends AgentBase { public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); // (Your code goes here) DbDirectory dir = session.getDbDirectory(null); Database db = dir.createDatabase("salesdisc"); } catch(Exception e) { e.printStackTrace(); } } }
- This agent creates a local database named salesdisc.nsf based
on a template and changes the title. The third argument to createFromTemplate
is for inheriting design changes.
import lotus.domino.*; public class JavaAgent extends AgentBase { public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); // (Your code goes here) DbDirectory dir = session.getDbDirectory(null); Database template = dir.openDatabase( "discsw50.ntf"); Database db = template.createFromTemplate (null, "salesdisc", true); db.setTitle("Sales Discussion Database"); } catch(Exception e) { e.printStackTrace(); } } }
- This agent creates a local replica of a database on a server and
initializes it.
import lotus.domino.*; public class JavaAgent extends AgentBase { public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); // (Your code goes here) DbDirectory dir = session.getDbDirectory("market"); Database basedb = dir.openDatabase("salesdisc"); Database db = basedb.createReplica(null, "salesdisc"); if (db.replicate("market")) System.out.println("Replication OK"); else System.out.println("Replication errors"); } catch(Exception e) { e.printStackTrace(); } } }
- This agent creates a copy of names.nsf in the local directory.
import lotus.domino.*; public class JavaAgent extends AgentBase { public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); // (Your code goes here) DbDirectory dir = session.getDbDirectory(null); Database basedb = dir.openDatabase("names"); Database db = basedb.createCopy(null, "namescpy"); db.setTitle("Copy of names.nsf"); } catch(Exception e) { e.printStackTrace(); } } }