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

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

public final class AnnotationDAO
extends AbstractDAO<Annotation>

Data Access Object for System Entity "Lecture".

Version:
$LastChangedRevision: 275 $
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
AnnotationDAO(SQLConnection db)
          DAO Constructor.
 
Method Summary
 java.lang.Long createEntity(Annotation entity)
          Creates an entity of type T and returns the inserted id.
 ResponseStatusEnum deleteAnnotation(long annotationId)
          Will delete an Annotation object identified by long annotationId.
 Annotation getAnnotationById(long id)
          Will return a (first level) Annotation where parentId = 0.
 java.util.List<Annotation> getAnnotationListBySQL(java.lang.String sqlQuery)
          Fetches a List of Annotation objects by using SQL statement String sqlQuery.
 java.util.List<Annotation> getAnnotationsByParagraphId(long paragraphId, AnnotationAttributeEnum orderAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of (first level) Annotation objects where parentId = 0 and paragraphId = long paragraphId.
 java.util.List<Annotation> getAnnotationsByParagraphId(long paragraphId, AnnotationDiscriminatorEnum disc, AnnotationAttributeEnum orderAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of (first level) Annotation objects where parentId = 0 and paragraphId = long paragraphId and annotationDiscriminator is AnnotationDiscriminatorEnum disc.
 java.util.List<Annotation> getAnnotationsByParaId(long paraId, AnnotationAttributeEnum orderAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of (first level) Annotation objects where parentId = 0 for Paragraph with paraId = long paraId.
 java.util.List<Annotation> getAnnotationsByParaId(long paraId, AnnotationDiscriminatorEnum disc, AnnotationAttributeEnum orderAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of (first level) Annotation objects where parentId = 0 and annotationDiscriminator is AnnotationDiscriminatorEnum disc for Paragraph with paraId = long paraId.
 Annotation getAnyAnnotationById(long id)
          Will return any Annotation regardless if its parentId = 0 or not.
 java.util.List<Annotation> getChildAnnotationsForAnnotation(long parentId, AnnotationAttributeEnum orderAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of Annotation objects that are responses to a parent Annotation identified by long parentId.
 java.lang.Long getNumberAnnotationForParagraph(long paraId, boolean withResponses)
          Will return the number of annotations for Paragraph row(s) with long paraIdId.
 java.lang.Long getNumberResponsesForAnnotation(long annotationId)
          Will return the number of response annotations for Annotation with long annotationId.
 java.util.List<Annotation> getOwnershipAnnotationsByParaId(long userId, long paraId, AnnotationAttributeEnum orderAttribute, SQLSortDirectionEnum sortDirection)
          Will return a List of (first level) Annotation objects owned by User with long userId where parentId = 0 for Paragraph with paraId = long paraId.
 java.util.List<ParagraphStats> getTopAnnotatedParagraphs(long lectureId, long limitValue, boolean withResponses, boolean withContents, SQLSortDirectionEnum sortDirection)
          Will return the top annotated Paragraph entities, wrapped in a ParagraphStats object for increased transport performance.
 java.lang.Integer updatePosition(long annotationId, AnnotationStickyPositionEnum position)
          Will update the position of an Annotation.
 
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

AnnotationDAO

public AnnotationDAO(SQLConnection db)
DAO Constructor.

Parameters:
db - SQLConnection connection
Method Detail

getAnnotationListBySQL

public java.util.List<Annotation> getAnnotationListBySQL(java.lang.String sqlQuery)
Fetches a List of Annotation objects by using SQL statement String sqlQuery.

Parameters:
sqlQuery - String
Returns:
List of Annotation

getAnyAnnotationById

public Annotation getAnyAnnotationById(long id)
Will return any Annotation regardless if its parentId = 0 or not.

Parameters:
id - long
Returns:
Annotation

getAnnotationById

public Annotation getAnnotationById(long id)
Will return a (first level) Annotation where parentId = 0.

Parameters:
id - long
Returns:
Annotation

getAnnotationsByParagraphId

public java.util.List<Annotation> getAnnotationsByParagraphId(long paragraphId,
                                                              AnnotationAttributeEnum orderAttribute,
                                                              SQLSortDirectionEnum sortDirection)
Will return a List of (first level) Annotation objects where parentId = 0 and paragraphId = long paragraphId. The List is sorted by the given parameters.

Parameters:
paragraphId - long
orderAttribute - AnnotationAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Annotation

getAnnotationsByParagraphId

public java.util.List<Annotation> getAnnotationsByParagraphId(long paragraphId,
                                                              AnnotationDiscriminatorEnum disc,
                                                              AnnotationAttributeEnum orderAttribute,
                                                              SQLSortDirectionEnum sortDirection)
Will return a List of (first level) Annotation objects where parentId = 0 and paragraphId = long paragraphId and annotationDiscriminator is AnnotationDiscriminatorEnum disc. The List is sorted by the given parameters.

Parameters:
paragraphId - long
disc - AnnotationDiscriminatorEnum
orderAttribute - AnnotationAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Annotation

getAnnotationsByParaId

public java.util.List<Annotation> getAnnotationsByParaId(long paraId,
                                                         AnnotationAttributeEnum orderAttribute,
                                                         SQLSortDirectionEnum sortDirection)
Will return a List of (first level) Annotation objects where parentId = 0 for Paragraph with paraId = long paraId. The List is sorted by the given parameters.

Parameters:
paraId - long
orderAttribute - AnnotationAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Annotation

getOwnershipAnnotationsByParaId

public java.util.List<Annotation> getOwnershipAnnotationsByParaId(long userId,
                                                                  long paraId,
                                                                  AnnotationAttributeEnum orderAttribute,
                                                                  SQLSortDirectionEnum sortDirection)
Will return a List of (first level) Annotation objects owned by User with long userId where parentId = 0 for Paragraph with paraId = long paraId. The List is sorted by the given parameters.

Parameters:
userId - long that is within the ownership User object
paraId - long
orderAttribute - AnnotationAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Annotation

getAnnotationsByParaId

public java.util.List<Annotation> getAnnotationsByParaId(long paraId,
                                                         AnnotationDiscriminatorEnum disc,
                                                         AnnotationAttributeEnum orderAttribute,
                                                         SQLSortDirectionEnum sortDirection)
Will return a List of (first level) Annotation objects where parentId = 0 and annotationDiscriminator is AnnotationDiscriminatorEnum disc for Paragraph with paraId = long paraId. The List is sorted by the given parameters.

Parameters:
paraId - long
disc - AnnotationDiscriminatorEnum
orderAttribute - AnnotationAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Annotation

getChildAnnotationsForAnnotation

public java.util.List<Annotation> getChildAnnotationsForAnnotation(long parentId,
                                                                   AnnotationAttributeEnum orderAttribute,
                                                                   SQLSortDirectionEnum sortDirection)
Will return a List of Annotation objects that are responses to a parent Annotation identified by long parentId. The List is sorted by the given parameters.

Parameters:
parentId - long
orderAttribute - AnnotationAttributeEnum
sortDirection - SQLSortDirectionEnum
Returns:
List of Annotation

deleteAnnotation

public ResponseStatusEnum deleteAnnotation(long annotationId)
Will delete an Annotation object identified by long annotationId. Will return SUCCESS if the operation was successful or FAILURE otherwise.

Parameters:
annotationId - long
Returns:
ResponseStatusEnum.

getNumberResponsesForAnnotation

public java.lang.Long getNumberResponsesForAnnotation(long annotationId)
Will return the number of response annotations for Annotation with long annotationId.

Parameters:
annotationId - long
Returns:
Long

getNumberAnnotationForParagraph

public java.lang.Long getNumberAnnotationForParagraph(long paraId,
                                                      boolean withResponses)
Will return the number of annotations for Paragraph row(s) with long paraIdId. boolean withResponses indicates whether the responses to the annotations shall be included in the calculation, because they are also Annotation entities.

Parameters:
paraId - long
withResponses - boolean
Returns:
Long

getTopAnnotatedParagraphs

public java.util.List<ParagraphStats> getTopAnnotatedParagraphs(long lectureId,
                                                                long limitValue,
                                                                boolean withResponses,
                                                                boolean withContents,
                                                                SQLSortDirectionEnum sortDirection)
Will return the top annotated Paragraph entities, wrapped in a ParagraphStats object for increased transport performance. The paragraph with the most relations to Annotation entities.

Parameters:
lectureId - long that describes the Lecture
limitValue - long that limits the return rows to the specified value
withResponses - boolean that specifies whether response annotations shall be included in the calculation
withContents - boolean that specifies whether the content field of the Paragraph objects shall be correctly transfered or not (if not needed). This is for transport performance
sortDirection - SQLSortDirectionEnum that specifies the SQL sort direction
Returns:
List of ParagraphStats objects

updatePosition

public java.lang.Integer updatePosition(long annotationId,
                                        AnnotationStickyPositionEnum position)
Will update the position of an Annotation. Returns the number of updated rows. Should be exactly 1 if successful, otherwise there was a problem.

Parameters:
annotationId - annotationId
position - AnnotationStickyPositionEnum
Returns:
Integer.

createEntity

public java.lang.Long createEntity(Annotation entity)
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.