public void setUp(short pageSize, IndexFactory<Long, Integer> indexType) throws IOException { File path = File.createTempFile("test-mixed", ".tmp", new File("test")); path.delete(); System.out.println("file: " + path); m_pageSize = pageSize; m_dataSize = (short) (pageSize - (MAGIC.length + Long.SIZE / 8)); m_pageFile = createFileFactory(path, pageSize); m_indexFactory = indexType; // create the index Transaction tx = m_pageFile.tx(); try { Index<Long, Integer> index = m_indexFactory.create(tx); // seed the index with some metadata about the test index.put(-2L, (int) m_pageSize); index.put(-3L, (int) m_dataSize); index.put(-4L, MAGIC.length); } finally { tx.commit(); } m_pageFile.flush(); }
public void addAssignmentToIndex(Assignment assignment) { for (int i = 0; i < assignment.size(); i++) { GdlConstant c = assignment.get(i); if (indices.size() <= i) indices.add(new Index()); Index index = indices.get(i); if (!index.containsKey(c)) index.put(c, new Assignments()); Assignments val = index.get(c); val.add(assignment); } }
private void store(CustomObject c) { Transaction tx = m_pageFile.tx(); try { Index<Long, Integer> idx = m_indexFactory.open(tx); Integer pageNumber = idx.get(c.id); // see if the index contains this object if (pageNumber == null) { pageNumber = tx.alloc(); store(tx, pageNumber, c); idx.put(c.id, pageNumber); } else { store(tx, pageNumber, c); } tx.commit(); } finally { tx.close(); } }
public void testIndexTransactions() { TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph(); if (graph.getFeatures().supportsVertexIndex) { this.stopWatch(); Index<Vertex> index = ((IndexableGraph) graph).createIndex("txIdx", Vertex.class); Vertex v = graph.addVertex(null); Object id = v.getId(); v.setProperty("name", "marko"); index.put("name", "marko", v); vertexCount(graph, 1); v = getOnlyElement( ((IndexableGraph) graph).getIndex("txIdx", Vertex.class).get("name", "marko")); assertEquals(v.getId(), id); assertEquals(v.getProperty("name"), "marko"); graph.stopTransaction(Conclusion.SUCCESS); printPerformance( graph.toString(), 1, "vertex added and retrieved from index in a successful transaction", this.stopWatch()); this.stopWatch(); vertexCount(graph, 1); v = getOnlyElement( ((IndexableGraph) graph).getIndex("txIdx", Vertex.class).get("name", "marko")); assertEquals(v.getId(), id); assertEquals(v.getProperty("name"), "marko"); printPerformance( graph.toString(), 1, "vertex retrieved from index outside successful transaction", this.stopWatch()); this.stopWatch(); v = graph.addVertex(null); v.setProperty("name", "pavel"); index.put("name", "pavel", v); vertexCount(graph, 2); v = getOnlyElement( ((IndexableGraph) graph).getIndex("txIdx", Vertex.class).get("name", "marko")); assertEquals(v.getProperty("name"), "marko"); v = getOnlyElement( ((IndexableGraph) graph).getIndex("txIdx", Vertex.class).get("name", "pavel")); assertEquals(v.getProperty("name"), "pavel"); graph.stopTransaction(Conclusion.FAILURE); printPerformance( graph.toString(), 1, "vertex not added in a failed transaction", this.stopWatch()); this.stopWatch(); vertexCount(graph, 1); assertEquals( count(((IndexableGraph) graph).getIndex("txIdx", Vertex.class).get("name", "pavel")), 0); printPerformance( graph.toString(), 1, "vertex not retrieved in a successful transaction", this.stopWatch()); v = getOnlyElement( ((IndexableGraph) graph).getIndex("txIdx", Vertex.class).get("name", "marko")); assertEquals(v.getProperty("name"), "marko"); } graph.shutdown(); }