DiskPersistence implements SQLitePersistence<O, A>, Closeable { public static <O, A extends Comparable<A>> DiskPersistence<O, A> onPrimaryKeyInFile(SimpleAttribute<O, A> primaryKeyAttribute, File file) { return DiskPersistence.onPrimaryKeyInFileWithProperties(primaryKeyAttribute, file, new Properties()); } protected  DiskPersistence(SimpleAttribute<O, A> primaryKeyAttribute, File file, Properties overrideProperties); @Override SimpleAttribute<O, A> getPrimaryKeyAttribute(); File getFile(); @Override Connection getConnection(Index<?> index, QueryOptions queryOptions); @Override boolean supportsIndex(Index<O> index); @Override void close(); @Override long getBytesUsed(); @Override void compact(); @Override void expand(long numBytes); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override ObjectStore<O> createObjectStore(); @Override SQLiteDiskIdentityIndex<A, O> createIdentityIndex(); @Override void openRequestScopeResources(QueryOptions queryOptions); @Override void closeRequestScopeResources(QueryOptions queryOptions); static File createTempFile(); static DiskPersistence<O, A> onPrimaryKey(SimpleAttribute<O, A> primaryKeyAttribute); static DiskPersistence<O, A> onPrimaryKeyInFile(SimpleAttribute<O, A> primaryKeyAttribute, File file); static DiskPersistence<O, A> onPrimaryKeyInFileWithProperties(SimpleAttribute<O, A> primaryKeyAttribute, File file, Properties overrideProperties);  }
@Test @Ignore public void testSaveToDisk() { Set<Car> collectionOfCars = CarFactory.createCollectionOfCars(50); Set<Integer> expectedCarIds = collectionOfCars.stream().map(Car::getCarId).collect(toSet()); File persistenceFile = new File("cqengine-persisted.dat"); System.out.println("Persistence file: " + persistenceFile.getAbsolutePath()); DiskPersistence<Car, Integer> persistence = DiskPersistence.onPrimaryKeyInFile(Car.CAR_ID, persistenceFile); IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(persistence); cars.addAll(collectionOfCars); Set<Integer> actualCarIds = cars.stream().map(Car::getCarId).collect(toSet()); Assert.assertEquals(expectedCarIds, actualCarIds); System.out.println("Saved to disk: " + actualCarIds); }
@Test @Ignore public void testReadFromDisk() { Set<Car> collectionOfCars = CarFactory.createCollectionOfCars(50); Set<Integer> expectedCarIds = collectionOfCars.stream().map(Car::getCarId).collect(toSet()); File persistenceFile = new File("cqengine-persisted.dat"); System.out.println("Persistence file: " + persistenceFile.getAbsolutePath()); DiskPersistence<Car, Integer> persistence = DiskPersistence.onPrimaryKeyInFile(Car.CAR_ID, persistenceFile); IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(persistence); Set<Integer> actualCarIds = cars.stream().map(Car::getCarId).collect(toSet()); Assert.assertEquals(expectedCarIds, actualCarIds); System.out.println("Loaded from disk: " + actualCarIds); }