@Override public void start() { DependencyResolver resolver = database.getGraph().getDependencyResolver(); this.executionEngine = (ExecutionEngine) resolver.resolveDependency( QueryExecutionEngine.class ); this.service = resolver.resolveDependency( GraphDatabaseQueryService.class ); this.contextFactory = Neo4jTransactionalContextFactory.create( this.service, locker ); }
@Override public Result execute( String query, Map<String,Object> parameters ) throws QueryExecutionException { // ensure we have a tx and create a context (the tx is gonna get closed by the Cypher result) InternalTransaction transaction = beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); return execute( transaction, query, ValueUtils.asParameterMapValue( parameters ) ); }
private void shutdownDatabase() { if ( database != null ) { log.log( "Shutting down '%s' database.", database.databaseLayout().getDatabaseName() ); database.shutdown(); } }
public Index<Relationship> createRelationshipIndex( String named ) { try ( Transaction transaction = database.getGraph().beginTransaction( implicit, AUTH_DISABLED ) ) { RelationshipIndex relationshipIndex = database.getGraph().index() .forRelationships( named ); transaction.success(); return relationshipIndex; } }
public long createNode( Label... labels ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Node node = database.getGraph().createNode( labels ); tx.success(); return node.getId(); } }
private long createNode( Map<String, Object> properties ) { long nodeId; try ( Transaction tx = database.getGraph().beginTx() ) { Node node = database.getGraph().createNode( LABEL ); for ( Map.Entry<String, Object> entry : properties.entrySet() ) { node.setProperty( entry.getKey(), entry.getValue() ); } nodeId = node.getId(); tx.success(); } return nodeId; }
@Test public void shouldBeAbleToRemoveNodeProperty() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); long nodeId = createNode( properties ); actions.removeNodeProperty( nodeId, "foo" ); try ( Transaction tx = database.getGraph().beginTx() ) { Node node = database.getGraph().getNodeById( nodeId ); assertEquals( 15, node.getProperty( "number" ) ); assertFalse( node.hasProperty( "foo" ) ); tx.success(); } }
public long createRelationship( String type, long startNodeId, long endNodeId ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Node startNode = database.getGraph().getNodeById( startNodeId ); Node endNode = database.getGraph().getNodeById( endNodeId ); Relationship relationship = startNode.createRelationshipTo( endNode, RelationshipType.withName( type ) ); tx.success(); return relationship.getId(); } }
public long createRelationship( String type ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Node startNode = database.getGraph().createNode(); Node endNode = database.getGraph().createNode(); Relationship relationship = startNode.createRelationshipTo( endNode, RelationshipType.withName( type ) ); tx.success(); return relationship.getId(); } }
public void setNodeProperties( long nodeId, Map<String, Object> properties ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { Node node = database.getGraph().getNodeById( nodeId ); for ( Map.Entry<String, Object> propertyEntry : properties.entrySet() ) { node.setProperty( propertyEntry.getKey(), propertyEntry.getValue() ); } tx.success(); } }
@Before public void setup() { db = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase(); try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.createRelationshipTo( db.createNode(), withName( "a" ) ); node.createRelationshipTo( db.createNode(), withName( "b" ) ); relId = node.createRelationshipTo( db.createNode(), withName( "c" ) ).getId(); tx.success(); } }
public void deleteNode( long id ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.write() ) ) { Node node = database.getGraph().getNodeById( id ); node.delete(); tx.success(); } }
/** * Lookup list of properties being autoindexed. */ @Test public void listAutoIndexingPropertiesForNodes() throws JsonParseException { int initialPropertiesSize = getAutoIndexedPropertiesForType( "node" ).size(); String propName = "some-property" + System.currentTimeMillis(); GraphDatabaseFacade db = server().getDatabase().getGraph(); try ( Transaction tx = db.beginTx() ) { db.index().getNodeAutoIndexer().startAutoIndexingProperty( propName ); tx.success(); } List<String> properties = getAutoIndexedPropertiesForType( "node" ); assertEquals( initialPropertiesSize + 1, properties.size() ); assertThat( properties, hasItem( propName ) ); }
public void addLabelToNode( long node, String labelName ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.writeToken() ) ) { database.getGraph().getNodeById( node ).addLabel( label( labelName ) ); tx.success(); } }
public Map<String, Object> getNodeProperties( long nodeId ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.read() ) ) { Node node = database.getGraph().getNodeById( nodeId ); Map<String, Object> allProperties = node.getAllProperties(); tx.success(); return allProperties; } }
@Test public void shouldBeAbleToRemoveNodeProperties() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); long nodeId = createNode( properties ); actions.removeAllNodeProperties( nodeId ); try ( Transaction tx = database.getGraph().beginTx() ) { Node node = database.getGraph().getNodeById( nodeId ); assertFalse( node.getPropertyKeys().iterator().hasNext() ); tx.success(); } }
public Map<String, Object> getRelationshipProperties( long relationshipId ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.read() ) ) { Relationship relationship = database.getGraph().getRelationshipById( relationshipId ); Map<String, Object> allProperties = relationship.getAllProperties(); tx.success(); return allProperties; } }
public IndexDefinition createSchemaIndex( String labelName, String propertyKey ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AUTH_DISABLED ) ) { IndexDefinition index = database.getGraph().schema().indexFor( label( labelName ) ).on( propertyKey ).create(); tx.success(); return index; } }
private void resolveMonitor( Node node ) { if ( dataMonitor == null ) { GraphDatabaseService service = node.getGraphDatabase(); if ( service instanceof GraphDatabaseFacade ) { Monitors monitors = ((GraphDatabaseFacade) service).getDependencyResolver().resolveDependency( Monitors.class ); dataMonitor = monitors.newMonitor( DataMonitor.class ); } } }