builder.setProxyMode(true);
builder.setCrashSafeMode(true);
builder.setPathName(STORAGE_DIRECTORY.getPath());
builder.setRemoveFiles(false);
builder.setGarbageManagement(false);
final IFilePersistence filePersistence =
// /**/new FilePersistence(1, null, STORAGE_DIRECTORY, false, false);
builder.build();
final IDataAccessSession session = filePersistence
.createDataAccessSession();
/* store new item table (empty) */
session.open();
ItemTable itemTable = new ItemTable();
session.setObject(ITEM_TABLE, itemTable);
session.close(EnumFilePersistenceCloseAction.SAVE);
/* populate item table */
session.open();
itemTable = (ItemTable) session.getObject(ITEM_TABLE);
Item item = new Item("123", 10);
itemTable.addItem(item);
item = new Item("456", 10);
itemTable.addItem(item);
item = new Item("789", 11);
itemTable.addItem(item);
session.close(EnumFilePersistenceCloseAction.SAVE);
/* retrieve by code */
session.open();
itemTable = (ItemTable) session.getObject(ITEM_TABLE);
item = itemTable.getItemByCode("456");
// _log.info("retrieved by code 456: " + item);
item = (Item) filePersistence.deepCopy(item, true);// create accessible
// out of
// session
session.close(EnumFilePersistenceCloseAction.DO_NOT_SAVE);
LOGGER.info("retrieved by code 456:" + item);
session.open();
itemTable = (ItemTable) session.getObject(ITEM_TABLE);
final Collection<Item> collection = itemTable.getAllItem();
LOGGER.info("all item: " + collection);
session.close(EnumFilePersistenceCloseAction.DO_NOT_SAVE);
/* update */
session.open();
itemTable = (ItemTable) session.getObject(ITEM_TABLE);
item = itemTable.getItemByCode("123");
item.setPrice(9);
session.close(EnumFilePersistenceCloseAction.SAVE);
/* delete */
session.open();
itemTable = (ItemTable) session.getObject(ITEM_TABLE);
item = itemTable.removeItem("456");
LOGGER.info("deleted " + item);
session.close(EnumFilePersistenceCloseAction.SAVE);
/* retrieve by price */
session.open();
itemTable = (ItemTable) session.getObject(ITEM_TABLE);
final List<Item> list = itemTable
.getItemByPrice(9/* fromPrice */, 11/* toPrice */);
LOGGER.info("retrieved by price from 9 thru 11:" + list);
session.close(EnumFilePersistenceCloseAction.DO_NOT_SAVE);
/* close file persistence */
filePersistence.close();
}