@Override public synchronized long getNextId() { try { if (nextId > maxId) { synchronize(); } return nextId++; } catch (IOException e) { throw new RepositoryException(e); } }
/** * Use the given File for persistence with a cache of 100 increments * * @param file * @param cache */ public FileIdSequence(File file, int cache) { try { if (!file.exists()) { if (!file.getParentFile().exists()) { if (!file.getParentFile().mkdirs()) { logger.error("Creation of " + file.getParentFile().getPath() + " failed"); } } if (!file.createNewFile()) { logger.error("Creation of " + file.getPath() + " failed"); } } this.file = file; this.fileChannel = new RandomAccessFile(file, "rwd").getChannel(); this.cache = cache; synchronize(); } catch (FileNotFoundException e) { throw new RepositoryException(e); } catch (IOException e) { throw new RepositoryException(e); } }