public void create() throws IOException { segment.create(START_SIZE); super.create(); final OFile f = segment.getFile(); if (OGlobalConfiguration.STORAGE_CONFIGURATION_SYNC_ON_UPDATE.getValueAsBoolean()) f.synch(); }
@Override public OStorageConfiguration load() throws OSerializationException { try { if (segment.getFile().exists()) segment.open(); else { segment.create(START_SIZE); // @COMPATIBILITY0.9.25 // CHECK FOR OLD VERSION OF DATABASE final ORawBuffer rawRecord = storage.readRecord(CONFIG_RID, null, false, null).getResult(); if (rawRecord != null) fromStream(rawRecord.buffer); update(); return this; } final int size = segment.getFile().readInt(0); byte[] buffer = new byte[size]; segment.getFile().read(OBinaryProtocol.SIZE_INT, buffer, size); fromStream(buffer); } catch (Exception e) { throw new OSerializationException( "Cannot load database's configuration. The database seems to be corrupted.", e); } return this; }
@Override public void update() throws OSerializationException { try { final OFile f = segment.getFile(); if (!f.isOpen()) return; final byte[] buffer = toStream(); final int len = buffer.length + OBinaryProtocol.SIZE_INT; if (len > f.getFileSize()) f.allocateSpace(len - f.getFileSize()); f.writeInt(0, buffer.length); f.write(OBinaryProtocol.SIZE_INT, buffer); if (OGlobalConfiguration.STORAGE_CONFIGURATION_SYNC_ON_UPDATE.getValueAsBoolean()) f.synch(); } catch (Exception e) { throw new OSerializationException("Error on update storage configuration", e); } }
@Override public void unlock() throws IOException { if (segment != null) segment.getFile().unlock(); }
public void close() throws IOException { segment.close(); }
@Override public void setSoftlyClosed(boolean softlyClosed) throws IOException { segment.getFile().setSoftlyClosed(softlyClosed); }
public void synch() throws IOException { segment.getFile().synch(); }
public void create() throws IOException { segment.create(START_SIZE); super.create(); }