// Done !!! :D :D public void insertRecord(Hashtable<String, String> htblColNameValue, int numberOfRows) throws ClassNotFoundException, IOException, DBAppException { ArrayList<String> colName = DBApp.getKeysOfHashtable(htblColNameValue); for (int i = 0; i < colName.size(); i++) { if (!ColNameType.containsKey(colName.get(i))) throw new DBAppException(); } Page p = (Page) DBApp.readObj("src/classes/Datei/" + tableName + numberOfPages + ".class"); if (p.isFull()) { p = addPage(numberOfRows, colName); } int row = p.insert(htblColNameValue, colName); for (int i = 0; i < singleIndexedColumns.size(); i++) if (htblColNameValue.containsKey(singleIndexedColumns.get(i))) { LinearHashTable LHT = (LinearHashTable) DBApp.readObj( "src/classes/Datei/Hashtable#" + tableName + "#" + singleIndexedColumns.get(i) + ".class"); LHT.put(htblColNameValue.get(singleIndexedColumns.get(i)), p.getPageNumber() + "#" + row); DBApp.writeObj( LHT, "src/classes/Datei/Hashtable#" + tableName + "#" + singleIndexedColumns.get(i) + ".class"); } for (int i = 0; i < multiIndexedColumns.size(); i++) { String[] thisKDTreeColumns = multiIndexedColumns.get(i); boolean weNeedIt = true; for (int j = 0; j < thisKDTreeColumns.length; j++) weNeedIt = weNeedIt && htblColNameValue.containsKey(thisKDTreeColumns[j]); String thisKDTreeName = DBApp.getKDTreeName(thisKDTreeColumns); KDTree kdtree = (KDTree) DBApp.readObj( "src/classes/Datei/KDTree#" + tableName + "#" + thisKDTreeName + ".class"); kdtree.insert(p.getValues(row, thisKDTreeColumns), p.getPageNumber() + "#" + row); DBApp.writeObj( kdtree, "src/classes/Datei/KDTree#" + tableName + "#" + thisKDTreeName + ".class"); } DBApp.writeObj(p, "src/classes/Datei/" + tableName + p.getPageNumber() + ".class"); }
// Done !!! :D :D :D public void addSingleIndex(String column, float loadFactor, int bucketSize) throws IOException, ClassNotFoundException, DBAppException { if (!ColNameType.containsKey(column)) throw new DBAppException(); singleIndexedColumns.add(column); LinearHashTable LHT = new LinearHashTable(tableName, column, loadFactor, bucketSize); for (int i = 1; i <= numberOfPages; i++) { Page p = (Page) DBApp.readObj("src/classes/Datei/" + tableName + i + ".class"); for (int j = 0; j < p.length(); j++) { String val = p.getValue(j, column); if (val != null) LHT.put(p.getValue(j, column), p.getPageNumber() + "#" + j); } } DBApp.writeObj(LHT, "src/classes/Datei/Hashtable#" + tableName + "#" + column + ".class"); }