Search in sources :

Example 1 with TransactionalGraph

use of com.tinkerpop.blueprints.TransactionalGraph in project orientdb by orientechnologies.

the class OrientGraphSpecificTestSuite method testComplexMapProperty.

@Test
public void testComplexMapProperty() throws Exception {
    // complex map properties have problems when unmarshalled from disk to
    // an OTrackedMap
    Graph graph = graphTest.generateGraph("complex-map");
    final HashMap<String, Object> consignee = new HashMap<String, Object>();
    consignee.put("name", "Company 4");
    final ArrayList consigneeAddress = new ArrayList();
    consigneeAddress.add("Lilla Bommen 6");
    consignee.put("address", consigneeAddress);
    consignee.put("zipCode", "41104");
    consignee.put("city", "G\u00f6teborg");
    final HashMap<String, Object> consigneeCountry = new HashMap<String, Object>();
    consigneeCountry.put("name", "Sverige");
    consigneeCountry.put("code", "SV");
    consignee.put("country", consigneeCountry);
    consignee.put("contactName", "Contact Person 4");
    consignee.put("telephone", "0731123456");
    consignee.put("telefax", null);
    consignee.put("mobileTelephone", "072345678");
    consignee.put("email", "test@company4.com");
    consignee.put("hiflexId", null);
    final HashMap<String, Object> delivery = new HashMap<String, Object>();
    delivery.put("name", "Company 5");
    final ArrayList deliveryAddress = new ArrayList();
    deliveryAddress.add("Stora Enens V\u00e4g 38");
    delivery.put("address", deliveryAddress);
    delivery.put("zipCode", "43931");
    delivery.put("city", "Onsala");
    final HashMap<String, Object> deliveryCountry = new HashMap<String, Object>();
    deliveryCountry.put("name", "Sverige");
    deliveryCountry.put("code", "SV");
    delivery.put("country", deliveryCountry);
    delivery.put("contactName", "Contact Person 5");
    delivery.put("telephone", "030060094");
    delivery.put("telefax", null);
    delivery.put("mobileTelephone", null);
    delivery.put("email", "test@company5.com");
    delivery.put("hiflexId", null);
    final HashMap<String, Object> pickup = new HashMap<String, Object>();
    pickup.put("name", "Pickup Company 2");
    final ArrayList pickupAddress = new ArrayList();
    pickupAddress.add("Drottninggatan 1");
    pickup.put("address", pickupAddress);
    pickup.put("zipCode", "41103");
    pickup.put("city", "G\u00f6teborg");
    final HashMap<String, Object> pickupCountry = new HashMap<String, Object>();
    pickupCountry.put("name", "Sverige");
    pickupCountry.put("code", "SV");
    pickup.put("country", pickupCountry);
    pickup.put("contactName", "Contact Person 6");
    pickup.put("telephone", "071234567");
    pickup.put("telefax", null);
    pickup.put("mobileTelephone", null);
    pickup.put("email", "test@pickupcompany2.com");
    pickup.put("hiflexId", null);
    final Map shipping = new HashMap();
    shipping.put("name", "Posten MyPack");
    shipping.put("code", "postenmypack");
    shipping.put("templateName", "POSTENMYPACK");
    shipping.put("rates", new ArrayList());
    final Vertex v = graph.addVertex(null);
    v.setProperty("weight", 20);
    v.setProperty("height", 20);
    v.setProperty("consigneeAddress", consignee);
    v.setProperty("width", 10);
    v.setProperty("sum", 400);
    v.setProperty("shippingMethod", shipping);
    v.setProperty("type", "shipment");
    v.setProperty("depth", 30);
    v.setProperty("estimatedCost", 200);
    v.setProperty("deliveryAddress", delivery);
    v.setProperty("pickupAddress", pickup);
    ((TransactionalGraph) graph).commit();
    // have to shutdown the graph so that the map will read back out as an
    // OTrackedMap. Maps that exist in memory
    // do not show the problem.
    graph.shutdown();
    graph = graphTest.generateGraph("complex-map");
    final Vertex v1 = graph.getVertex(v.getId());
    assertNotNull(v1);
    // check the delivery address. not sure if there should be other
    // assertions here, but the basic issues
    // is that the keys/values in the OTrackedMap appear like this:
    // mobileTelephone=null:null
    final Map d = v1.getProperty("deliveryAddress");
    assertNotNull(d);
    assertTrue(d.containsKey("telefax"));
    graph.shutdown();
    graphTest.dropGraph(((OrientGraphTest) graphTest).getWorkingDirectory() + File.separator + "complex-map");
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) Graph(com.tinkerpop.blueprints.Graph) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) HashMap(java.util.HashMap) Map(java.util.Map) GraphTest(com.tinkerpop.blueprints.impls.GraphTest) Test(org.junit.Test)

Example 2 with TransactionalGraph

use of com.tinkerpop.blueprints.TransactionalGraph in project blueprints by tinkerpop.

the class KeyIndexableGraphHelper method reIndexElements.

/**
 * For those graphs that do no support automatic reindexing of elements when a key is provided for indexing, this method can be used to simulate that behavior.
 * The elements in the graph are iterated and their properties (for the provided keys) are removed and then added.
 * Be sure that the key indices have been created prior to calling this method so that they can pick up the property mutations calls.
 * Finally, if the graph is a TransactionalGraph, then a 1000 mutation buffer is used for each commit.
 *
 * @param graph    the graph containing the provided elements
 * @param elements the elements to index into the key indices
 * @param keys     the keys of the key indices
 * @return the number of element properties that were indexed
 */
