private static void checkAttributesSanity( final int attributeRecordId, final IntArrayList usedAttributeRecordIds, final IntArrayList validAttributeIds) throws IOException { assert !usedAttributeRecordIds.contains(attributeRecordId); usedAttributeRecordIds.add(attributeRecordId); final DataInputStream dataInputStream = getAttributesStorage().readStream(attributeRecordId); try { while (dataInputStream.available() > 0) { int attId = DataInputOutputUtil.readINT(dataInputStream); int attDataRecordId = DataInputOutputUtil.readINT(dataInputStream); assert !usedAttributeRecordIds.contains(attDataRecordId); usedAttributeRecordIds.add(attDataRecordId); if (!validAttributeIds.contains(attId)) { assert getNames().valueOf(attId).length() > 0; validAttributeIds.add(attId); } getAttributesStorage().checkSanity(attDataRecordId); } } finally { dataInputStream.close(); } }
private static void deleteContentAndAttributes(int id) throws IOException { int content_page = getContentRecordId(id); if (content_page != 0) { getContentStorage().releaseRecord(content_page); } int att_page = getAttributeRecordId(id); if (att_page != 0) { final DataInputStream attStream = getAttributesStorage().readStream(att_page); while (attStream.available() > 0) { DataInputOutputUtil.readINT(attStream); // Attribute ID; int attAddress = DataInputOutputUtil.readINT(attStream); getAttributesStorage().deleteRecord(attAddress); } attStream.close(); getAttributesStorage().deleteRecord(att_page); } }
private static int findAttributePage(int fileId, String attrId, boolean toWrite) throws IOException { checkFileIsValid(fileId); Storage storage = getAttributesStorage(); int encodedAttrId = DbConnection.getAttributeId(attrId); int recordId = getAttributeRecordId(fileId); if (recordId == 0) { if (!toWrite) return 0; recordId = storage.createNewRecord(); setAttributeRecordId(fileId, recordId); } else { DataInputStream attrRefs = storage.readStream(recordId); try { while (attrRefs.available() > 0) { final int attIdOnPage = DataInputOutputUtil.readINT(attrRefs); final int attrAddress = DataInputOutputUtil.readINT(attrRefs); if (attIdOnPage == encodedAttrId) return attrAddress; } } finally { attrRefs.close(); } } if (toWrite) { Storage.AppenderStream appender = storage.appendStream(recordId); DataInputOutputUtil.writeINT(appender, encodedAttrId); int attrAddress = storage.createNewRecord(); DataInputOutputUtil.writeINT(appender, attrAddress); DbConnection.REASONABLY_SMALL.myAttrPageRequested = true; try { appender.close(); } finally { DbConnection.REASONABLY_SMALL.myAttrPageRequested = false; } return attrAddress; } return 0; }