Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/fencedb/base/Test.java


1   
2   package org.fencedb.base;
3   
4   import org.odmg.Implementation;
5   import org.odmg.Database;
6   import org.odmg.ODMGException;
7   import org.odmg.Transaction;
8   import org.odmg.OQLQuery;
9   import org.odmg.DList;
10  
11  import org.apache.ojb.odmg.OJB;
12  
13  import java.io.File;
14  import java.io.FileReader;
15  import java.io.BufferedReader;
16  import java.util.Vector;
17  import java.util.StringTokenizer;
18  
19  /**
20   *  Description of the Class
21   *
22   * @author  vico
23   * @created  June 7, 2003
24   */
25  public class Test
26  {
27  
28      /**
29       *Constructor for the Test object
30       *
31       * @param  file Description of the Parameter
32       */
33      Test(String file)
34      {
35  
36          Vector v = null;
37          try {
38  
39              File f = new File(file);
40  
41              FileReader reader = new FileReader(f);
42              BufferedReader br = new BufferedReader(reader);
43  
44              v = new Vector();
45              String line = null;
46  
47              while ((line = br.readLine()) != null) {
48                  Country c = new Country();
49                  StringTokenizer st = new StringTokenizer(line);
50  
51                  String s = st.nextToken();
52  
53                  c.setShortName(s);
54  
55                  s = st.nextToken();
56  
57                  while (st.hasMoreTokens()) {
58                      s = s + " " + st.nextToken();
59                  }
60  
61                  c.setName(s);
62  
63                  v.addElement(c);
64              }
65  
66          }
67          catch (Exception e) {
68              e.printStackTrace();
69          }
70  
71          // get odmg facade instance
72          Implementation odmg = OJB.getInstance();
73          Database db = odmg.newDatabase();
74          //open database
75          try {
76              db.open("default", Database.OPEN_READ_WRITE);
77          }
78          catch (ODMGException ex) {
79              ex.printStackTrace();
80          }
81  
82          try {
83  
84              // save all country objects read...
85              for (int i = 0; i < v.size(); i++) {
86                  Transaction tx = odmg.newTransaction();
87                  tx.begin();
88                  Country c = (Country)v.elementAt(i);
89                  tx.lock(c, Transaction.WRITE);
90                  tx.commit();
91              }
92  
93          }
94          catch (Throwable t) {
95              t.printStackTrace();
96          }
97  
98      }
99  
100 
101     /**
102      *  Description of the Method
103      *
104      * @param  args Description of the Parameter
105      */
106     public static void main(String args[])
107     {
108         new Test(args[0]);
109     }
110 }
111