Package net.sf.joafip.service

Examples of net.sf.joafip.service.IFilePersistence


    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();
  }
 
View Full Code Here


    builder.setGarbageManagement(false);
    builder.setAutoSaveEnabled(true);
    builder.setMaxInMemoryThreshold(1000);
    builder.setMaintenedInMemory(false);
    // builder.setMaintenedInMemoryQuota(100);
    final IFilePersistence filePersistence = builder.build();
    filePersistence.setAutoSaveEventListener(this);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    session.open();
    final Tree<String> tree = Tree.newInstance(instanceFactory);
    appendLoop(tree);
    session.close();
    filePersistence.close();
  }
View Full Code Here

    builder.setGarbageManagement(false);
    // builder.setAutoSaveEnabled(true);
    // builder.setMaxInMemoryThreshold(1000);
    // builder.setMaintenedInMemory(false);
    // // builder.setMaintenedInMemoryQuota(100);
    final IFilePersistence filePersistence = builder.build();
    session = filePersistence.createDataAccessSession();

    session.open();
    Tree<String> tree = new Tree<String>();
    session.setObject("key", tree);
    session.close(EnumFilePersistenceCloseAction.SAVE);

    session.open();
    tree = (Tree<String>) session.getObject("key");
    appendLoop(tree);
    session.close(EnumFilePersistenceCloseAction.SAVE);
    filePersistence.close();
  }
View Full Code Here

    builder.setDataManager(dataManager);
    builder.setProxyMode(true);
    builder.setRemoveFiles(false);
    builder.setGarbageManagement(false);
    builder.setCrashSafeMode(false);
    final IFilePersistence filePersistence = builder.build();
    filePersistence.setExportListener(this);
    final int numberOfDataRecord = filePersistence.getNumberOfDataRecord();
    System.out.println("numberOfDataRecord=" + numberOfDataRecord); // NOPMD
    startTime = System.currentTimeMillis();
    filePersistence.xmlExport("runtime_perf/export", "runtime_perf/tmp",
        false/* exportPersistedClassByteCode */);
    System.out.println("duration " // NOPMD
        + (System.currentTimeMillis() - startTime) + " mS");
    filePersistence.close();
  }
View Full Code Here

      builder.setPathName("runtime");
      builder.setProxyMode(true);
      builder.setRemoveFiles(false);
      builder.setGarbageManagement(GARBAGE);
      builder.setCrashSafeMode(CRASH_SAFE_MODE);
      final IFilePersistence filePersistence = builder.build();

      String message = "to garbage="
          + filePersistence.getNumberOfToGarbage();
      printMessage(message);
      message = "garbage candidate="
          + filePersistence.getNumberOfGarbageCandidate();
      printMessage(message);
      message = "nb of data record="
          + filePersistence.getNumberOfDataRecord();
      printMessage(message);
      message = "nb of free record="
          + filePersistence.getNumberOfFreeRecord();
      printMessage(message);
      message = "used size=" + filePersistence.usedSize();
      printMessage(message);
      message = "free size=" + filePersistence.freeSize();
      printMessage(message);
      message = "heap size=" + filePersistence.totalSize();
      printMessage(message);

      filePersistence.close();

    } catch (FilePersistenceException exception) {
      exception.printStackTrace();// NOPMD
    } catch (FilePersistenceInvalidClassException exception) {
      exception.printStackTrace();// NOPMD
View Full Code Here

    builder.setFileAccessMode(EnumFileAccessMode.MAPPED_RANDOM_FILE_ACCESS);
    builder.setMaxBufferSize(8 * 1024);
    builder.setMaxNumberOfBuffer(32);
    builder.setPathName(TestConstant.getWinRamDiskRuntimeDir());
    builder.setProxyMode(true);
    final IFilePersistence filePersistence = builder.build();
    filePersistence.setAutoSaveEnabled(true);
    // 0 for immediate saving
    filePersistence.autoSaveSetup(0);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    final Element element = Element.newInstance(instanceFactory);
    element.addNameSpace(HELLO);
    final Element clone = element.clone();
    List<String> list = clone.getAdditionalNamespaces();
    assertEquals(BAD_CONTENT, HELLO, list.get(0));
    list = clone.getAdditionalNamespacesList();
    assertEquals(BAD_CONTENT, HELLO, list.get(0));

    session.close();
    filePersistence.close();
  }
View Full Code Here

    builder.setFileAccessMode(EnumFileAccessMode.MAPPED_RANDOM_FILE_ACCESS);
    builder.setMaxBufferSize(8 * 1024);
    builder.setMaxNumberOfBuffer(32);
    builder.setPathName(TestConstant.getWinRamDiskRuntimeDir());
    builder.setProxyMode(true);
    final IFilePersistence filePersistence = builder.build();
    filePersistence.setAutoSaveEnabled(true);
    // 0 for immediate saving
    filePersistence.autoSaveSetup(0);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    try {
      ElementKo.newInstance(instanceFactory);
      fail("must fail because of method ElementKo#setAdditionnalNamespaces");
    } catch (Exception exception) {
      Throwable current = exception;
      while (current != null
          && !EnhanceException.class.equals(current.getClass())) {
        current = current.getCause();
      }
      if (current == null) {
        fail("EnhanceException expected");
      }
    }

    // element.addNameSpace(HELLO);
    // final ElementKo clone = element.clone();
    //
    // List<String> list = clone.getAdditionalNamespaces();
    // assertEquals(BAD_CONTENT, HELLO, list.get(0));
    // list = clone.getAdditionalNamespacesList();
    // assertEquals(BAD_CONTENT, HELLO, list.get(0));

    session.close();
    filePersistence.close();
  }
View Full Code Here

    builder.setGarbageManagement(false);
    builder.setAutoSaveEnabled(true);
    builder.setMaxInMemoryThreshold(1000);
    builder.setMaintenedInMemory(false);
    // builder.setMaintenedInMemoryQuota(100);
    final IFilePersistence filePersistence = builder.build();
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    session.open();
    final Tree<String> tree = Tree.newInstance(instanceFactory);
    appendLoop(tree);
    session.close();
    filePersistence.close();
  }
View Full Code Here

      builder.setFileCache(pageSize, numberOfPage);
      builder.setProxyMode(true);
      builder.setRemoveFiles(true);
      builder.setGarbageManagement(GARBAGE);
      builder.setCrashSafeMode(CRASH_SAFE_MODE);
      final IFilePersistence filePersistence = builder.build();
      final IDataAccessSession session = filePersistence
          .createDataAccessSession();
      session.open();
      session.setObject("key", new EmptyClass());
      session.close(EnumFilePersistenceCloseAction.SAVE);

      printState(filePersistence);

      filePersistence.garbageSweep("runtime/set");

      printState(filePersistence);

      session.open();
      session.getObject("key");
      session.close(EnumFilePersistenceCloseAction.SAVE);

      filePersistence.close();

    } catch (final FilePersistenceException exception) {
      exception.printStackTrace();// NOPMD
    } catch (final FilePersistenceInvalidClassException exception) {
      exception.printStackTrace();// NOPMD
View Full Code Here

    builder.setGarbageManagement(false);
    builder.setAutoSaveEnabled(true);
    builder.setMaxInMemoryThreshold(1000);
    builder.setMaintenedInMemory(false);
    // builder.setMaintenedInMemoryQuota(100);
    final IFilePersistence filePersistence = builder.build();
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    session.open();
    final Tree<String> tree = Tree.newInstance(instanceFactory);
    appendLoop(tree);
    session.close();
    filePersistence.close();
  }
View Full Code Here

TOP

Related Classes of net.sf.joafip.service.IFilePersistence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.