Biblioteca Java - Blame information for rev 18

Subversion Repositories:
Rev:
Rev Author Line No. Line
18 mihai 1 package com.linkscreens.graphsin.repository;
2  
3 import java.util.ArrayList;
4 import java.util.concurrent.atomic.AtomicLong;
5  
6 import org.neo4j.graphdb.GraphDatabaseService;
7 import org.neo4j.graphdb.Node;
8 import org.neo4j.graphdb.Relationship;
9 import org.neo4j.graphdb.index.Index;
10 import org.neo4j.graphdb.index.IndexHits;
11  
12 import scala.NotImplementedError;
13  
14 public class AlbumRepository {
15         public static AtomicLong ID_GENERATOR = new AtomicLong(0);
16         private final GraphDatabaseService graphDb;
17     private final Index<Node> index;
18  
19     public AlbumRepository( GraphDatabaseService graphDb, Index<Node> index )
20     {
21         this.graphDb = graphDb;
22         this.index = index;
23     }
24  
25     //temporary fast way to generate a unique id for album
26     private synchronized long generateID(){
27         return  ID_GENERATOR.getAndAdd(1);
28     }
29  
30     public AlbumNode createAlbum( String albumName ) throws Exception
31     {
32         Node newAlbum = graphDb.createNode();
33         String id = "_aid_"+generateID();
34         Node alreadyExist = index.get( AlbumNode.ID, id ).getSingle();
35         if ( alreadyExist != null )
36         {
37             throw new Exception( "Album with this title already exists " );
38         }
39         newAlbum.setProperty( AlbumNode.TITLE, albumName );
40         newAlbum.setProperty( AlbumNode.ID, id );
41         index.add( newAlbum, AlbumNode.ID, id );  
42  
43         return new AlbumNode( newAlbum );
44     }
45  
46     public AlbumNode getAlbumById( String id )
47     {
48         Node albumNode = index.get( AlbumNode.ID, id ).getSingle();
49         if ( albumNode == null )
50         {
51             throw new IllegalArgumentException( "Album[" + id
52                     + "] not found" );
53         }
54         return new AlbumNode( albumNode );
55     }
56  
57     /**
58      * TBD need to be implemented. delete album and all contained media items
59      * @param person
60      */
61     public void deleteAlbum( AlbumNode album )
62     {
63         throw new NotImplementedError("To be implemented");
64     }
65  
66     public Iterable<PersonNode> getAllPersonAlbums(PersonNode p)
67     {
68  
69         throw new NotImplementedError("To be implemented");
70     }
71  
72  
73 }