Copies Database And Maintains Folder Structure

Java / NOI Code that copies database and maintains folder structure. Good for
copying databases such as mail file.
import lotus.notes.*;
import java.util.*;

public class bm extends NotesThread
{
public String destserver;
public String destdbname;
public String sourserver;
public String sourpath;
public static void main(String argv[])

{
if (argv.length < 4)
System.out.println("Usage : java bm &LTsource server> &LTsource
path> &LTdestination server> &LTdestination path>");
else
{
bm t = new bm();
t.sourserver = argv[0];
t.sourpath = argv[1];
t.destserver = argv[2];
if (t.destserver.equals ("local"))
t.destserver = "";
else
{
t.destserver = argv[2];
}
t.destdbname = argv[3];
t.start();
}
}

public void runNotes()
{
try
{
Session s = Session.newInstance();
Database sourcedb = s.getDatabase(sourserver, sourpath);
System.out.println("Creating empty copy of file please wait.....");
Database destdb = sourcedb.createCopy(destserver, destdbname);
DocumentCollection alldocs = sourcedb.getAllDocuments();
Document doc = alldocs.getFirstDocument();
System.out.println("Copying documents please wait.....");
int i = 0;
while (doc != null)
{
Document newdoc = doc.copyToDatabase(destdb);
newdoc.replaceItemValue("locator", doc.getUniversalID());
newdoc.save(false, false);
doc = alldocs.getNextDocument(doc);
i++;
}
System.out.println("Copied " + i + " documents successfully.");
java.util.Vector viewnames = sourcedb.getViews();
System.out.println("Rebuilding folders .....Please Wait");
System.out.println("Note that Private folders will not be maintained");
i = 0;
String sourcestring;
String deststring;
alldocs = destdb.getAllDocuments();
for (i = 0; i < viewnames.size(); i++)
{
View o = (View)viewnames.elementAt(i);
doc = o.getFirstDocument();
if (o.isFolder())
{
System.out.println("Processing Folder " + o.getName());
while (doc != null)
{
sourcestring = doc.getUniversalID();
Document newdoc = alldocs.getFirstDocument();
// System.out.println(sourcestring);
while (newdoc != null)
{
deststring =
newdoc.getItemValueString("locator");
if (deststring.equals(sourcestring))
{
System.out.println("Putting
document " + doc.getItemValue("Subject") + " in folder " +
o.getName());
newdoc.putInFolder(o.getName());
}
newdoc =
alldocs.getNextDocument(newdoc);
} // End While for newdoc
doc = o.getNextDocument(doc);
} // End while for doc
} // End If
} // End For
System.out.println("Process Completed Sucessfully!!");
} // End Try
catch (Exception e) {e.printStackTrace();}

}// End Public
} // End Class

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close