Home > Domino Tips > Developer > Java > Copies Database And Maintains Folder Structure
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVA

Copies Database And Maintains Folder Structure


Christopher Connor
03.10.1999
Rating: --- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Java / NOI Code that copies database and maintains folder structure. Good for
copying databases such as mail file.

Code

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 <source server> <source
path> <destination server> <destination 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

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Java
Java code inserts data from Notes documents into a SQL table
Java code shortens strings in a SQL table
How to execute a stored procedure in Lotus Notes Domino using Java
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
FAQ: Java for Lotus Notes and Domino

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts