Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java	(revision 4495)
@@ -65,4 +65,6 @@
     public List<Number> getAllAnnotationIDs();
     
+    public List<Number> sublistOrderedAnnotationIDs(List<Number> annotationIDs, int offset, int limit, String orderedBy, String desc);
+    
        /**
      * unit test is missing
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/DBIntegrityService.java	(revision 4495)
@@ -18,9 +18,11 @@
 package eu.dasish.annotation.backend.dao;
 
-
 import eu.dasish.annotation.schema.Annotation;
 import eu.dasish.annotation.schema.AnnotationBody;
 import eu.dasish.annotation.schema.AnnotationInfoList;
 import eu.dasish.annotation.schema.CachedRepresentationInfo;
+import eu.dasish.annotation.schema.Notebook;
+import eu.dasish.annotation.schema.NotebookInfo;
+import eu.dasish.annotation.schema.NotebookInfoList;
 import eu.dasish.annotation.schema.Permission;
 import eu.dasish.annotation.schema.UserWithPermissionList;
@@ -31,5 +33,4 @@
 import java.io.InputStream;
 import java.sql.SQLException;
-import java.sql.Timestamp;
 import java.util.List;
 import java.util.Map;
@@ -39,224 +40,228 @@
  *
  * @author olhsha
- **/
-
-
-
-
-public interface DBIntegrityService{
-    
+ *
+ */
+public interface DBIntegrityService {
+
     public void setServiceURI(String serviceURI);
-    
-    
+
     /**
      * GETTERS
      */
-    
-    /**
-     * 
+    /**
+     *
      * @param UUID
-     * @return the internal identifier of the annotations with "externalID", or null if no such annotation. 
+     * @return the internal identifier of the annotations with "externalID", or
+     * null if no such annotation.
      */
     Number getAnnotationInternalIdentifier(UUID externalID);
-    
-    /**
-     * 
-     * @param annotationID
-     * @return the externalID of the annotation with "internalID" or null if there is no such annotation.
+
+    /**
+     *
+     * @param annotationID
+     * @return the externalID of the annotation with "internalID" or null if
+     * there is no such annotation.
      */
     UUID getAnnotationExternalIdentifier(Number annotationID);
-    
 
     Number getAnnotationInternalIdentifierFromURI(String uri);
-    
-
-   /**
-    * 
-    * @param word
-    * @param text
-    * @param access
-    * @param namespace
-    * @param after
-    * @param before
-    * @return the list of internal id-s of the annotations such that:
-    * -- Targets' links of which contain "link" (as a substring),
-    * -- serialized bodies of which contain "text",
-    * -- current user has "access" (owner, reader, writer)  to them,
-    * -- namespace ???,
-    * -- owned by "owner",
-    * -- created after time-samp "after and before time-stamp "before".
-    */
+
+    /**
+     *
+     * @param word
+     * @param text
+     * @param access
+     * @param namespace
+     * @param after
+     * @param before
+     * @return the list of internal id-s of the annotations such that: --
+     * Targets' links of which contain "link" (as a substring), -- serialized
+     * bodies of which contain "text", -- current user has "access" (owner,
+     * reader, writer) to them, -- namespace ???, -- owned by "owner", --
+     * created after time-samp "after and before time-stamp "before".
+     */
     List<Number> getFilteredAnnotationIDs(UUID ownerId, String link, String text, Number inloggedUserID, String access, String namespace, String after, String before);
-    
+
     AnnotationInfoList getAllAnnotationInfos();
-    
-    /**
-     * 
-     @param word
-    * @param text
-    * @param access
-    * @param namespace
-    * @param owner
-    * @param after
-    * @param before
-     * @return the list of the annotationInfos of the annotations such that:
-    * -- Targets' links of which contain "link" (as a substring),
-    * -- serialized bodies of which contain "text",
-    * -- current user has "access" (owner, reader, writer)  to them,
-    * -- namespace ???,
-    * -- owned by "owner",
-    * -- created after time-samp "after and before time-stamp "before".
-     */
-    AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID,  String access, String namespace, String after, String before);
-
-    /**
-     * 
-     * @param userID
-     * @return the external identifier of the user "userID", or null if no such user.
+
+    /**
+     *
+     * @param word
+     * @param text
+     * @param access
+     * @param namespace
+     * @param owner
+     * @param after
+     * @param before
+     * @return the list of the annotationInfos of the annotations such that: --
+     * Targets' links of which contain "link" (as a substring), -- serialized
+     * bodies of which contain "text", -- current user has "access" (owner,
+     * reader, writer) to them, -- namespace ???, -- owned by "owner", --
+     * created after time-samp "after and before time-stamp "before".
+     */
+    AnnotationInfoList getFilteredAnnotationInfos(UUID ownerId, String word, String text, Number inloggedUserID, String access, String namespace, String after, String before);
+
+    /**
+     *
+     * @param userID
+     * @return the external identifier of the user "userID", or null if no such
+     * user.
      */
     UUID getUserExternalIdentifier(Number userID);
 
     /**
-     * 
+     *
      * @param externalID
-     * @return the internal identifier of the user with "externalID", or null if there is no such user.
+     * @return the internal identifier of the user with "externalID", or null if
+     * there is no such user.
      */
     Number getUserInternalIdentifier(UUID externalID);
-    
-      /**
-     * 
+
+    /**
+     *
      * @param cachedID
-     * @return the external identifier of the cached representation "cachedID", or null if no such one.
+     * @return the external identifier of the cached representation "cachedID",
+     * or null if no such one.
      */
     UUID getCachedRepresentationExternalIdentifier(Number cachedID);
 
     /**
-     * 
+     *
      * @param externalID
-     * @return the internal identifier of the cachedRepresentation with "externalID", or null if there is no such one.
+     * @return the internal identifier of the cachedRepresentation with
+     * "externalID", or null if there is no such one.
      */
     Number getCachedRepresentationInternalIdentifier(UUID externalID);
-    
-    Number getTargetInternalIdentifier(UUID externalID); 
+
+    Number getTargetInternalIdentifier(UUID externalID);
 
     String getTargetURI(Number targetID);
-   
+
     UUID getTargetExternalIdentifier(Number targetID);
-     
-    String getUserURI(Number userID); 
-    
-    /**
-     * 
+
+    String getUserURI(Number userID);
+
+    /**
+     *
      * @param internalID
-     * @return CachedRepresentationInfo (i.e. "metadata") for cached representation with the internal id "intenalID"
+     * @return CachedRepresentationInfo (i.e. "metadata") for cached
+     * representation with the internal id "intenalID"
      */
     CachedRepresentationInfo getCachedRepresentationInfo(Number internalID);
-    
-    /**
-     * 
-     * @param annotationID
-     * @return the object Annotation generated from the tables "annotation", "annotations_target_Targets", "Target", "annotations_principals_permissions".
-     * @throws SQLException 
+
+    /**
+     *
+     * @param annotationID
+     * @return the object Annotation generated from the tables "annotation",
+     * "annotations_target_Targets", "Target",
+     * "annotations_principals_permissions".
+     * @throws SQLException
      */
     Annotation getAnnotation(Number annotationID);
-    
+
     Number getAnnotationOwner(Number annotationID);
-    
-     /**
-     * 
-     * @param annotationID
-     * @return the object TargetList containing all target Targets of the annotationID
-     * @throws SQLException 
+
+    /**
+     *
+     * @param annotationID
+     * @return the object TargetList containing all target Targets of the
+     * annotationID
+     * @throws SQLException
      */
     ReferenceList getAnnotationTargets(Number annotationID);
-    
-   
-    
-    /**
-     * 
-     * @param annotationID
-     * @return the list of targetURI's for which there is no cached representation
+
+    /**
+     *
+     * @param annotationID
+     * @return the list of targetURI's for which there is no cached
+     * representation
      */
     List<String> getTargetsWithNoCachedRepresentation(Number annotationID);
-    
+
     List<String> getUsersWithNoInfo(Number annotationID);
-    
-    /**
-     * 
-     * @param annotationID
-     * @return the list of TargetID's for which there is no cached representation
+
+    /**
+     *
+     * @param annotationID
+     * @return the list of TargetID's for which there is no cached
+     * representation
      */
     public UserWithPermissionList getPermissionsForAnnotation(Number annotationID);
-    
-     /**
-     * 
+
+    /**
+     *
      * @param TargetID
-     * @return the list of the external version ID-s that refers to the same source (link) as targetID 
+     * @return the list of the external version ID-s that refers to the same
+     * source (link) as targetID
      */
     public ReferenceList getTargetsForTheSameLinkAs(Number targetID);
-    
-    /**
-     * 
+
+    /**
+     *
      * @param cachedID
      * @return BLOB of the cachedID
      */
-    public InputStream getCachedRepresentationBlob(Number cachedID) ;
-    
-    
-    
+    public InputStream getCachedRepresentationBlob(Number cachedID);
+
     public Target getTarget(Number internalID);
-    
-    /**
-     * 
+
+    /**
+     *
      * @param userID
      * @return user with "userID"
      */
     public User getUser(Number userID);
-            
-    /**
-     * 
+
+    /**
+     *
      * @param eMail
      * @return user with e-mail "eMail"
      */
     public User getUserByInfo(String eMail);
-    
-    
+
     public String getUserRemoteID(Number internalID);
-    
+
     public Number getUserInternalIDFromRemoteID(String remoteID);
-  
-    /**
-     * 
-     * @param annotationID
-     * @param userID
-     * @return permission of the userID w.r.t. annotationID, or null if the permission is not given
-     */ 
-    public Permission  getPermission(Number annotationID, Number userID);
-    
-    
+
+    /**
+     *
+     * @param annotationID
+     * @param userID
+     * @return permission of the userID w.r.t. annotationID, or null if the
+     * permission is not given
+     */
+    public Permission getPermission(Number annotationID, Number userID);
+
     public String getTypeOfUserAccount(Number userID);
-    
+
     public boolean canRead(Number userID, Number annotationID);
-            
-    public boolean canWrite(Number userID, Number annotationID);        
-    
+
+    public boolean canWrite(Number userID, Number annotationID);
+
+    /// notebooks ///
+    public NotebookInfoList getNotebooks(Number prinipalID, Permission permission);
+
+    public NotebookInfoList getNotebooksOwnedBy(Number principalID);
+
+    public List<UUID> getPrincipals(Number notebookID, Permission permission);
+
+    public NotebookInfo getNotebookInfo(Number notebookID);
+
+    List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc);
+
     /**
      * UPDATERS
      */
-    
     public boolean updateAccount(UUID userExternalID, String account);
-   
-    
-    /**
-     * 
+
+    /**
+     *
      * @param annotation
      * @return 1 of the annotation if it is updated
      */
     int updateAnnotation(Annotation annotation);
-    
-     
-    
-    /**
-     * 
+
+    /**
+     *
      * @param userID
      * @param annotationBody
@@ -264,130 +269,145 @@
      */
     int updateAnnotationBody(Number internalID, AnnotationBody annotationBody);
-    
-    
-    
-       /**
-     * 
+
+    /**
+     *
      * @param annotationID
      * @param userID
      * @param permission
      * @return # rows updated to the table "annotations_principals_permissions"
-     * Sets the "permission" for the "userID" w.r.t. the annotation with "annotationID".
+     * Sets the "permission" for the "userID" w.r.t. the annotation with
+     * "annotationID".
      */
     public int updateAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
-    
-   /**
-     * 
+
+    /**
+     *
      * @param annotationID
      * @param permissionList
-     * @return # of rows updated or added in the table annotations_principals_permissions
+     * @return # of rows updated or added in the table
+     * annotations_principals_permissions
      */
     public int updatePermissions(Number annotationID, UserWithPermissionList permissionList);
-    
+
     public Number updateUser(User user);
-   
-   /**
-    * ADDERS
-    */
-    /**
-     * 
+
+    /// notebooks ///
+    public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo);
+
+    public boolean addAnnotationToNotebook(Number notebookID, Number annotationID);
+
+    /**
+     * ADDERS
+     */
+    /**
+     *
      * @param targetID
      * @param cachedInfo
      * @param cachedBlob
-     * @return result[0] = # updated rows in the table "Targets_cached_representations" (must be 1 or 0).
-     * result[1] = the internal ID of the added cached (a new one if "cached" was new for the Data Base).
+     * @return result[0] = # updated rows in the table
+     * "Targets_cached_representations" (must be 1 or 0). result[1] = the
+     * internal ID of the added cached (a new one if "cached" was new for the
+     * Data Base).
      */
     Number[] addCachedForTarget(Number targetID, String fragmentDescriptor, CachedRepresentationInfo cachedInfo, InputStream cachedBlob);
-    
- 
-    /**
-     * 
+
+    /**
+     *
      * @param annotationID
      * @param targets
-     * @return map temporaryTargetID |--> TargetExternalID. Its domain is the temporary IDs of all the new Targets. While adding a new Target a new external ID is generated for it and it becomes the value of the map. The TargetIDs which are already present in the DB are not in the domain. If all Targets are old, then the map is empty. 
-     * @throws SQLException 
+     * @return map temporaryTargetID |--> TargetExternalID. Its domain is the
+     * temporary IDs of all the new Targets. While adding a new Target a new
+     * external ID is generated for it and it becomes the value of the map. The
+     * TargetIDs which are already present in the DB are not in the domain. If
+     * all Targets are old, then the map is empty.
+     * @throws SQLException
      */
     Map<String, String> addTargetsForAnnotation(Number annotationID, List<TargetInfo> targets);
 
     /**
-     * 
+     *
      * @param userID
      * @param annotation
-     * @return the internalId of the just added "annotation" (or null if it is not added) by the owner "userID". 
-     * calls "addTargetsForAnnotation" 
-     * @throws SQLException 
+     * @return the internalId of the just added "annotation" (or null if it is
+     * not added) by the owner "userID". calls "addTargetsForAnnotation"
+     * @throws SQLException
      */
     Number addUsersAnnotation(Number ownerID, Annotation annotation);
-    
-    /**
-     * 
+
+    /**
+     *
      * @param user
      * @param remoteID is got from the server
-     * @return the internal Id of the just added "user", or null if it was not added for some reason (already exists)
-     * @throws SQLException 
+     * @return the internal Id of the just added "user", or null if it was not
+     * added for some reason (already exists)
+     * @throws SQLException
      */
     Number addUser(User user, String remoteID);
 
     int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission);
-    
+
+    /// notebooks ////
+    Number createNotebook(Notebook notebook, Number ownerID);
+
+    boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID);
+
     /**
      * DELETERS
      */
-    
-    /**
-     * 
-     * @param userID
-     * @return # of affected rows in the table "principal". 
-     * It is 1 if the userId is found and deleted; 
-     * it is 0 if it is not found or not deleted, e.g. because it is in use in the table "annotationsPreincipalsPermissions"
+    /**
+     *
+     * @param userID
+     * @return # of affected rows in the table "principal". It is 1 if the
+     * userId is found and deleted; it is 0 if it is not found or not deleted,
+     * e.g. because it is in use in the table
+     * "annotationsPreincipalsPermissions"
      */
     public int deleteUser(Number userID);
-    
-     /**
-     * 
-     * @param userID
-     * @return # of affected rows in the table "principal". 
-     * It is 1 if the userId is found and deleted; 
-     * it is 0 if it is not found or not deleted, e.g. because it is in use in the table "annotationsPreincipalsPermissions"
+
+    /**
+     *
+     * @param userID
+     * @return # of affected rows in the table "principal". It is 1 if the
+     * userId is found and deleted; it is 0 if it is not found or not deleted,
+     * e.g. because it is in use in the table
+     * "annotationsPreincipalsPermissions"
      */
     public int deleteUserSafe(Number userID);
-    
-    /**
-     * 
+
+    /**
+     *
      * @param TargetID
      * @param cachedID
-     * @return result[0] = # deleted rows in the table "Targets_cached_representations" (1, or 0).
-     * result[1] = # deleted rows in the table "cached_representation" (should be 0 if the cached representation is in use by some other Target???).
-     */
-    int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID) ;
-
+     * @return result[0] = # deleted rows in the table
+     * "Targets_cached_representations" (1, or 0). result[1] = # deleted rows in
+     * the table "cached_representation" (should be 0 if the cached
+     * representation is in use by some other Target???).
+     */
+    int[] deleteCachedRepresentationOfTarget(Number TargetID, Number cachedID);
+
+    /**
+     *
+     * @param targetID
+     * @return result[0] = # deleted rows in the table
+     * "targets_cached_representations". result[1] = # deleted rows in the table
+     * "cached_representation".
+     *
+     */
+    int[] deleteAllCachedRepresentationsOfTarget(Number versionID);
+
+    /**
+     *
+     * @param annotationID
+     * @return result[0] = # deleted rows in the table "annotation" (1 or 0).
+     * result[1] = # deleted rows in the table
+     * "annotations_principals_permissions". result[2] = # deleted rows in the
+     * table "annotations_target_Targets". result[3] = # deleted rows in the
+     * table "Target".
+     * @throws SQLException
+     */
+    int[] deleteAnnotation(Number annotationID);
     
-    
-
-    
-    /**
-     * 
-     * @param targetID
-     * @return 
-     * result[0] =  # deleted rows in the table "targets_cached_representations".
-     * result[1] = # deleted rows in the table "cached_representation".
-     **/
-    
-    int[] deleteAllCachedRepresentationsOfTarget(Number versionID);
-
-      
-    
-    /**
-     * 
-     * @param annotationID
-     * @return result[0] = # deleted rows in the table "annotation" (1 or 0).
-     * result[1] = # deleted rows in the table "annotations_principals_permissions".
-     * result[2] = # deleted rows in the table "annotations_target_Targets".
-     * result[3] = # deleted rows in the table "Target".
-     * @throws SQLException 
-     */
-    int[] deleteAnnotation(Number annotationID);
-
-    
+    /// notebooks ///
+    boolean deleteNotebook(Number notebookID);
     
 }
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java	(revision 4495)
@@ -23,4 +23,5 @@
 import eu.dasish.annotation.schema.NotebookInfo;
 import java.util.List;
+import java.util.UUID;
 
 /**
@@ -39,12 +40,15 @@
      * GETTERS 
      * 
-     */
-    // Returns a list of notebook Ids for the notebooks for which the given user "userID' has "permission" access.
-    List<Number> getNotebookIDs(Number userID, Permission acessMode);
+  **/
+    
+    Number getOwner(Number notebookID);
+    
+    List<Number> getNotebookIDs(Number principalID, Permission acessMode);
     
     // Returns a list of notebook Ids for the notebooks for which the given user "userID" is the owner.
-    List<Number> getOwnerNotebookIDs(Number userID);
+    List<Number> getNotebookIDsOwnedBy(Number principaID);
     
     public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission);
+    
     
     
@@ -55,5 +59,5 @@
      * @return the notebook info for the notebook with notebookID
      */
-    NotebookInfo getNotebookInfo(Number notebookID);
+    NotebookInfo getNotebookInfoWithoutOwner(Number notebookID);
     
    
@@ -63,16 +67,8 @@
      * @return notebook metadata for the notebook with notebookID
      */
-    Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID);
+    Notebook getNotebookWithoutAnnotationsAndPermissionsAndOwner(Number notebookID);
     
-    //? Which type shul be orderedby? 
-    /**
-     * 
-     * @param maximumAnnotations
-     * @param startannotation
-     * @param orderedBy
-     * @param orederingMode if true then descending, if falset hen ascending
-     * @return 
-     */
-    List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode);
+   
+    List<Number> getAnnotations(Number notebookID);
     
     /**
@@ -90,5 +86,9 @@
      * @return true if updated, false otherwise. Logs the reason if the notebook is not updated.
      */
-    boolean updateNotebookMetadata(Number notebookID);
+    boolean updateNotebookMetadata(Number notebookID, String title, Number ownerID);
+    
+    boolean setOwner(Number notebookID, Number ownerID);
+    
+    boolean updateUserPermissionForNotebook(Number notebookID, Number principalID, Permission permission);
     
      /**
@@ -99,7 +99,9 @@
      */
     
-    Number createNotebook(Notebook notebook);
+    public Number createNotebookWithoutPermissionsAndAnnotations(Notebook notebook, Number ownerID);
     
-    boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID);
+    boolean addAnnotationToNotebook(Number notebookID, Number annotationID);
+    
+    boolean addPermissionToNotebook(Number notebookID, Number userID, Permission permission);
     
     
@@ -107,10 +109,16 @@
     /**
      * 
-     * DELETERS (ADDER)
+     * DELETERS 
      * 
      * 
      */
     
-    boolean deleteannotationFromNotebook(Number notebookID, Number annotationID);
+    boolean deleteAnnotationFromNotebook(Number notebookID, Number annotationID);
+    
+    boolean deleteAllAnnotationsFromNotebook(Number notebookID);
+    
+    boolean deleteNotebookPrincipalPermission(Number notebookID, Number principalID);
+    
+    boolean deleteAllPermissionsForNotebook(Number notebookID);
     
     boolean deleteNotebook(Number notebookID);
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceImlp.java	(revision 4495)
@@ -22,4 +22,5 @@
 import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
 import eu.dasish.annotation.backend.dao.DBIntegrityService;
+import eu.dasish.annotation.backend.dao.NotebookDao;
 import eu.dasish.annotation.backend.dao.TargetDao;
 import eu.dasish.annotation.backend.dao.UserDao;
@@ -32,4 +33,7 @@
 import eu.dasish.annotation.schema.CachedRepresentationFragmentList;
 import eu.dasish.annotation.schema.CachedRepresentationInfo;
+import eu.dasish.annotation.schema.Notebook;
+import eu.dasish.annotation.schema.NotebookInfo;
+import eu.dasish.annotation.schema.NotebookInfoList;
 import eu.dasish.annotation.schema.TargetInfoList;
 import eu.dasish.annotation.schema.Permission;
@@ -65,5 +69,6 @@
     @Autowired
     AnnotationDao annotationDao;
-    
+    @Autowired
+    NotebookDao notebookDao;
     final static protected String admin = "admin";
     private static final Logger logger = LoggerFactory.getLogger(AnnotationResource.class);
@@ -403,5 +408,5 @@
         return userDao.getTypeOfUserAccount(userID);
     }
-    
+
     @Override
     public boolean canRead(Number userID, Number annotationID) {
@@ -429,4 +434,76 @@
             return false;
         }
+    }
+
+    /// notebooks ///
+    @Override
+    public NotebookInfoList getNotebooks(Number prinipalID, Permission permission) {
+        NotebookInfoList result = new NotebookInfoList();
+        List<Number> notebookIDs = notebookDao.getNotebookIDs(prinipalID, permission);
+        for (Number notebookID : notebookIDs) {
+            NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID);
+            Number ownerID = notebookDao.getOwner(notebookID);
+            notebookInfo.setOwnerRef(userDao.getURIFromInternalID(ownerID));
+            result.getNotebookInfo().add(notebookInfo);
+        }
+
+        return result;
+    }
+
+    @Override
+    public NotebookInfoList getNotebooksOwnedBy(Number principalID) {
+        NotebookInfoList result = new NotebookInfoList();
+        List<Number> notebookIDs = notebookDao.getNotebookIDsOwnedBy(principalID);
+        String ownerRef = userDao.getURIFromInternalID(principalID);
+        for (Number notebookID : notebookIDs) {
+            NotebookInfo notebookInfo = notebookDao.getNotebookInfoWithoutOwner(notebookID);
+            notebookInfo.setOwnerRef(ownerRef);
+            result.getNotebookInfo().add(notebookInfo);
+        }
+
+        return result;
+    }
+
+    @Override
+    public List<UUID> getPrincipals(Number notebookID, Permission permission) {
+        List<UUID> result = new ArrayList<UUID>();
+        List<Number> principalIDs = notebookDao.getPrincipalIDsWithPermission(notebookID, permission);
+        for (Number principalID : principalIDs) {
+            UUID uuid = userDao.getExternalID(principalID);
+            result.add(uuid);
+        }
+        return result;
+    }
+
+    @Override
+    public NotebookInfo getNotebookInfo(Number notebookID) {
+        NotebookInfo result = notebookDao.getNotebookInfoWithoutOwner(notebookID);
+        result.setOwnerRef(userDao.getURIFromInternalID(notebookDao.getOwner(notebookID)));
+        return result;
+    }
+
+    /////////////////////////////////////////////////////////////
+    @Override
+    public List<UUID> getAnnotationsForNotebook(Number notebookID, int startAnnotation, int maximumAnnotations, String orderedBy, boolean desc) {
+        List<Number> annotationIDs = notebookDao.getAnnotations(notebookID);
+
+        if (startAnnotation < -1) {
+            logger.info("Variable's startAnnotation value " + startAnnotation + " is invalid. I will return null.");
+            return null;
+        }
+
+        if (maximumAnnotations < -1) {
+            logger.info("Variable's maximumAnnotations value " + maximumAnnotations + " is invalid. I will return null.");
+            return null;
+        }
+
+        int offset = (startAnnotation > 0) ? startAnnotation - 1 : 0;
+        String direction = desc ? " DESC " : " ASC ";
+        List<Number> selectedAnnotIDs = annotationDao.sublistOrderedAnnotationIDs(annotationIDs, offset, maximumAnnotations, orderedBy, direction);
+        List<UUID> annotationUUIDs = new ArrayList<UUID>();
+        for (Number annotationID : selectedAnnotIDs) {
+            annotationUUIDs.add(annotationDao.getExternalID(annotationID));
+        }
+        return annotationUUIDs;
     }
 
@@ -489,4 +566,21 @@
     }
 
+    @Override
+    public Number updateUser(User user) {
+        return userDao.updateUser(user);
+    }
+    /// notebooks ///
+
+    @Override
+    public boolean updateNotebookMetadata(Number notebookID, NotebookInfo upToDateNotebookInfo) {
+        Number ownerID = userDao.getInternalIDFromURI(upToDateNotebookInfo.getOwnerRef());
+        return notebookDao.updateNotebookMetadata(notebookID, upToDateNotebookInfo.getTitle(), ownerID);
+    }
+
+    @Override
+    public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) {
+        return notebookDao.addAnnotationToNotebook(notebookID, annotationID);
+    }
+
     /////////////// ADDERS  /////////////////////////////////
     @Override
@@ -535,9 +629,4 @@
 
     @Override
