Package net.sf.joafip.service

Examples of net.sf.joafip.service.IFilePersistence


    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();
    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.setFileCache(/**/1024/* PAGE_SIZE */, 1024/* NUMBER_OF_PAGE */);
    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.setProxyMode(true);
    builder.setRemoveFiles(false);
    builder.setGarbageManagement(false);
    builder.setCrashSafeMode(false);
    builder.setRemoveFiles(true);
    final IFilePersistence filePersistence = builder.build();

    filePersistence.setImportListener(this);
    startTime = System.currentTimeMillis();
    filePersistence.xmlImport("runtime_perf/export", true);
    System.out.println(numberOfImported + " imported, duration "// NOPMD
        + (System.currentTimeMillis() - startTime));
    filePersistence.close();
  }
View Full Code Here

    builder.setProxyMode(true);
    builder.setRemoveFiles(true);
    builder.setFileCache(16 * 1024/* pageSize */, 8 * 1024/* maxPage */);
    builder.setGarbageManagement(false);
    builder.setCrashSafeMode(false);
    final IFilePersistence filePersistence = builder.build();

    filePersistence.autoSaveSetup(0);// 0 is important for the test
    filePersistence.setAutoSaveEnabled(true);
    filePersistence.maintainInMemorySetup(500);
    filePersistence.setMaintainedInMemoryEnabled(true);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    session.open();
    session.setObject("key1", new Object());
    session.save();
    session.setObject("key2", new Object());
    session.save();
    session.close();
    filePersistence.close();
  }
View Full Code Here

      FilePersistenceInvalidClassException,
      FilePersistenceNotSerializableException,
      FilePersistenceClassNotFoundException,
      FilePersistenceDataCorruptedException,
      FilePersistenceTooBigForSerializationException, RBTException {
    final IFilePersistence filePersistence = createFilePersistence();
    // filePersistence.setAutoSaveEventListener(this);
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instanceFactory = session.getInstanceFactory();

    session.open();

    try {
      TypeA typeA = TypeA.newInstance(instanceFactory);
      TypeB typeB = TypeB.newInstance(instanceFactory);
      typeA.setTypeB(typeB);
      typeB.setTypeA(typeA);
      session.setObject("key", typeA);

      for (int count = 0; count < 1000; count++) {
        typeA = (TypeA) session.getObject("key");
        typeB = typeA.getTypeB();
        if (typeB.getTypeA() != typeA) {
          throw new Exception("not same object count=" + count);
        }
        typeA = null;// NOPMD
        typeB = null;// NOPMD
      }

    } catch (Exception e) {
      e.printStackTrace();// NOPMD
    } finally {
      session.close();
    }

    filePersistence.xmlExport("runtime", "runtime/temp", false);
    filePersistence.close();
  }
