use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class AbstractMongoDBVDatabaseTest method putPerson.
/**
* Put a person into the database
* @param name the person's name
* @param age the person's age
* @return the person (after the put)
*/
protected Map<String, Object> putPerson(String name, int age) {
VCollection persons = _master.getCollection("persons");
assertNotNull(persons);
Map<String, Object> peter = new HashMap<String, Object>();
peter.put("name", name);
peter.put("age", age);
persons.insert(peter);
assertNotNull(peter.get("uid"));
return peter;
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class FiveMinutes method main.
/**
* Runs the tutorial
* @param args the program arguments
*/
public static void main(String[] args) {
// 1. Connect to a database
VFactory factory = new MongoDBVFactory();
VDatabase db = factory.createDatabase();
db.connect("mongomvcc-five-minutes-tutorial");
// Checkout the "master" branch
VBranch master = db.checkout(VConstants.MASTER);
// 2. Put something into the index
VCollection persons = master.getCollection("persons");
Map<String, Object> elvis = factory.createDocument();
elvis.put("name", "Elvis");
elvis.put("age", 3);
persons.insert(elvis);
// insert another person
persons.insert(factory.createDocument("name", "Peter"));
// 3. Commit index to the database
long firstCid = master.commit();
// 4. Read documents from the database
VCursor c = persons.find();
for (Map<String, Object> person : c) {
System.out.print("Person { name: " + person.get("name"));
if (person.containsKey("age")) {
System.out.print(", age: " + person.get("age"));
}
System.out.println(" }");
}
Map<String, Object> elvis2 = persons.findOne(factory.createDocument("name", "Elvis"));
if (elvis2 != null) {
System.out.println("Elvis lives!");
}
// 5. Make another commit
persons.insert(factory.createDocument("name", "Max"));
elvis.put("age", 4);
persons.insert(elvis);
master.commit();
// 6. Checkout a previous version
System.out.println("There are " + persons.find().size() + " persons");
Map<String, Object> elvis3 = persons.findOne(factory.createDocument("name", "Elvis"));
System.out.println("Elvis is now " + elvis3.get("age") + " years old");
VBranch oldMaster = db.checkout(firstCid);
VCollection oldPersons = oldMaster.getCollection("persons");
System.out.println("Previously, there were only " + oldPersons.find().size() + " persons");
Map<String, Object> oldElvis = oldPersons.findOne(factory.createDocument("name", "Elvis"));
System.out.println("Last year, Elvis was " + oldElvis.get("age") + " years old");
// 7. Drop the database
db.drop();
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method mvccInsert.
private void mvccInsert(int offset) {
VCollection coll = _master.getCollection("persons");
for (long i = 0; i < DOCUMENTS; ++i) {
Map<String, Object> obj = _factory.createDocument();
obj.put("name", String.valueOf(i));
obj.put("age", i + offset);
obj.put("uid", 1 + i + offset);
coll.insert(obj);
}
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method mvccInsertDelete.
/**
* Inserts a lot of documents using MongoMVCC and then deletes them
*/
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void mvccInsertDelete() {
mvccInsert();
VCollection coll = _master.getCollection("persons");
for (long i = 0; i < DOCUMENTS; ++i) {
coll.delete(1 + i);
}
}
use of de.fhg.igd.mongomvcc.VCollection in project mongomvcc by igd-geo.
the class MongoDBVLargeCollectionTest method largeObjectFloat.
/**
* Tests if large objects with float arrays/streams/buffers can be saved in the database
* @throws Exception if something goes wrong
*/
@Test
public void largeObjectFloat() throws Exception {
VCollection coll = _master.getLargeCollection("images");
float[] test = new float[1024 * 1024];
for (int i = 0; i < test.length; ++i) {
test[i] = (byte) (i & 0xFF);
}
Map<String, Object> obj = new HashMap<String, Object>();
obj.put("name", "Mona Lisa");
obj.put("data", test);
coll.insert(obj);
VCursor vc = coll.find();
assertEquals(1, vc.size());
Map<String, Object> obj2 = vc.iterator().next();
assertEquals("Mona Lisa", obj2.get("name"));
assertArrayEquals(test, (float[]) obj2.get("data"), 0.00001f);
FloatBuffer bb = FloatBuffer.wrap(test);
obj = new HashMap<String, Object>();
obj.put("name", "Mona Lisa");
obj.put("data", bb);
coll.insert(obj);
Map<String, Object> obj4 = coll.findOne(_factory.createDocument("uid", obj.get("uid")));
assertEquals("Mona Lisa", obj4.get("name"));
FloatBuffer bb4 = (FloatBuffer) obj4.get("data");
bb4.rewind();
float[] test4 = new float[bb4.remaining()];
bb4.get(test4);
assertArrayEquals(test, test4, 0.00001f);
}
Aggregations