@Before public void setUp() { file = new File("target", String.valueOf(System.currentTimeMillis())); if (file.exists()) { if (!file.delete()) { logger.error("Deletion of " + file.getPath() + " failed"); } } idSource = new FileIdSequence(file, 100); }
@Test public void test2() throws IOException { for (int i = 0; i < 50; i++) { idSource.getNextId(); } idSource.close(); idSource = new FileIdSequence(file, 100); assertEquals(101l, idSource.getNextId()); }
@Override public synchronized long getNextId() { try { if (nextId > maxId) { synchronize(); } return nextId++; } catch (IOException e) { throw new RepositoryException(e); } }
@After public void tearDown() throws IOException { idSource.close(); if (file.exists()) { if (!file.delete()) { logger.error("Deletion of " + file.getPath() + " failed"); } } }
@Test public void test3() throws IOException { for (int i = 0; i < 300; i++) { idSource.getNextId(); } }
@Override protected Repository createRepository(boolean sesameInference) { if (this.url != null) { org.openrdf.repository.http.HTTPRepository repository = new org.openrdf.repository.http.HTTPRepository(url); if (dataDir != null) { repository.setDataDir(dataDir); } if (username != null || password != null) { repository.setUsernameAndPassword(username, password); } if (dataDir != null) { idSource = new FileIdSequence(new File(dataDir, "lastLocalId")); } else { idSource = new MemoryIdSequence(); } return repository; } else { throw new RepositoryException("URL for remote repository not provided."); } }
@Test public void test() throws IOException { // 001-100 // 101-200 // 201-300 long s = System.currentTimeMillis(); for (int i = 0; i < 10000; i++) { idSource.getNextId(); } long e = System.currentTimeMillis(); System.out.println((e - s) + "ms"); idSource.close(); idSource = new FileIdSequence(file, 100); assertEquals(10001l, idSource.getNextId()); }
/** * 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); } }
@Override protected Repository createRepository(boolean sesameInference) { NativeStore store = new NativeStore(Assert.notNull(dataDir, "dataDir")); if (indexes != null) { store.setTripleIndexes(indexes); } idSource = new FileIdSequence(new File(dataDir, "lastLocalId")); if (sesameInference) { return new SailRepository(new ExtendedRDFSInferencer(store)); } else { return new SailRepository(store); } }
@Override protected Repository createRepository(boolean sesameInference) { NativeStore store = new NativeStore(Assert.notNull(dataDir,"dataDir")); if (indexes != null){ store.setTripleIndexes(indexes); } idSource = new FileIdSequence(new File(dataDir, "lastLocalId")); if (sesameInference){ return new SailRepository(new ExtendedRDFSInferencer(store)); }else{ return new SailRepository(store); } }
@Override protected Repository createRepository(boolean sesameInference) { NativeStore store = new NativeStore(Assert.notNull(dataDir, "dataDir")); if (indexes != null) { store.setTripleIndexes(indexes); } idSource = new FileIdSequence(new File(dataDir, "lastLocalId")); if (sesameInference) { return new SailRepository(new ExtendedRDFSInferencer(store)); } else { return new SailRepository(store); } }
@Override protected Repository createRepository(boolean sesameInference) { MemoryStore store; if (dataDir != null){ store = new MemoryStore(dataDir); idSource = new FileIdSequence(new File(dataDir, "lastLocalId")); }else{ store = new MemoryStore(); idSource = new MemoryIdSequence(); } if (syncDelay > 0){ store.setSyncDelay(syncDelay); } if (sesameInference){ return new SailRepository(new ExtendedRDFSInferencer(store)); }else{ return new SailRepository(store); } }
@Override protected Repository createRepository(boolean sesameInference) { MemoryStore store; if (dataDir != null) { store = new MemoryStore(dataDir); idSource = new FileIdSequence(new File(dataDir, "lastLocalId")); } else { store = new MemoryStore(); idSource = new MemoryIdSequence(); } if (syncDelay > 0) { store.setSyncDelay(syncDelay); } if (sesameInference) { return new SailRepository(new ExtendedRDFSInferencer(store)); } else { return new SailRepository(store); } }
@Override protected Repository createRepository(boolean sesameInference) { MemoryStore store; if (dataDir != null) { store = new MemoryStore(dataDir); idSource = new FileIdSequence(new File(dataDir, "lastLocalId")); } else { store = new MemoryStore(); idSource = new MemoryIdSequence(); } if (syncDelay > 0) { store.setSyncDelay(syncDelay); } if (sesameInference) { return new SailRepository(new ExtendedRDFSInferencer(store)); } else { return new SailRepository(store); } }