Package com.logicaldoc.core.metadata

# Class HibernateTemplateDAO

java.lang.Object
com.logicaldoc.core.HibernatePersistentObjectDAO<Template>
com.logicaldoc.core.metadata.HibernateTemplateDAO

All Implemented Interfaces:
  `TemplateDAO`, `PersistentObjectDAO<Template>`

@Repository("templateDAO") public class HibernateTemplateDAO extends HibernatePersistentObjectDAO<Template> implements TemplateDAO
Hibernate implementation of `TemplateDAO`

Since:
  3.0
Author:
  Marco Meschieri - LogicalDOC

## Field Summary

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

`ENTITY`

## Constructor Summary

Constructors
Constructor
Description
`HibernateTemplateDAO()`

## Method Summary

Modifier and Type
Method
Description
`Template`
`clone(long id, String cloneName)`
Creates a clone of an existing template
`long`
`countDocs(long id)`
Counts the total number of documents using this template
`long`
`countFolders(long id)`
Counts the total number of folders using this template
`void`
`delete(long id, int code)`
This method deletes an entity and you can give a deletion code
`List<Template>`
`findAll()`
Finds all entities in the database
`List<Template>`
`findAll(long tenantId)`
Finds all entities in a specific tenant.
`Template`
`findByName(String name, long tenantId)`
This method finds a template by name
`List<Template>`
`findByType(int type, long tenantId)`
This method finds a template by type
`Set<Permission>`
`getAllowedPermissions(long templateId, long userId)`
Finds all permissions of a user enabled on the specified template
`void`
`initialize(Template template)`
Doesn't do anything by default
`boolean`
`isReadEnable(long templateId, long userId)`
This method is looking up for read rights for a template and an user
`boolean`
`isWriteEnable(long templateId, long userId)`
Returns if a template is writable for a user
`void`
`store(Template template)`
This method persists the entity object

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

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

### 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, findAllIds, findAllIds, findById, findById, findByObjectQuery, findByQuery, findByQuery, findByWhere, findByWhere, findIdsByWhere, findIdsByWhere, getDatabaseMetadata, getDbms, initialize, isMariaDB, isMySQL, isOracle, isPostgreSQL, isSQLServer, jdbcUpdate, jdbcUpdate, query, query, queryForDouble, queryForDouble, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForObject, queryForObject, queryForResultSet, queryForString, queryForString`

## Constructor Details

### HibernateTemplateDAO

public HibernateTemplateDAO()

## Method Details

### findAll

public List<Template> findAll()
Description copied from interface: `PersistentObjectDAO`
Finds all entities in the database

Specified by:
  `findAll` in interface `PersistentObjectDAO<Template>`
Returns:
  The list of all entities

### findAll

public List<Template> findAll(long tenantId)
Description copied from interface: `PersistentObjectDAO`
Finds all entities in a specific tenant.

Specified by:
  `findAll` in interface `PersistentObjectDAO<Template>`
Parameters:
  `tenantId` - Identifier of the tenant to search in
Returns:
  The list of all entities

### findByName

public Template findByName(String name, long tenantId) throws PersistenceException
Description copied from interface: `TemplateDAO`
This method finds a template by name

Specified by:
  `findByName` in interface `TemplateDAO`
Parameters:
  `name` - Name of the template
  `tenantId` - ID of the owning tenant
Returns:
  Template with given name
Throws:
  `PersistenceException` - Error in the data layer

### 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<Template>`
Overrides:
  `delete` in class `HibernatePersistentObjectDAO<Template>`
Parameters:
  `id` - ID of the entity which should be deleted
  `code` - Deletion code
Throws:
  `PersistenceException` - raised in case of errors in the database

### store

public void store(Template template) throws PersistenceException
Description copied from interface: `PersistentObjectDAO`
This method persists the entity object

Specified by:
  `store` in interface `PersistentObjectDAO<Template>`
Overrides:
  `store` in class `HibernatePersistentObjectDAO<Template>`
Parameters:
  `template` - entity to be stored
Throws:
  `PersistenceException` - raised in case of errors in the database

### countFolders

public long countFolders(long id)
Description copied from interface: `TemplateDAO`
Counts the total number of folders using this template

Specified by:
  `countFolders` in interface `TemplateDAO`
Parameters:
  `id` - The template ID
Returns:
  the folders count

### countDocs

public long countDocs(long id) throws PersistenceException
Description copied from interface: `TemplateDAO`
Counts the total number of documents using this template

Specified by:
  `countDocs` in interface `TemplateDAO`
Parameters:
  `id` - The template ID
Returns:
  the documents count
Throws:
  `PersistenceException` - Error in the data layer

### findByType

public List<Template> findByType(int type, long tenantId) throws PersistenceException
Description copied from interface: `TemplateDAO`
This method finds a template by type

Specified by:
  `findByType` in interface `TemplateDAO`
Parameters:
  `type` - Type of the template
  `tenantId` - ID of the owning tenant
Returns:
  Template with given type
Throws:
  `PersistenceException` - Error in the data layer

### initialize

public void initialize(Template template)
Description copied from class: `HibernatePersistentObjectDAO`
Doesn't do anything by default

Specified by:
  `initialize` in interface `PersistentObjectDAO<Template>`
Specified by:
  `initialize` in interface `TemplateDAO`
Overrides:
  `initialize` in class `HibernatePersistentObjectDAO<Template>`
Parameters:
  `template` - The entity to be initialised

### isWriteEnable

public boolean isWriteEnable(long templateId, long userId)
Description copied from interface: `TemplateDAO`
Returns if a template is writable for a user

Specified by:
  `isWriteEnable` in interface `TemplateDAO`
Parameters:
  `templateId` - check this template
  `userId` - privileges for this should be checked
Returns:
  if the user can edit the template

### isReadEnable

public boolean isReadEnable(long templateId, long userId)
Description copied from interface: `TemplateDAO`
This method is looking up for read rights for a template and an user

Specified by:
  `isReadEnable` in interface `TemplateDAO`
Parameters:
  `templateId` - ID of the template
  `userId` - ID of the user
Returns:
  if the user can access the template

### getAllowedPermissions

public Set<Permission> getAllowedPermissions(long templateId, long userId)
Description copied from interface: `TemplateDAO`
Finds all permissions of a user enabled on the specified template

Specified by:
  `getAllowedPermissions` in interface `TemplateDAO`
Parameters:
  `templateId` - ID of the template
  `userId` - ID of the user
Returns:
  Collection of enabled permissions

### clone

public Template clone(long id, String cloneName) throws PersistenceException
Description copied from interface: `TemplateDAO`
Creates a clone of an existing template

Specified by:
  `clone` in interface `TemplateDAO`
Parameters:
  `id` - Identifier of the original template
  `cloneName` - Name of the cloned template
Returns:
  the created clone
Throws:
  `PersistenceException` - Error in the data layer