Package com.logicaldoc.core.document

# Class HibernateRatingDAO

java.lang.Object
com.logicaldoc.core.HibernatePersistentObjectDAO<Rating>
com.logicaldoc.core.document.HibernateRatingDAO

All Implemented Interfaces:
  `RatingDAO`, `PersistentObjectDAO<Rating>`

@Repository("ratingDAO") public class HibernateRatingDAO extends HibernatePersistentObjectDAO<Rating> implements RatingDAO
Hibernate implementation of `RatingDAO`

Since:
  6.1
Author:
  Matteo Caruso - LogicalDOC

## Field Summary

### Fields inherited from interface com.logicaldoc.core.PersistentObjectDAO

`ENTITY`

## Constructor Summary

Constructors
Constructor
Description
`HibernateRatingDAO()`

## Method Summary

Modifier and Type
Method
Description
`void`
`delete(long id, int code)`
This method deletes an entity and you can give a deletion code
`List<Rating>`
`findByDocId(long docId)`
Finds the ratings stored for the given document id
`Rating`
`findByDocIdAndUserId(long docId, long userId)`
Finds the rating for the given user id and the given document id
`Rating`
`findVotesByDocId(long docId)`
Returns a rating that contains count and average of vote on the given document
`void`
`store(Rating rating, DocumentHistory transaction)`
Stores a rating and saves the document's history
`int`
`updateDocumentRating(long docId, DocumentHistory transaction)`
Updates the document's rating with the votes average

### Methods inherited from class com.logicaldoc.core.HibernatePersistentObjectDAO

`bulkUpdate, count, deleteAll, evict, evict, findById, findByObjectQuery, findByQuery, findByQuery, findByWhere, findIdsByWhere, getDatabaseMetadata, initialize, jdbcUpdate, jdbcUpdate, query, queryForDouble, queryForDouble, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForObject, queryForObject, queryForResultSet, queryForString, queryForString, setSessionFactory, store`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface com.logicaldoc.core.PersistentObjectDAO

`bulkUpdate, count, count, count, delete, deleteAll, deleteAll, evict, evict, findAll, findAll, findAllIds, findAllIds, findById, findById, findByObjectQuery, findByQuery, findByQuery, findByWhere, findByWhere, findIdsByWhere, findIdsByWhere, getDatabaseMetadata, getDbms, initialize, initialize, isMariaDB, isMySQL, isOracle, isPostgreSQL, isSQLServer, jdbcUpdate, jdbcUpdate, query, query, queryForDouble, queryForDouble, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForObject, queryForObject, queryForResultSet, queryForString, queryForString, store`

## Constructor Details

### HibernateRatingDAO

public HibernateRatingDAO()

## Method Details

### store

public void store(Rating rating, DocumentHistory transaction) throws PersistenceException
Description copied from interface: `RatingDAO`
Stores a rating and saves the document's history

Specified by:
  `store` in interface `RatingDAO`
Parameters:
  `rating` - the rating
  `transaction` - session informations
Throws:
  `PersistenceException` - error at data layer

### updateDocumentRating

public int updateDocumentRating(long docId, DocumentHistory transaction) throws PersistenceException
Description copied from interface: `RatingDAO`
Updates the document's rating with the votes average

Specified by:
  `updateDocumentRating` in interface `RatingDAO`
Parameters:
  `docId` - Identifier of the document
  `transaction` - session informations
Returns:
  the new rating
Throws:
  `PersistenceException` - raised in case of database error

### findVotesByDocId

public Rating findVotesByDocId(long docId) throws PersistenceException
Description copied from interface: `RatingDAO`
Returns a rating that contains count and average of vote on the given document

Specified by:
  `findVotesByDocId` in interface `RatingDAO`
Parameters:
  `docId` - ID of the document
Returns:
  the rating for the document
Throws:
  `PersistenceException` - Error in the database

### findByDocIdAndUserId

public Rating findByDocIdAndUserId(long docId, long userId) throws PersistenceException
Description copied from interface: `RatingDAO`
Finds the rating for the given user id and the given document id

Specified by:
  `findByDocIdAndUserId` in interface `RatingDAO`
Parameters:
  `docId` - ID of the document
  `userId` - ID of the user
Returns:
  the vote of the given user on the document
Throws:
  `PersistenceException` - Error in the database

### findByDocId

public List<Rating> findByDocId(long docId) throws PersistenceException
Description copied from interface: `RatingDAO`
Finds the ratings stored for the given document id

Specified by:
  `findByDocId` in interface `RatingDAO`
Parameters:
  `docId` - ID of the document
Returns:
  the list of ratings
Throws:
  `PersistenceException` - Error in the database

### delete

public void delete(long id, int code) throws PersistenceException
Description copied from interface: `PersistentObjectDAO`
This method deletes an entity and you can give a deletion code

Specified by:
  `delete` in interface `PersistentObjectDAO<Rating>`
Overrides:
  `delete` in class `HibernatePersistentObjectDAO<Rating>`
Parameters:
  `id` - ID of the entity which should be deleted
  `code` - Deletion code
Throws:
  `PersistenceException` - raised in case of errors in the database