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