-    public Number updateUser(User user) {
-        return userDao.updateUser(user);
-    }
-
-    @Override
     public Number addUser(User user, String remoteID) {
         if (userDao.userExists(user)) {
@@ -551,4 +640,25 @@
     public int addAnnotationPrincipalPermission(Number annotationID, Number userID, Permission permission) {
         return annotationDao.addAnnotationPrincipalPermission(annotationID, userID, permission);
+    }
+    
+    //////////// notebooks //////
+
+    @Override
+    public Number createNotebook(Notebook notebook, Number ownerID) {
+        Number notebookID = notebookDao.createNotebookWithoutPermissionsAndAnnotations(notebook, ownerID);
+        boolean updateOwner = notebookDao.setOwner(notebookID, ownerID);
+        List<UserWithPermission> permissions = notebook.getPermissions().getUserWithPermission();
+        for (UserWithPermission principalPermission : permissions) {
+            Number principalID = userDao.getInternalIDFromURI(principalPermission.getRef());
+            Permission permission = principalPermission.getPermission();
+            boolean updatePermissions = notebookDao.addPermissionToNotebook(notebookID, principalID, permission);
+        }
+        return notebookID;
+    }
+
+    @Override
+    public boolean createAnnotationInNotebook(Number notebookID, Annotation annotation, Number ownerID) {
+        Number newAnnotationID = this.addUsersAnnotation(ownerID, annotation);
+        return notebookDao.addAnnotationToNotebook(notebookID, newAnnotationID);
     }
 
@@ -609,4 +719,11 @@
         return result;
     }
+    
+    @Override
+    public boolean deleteNotebook(Number notebookID) {
+        boolean deletePermissions = notebookDao.deleteAllPermissionsForNotebook(notebookID);
+        boolean deleteAnnotations = notebookDao.deleteAllAnnotationsFromNotebook(notebookID);
+        return notebookDao.deleteNotebook(notebookID);
+    }
 
     ////////////// HELPERS ////////////////////
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java	(revision 4495)
@@ -67,5 +67,5 @@
             StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
             sql.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ?");
-            return getSimpleJdbcTemplate().query(sql.toString(), TargetIDRowMapper, annotationID);
+            return getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, annotationID);
         } else {
             loggerAnnotationDao.debug(nullArgument);
@@ -94,6 +94,4 @@
     };
 
-    
-    
     @Override
     public Permission getPermission(Number annotationID, Number userID) {
@@ -128,7 +126,4 @@
     };
 
-   
-    
-    
     ////////////////////////////////////////////////////////////////////////
     @Override
@@ -143,5 +138,5 @@
             params.put("ownerId", ownerID);
         }
-        
+
         if (after != null) {
             sql.append(" AND ").append(last_modified).append("  > :afterTimestamp");
@@ -161,13 +156,13 @@
     }
 
-     ///////////////////////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////////////////////
     @Override
     public List<Number> getAnnotationIDsForUserWithPermission(Number userID, String access) {
-       
+
         if (userID == null) {
             loggerAnnotationDao.debug("userID: " + nullArgument);
             return null;
         }
-        
+
         if (access == null) {
             logger.info("The access argument is null. I assign it a default value 'reader'.");
@@ -175,5 +170,5 @@
         }
 
-        
+
         StringBuilder sql = new StringBuilder("SELECT ");
         sql.append(annotation_id).append(" FROM ").append(permissionsTableName).append(" WHERE ").
@@ -183,8 +178,4 @@
     }
 
-    
-  
-    
-
     //////////////////////////////
     @Override
@@ -203,8 +194,5 @@
         return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper);
     }
-    
-    
-    
-    
+
     /////////////////////////////////////////
     @Override
@@ -215,4 +203,33 @@
     }
 
+    @Override
+    public List<Number> sublistOrderedAnnotationIDs(List<Number> annotationIDs, int offset, int limit, String orderedBy, String direction) {
+        if (annotationIDs == null) {
+            return null;
+        }
+
+        if (annotationIDs.isEmpty()) {
+            return annotationIDs;
+        }
+
+        
+        String values = makeListOfValues(annotationIDs);
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("offset", offset);
+        params.put("limit", limit);
+
+        StringBuilder query = new StringBuilder("SELECT DISTINCT ");
+        query.append(annotation_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append(" IN ");
+        query.append(values).append(" ORDER BY ").append(orderedBy);
+
+        if (limit > -1) {
+            query.append(direction).append(" LIMIT :limit ");
+        }
+
+        query.append(" OFFSET :offset ");
+        return getSimpleJdbcTemplate().query(query.toString(), internalIDRowMapper, params);
+    }
+
+    //////////////////////////////////////////////////////////////////////
     @Override
     public AnnotationInfo getAnnotationInfoWithoutTargets(Number annotationID) {
@@ -265,5 +282,5 @@
         String values = makeListOfValues(annotationIDs);
         StringBuilder sql = new StringBuilder("SELECT DISTINCT ");
-        sql.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotationAnnotation_id).append("  IN ").append(values);
+        sql.append(external_id).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation_id).append("  IN ").append(values);
         return getSimpleJdbcTemplate().query(sql.toString(), annotationREFRowMapper);
     }
@@ -283,5 +300,5 @@
         }
         StringBuilder sql = new StringBuilder("SELECT ");
-        sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotationAnnotation_id).append("= ? LIMIT  1");
+        sql.append(annotationStar).append(" FROM ").append(annotationTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT  1");
         List<Annotation> respond = getSimpleJdbcTemplate().query(sql.toString(), annotationRowMapper, annotationID);
         return (respond.isEmpty() ? null : respond.get(0));
@@ -327,6 +344,4 @@
         return (respond.isEmpty() ? null : respond.get(0));
     }
-    
-    
 
     /////////////////////////////
@@ -342,5 +357,5 @@
         StringBuilder sqlTargets = new StringBuilder("SELECT ");
         sqlTargets.append(target_id).append(" FROM ").append(annotationsTargetsTableName).append(" WHERE ").append(annotation_id).append("= ? LIMIT 1");