public static long reIndexElements(final Graph graph, final Iterable<? extends Element> elements, final Set<String> keys) {
    final boolean isTransactional = graph instanceof TransactionalGraph;
    long counter = 0;
    for (final Element element : elements) {
        for (final String key : keys) {
            final Object value = element.removeProperty(key);
            if (null != value) {
                counter++;
                element.setProperty(key, value);
                if (isTransactional && (counter % 1000 == 0)) {
                    ((TransactionalGraph) graph).commit();
                }
            }
        }
    }
    if (isTransactional) {
        ((TransactionalGraph) graph).commit();
    }
    return counter;
}
Also used : Element(com.tinkerpop.blueprints.Element) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph)

Example 3 with TransactionalGraph

use of com.tinkerpop.blueprints.TransactionalGraph in project blueprints by tinkerpop.

the class SparkseeGraphSpecificTestSuite method testTx.

public void testTx() {
    TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
    ((SparkseeGraph) graph).typeScope.set(true);
    this.stopWatch();
    graph.commit();
    graph.addVertex(null).setProperty("name", "sergio");
    graph.addVertex(null).setProperty("name", "marko");
    assertTrue(graph.getVertices("name", "sergio").iterator().next().getProperty("name").equals("sergio"));
    graph.commit();
    assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
    assertTrue(graph.getVertices("name", "sergio").iterator().next().getProperty("name").equals("sergio"));
    graph.commit();
    assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
    graph.commit();
    assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
    graph.addVertex(null);
    graph.shutdown();
    assertTrue(((SparkseeGraph) graph).getRawSession(false) == null);
    printPerformance(graph.toString(), null, "testTx", this.stopWatch());
    graph.shutdown();
}
Also used : TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph)

Example 4 with TransactionalGraph

use of com.tinkerpop.blueprints.TransactionalGraph in project blueprints by tinkerpop.

the class SparkseeKeyIndexableGraphTestSuite method testUpdateValuesInIndexKeys.

public void testUpdateValuesInIndexKeys() throws Exception {
    KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
    graph.createKeyIndex("name", Vertex.class);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    Vertex v1 = graph.addVertex(null);
    v1.setProperty("name", "marko");
    assertEquals(v1.getProperty("name"), "marko");
    vertexCount(graph, 1);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    v1 = graph.getVertices("name", "marko").iterator().next();
    assertEquals(v1.getProperty("name"), "marko");
    v1.setProperty("name", "marko a. rodriguez");
    assertEquals(v1.getProperty("name"), "marko a. rodriguez");
    vertexCount(graph, 1);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    assertFalse(graph.getVertices("name", "marko").iterator().hasNext());
    v1 = graph.getVertices("name", "marko a. rodriguez").iterator().next();
    assertEquals(v1.getProperty("name"), "marko a. rodriguez");
    vertexCount(graph, 1);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph)

Example 5 with TransactionalGraph

use of com.tinkerpop.blueprints.TransactionalGraph in project frames by tinkerpop.

the class FramedGraphFactory method getConfiguration.

/**
 * Returns a configuration that can be used when constructing a framed graph.
 * @param requiredType The type of graph required after configuration e.g. {@link TransactionalGraph}
 * @param baseGraph The base graph to get a configuration for.
 * @return The configuration.
 */
protected <T extends Graph> FramedGraphConfiguration getConfiguration(Class<T> requiredType, T baseGraph) {
    Graph configuredGraph = baseGraph;
    FramedGraphConfiguration config = getBaseConfig();
    for (Module module : modules) {
        configuredGraph = module.configure(configuredGraph, config);
        if (!(requiredType.isInstance(configuredGraph))) {
            throw new UnsupportedOperationException("Module '" + module.getClass() + "' returned a '" + baseGraph.getClass().getName() + "' but factory requires '" + requiredType.getName() + "'");
        }
    }
    config.setConfiguredGraph(configuredGraph);
    return config;
}
Also used : Graph(com.tinkerpop.blueprints.Graph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) Module(com.tinkerpop.frames.modules.Module)

Aggregations

TransactionalGraph (com.tinkerpop.blueprints.TransactionalGraph)13 Graph (com.tinkerpop.blueprints.Graph)6 Test (org.junit.Test)6 Vertex (com.tinkerpop.blueprints.Vertex)3 FramedGraphConfiguration (com.tinkerpop.frames.FramedGraphConfiguration)2 AbstractModule (com.tinkerpop.frames.modules.AbstractModule)2 ArrayList (java.util.ArrayList)2 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)1 Element (com.tinkerpop.blueprints.Element)1 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)1 GraphTest (com.tinkerpop.blueprints.impls.GraphTest)1 GraphMLReader (com.tinkerpop.blueprints.util.io.graphml.GraphMLReader)1 Module (com.tinkerpop.frames.modules.Module)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ReturnsArgumentAt (org.mockito.internal.stubbing.answers.ReturnsArgumentAt)1 DefaultSailChangedEvent (org.openrdf.sail.helpers.DefaultSailChangedEvent)1