Permalink
Browse files

removing legacy index API references

  • Loading branch information...
1 parent 7491ee7 commit 789b7dfe9dadbe1b89c02f063c7d9fb0d7f12df3 @peterneubauer peterneubauer committed Feb 4, 2011
@@ -18,6 +18,8 @@
*/
package org.neo4j.examples;
+import java.io.File;
+
import org.neo4j.graphalgo.GraphAlgoFactory;
import org.neo4j.graphalgo.PathFinder;
import org.neo4j.graphdb.Direction;
@@ -27,27 +29,24 @@
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
-import org.neo4j.index.IndexService;
-import org.neo4j.index.lucene.LuceneIndexService;
+import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.kernel.Traversal;
-import java.io.File;
-
public class CalculateShortestPath
{
private static final String DB_PATH = "neo4j-shortest-path";
private static final String NAME_KEY = "name";
private static RelationshipType KNOWS = DynamicRelationshipType.withName( "KNOWS" );
private static GraphDatabaseService graphDb;
- private static IndexService indexService;
+ private static Index<Node> indexService;
public static void main( final String[] args )
{
deleteFileOrDirectory( new File( DB_PATH ) );
graphDb = new EmbeddedGraphDatabase( DB_PATH );
- indexService = new LuceneIndexService( graphDb );
+ indexService = graphDb.index().forNodes( "nodes" );
registerShutdownHook();
Transaction tx = graphDb.beginTx();
try
@@ -84,7 +83,6 @@ public static void main( final String[] args )
// END SNIPPET: shortestPathUsage
System.out.println( "Shutting down database ..." );
- indexService.shutdown();
graphDb.shutdown();
}
@@ -100,12 +98,12 @@ private static void createChain( String... names )
private static Node getOrCreateNode( String name )
{
- Node node = indexService.getSingleNode( NAME_KEY, name );
+ Node node = indexService.get( NAME_KEY, name ).getSingle();
if ( node == null )
{
node = graphDb.createNode();
node.setProperty( NAME_KEY, name );
- indexService.index( node, NAME_KEY, name );
+ indexService.add( node, NAME_KEY, name );
}
return node;
}
@@ -120,7 +118,6 @@ private static void registerShutdownHook()
@Override
public void run()
{
- indexService.shutdown();
graphDb.shutdown();
}
} );
@@ -24,16 +24,15 @@
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
-import org.neo4j.index.IndexService;
-import org.neo4j.index.lucene.LuceneIndexService;
+import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.EmbeddedGraphDatabase;
public class EmbeddedNeo4jWithIndexing
{
private static final String DB_PATH = "neo4j-store";
private static final String USERNAME_KEY = "username";
private static GraphDatabaseService graphDb;
- private static IndexService indexService;
+ private static Index<Node> indexService;
// START SNIPPET: createRelTypes
private static enum RelTypes implements RelationshipType
@@ -47,7 +46,7 @@ public static void main( final String[] args )
{
// START SNIPPET: startDb
graphDb = new EmbeddedGraphDatabase( DB_PATH );
- indexService = new LuceneIndexService( graphDb );
+ indexService = graphDb.index().forNodes( "nodes" );
registerShutdownHook();
// END SNIPPET: startDb
@@ -73,8 +72,8 @@ public static void main( final String[] args )
// Find a user through the search index
// START SNIPPET: findUser
int idToFind = 45;
- Node foundUser = indexService.getSingleNode( USERNAME_KEY,
- idToUserName( idToFind ) );
+ Node foundUser = indexService.get( USERNAME_KEY,
+ idToUserName( idToFind ) ).getSingle();
System.out.println( "The username of user " + idToFind + " is "
+ foundUser.getProperty( USERNAME_KEY ) );
// END SNIPPET: findUser
@@ -84,7 +83,7 @@ public static void main( final String[] args )
RelTypes.USER, Direction.OUTGOING ) )
{
Node user = relationship.getEndNode();
- indexService.removeIndex( user, USERNAME_KEY,
+ indexService.remove( user, USERNAME_KEY,
user.getProperty( USERNAME_KEY ) );
user.delete();
relationship.delete();
@@ -104,7 +103,6 @@ public static void main( final String[] args )
private static void shutdown()
{
- indexService.shutdown();
graphDb.shutdown();
}
@@ -118,7 +116,7 @@ private static Node createAndIndexUser( final String username )
{
Node node = graphDb.createNode();
node.setProperty( USERNAME_KEY, username );
- indexService.index( node, USERNAME_KEY, username );
+ indexService.add( node, USERNAME_KEY, username );
return node;
}
// END SNIPPET: helperMethods
@@ -25,7 +25,6 @@
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.index.Index;
-import org.neo4j.index.IndexService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
/**
@@ -18,20 +18,24 @@
*/
package org.neo4j.examples.socnet;
-import org.neo4j.graphdb.*;
-import org.neo4j.helpers.collection.IterableWrapper;
-import org.neo4j.index.IndexService;
-
import static org.neo4j.examples.socnet.RelTypes.A_PERSON;
import static org.neo4j.examples.socnet.RelTypes.REF_PERSONS;
+import org.neo4j.graphdb.Direction;
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Relationship;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.graphdb.index.Index;
+import org.neo4j.helpers.collection.IterableWrapper;
+
public class PersonRepository
{
private final GraphDatabaseService graphDb;
- private final IndexService index;
+ private final Index<Node> index;
private final Node personRefNode;
- public PersonRepository( GraphDatabaseService graphDb, IndexService index )
+ public PersonRepository( GraphDatabaseService graphDb, Index<Node> index )
{
this.graphDb = graphDb;
this.index = index;
@@ -75,14 +79,14 @@ public Person createPerson( String name ) throws Exception
Node newPersonNode = graphDb.createNode();
personRefNode.createRelationshipTo( newPersonNode, A_PERSON );
// lock now taken, we can check if already exist in index
- Node alreadyExist = index.getSingleNode( Person.NAME, name );
+ Node alreadyExist = index.get( Person.NAME, name ).getSingle();
if ( alreadyExist != null )
{
tx.failure();
throw new Exception( "Person with this name already exists " );
}
newPersonNode.setProperty( Person.NAME, name );
- index.index( newPersonNode, Person.NAME, name );
+ index.add( newPersonNode, Person.NAME, name );
tx.success();
return new Person( newPersonNode );
}
@@ -94,7 +98,7 @@ public Person createPerson( String name ) throws Exception
public Person getPersonByName( String name )
{
- Node personNode = index.getSingleNode( Person.NAME, name );
+ Node personNode = index.get( Person.NAME, name ).getSingle();
if ( personNode == null )
{
throw new IllegalArgumentException( "Person[" + name
@@ -109,7 +113,7 @@ public void deletePerson( Person person )
try
{
Node personNode = person.getUnderlyingNode();
- index.removeIndex( personNode, Person.NAME, person.getName() );
+ index.remove( personNode, Person.NAME, person.getName() );
for ( Person friend : person.getFriends() )
{
person.removeFriend( friend );
@@ -34,8 +34,7 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.TraversalPosition;
import org.neo4j.graphdb.Traverser;
-import org.neo4j.index.IndexService;
-import org.neo4j.index.lucene.LuceneIndexService;
+import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.EmbeddedGraphDatabase;
public class RolesOldTest
@@ -53,22 +52,21 @@
private static final String ROLES_DB = "target/roles-db";
private static GraphDatabaseService graphDb;
- private static IndexService index;
+ private static Index<Node> index;
@BeforeClass
public static void setUp()
{
deleteFileOrDirectory( new File( ROLES_DB ) );
graphDb = new EmbeddedGraphDatabase( ROLES_DB );
- index = new LuceneIndexService( graphDb );
+ index = graphDb.index().forNodes( "nodes" );
registerShutdownHook();
createNodespace();
}
@AfterClass
public static void tearDown()
{
- index.shutdown();
graphDb.shutdown();
}
@@ -144,7 +142,7 @@ private static Node createNode( final String name,
{
Node node = graphDb.createNode();
node.setProperty( NAME, name );
- index.index( node, category, name );
+ index.add( node, category, name );
for ( Node parent : containedIn )
{
node.createRelationshipTo( parent, relType );
@@ -164,7 +162,7 @@ private static Node getGroupByName( String name )
private static Node getNodeByName( final String category, final String name )
{
- return index.getSingleNode( category, name );
+ return index.get( category, name ).getSingle();
}
@Test
@@ -298,7 +296,6 @@ private static void registerShutdownHook()
@Override
public void run()
{
- index.shutdown();
graphDb.shutdown();
}
} );
@@ -30,10 +30,9 @@
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
+import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.helpers.Predicate;
-import org.neo4j.index.IndexService;
-import org.neo4j.index.lucene.LuceneIndexService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.kernel.Traversal;
@@ -52,22 +51,21 @@
private static final String ROLES_DB = "target/roles-db";
private static GraphDatabaseService graphDb;
- private static IndexService index;
+ private static Index<Node> index;
@BeforeClass
public static void setUp()
{
deleteFileOrDirectory( new File( ROLES_DB ) );
graphDb = new EmbeddedGraphDatabase( ROLES_DB );
- index = new LuceneIndexService( graphDb );
+ index = graphDb.index().forNodes( "nodes" );
registerShutdownHook();
createNodespace();
}
@AfterClass
public static void tearDown()
{
- index.shutdown();
graphDb.shutdown();
}
@@ -143,7 +141,7 @@ private static Node createNode( final String name,
{
Node node = graphDb.createNode();
node.setProperty( NAME, name );
- index.index( node, category, name );
+ index.add( node, category, name );
for ( Node parent : containedIn )
{
node.createRelationshipTo( parent, relType );
@@ -163,7 +161,7 @@ private static Node getGroupByName( String name )
private static Node getNodeByName( final String category, final String name )
{
- return index.getSingleNode( category, name );
+ return index.get( category, name ).getSingle();
}
@Test
@@ -298,7 +296,6 @@ private static void registerShutdownHook()
@Override
public void run()
{
- index.shutdown();
graphDb.shutdown();
}
} );
@@ -18,38 +18,38 @@
*/
package org.neo4j.examples.socnet;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.collection.IsCollectionContaining.hasItems;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Random;
+
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.index.Index;
import org.neo4j.helpers.collection.IteratorUtil;
-import org.neo4j.index.IndexService;
-import org.neo4j.index.lucene.LuceneIndexService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Random;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.collection.IsCollectionContaining.hasItems;
-import static org.junit.Assert.assertThat;
-
public class SocnetTest
{
private static final Random r = new Random( System.currentTimeMillis() );
private GraphDatabaseService graphDb;
- private IndexService index;
+ private Index<Node> index;
private PersonRepository personRepository;
private int nrOfPersons;
@Before
public void setup() throws Exception
{
graphDb = new EmbeddedGraphDatabase( "target/socnetdb" );
- index = new LuceneIndexService( graphDb );
+ index = graphDb.index().forNodes( "nodes" );
personRepository = new PersonRepository( graphDb, index );
deleteSocialGraph();
@@ -67,7 +67,6 @@ public void teardown()
}
finally
{
- index.shutdown();
graphDb.shutdown();
}
}

0 comments on commit 789b7df

Please sign in to comment.