-        List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), TargetIDRowMapper, annotationID);
+        List<Number> resultTargets = getSimpleJdbcTemplate().query(sqlTargets.toString(), targetIDRowMapper, annotationID);
         if (resultTargets.size() > 0) {
             return true;
@@ -449,5 +464,10 @@
         if (annotation == null) {
             loggerAnnotationDao.debug("annotation: " + nullArgument);
-            return 0;
+            return null;
+        }
+        
+        if (ownerID == null) {
+            loggerAnnotationDao.debug("ownerID: " + nullArgument);
+            return null;
         }
 
@@ -575,6 +595,6 @@
                 StringBuilder sqlPermissions = new StringBuilder("DELETE FROM ");
                 sqlPermissions.append(permissionsTableName).append(" WHERE ").append(annotation_id).append(" = :annotationId AND ").
-                append(principal_id).append(" = :userId");                
-                return getSimpleJdbcTemplate().update(sqlPermissions.toString(), params);  
+                        append(principal_id).append(" = :userId");
+                return getSimpleJdbcTemplate().update(sqlPermissions.toString(), params);
             } else {
                 loggerAnnotationDao.debug("userID: " + nullArgument);
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDao.java	(revision 4495)
@@ -119,5 +119,5 @@
         StringBuilder sql = new StringBuilder("SELECT ");
         sql.append(target_id).append(" FROM ").append(targetsCachedRepresentationsTableName).append(" WHERE ").append(cached_representation_id).append("= ? LIMIT 1");
-        List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), TargetIDRowMapper, cachedID);
+        List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), targetIDRowMapper, cachedID);
         if (result != null) {
             return (!result.isEmpty());
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java	(revision 4495)
@@ -28,4 +28,5 @@
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 import javax.sql.DataSource;
 import org.springframework.jdbc.core.RowMapper;
@@ -33,4 +34,6 @@
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.XMLGregorianCalendar;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
@@ -42,6 +45,6 @@
 public class JdbcNotebookDao extends JdbcResourceDao implements NotebookDao {
 
-//    @Autowired
-//    private AnnotationDao jdbcAnnotationDao;
+    private final Logger loggerNotebookDao = LoggerFactory.getLogger(JdbcNotebookDao.class);
+
     public JdbcNotebookDao(DataSource dataSource) {
         setDataSource(dataSource);
@@ -52,43 +55,94 @@
     /// GETTERS /////////
     ////////////////////////////////////////////////
-    @Override
-    public List<Number> getNotebookIDs(Number userID, Permission acessMode) {
-        Map<String, Object> params = new HashMap<String, Object>();
-        params.put("principalID", userID);
-        params.put("accessMode", acessMode.value());
-        String sql = "SELECT " + notebook_id + " FROM " + notebookPermissionsTableName + " WHERE " + principalPrincipal_id + " = :principalID" + " AND " + permission + " = :accessMode";
-        return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, params);
-    }
-
     ////////////////////////////////////////////////
     @Override
-    public List<Number> getOwnerNotebookIDs(Number userID) {
-        String sql = "SELECT " + notebook_id + " FROM " + notebookTableName + " WHERE " + owner_id + " = ?";
-        return getSimpleJdbcTemplate().query(sql, internalIDRowMapper, userID);
-    }
-
-  
+    public Number getOwner(Number notebookID) {
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return null;
+        }
+        StringBuilder sql = new StringBuilder("SELECT ");
+        sql.append(owner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").
+                append(notebook_id).append(" = ?");
+        List<Number> result = getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, notebookID);
+        if (result.isEmpty()) {
+            return null;
+        } else {
+            return result.get(0);
+        }
+    }
+
+    @Override
+    public List<Number> getNotebookIDs(Number principalID, Permission permission) {
+
+        if (principalID == null) {
+            loggerNotebookDao.debug("princiaplID: " + nullArgument);
+            return null;
+        }
+
+        if (permission == null) {
+            loggerNotebookDao.debug("permission: " + nullArgument);
+            return null;
+        }
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("principalID", principalID);
+        params.put("accessMode", permission.value());
+        StringBuilder sql = new StringBuilder("SELECT ");
+        sql.append(notebook_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").
+                append(principal_id).append(" = :principalID AND ").append(permission).append(" = :accessMode");
+        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, params);
+    }
+
+    ////////////////////////////////////////////////
+    @Override
+    public List<Number> getNotebookIDsOwnedBy(Number principalID) {
+
+        if (principalID == null) {
+            loggerNotebookDao.debug("principalID: " + nullArgument);
+            return null;
+        }
+
+        StringBuilder sql = new StringBuilder("SELECT ");
+        sql.append(notebook_id).append(" FROM ").append(notebookTableName).append(" WHERE ").
+                append(owner_id).append(" = ?");
+        return getSimpleJdbcTemplate().query(sql.toString(), internalIDRowMapper, principalID);
+    }
 
     @Override
     public List<Number> getPrincipalIDsWithPermission(Number notebookID, Permission permission) {
-         if (notebookID == null) {
-            return null;
-        }         
-        Map<String, Object> params= new HashMap<String, Object>();
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return null;
+        }
+
+        if (permission == null) {
+            loggerNotebookDao.debug("permission: " + nullArgument);
+            return null;
+        }
+        Map<String, Object> params = new HashMap<String, Object>();
         params.put("notebookID", notebookID);
-        params.put("permission", permission.value());
-        
-        String sql = "SELECT  " + owner_id + " FROM " + notebookPermissionsTableName + " WHERE " + notebook_id +" = :notebookID AND " +this.permission + " = :permission";
-        return getSimpleJdbcTemplate().query(sql, principalIDRowMapper, params);
-       
-    }
-
-    @Override
-    public NotebookInfo getNotebookInfo(Number notebookID) {
-        if (notebookID == null) {
-            return null;
-        }
-        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
-        List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql, notebookInfoRowMapper, notebookID);
+        params.put("accessMode", permission.value());
+
+        StringBuilder sql = new StringBuilder("SELECT ");
+        sql.append(principal_id).append(" FROM ").append(notebookPermissionsTableName).append(" WHERE ").
+                append(notebook_id).append(" = :notebookID AND ").append(this.permission).append(" = :accessMode");
+
+        return getSimpleJdbcTemplate().query(sql.toString(), principalIDRowMapper, params);
+
+    }
+
+    @Override
+    public NotebookInfo getNotebookInfoWithoutOwner(Number notebookID) {
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return null;
+        }
+
+        StringBuilder sql = new StringBuilder("SELECT ");
+        sql.append(external_id).append(" , ").append(title).
+                append(" FROM ").append(notebookTableName).append(" WHERE ").
+                append(notebook_id).append(" = :notebookID");
+        List<NotebookInfo> result = getSimpleJdbcTemplate().query(sql.toString(), notebookInfoRowMapper, notebookID);
         return (!result.isEmpty() ? result.get(0) : null);
     }
@@ -104,10 +158,14 @@
 
     @Override
-    public Notebook getNotebookWithoutAnnotationsAndPermissions(Number notebookID) {
-        if (notebookID == null) {
-            return null;
-        }
-        String sql = "SELECT  " + notebookExternal_id + "," + notebookTitle + "," + last_modified + " FROM " + notebookTableName + " where " + notebook_id + " = ? LIMIT 1";
-        List<Notebook> result = getSimpleJdbcTemplate().query(sql, notebookRowMapper, notebookID);
+    public Notebook getNotebookWithoutAnnotationsAndPermissionsAndOwner(Number notebookID) {
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return null;
+        }
+        StringBuilder sql = new StringBuilder("SELECT ");
+        sql.append(external_id).append(" , ").append(title).append(" , ").append(last_modified).
+                append(" FROM ").append(notebookTableName).append(" WHERE ").
+                append(notebook_id).append(" = :notebookID");
+        List<Notebook> result = getSimpleJdbcTemplate().query(sql.toString(), notebookRowMapper, notebookID);
         return (!result.isEmpty() ? result.get(0) : null);
     }
@@ -129,63 +187,329 @@
         }
     };
+
+    @Override
+    public List<Number> getAnnotations(Number notebookID) {
+
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return null;
+        }
+
+        StringBuilder sql = new StringBuilder("SELECT ");
+        sql.append(annotation_id).
+                append(" FROM ").append(notebooksAnnotationsTableName).append(" WHERE ").
+                append(notebook_id).append(" = :notebookID");
+        return getSimpleJdbcTemplate().query(sql.toString(), annotationIDRowMapper, notebookID);
+
+    }
+
+    /**
+     *
+     * UPDATERS
+     *
+     *
+     */
+    /**
+     *
+     * @param notebookID
+     * @return true if updated, false otherwise. Logs the reason if the notebook
+     * is not updated.
+     */
+    @Override
+    public boolean updateNotebookMetadata(Number notebookID, String title, Number ownerID) {
+
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+
+        if (title == null) {
+            loggerNotebookDao.debug("title: " + nullArgument);
+            return false;
+        }
+
+        if (ownerID == null) {
+            loggerNotebookDao.debug("ownerID: " + nullArgument);
+            return false;
+        }
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("notebookID", notebookID);
+        params.put("title", title);
+        params.put("owner", ownerID);
+
+        StringBuilder sql = new StringBuilder("UPDATE ");
+        sql.append(notebookTableName).append(" SET ").
+                append(last_modified).append("=  default,").
+                append(this.title).append("= :title, ").
+                append(owner_id).append("= :owner").
+                append(" WHERE ").append(notebook_id).append("= :notebookID");
+        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
+        if (affectedRows <= 0) {
+            logger.info("For some reason no rows in the table notebooks were updated. ");
+            return false;
+        } else {
+            if (affectedRows > 1) {
+                logger.info("For some reason more than 1 row in the table notebooks were updated. that's strange.");
+                return true;
+            } else {
+                return true;
+            }
+        }
+    }
     
