// Inherit interface docs. @Override public TableInfo createTable(String tableName, TableSchema schema, CommandProperties properties) throws IOException { int pageSize = StorageManager.getCurrentPageSize(); String storageType = "heap"; ArrayList<Integer> hashColumns = new ArrayList<Integer>(); if (properties != null) { logger.info("Using command properties " + properties); pageSize = properties.getInt("pagesize", pageSize); storageType = properties.getString("storage", storageType); String hashString = properties.getString("hashkey", null); if (hashString != null) { List<String> hashList = Arrays.asList(hashString.split("\\s*,\\s*")); for (String s : hashList) { hashColumns.add(Integer.valueOf(s)); } } HashSet<String> names = new HashSet<String>(properties.getNames()); names.remove("pagesize"); names.remove("storage"); names.remove("hashkey"); if (!names.isEmpty()) { throw new IllegalArgumentException( "Unrecognized property " + "name(s) specified: " + names); } } String tblFileName = getTableFileName(tableName); DBFileType type; if ("heap".equals(storageType)) { type = DBFileType.HEAP_TUPLE_FILE; } else if ("btree".equals(storageType)) { type = DBFileType.BTREE_TUPLE_FILE; } else if ("lin-hash".equals(storageType)) { type = DBFileType.LINEAR_HASH_FILE; if (hashColumns.isEmpty()) { throw new IllegalArgumentException("Hash storage must specify a key!"); } } else { throw new IllegalArgumentException("Unrecognized table file " + "type: " + storageType); } TupleFileManager tupleFileManager = storageManager.getTupleFileManager(type); // First, create a new DBFile that the tuple file will go into. FileManager fileManager = storageManager.getFileManager(); DBFile dbFile = fileManager.createDBFile(tblFileName, type, pageSize); logger.debug("Created new DBFile for table " + tableName + " at path " + dbFile.getDataFile()); // Now, initialize it to be a tuple file with the specified type and // schema. TupleFile tupleFile; if (type == DBFileType.LINEAR_HASH_FILE) { DBFile overflow = fileManager.createDBFile("ovflw_" + tblFileName, DBFileType.OVERFLOW_FILE, pageSize); HashTupleFileManager hashManager = (HashTupleFileManager) tupleFileManager; tupleFile = hashManager.createTupleFile(dbFile, schema, hashColumns, overflow); } else { tupleFile = tupleFileManager.createTupleFile(dbFile, schema); } // Cache this table since it's now considered "open". TableInfo tableInfo = new TableInfo(tableName, tupleFile); openTables.put(tableName, tableInfo); return tableInfo; }
// Inherit interface docs. @Override public void saveTableInfo(TableInfo tableInfo) throws IOException { TupleFile tupleFile = tableInfo.getTupleFile(); TupleFileManager manager = tupleFile.getManager(); manager.saveMetadata(tupleFile); }