1 18 19 package sync4j.syncclient.sps.pocketpc.util; 20 21 import java.io.*; 22 import java.util.StringTokenizer ; 23 24 import sync4j.syncclient.sps.pocketpc.RapiDB; 25 26 34 public class CEDatabaseImport { 35 36 37 42 public static void main(String [] args) throws Exception { 43 boolean create = false; 44 int argc = 0 ; 45 int keyField = 1 ; 46 int statusField = 2 ; 47 48 if (args.length < 4) { 49 syntax(); 50 System.exit(-1); 51 } 52 53 if ((args.length == 5) && ("-create".equals(args[0]))) { 54 create = true; 55 argc = 1; 56 } 57 58 RapiDB db = new RapiDB(args[argc++], args[argc++]); 59 60 keyField = Integer.parseInt(args[argc++]); 61 statusField = Integer.parseInt(args[argc++]); 62 63 if (create) { 64 if (db.openDB(keyField, statusField, keyField) == true) { 65 db.deleteDB(); 66 } 67 68 if (!db.createDB(keyField, statusField)) { 69 System.out.println("Error creating the database!"); 70 System.exit(-1); 71 } 72 } 73 74 if (!db.openDB(keyField, statusField, keyField)) { 75 System.out.println("Error creating the database!"); 76 System.exit(-1); 77 } 78 79 BufferedReader reader = new BufferedReader( new InputStreamReader(System.in)); 80 81 int i=0; 82 Object [] data; 83 String key; 84 String line; 85 StringTokenizer stk; 86 while((line = reader.readLine()) != null) { 87 if (line.startsWith("#") || (line.trim().length() == 0)) { 88 continue; 89 } 90 91 System.out.println("processing.... " + line); 92 93 stk = new StringTokenizer (line, "|"); 94 95 key = stk.nextToken(); 99 100 data = new Object [stk.countTokens()]; 101 i = 0; 102 while (stk.hasMoreTokens()) { 103 data[i++] = stk.nextToken(); 104 } 105 106 db.storeRecord(key, data); 107 } 108 109 db.closeDB(); 110 reader.close(); 111 } 112 113 private static void syntax() { 114 System.out.println("Wrong syntax."); 115 System.out.println("Syntax:"); 116 System.out.println("sync4j.syncclient.sps.common.util.CEDatabaseImport [-create] volume database"); 117 } 118 119 } | Popular Tags |