-    
-    @Override
-    public List<Number> getAnnotations(int maximumAnnotations, int startannotation, String orderedBy, boolean orderingMode){
-        return null;
-    }
-    
-    
-       /**
-     * 
-     * UPDATERS 
-     * 
-     * 
+    @Override
+    public boolean setOwner(Number notebookID, Number ownerID) {
+
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+
+        if (ownerID == null) {
+            loggerNotebookDao.debug("ownerID: " + nullArgument);
+            return false;
+        }
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("notebookID", notebookID);
+        params.put("ownerID", ownerID);
+
+        StringBuilder sql = new StringBuilder("UPDATE ");
+        sql.append(notebookTableName).append(" SET ").
+                append(last_modified).append("=  default,").
+                append(owner_id).append("= :ownerID").
+                append(" WHERE ").append(notebook_id).append("= :notebookID");
+        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
+        if (affectedRows <= 0) {
+            logger.info("For some reason no rows in the table notebooks were updated. ");
+            return false;
+        } else {
+            if (affectedRows > 1) {
+                logger.info("For some reason more than 1 row in the table notebooks were updated. that's strange.");
+                return true;
+            } else {
+                return true;
+            }
+        }
+    }
+
+    @Override
+    public boolean updateUserPermissionForNotebook(Number notebookID, Number principalID, Permission permission) {
+
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+
+        if (principalID == null) {
+            loggerNotebookDao.debug("principalID: " + nullArgument);
+            return false;
+        }
+
+        if (permission == null) {
+            loggerNotebookDao.debug("permission: " + nullArgument);
+            return false;
+        }
+
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("notebookID", notebookID);
+        params.put("principalID", principalID);
+        params.put("permission", permission.value());
+
+        StringBuilder sql = new StringBuilder("UPDATE ");
+        sql.append(notebookPermissionsTableName).append(" SET ").
+                append(notebook_id).append("= :notebookID, ").
+                append(principal_id).append("= :principalID").
+                append(this.permission).append("= :permission").
+                append(" WHERE ").append(notebook_id).append("= :notebookID");
+        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
+        if (affectedRows <= 0) {
+            logger.info("For some reason no rows in the table notebooks-permissions were updated. ");
+            return false;
+        } else {
+            if (affectedRows > 1) {
+                logger.info("For some reason more than 1 row in the table notebooks-permissions were updated. that's strange.");
+                return true;
+            } else {
+                return true;
+            }
+        }
+    }
+
+    /**
+     *
+     * ADDERS
+     *
+     *
      */