View Full Code Here

      FilePersistenceNotSerializableException,
      FilePersistenceClassNotFoundException,
      FilePersistenceDataCorruptedException, ProxyException,
      FilePersistenceTooBigForSerializationException {

    IFilePersistence filePersistence = createFilePersistence();
    IDataAccessSession dataAccessSession = filePersistence
        .createDataAccessSession();

    dataAccessSession.open();
    final Holder writeByteHolder = new Holder();
    final Holder writeShortHolder = new Holder();
    final Holder writeIntegerHolder = new Holder();
    final Holder writeLongHolder = new Holder();
    final Holder writeFloatHolder = new Holder();
    final Holder writeDoubleHolder = new Holder();
    final Holder writeBooleanHolder = new Holder();
    final Holder writeCharacterHolder = new Holder();
    /*
     * use of new Integer(0) is important for the test, even if good
     * practice said to use Integer.valueOf. For this test we need to manage
     * two instance of integer with the same value.
     */
    writeByteHolder.setObject1(new Byte((byte) 0));// NOPMD must be new for
    // the test
    writeByteHolder.setObject2(new Byte((byte) 0));// NOPMD must be new for
    // the test
    writeShortHolder.setObject1(new Short((short) 0));// NOPMD must be new
    // for the test
    writeShortHolder.setObject2(new Short((short) 0));// NOPMD must be new
    // for the test
    writeIntegerHolder.setObject1(new Integer(0));// NOPMD must be new for
    // the test
    writeIntegerHolder.setObject2(new Integer(0));// NOPMD must be new for
    // the test
    writeLongHolder.setObject1(new Long((short) 0));// NOPMD must be new for
    // the test
    writeLongHolder.setObject2(new Long((short) 0));// NOPMD must be new for
    // the test
    writeFloatHolder.setObject1(new Float(0.0));// NOPMD must be new for the
    // test
    writeFloatHolder.setObject2(new Float(0.0));// NOPMD must be new for the
    // test
    writeDoubleHolder.setObject1(new Double(0.0));// NOPMD must be new for
    // the test
    writeDoubleHolder.setObject2(new Double(0.0));// NOPMD must be new for
    // the test
    writeBooleanHolder.setObject1(new Boolean(false));// NOPMD must be new
    // for the test
    writeBooleanHolder.setObject2(new Boolean(false));// NOPMD must be new
    // for the test
    writeCharacterHolder.setObject1(new Character('a'));// NOPMD must be new
    // for the test
    writeCharacterHolder.setObject2(new Character('a'));// NOPMD must be new
    // for the test

    dataAccessSession.setObject("byte", writeByteHolder);
    dataAccessSession.setObject("short", writeShortHolder);
    dataAccessSession.setObject("integer", writeIntegerHolder);
    dataAccessSession.setObject("long", writeLongHolder);
    dataAccessSession.setObject("float", writeFloatHolder);
    dataAccessSession.setObject("double", writeDoubleHolder);
    dataAccessSession.setObject("boolean", writeBooleanHolder);
    dataAccessSession.setObject("character", writeCharacterHolder);

    dataAccessSession.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
    filePersistence.close();

    filePersistence = createFilePersistence();
    dataAccessSession = filePersistence.createDataAccessSession();

    dataAccessSession.open();
    final Holder readByteHolder = (Holder) dataAccessSession
        .getObject("byte");
    final Holder readShortHolder = (Holder) dataAccessSession
        .getObject("short");
    final Holder readIntegerHolder = (Holder) dataAccessSession
        .getObject("integer");
    final Holder readLongHolder = (Holder) dataAccessSession
        .getObject("long");
    final Holder readFloatHolder = (Holder) dataAccessSession
        .getObject("float");
    final Holder readDoubleHolder = (Holder) dataAccessSession
        .getObject("double");
    final Holder readBooleanHolder = (Holder) dataAccessSession
        .getObject("boolean");
    final Holder readCharacterHolder = (Holder) dataAccessSession
        .getObject("character");

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readByteHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeByteHolder, readByteHolder);
    Object object1 = readByteHolder.getObject1();
    assertEquals(BAD_VALUE, Byte.valueOf((byte) 0), object1);
    Object object2 = readByteHolder.getObject2();
    assertEquals(BAD_VALUE, Byte.valueOf((byte) 0), object2);

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readShortHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeShortHolder, readShortHolder);
    object1 = readShortHolder.getObject1();
    assertEquals(BAD_VALUE, Short.valueOf((short) 0), object1);// NOPMD
    object2 = readShortHolder.getObject2();
    assertEquals(BAD_VALUE, Short.valueOf((short) 0), object2);// NOPMD

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readIntegerHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeIntegerHolder, readIntegerHolder);
    object1 = readIntegerHolder.getObject1();
    assertEquals(BAD_VALUE, Integer.valueOf(0), object1);
    object2 = readIntegerHolder.getObject2();
    assertEquals(BAD_VALUE, Integer.valueOf(0), object2);

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readLongHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeLongHolder, readLongHolder);
    object1 = readLongHolder.getObject1();
    assertEquals(BAD_VALUE, Long.valueOf(0), object1);
    object2 = readLongHolder.getObject2();
    assertEquals(BAD_VALUE, Long.valueOf(0), object2);

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readFloatHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeFloatHolder, readFloatHolder);
    object1 = readFloatHolder.getObject1();
    assertEquals(BAD_VALUE, Float.valueOf((float) 0.0), object1);
    object2 = readFloatHolder.getObject2();
    assertEquals(BAD_VALUE, Float.valueOf((float) 0.0), object2);

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readDoubleHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeDoubleHolder, readDoubleHolder);
    object1 = readDoubleHolder.getObject1();
    assertEquals(BAD_VALUE, Double.valueOf(0.0), object1);
    object2 = readDoubleHolder.getObject2();
    assertEquals(BAD_VALUE, Double.valueOf(0.0), object2);

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readBooleanHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeBooleanHolder, readBooleanHolder);
    object1 = readBooleanHolder.getObject1();
    assertEquals(BAD_VALUE, Boolean.FALSE, object1);
    object2 = readBooleanHolder.getObject2();
    assertEquals(BAD_VALUE, Boolean.FALSE, object2);

    assertTrue(MUST_BE_A_PROXY,
        ProxyManager2.isProxyOrEnhanced(readCharacterHolder));
    assertNotSame(MUST_NOT_BE_SAME, writeCharacterHolder,
        readCharacterHolder);
    object1 = readCharacterHolder.getObject1();
    assertEquals(BAD_VALUE, Character.valueOf('a'), object1);
    object2 = readCharacterHolder.getObject2();
    assertEquals(BAD_VALUE, Character.valueOf('a'), object2);

    dataAccessSession.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
    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();
    final IExclusiveDataAccessSession session = filePersistence
        .createExclusiveDataAccessSession();
    final IInstanceFactory instancefactory = session.getInstanceFactory();
    session.open();
    final PHashMap map = PHashMap.newInstance(instancefactory);
    assertNotNull("must succeed create an iterator", map.keySet()
        .iterator());
    session.close();
    filePersistence.close();
  }
