de.hs_rm.cs.lecturenotes.server.core.persistence.dao
Class LectureDAO

java.lang.Object
  extended by de.hs_rm.cs.lecturenotes.server.core.persistence.dao.AbstractDAO<Lecture>
      extended by de.hs_rm.cs.lecturenotes.server.core.persistence.dao.LectureDAO
All Implemented Interfaces:
IDAO<Lecture>

public final class LectureDAO
extends AbstractDAO<Lecture>

Data Access Object for System Entity Lecture. Manages all the persistence logicals. DBMS Database Logic and filesystem logic.

Version:
$LastChangedRevision: 296 $
Author:
Enrico Homann

Field Summary
static java.lang.String SQL_TABLENAME
          SQL Table Name.
 
Fields inherited from class de.hs_rm.cs.lecturenotes.server.core.persistence.dao.AbstractDAO
SQL_DELETEALL_TEMPLATE, SQL_DROP_TEMPLATE
 
Fields inherited from interface de.hs_rm.cs.lecturenotes.server.core.persistence.dao.IDAO
SQLERRORCODE_DUPLICATE_ENTRY
 
Constructor Summary
LectureDAO(SQLConnection db)
          DAO Constructor.
 
Method Summary
 java.lang.Long createEntity(Lecture entity)
          Creates an entity of type T and returns the inserted id.
 ResponseStatusEnum createLectureFileStructure(java.lang.String absRootDirectoryImagesWeb, java.lang.String absRootDirectoryImagesPrint, Lecture entity)
          Will create the file structure for media files on the file system of the server back-end system.
 Lecture getLectureById(long lectureId)
          Will return a lecture by it's long lectureId.
 Lecture getLectureByParaId(long paraId)
          Will return the Lecture related to the long paraId of a Paragraph.
 java.util.List<Lecture> getLectureListAll(LectureAttributeEnum sortAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of Lecture entities from the database with all known Lecture objects.
 java.util.List<Lecture> getLectureListMostAnnotations(SQLSortDirectionEnum sortDirection)
          Will return a List of Lecture objects sorted by the number of annotations (Parent Annotations and Child Annotations).
 java.util.List<Lecture> getLectureListOwnership(long userId, LectureAttributeEnum sortAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of Lecture owned by User with long userId.
 java.util.List<Lecture> getLecturesBySQL(java.lang.String sql)
          Will return all lectures by String sql.
 java.lang.Integer hardDeleteLecture(Lecture entity, javax.servlet.ServletContext cntxt)
          Hard deletes Lecture and all its dependencies, but the user.
 java.lang.Integer increaseLectureVersion(Lecture entity)
          Increases the Lecture version by one.
 java.lang.Integer resetLectureVersion(Lecture entity)
          Resets the Lecture version to 1.
 java.lang.Integer updateEntity(Lecture entity)
          Will update a Lecture entity and return the number of rows that were updated, which must be one.
 
Methods inherited from class de.hs_rm.cs.lecturenotes.server.core.persistence.dao.AbstractDAO
createEntity, deleteTableContents, dropTable, executeCreateSQL, executeUpdateSQL, getDb, setDb
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SQL_TABLENAME

public static final java.lang.String SQL_TABLENAME
SQL Table Name.

See Also:
Constant Field Values
Constructor Detail

LectureDAO

public LectureDAO(SQLConnection db)
DAO Constructor.

Parameters:
db - SQLConnection connection
Method Detail

createLectureFileStructure

public ResponseStatusEnum createLectureFileStructure(java.lang.String absRootDirectoryImagesWeb,
                                                     java.lang.String absRootDirectoryImagesPrint,
                                                     Lecture entity)
Will create the file structure for media files on the file system of the server back-end system.

Parameters:
absRootDirectoryImagesWeb - String absolute root directory for web images
absRootDirectoryImagesPrint - String absolute root directory for print images
entity - Lecture
Returns:
ResponseStatusEnum

getLecturesBySQL

public java.util.List<Lecture> getLecturesBySQL(java.lang.String sql)
Will return all lectures by String sql. This method does not fetch the paragraphs.

Parameters:
sql - String
Returns:
Lecture

getLectureListAll

public java.util.List<Lecture> getLectureListAll(LectureAttributeEnum sortAttribute,
                                                 SQLSortDirectionEnum sortDirection)
Will return a List of Lecture entities from the database with all known Lecture objects.

Parameters:
sortAttribute - LectureAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Lecture entities

getLectureListMostAnnotations

public java.util.List<Lecture> getLectureListMostAnnotations(SQLSortDirectionEnum sortDirection)
Will return a List of Lecture objects sorted by the number of annotations (Parent Annotations and Child Annotations).

Parameters:
sortDirection - SQLSortDirectionEnum
Returns:
List of Lecture

getLectureListOwnership

public java.util.List<Lecture> getLectureListOwnership(long userId,
                                                       LectureAttributeEnum sortAttribute,
                                                       SQLSortDirectionEnum sortDirection)
Will return a List of Lecture owned by User with long userId.

Parameters:
userId - long
sortAttribute - LectureAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Lecture

getLectureByParaId

public Lecture getLectureByParaId(long paraId)
Will return the Lecture related to the long paraId of a Paragraph.

Parameters:
paraId - long
Returns:
Lecture

getLectureById

public Lecture getLectureById(long lectureId)
Will return a lecture by it's long lectureId. This method does not fetch the paragraphs.

Parameters:
lectureId - long
Returns:
Lecture

increaseLectureVersion

public java.lang.Integer increaseLectureVersion(Lecture entity)
Increases the Lecture version by one.

Parameters:
entity - Lecture
Returns:
Integer

resetLectureVersion

public java.lang.Integer resetLectureVersion(Lecture entity)
Resets the Lecture version to 1. This is somewhat important, because with every database access to a paragraph is the version increased. If the user creates a new Lecture, there is automatically a new paragraph creates which involves the database access methods 1) moveToPosition and 2) createParagraph. The version is then at 3 . However it's expected that the user starts with version 1. So the version should be reseted to 1 after first setup.

Parameters:
entity - Lecture
Returns:
Integer

createEntity

public java.lang.Long createEntity(Lecture entity)
                            throws java.sql.SQLException
Description copied from interface: IDAO
Creates an entity of type T and returns the inserted id. Throws SQLException in case of a duplicated entry or other DBMS problems.

Parameters:
entity - T
Returns:
Long Id of the freshly inserted row. Must be not null and should be above 0.
Throws:
java.sql.SQLException - Exception thrown. Here to indicate a duplicate entry to the outside world.

updateEntity

public java.lang.Integer updateEntity(Lecture entity)
Will update a Lecture entity and return the number of rows that were updated, which must be one. If the number is not one a failure had occurred. Notice: Ownership will not be updated

Parameters:
entity - Lecture.
Returns:
Integer Number of rows that were updated

hardDeleteLecture

public java.lang.Integer hardDeleteLecture(Lecture entity,
                                           javax.servlet.ServletContext cntxt)
Hard deletes Lecture and all its dependencies, but the user.

Parameters:
entity - Lecture
cntxt - ServletContext
Returns:
Integer