1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH München (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.samples;
24  
25  import java.util.GregorianCalendar;
26  
27  import de.bea.domingo.DDatabase;
28  import de.bea.domingo.DDocument;
29  import de.bea.domingo.DNotesFactory;
30  import de.bea.domingo.DRichTextItem;
31  import de.bea.domingo.DSession;
32  import de.bea.domingo.monitor.AbstractMonitor;
33  import de.bea.domingo.monitor.ConsoleMonitor;
34  
35  /***
36   * This example creates a new database on a server and creates a huge number of
37   * documents to test proper recycling thru a Corba connection.
38   *
39   * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
40   */
41  public class CorbaCreateManyDocuments {
42  
43      /***
44       * Main method.
45       *
46       * @param args command line arguments: host username password
47       */
48      public static final void main(final String[] args) {
49          if (args.length != 3) {
50              System.out.println("Arguments: host username password");
51              return;
52          }
53          try {
54              ConsoleMonitor monitor = new ConsoleMonitor();
55              monitor.setLevel(AbstractMonitor.DEBUG);
56              DNotesFactory factory = DNotesFactory.getInstance(monitor);
57              DSession session = factory.getSession(args[0], args[1], args[2]);
58              DDatabase database = session.createDatabase("", "many.nsf");
59              monitor.debug("Database many.nsf created on server "  + args[0]);
60              for (int i = 0; i < 30; i++) {
61                  for (int j = 0; j < 1000; j++) {
62                      DDocument document = database.createDocument();
63                      document.replaceItemValue("Form", "Test");
64                      document.replaceItemValue("Test", "Test");
65                      document.replaceItemValue("Number", 1.1234);
66                      document.replaceItemValue("Date", new GregorianCalendar(2007, 01, 01, 17, 30, 00));
67                      DRichTextItem item = document.createRichTextItem("Body");
68                      item.appendText("some rich text");
69                      item.addNewLine(2);
70                      item.appendText("some more text");
71                      document.save();
72                  }
73                  monitor.debug("Created " + ((i + 1) * 1000) + " documents");
74              }
75              monitor.debug("finished successfully.");
76          } catch (Throwable e) {
77              e.printStackTrace();
78          }
79      }
80  }