View Full Code Here

      FilePersistenceNotSerializableException,
      FilePersistenceClassNotFoundException,
      FilePersistenceDataCorruptedException,
      FilePersistenceTooBigForSerializationException {

    IFilePersistence filePersistence = createFilePersistence(true);
    IDataAccessSession session = filePersistence.createDataAccessSession();
    session.open();
    Item item = new Item(0, "value");
    session.setObject("key", item);
    session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
    filePersistence.close();

    filePersistence = createFilePersistence(false);
    session = filePersistence.createDataAccessSession();
    session.open();
    item = (Item) session.getObject("key");
    assertEquals("bad state", 0, item.getIdentifier());
    assertEquals("bad state", "value", item.getValue());
    session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
    filePersistence.close();
  }
View Full Code Here

    builder.setPathName(path.getPath());
    builder.setProxyMode(true);
    builder.setRemoveFiles(true);
    builder.setGarbageManagement(false);
    builder.setCrashSafeMode(false);
    final IFilePersistence filePersistence = builder.build();

    // filePersistence.setSubstitutionOfJavaUtilCollection(true);
    filePersistence.storedImmutableEnum(PERSISTED_ENUM);
    // filePersistence.setNoLazyLoad(TextAttribute.class);

    final IDataAccessSession session = filePersistence
        .createDataAccessSession();
    session.open();
    session.setObject(EMISSION_STRING, new Object());
    session.close(EnumFilePersistenceCloseAction.SAVE);

    session.open();
    session.removeObject(EMISSION_STRING);
    session.close(EnumFilePersistenceCloseAction.SAVE);

    session.open();
    session.setObject(EMISSION_STRING, new Object());
    session.close(EnumFilePersistenceCloseAction.SAVE);

    session.open();
    session.close(EnumFilePersistenceCloseAction.SAVE);
    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.