-    
-    
-    
+    @Override
+    public Number createNotebookWithoutPermissionsAndAnnotations(Notebook notebook, Number ownerID) {
+        if (notebook == null) {
+            loggerNotebookDao.debug("notebook: " + nullArgument);
+            return null;
+        }
+
+        if (ownerID == null) {
+            loggerNotebookDao.debug("ownerID: " + nullArgument);
+            return null;
+        }
+
+        UUID externalID = UUID.randomUUID();
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("externalId", externalID.toString());
+        params.put("owner", ownerID);
+        params.put("title", notebook.getTitle());
+
+        StringBuilder sql = new StringBuilder("INSERT INTO ");
+        sql.append(notebookTableName).append("(").append(external_id).append(",").append(owner_id);
+        sql.append(",").append(title).
+                append(" ) VALUES (:externalId, :owner, :title)");
+        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
+        return ((affectedRows > 0) ? getInternalID(externalID) : null);
+    }
+
+    @Override
+    public boolean addAnnotationToNotebook(Number notebookID, Number annotationID) {
+
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+
+        if (annotationID == null) {
+            loggerNotebookDao.debug("annotationID: " + nullArgument);
+            return false;
+        }
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("notebookID", notebookID);
+        params.put("annotationID", annotationID);
+
+        StringBuilder sql = new StringBuilder("INSERT INTO ");
+        sql.append(notebooksAnnotationsTableName).append("(").append(notebook_id).append(",").append(annotation_id);
+        sql.append(",").append(" ) VALUES (:notebookID, :annotationID)");
+        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
+        return (affectedRows > 0);
+    }
+
+    @Override
+    public boolean addPermissionToNotebook(Number notebookID, Number principalID, Permission permission) {
+        if (notebookID == null) {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+
+        if (principalID == null) {
+            loggerNotebookDao.debug("principalID: " + nullArgument);
+            return false;
+        }
+
+        if (permission == null) {
+            loggerNotebookDao.debug("premission: " + nullArgument);
+            return false;
+        }
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("notebookID", notebookID);
+        params.put("principalID", principalID);
+        params.put("permission", permission.value());
+
+        StringBuilder sql = new StringBuilder("INSERT INTO ");
+        sql.append(notebookPermissionsTableName).append("(").append(notebook_id).append(",").append(principal_id);
+        sql.append(",").append(this.permission).
+                append(" ) VALUES (:notebookID, :principalID, :permission)");
+        int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
+        return (affectedRows > 0);
+    }
+
     /**
-     * 
-     * @param notebookID
-     * @return true if updated, false otherwise. Logs the reason if the notebook is not updated.
+     *
+     * DELETERS
+     *
+     *
      */
     @Override
-    public boolean updateNotebookMetadata(Number notebookID){
-        return false;
-    }
-     /**
-     * 
-     * ADDERS
-     * 
-     * 
-     */
-    
-    @Override
-    public Number createNotebook(Notebook notebook){
-        return null;
-    }
-    
-    @Override
-    public boolean addAnnotationToNotebook(Number noteboookId, Number AnnotationID){
-        return false;
-    }
-    
-    
-    /**
-     * 
-     * DELETERS (ADDER)
-     * 
-     * 
-     */
-    
-    @Override
-    public boolean deleteannotationFromNotebook(Number notebookID, Number annotationID){
-        return false;
-    }
-    
-    @Override
-    public boolean deleteNotebook(Number notebookID){
-        return false;
+    public boolean deleteAnnotationFromNotebook(Number notebookID, Number annotationID) {
+        if (notebookID != null) {
+            if (annotationID != null) {
+                Map<String, Number> params = new HashMap();
+                params.put("notebookID", notebookID);
+                params.put("annotationID", annotationID);
+                StringBuilder sql = new StringBuilder("DELETE FROM ");
+                sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(notebook_id).append(" = :notebookID AND ").
+                        append(annotation_id).append(" = :annotationID");
+                int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), params);
+                return (affectedRows > 0);
+            } else {
+                loggerNotebookDao.debug("annotationID: " + nullArgument);
+                return false;
+            }
+        } else {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean deleteNotebookPrincipalPermission(Number notebookID, Number principalID) {
+        if (notebookID != null) {
+            if (principalID != null) {
+                Map<String, Number> params = new HashMap();
+                params.put("notebookID", notebookID);
+                params.put("principalID", principalID);
+                StringBuilder sqlPermissions = new StringBuilder("DELETE FROM ");
+                sqlPermissions.append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append(" = :notebookID AND ").
+                        append(principal_id).append(" = :principalID");
+                int affectedRows = getSimpleJdbcTemplate().update(sqlPermissions.toString(), params);
+                return (affectedRows > 0);
+            } else {
+                loggerNotebookDao.debug("principalID: " + nullArgument);
+                return false;
+            }
+        } else {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean deleteAllAnnotationsFromNotebook(Number notebookID) {
+        if (notebookID != null) {
+            StringBuilder sql = new StringBuilder("DELETE FROM ");
+            sql.append(notebooksAnnotationsTableName).append(" WHERE ").append(notebook_id).append(" = ? ");
+            int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), notebookID);
+            return (affectedRows > 0);
+        } else {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean deleteAllPermissionsForNotebook(Number notebookID) {
+        if (notebookID != null) {
+            StringBuilder sqlPermissions = new StringBuilder("DELETE FROM ");
+            sqlPermissions.append(notebookPermissionsTableName).append(" WHERE ").append(notebook_id).append(" = ? ");
+            int affectedRows = getSimpleJdbcTemplate().update(sqlPermissions.toString(), notebookID);
+            return (affectedRows > 0);
+        } else {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean deleteNotebook(Number notebookID) {
+        if (notebookID != null) {
+            StringBuilder sql = new StringBuilder("DELETE FROM ");
+            sql.append(notebookTableName).append(" WHERE ").append(notebook_id).append(" = ? ");
+            int affectedRows = getSimpleJdbcTemplate().update(sql.toString(), notebookID);
+            return (affectedRows > 0);
+        } else {
+            loggerNotebookDao.debug("notebookID: " + nullArgument);
+            return false;
+        }
     }
 }
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java	(revision 4495)
@@ -82,15 +82,5 @@
     final static protected String fragment_descriptor = "fragment_descriptor";
     final static protected String fragment_descriptor_in_cached = "fragment_descriptor_in_cached";
-    // derived string constants: table+field names 
     final static protected String annotationStar = annotationTableName + ".*";
-    final static protected String annotationAnnotation_id = annotationTableName + "." + annotation_id;
-    final static protected String annotationExternal_id = annotationTableName + "." + external_id;
-    final static protected String notebookStar = notebookTableName + ".*";
-    final static protected String notebookNotebook_id = notebookTableName + "." + notebook_id;
-    final static protected String notebookTitle = notebookTableName + "." + title;
-    final static protected String notebookExternal_id = notebookTableName + "." + external_id;
-    final static protected String notebooksAnnotationsTableNameAnnotation_id = notebooksAnnotationsTableName + "." + annotation_id;
-    final static protected String principalPrincipal_id = principalTableName + "." + principal_id;
-    final static protected String principalExternal_id = principalTableName + "." + external_id;
     final static protected String cachedRepresentationStar = cachedRepresentationTableName + ".*";
     final static protected String targetStar = targetTableName + ".*";
@@ -202,5 +192,5 @@
         }
     };
-    protected final RowMapper<Number> TargetIDRowMapper = new RowMapper<Number>() {
+    protected final RowMapper<Number> targetIDRowMapper = new RowMapper<Number>() {
         @Override
         public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
@@ -234,10 +224,5 @@
     };
     
-    protected final RowMapper<Number> notebookOwnerIDRowMapper = new RowMapper<Number>() {
-        @Override
-        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
-            return rs.getInt(notebookOwner_id);
-        }
-    };
+
 
     @Override
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java	(revision 4495)
@@ -99,6 +99,6 @@
 
         StringBuilder sqlNotebooks = new StringBuilder("SELECT ");
-        sqlNotebooks.append(notebookOwner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(notebookOwner_id).append("= ? LIMIT 1");
-        List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), notebookOwnerIDRowMapper, userID);
+        sqlNotebooks.append(owner_id).append(" FROM ").append(notebookTableName).append(" WHERE ").append(owner_id).append("= ? LIMIT 1");
+        List<Number> resultNotebooks = getSimpleJdbcTemplate().query(sqlNotebooks.toString(), ownerIDRowMapper, userID);
         if (resultNotebooks.size() > 0) {
             return true;
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DBIntegrityServiceTest.java	(revision 4495)
@@ -22,4 +22,5 @@
 import eu.dasish.annotation.backend.dao.AnnotationDao;
 import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
+import eu.dasish.annotation.backend.dao.NotebookDao;
 import eu.dasish.annotation.backend.dao.TargetDao;
 import eu.dasish.annotation.backend.dao.UserDao;
@@ -62,4 +63,5 @@
 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockeryDao.xml", "/spring-test-config/mockAnnotationDao.xml",
     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockTargetDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", 
+    "/spring-test-config/mockNotebookDao.xml",
     "/spring-config/dbIntegrityService.xml"})
 public class DBIntegrityServiceTest {
@@ -77,4 +79,7 @@
     @Autowired
     private AnnotationDao annotationDao;
+    @Autowired
+    private NotebookDao notebookDao;
+    
     TestInstances testInstances = new TestInstances(TestBackendConstants._TEST_SERVLET_URI);
 
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java	(revision 4494)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java	(revision 4495)
@@ -89,5 +89,5 @@
 	// sorry for the duplication, but JerseyTest is not aware of
 	// @ContextConfiguration
-	return "classpath:spring-config/componentscan.xml, classpath:spring-config/annotationDao.xml, classpath:spring-config/userDao.xml, classpath:spring-config/targetDao.xml, classpath:spring-config/cachedRepresentationDao.xml, classpath:spring-config/dbIntegrityService.xml, classpath:spring-config/jaxbMarshallerFactory.xml, classpath:spring-test-config/dataSource.xml";
+	return "classpath:spring-config/componentscan.xml, classpath:spring-config/notebookDao.xml, classpath:spring-config/annotationDao.xml, classpath:spring-config/userDao.xml, classpath:spring-config/targetDao.xml, classpath:spring-config/cachedRepresentationDao.xml, classpath:spring-config/dbIntegrityService.xml, classpath:spring-config/jaxbMarshallerFactory.xml, classpath:spring-test-config/dataSource.xml";
     }
     
