(String[] args)
| 10 | |
| 11 | public class SimpleDb { |
| 12 | public static void main (String[] args) |
| 13 | throws DbException, TransactionAbortedException { |
| 14 | // convert a file |
| 15 | switch (args[0]) { |
| 16 | case "convert": |
| 17 | try { |
| 18 | if (args.length < 3 || args.length > 5) { |
| 19 | System.err.println("Unexpected number of arguments to convert "); |
| 20 | return; |
| 21 | } |
| 22 | File sourceTxtFile = new File(args[1]); |
| 23 | File targetDatFile = new File(args[1].replaceAll(".txt", ".dat")); |
| 24 | int numOfAttributes = Integer.parseInt(args[2]); |
| 25 | Type[] ts = new Type[numOfAttributes]; |
| 26 | char fieldSeparator = ','; |
| 27 | |
| 28 | if (args.length == 3) |
| 29 | for (int i = 0; i < numOfAttributes; i++) |
| 30 | ts[i] = Type.INT_TYPE; |
| 31 | else { |
| 32 | String typeString = args[3]; |
| 33 | String[] typeStringAr = typeString.split(","); |
| 34 | if (typeStringAr.length != numOfAttributes) { |
| 35 | System.err.println("The number of types does not agree with the number of columns"); |
| 36 | return; |
| 37 | } |
| 38 | int index = 0; |
| 39 | for (String s : typeStringAr) { |
| 40 | if (s.equalsIgnoreCase("int")) |
| 41 | ts[index++] = Type.INT_TYPE; |
| 42 | else if (s.equalsIgnoreCase("string")) |
| 43 | ts[index++] = Type.STRING_TYPE; |
| 44 | else { |
| 45 | System.err.println("Unknown type " + s); |
| 46 | return; |
| 47 | } |
| 48 | } |
| 49 | if (args.length == 5) |
| 50 | fieldSeparator = args[4].charAt(0); |
| 51 | } |
| 52 | |
| 53 | HeapFileEncoder.convert(sourceTxtFile, targetDatFile, |
| 54 | BufferPool.getPageSize(), numOfAttributes, ts, fieldSeparator); |
| 55 | |
| 56 | } catch (IOException e) { |
| 57 | throw new RuntimeException(e); |
| 58 | } |
| 59 | break; |
| 60 | case "print": |
| 61 | File tableFile = new File(args[1]); |
| 62 | int columns = Integer.parseInt(args[2]); |
| 63 | DbFile table = Utility.openHeapFile(columns, tableFile); |
| 64 | TransactionId tid = new TransactionId(); |
| 65 | DbFileIterator it = table.iterator(tid); |
| 66 | |
| 67 | if (null == it) { |
| 68 | System.out.println("Error: method HeapFile.iterator(TransactionId tid) not yet implemented!"); |
| 69 | } else { |
nothing calls this directly
no test coverage detected