private void populate(ObjectContainer container) { for (int i = 0; i < 10; i++) { container.store(new Item("delme")); } CrashData one = new CrashData(null, "one"); CrashData two = new CrashData(one, "two"); CrashData three = new CrashData(one, "three"); container.store(one); container.store(two); container.store(three); container.commit(); ObjectSet objectSet = container.query(Item.class); while (objectSet.hasNext()) { container.delete(objectSet.next()); } }
private void start() { ObjectContainer oc = com.db4o.cs.Db4oClientServer.openClient( Db4oNetworking.HOST, _port, Db4oNetworking.USERNAME, Db4oNetworking.PASSWORD); oc.store(new Item(0)); oc.commit(); print("[0]"); print(CLIENT_STARTED_OK); for (int i = 1; i < ITEM_COUNT; i++) { oc.store(new Item(i)); oc.commit(); print("[" + i + "]"); } oc.close(); print(CLIENT_COMPLETED_OK); }
public static void main(String[] args) { new File(FILE).delete(); ObjectContainer oc = Db4o.openFile(FILE); for (int i = 0; i < COUNT; i++) { oc.store(new AddJustOneObject()); } oc.close(); oc = Db4o.openFile(FILE); long start = System.currentTimeMillis(); oc.store(new AddJustOneObject()); oc.commit(); long stop = System.currentTimeMillis(); oc.close(); long duration = stop - start; System.out.println("Add one to " + COUNT + " and commit: " + duration + "ms"); }
public void test() { ObjectContainer con = Test.objectContainer(); Test.deleteAllInstances(this); IsStored isStored = new IsStored(); isStored.myString = "isStored"; con.store(isStored); Test.ensure(con.ext().isStored(isStored)); Test.ensure(Test.occurrences(this) == 1); con.delete(isStored); Test.ensure(!con.ext().isStored(isStored)); Test.ensure(Test.occurrences(this) == 0); con.commit(); if (con.ext().isStored(isStored)) { // this will fail in CS due to locally cached references if (!Test.clientServer) { Test.error(); } } Test.ensure(Test.occurrences(this) == 0); con.store(isStored); Test.ensure(con.ext().isStored(isStored)); Test.ensure(Test.occurrences(this) == 1); con.commit(); Test.ensure(con.ext().isStored(isStored)); Test.ensure(Test.occurrences(this) == 1); con.delete(isStored); Test.ensure(!con.ext().isStored(isStored)); Test.ensure(Test.occurrences(this) == 0); con.commit(); if (con.ext().isStored(isStored)) { // this will fail in CS due to locally cached references if (!Test.clientServer) { Test.error(); } } Test.ensure(Test.occurrences(this) == 0); }
/** @sharpen.remove */ public void test() throws IOException { boolean cached = USE_CACHE.value().booleanValue(); boolean useLogFile = USE_LOGFILE.value().booleanValue(); boolean writeTrash = WRITE_TRASH.value().booleanValue(); if (cached && writeTrash) { System.err.println( "DISABLED CrashSimulatingTestCase: combination of write trash and cache"); // The cache may touch more bytes than the ones we modified. // We should be safe even if we don't get this test to pass. return; } if (useLogFile && writeTrash) { System.err.println( "DISABLED CrashSimulatingTestCase: combination of write trash and use log file"); // The log file is not a public API yet anyway. // It's only needed for the PointerBasedIdSystem // With the new BTreeIdSystem it's not likely to become important // so we can safely ignore the failing write trash case. return; } if (Platform4.needsLockFileThread()) { System.out.println( "CrashSimulatingTestCase is ignored on platforms with lock file thread."); return; } String path = Path4.combine(Path4.getTempPath(), "crashSimulate"); String fileName = Path4.combine(path, "cs"); File4.delete(fileName); File4.mkdirs(path); createFile(baseConfig(useLogFile), fileName); CrashSimulatingStorage crashSimulatingStorage = new CrashSimulatingStorage(new FileStorage(), fileName); Storage storage = cached ? (Storage) new CachingStorage(crashSimulatingStorage) : crashSimulatingStorage; Configuration recordConfig = baseConfig(useLogFile); recordConfig.storage(storage); ObjectContainer oc = Db4o.openFile(recordConfig, fileName); ObjectSet objectSet = oc.queryByExample(new CrashData(null, "three")); oc.delete(objectSet.next()); oc.store(new CrashData(null, "four")); oc.store(new CrashData(null, "five")); oc.store(new CrashData(null, "six")); oc.store(new CrashData(null, "seven")); oc.store(new CrashData(null, "eight")); oc.store(new CrashData(null, "nine")); oc.store(new CrashData(null, "10")); oc.store(new CrashData(null, "11")); oc.store(new CrashData(null, "12")); oc.store(new CrashData(null, "13")); oc.store(new CrashData(null, "14")); oc.commit(); Query q = oc.query(); q.constrain(CrashData.class); objectSet = q.execute(); while (objectSet.hasNext()) { CrashData cData = (CrashData) objectSet.next(); if (!(cData._name.equals("10") || cData._name.equals("13"))) { oc.delete(cData); } } oc.commit(); oc.close(); int count = crashSimulatingStorage._batch.writeVersions(fileName, writeTrash); checkFiles(useLogFile, fileName, "R", crashSimulatingStorage._batch.numSyncs()); checkFiles(useLogFile, fileName, "W", count); if (VERBOSE) { System.out.println("Total versions: " + count); } }