Package com.axelor.db
Class JpaRepository<T extends Model>
- java.lang.Object
-
- com.axelor.db.JpaRepository<T>
-
- Type Parameters:
T
- the type of bean class
- All Implemented Interfaces:
Repository<T>
- Direct Known Subclasses:
AbstractMetaJsonModelRepository
,AbstractUserRepository
,DMSFileRepository
,DMSFileTagRepository
,DMSPermissionRepository
,GroupRepository
,MailAddressRepository
,MailFlagsRepository
,MailFollowerRepository
,MailMessageRepository
,MetaActionMenuRepository
,MetaActionRepository
,MetaAttachmentRepository
,MetaAttrsRepository
,MetaEnumRepository
,MetaFieldRepository
,MetaFileRepository
,MetaFilterRepository
,MetaHelpRepository
,MetaJsonFieldRepository
,MetaJsonRecordRepository
,MetaMenuRepository
,MetaModelRepository
,MetaModuleRepository
,MetaPermissionRepository
,MetaPermissionRuleRepository
,MetaScheduleParamRepository
,MetaScheduleRepository
,MetaSelectItemRepository
,MetaSelectRepository
,MetaSequenceRepository
,MetaTranslationRepository
,MetaViewCustomRepository
,MetaViewRepository
,PasswordResetTokenRepository
,PermissionRepository
,RoleRepository
,TeamRepository
,TeamTaskRepository
,TeamTopicRepository
public class JpaRepository<T extends Model> extends Object implements Repository<T>
The JPA implementation of theRepository
.
-
-
Field Summary
Fields Modifier and Type Field Description protected Class<T>
modelClass
-
Constructor Summary
Constructors Modifier Constructor Description protected
JpaRepository(Class<T> modelClass)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Query<T>
all()
Get theQuery
instance of the managed domain class.<U extends T>
Query<U>all(Class<U> type)
Get theQuery
instance of the given type.T
copy(T entity, boolean deep)
Create a duplicate copy of the given entity.
In case of deep copy, one-to-many records are duplicated.T
create(Map<String,Object> values)
Create a new instance of the domain model with the given default values.List<Property>
fields()
Return list of properties on the domain model managed by this repository.T
find(Long id)
Find by primary key.List<T>
findByIds(List<Long> ids)
Find multiple entities by their primary key.void
flush()
Synchronize the persistence context to the underlying database.T
merge(T entity)
Merge the state of the given entity into the current persistence context.static <U extends Model>
JpaRepository<U>of(Class<U> type)
void
persist(T entity)
Make an entity managed and persistent.Map<String,Object>
populate(Map<String,Object> json, Map<String,Object> context)
Populate the given json map with additional data.void
refresh(T entity)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any.void
remove(T entity)
Remove the given entity.T
save(T entity)
Save the given entity.Map<String,Object>
validate(Map<String,Object> json, Map<String,Object> context)
Validate the given json map before persisting.
-
-
-
Method Detail
-
fields
public List<Property> fields()
Description copied from interface:Repository
Return list of properties on the domain model managed by this repository.- Specified by:
fields
in interfaceRepository<T extends Model>
- Returns:
- list of
Property
-
all
public Query<T> all()
Description copied from interface:Repository
Get theQuery
instance of the managed domain class.- Specified by:
all
in interfaceRepository<T extends Model>
- Returns:
- instance of
Query
-
all
public <U extends T> Query<U> all(Class<U> type)
Get theQuery
instance of the given type.- Type Parameters:
U
- type of the model class- Parameters:
type
- the subtype of the managed model class.- Returns:
- instance of
Query
-
create
public T create(Map<String,Object> values)
Description copied from interface:Repository
Create a new instance of the domain model with the given default values.- Specified by:
create
in interfaceRepository<T extends Model>
- Parameters:
values
- the default values- Returns:
- an instance of the domain model managed by this repository
-
copy
public T copy(T entity, boolean deep)
Description copied from interface:Repository
Create a duplicate copy of the given entity.
In case of deep copy, one-to-many records are duplicated. Otherwise, one-to-many records will be skipped.- Specified by:
copy
in interfaceRepository<T extends Model>
- Parameters:
entity
- the entity bean to copydeep
- whether to create a deep copy- Returns:
- a copy of the given entity
-
find
public T find(Long id)
Description copied from interface:Repository
Find by primary key.- Specified by:
find
in interfaceRepository<T extends Model>
- Parameters:
id
- the record id- Returns:
- a domain object found by the given id, null otherwise
-
findByIds
public List<T> findByIds(List<Long> ids)
Description copied from interface:Repository
Find multiple entities by their primary key.- Specified by:
findByIds
in interfaceRepository<T extends Model>
- Parameters:
ids
- The ids to load- Returns:
- list of all the matched records
-
save
public T save(T entity)
Description copied from interface:Repository
Save the given entity.Depending on the implementation, it may return same entity or a copy of it. For example JPA implementation may return a copy if the given entity can't be managed.
- Specified by:
save
in interfaceRepository<T extends Model>
- Parameters:
entity
- the entity object to save- Returns:
- an instance of the entity with saved state
-
persist
public void persist(T entity)
Make an entity managed and persistent.- Parameters:
entity
- the entity instance- See Also:
EntityManager.persist(Object)
-
merge
public T merge(T entity)
Merge the state of the given entity into the current persistence context.- Parameters:
entity
- the entity instance- Returns:
- the managed instance
- See Also:
EntityManager.merge(Object)
-
remove
public void remove(T entity)
Description copied from interface:Repository
Remove the given entity.- Specified by:
remove
in interfaceRepository<T extends Model>
- Parameters:
entity
- the entity object
-
refresh
public void refresh(T entity)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any.- Specified by:
refresh
in interfaceRepository<T extends Model>
- Parameters:
entity
- the entity instance- See Also:
EntityManager.refresh(Object)
-
flush
public void flush()
Synchronize the persistence context to the underlying database.- Specified by:
flush
in interfaceRepository<T extends Model>
- See Also:
EntityManager.flush()
-
validate
public Map<String,Object> validate(Map<String,Object> json, Map<String,Object> context)
Description copied from interface:Repository
Validate the given json map before persisting.This method is called before the json map is converted to model object.
- Specified by:
validate
in interfaceRepository<T extends Model>
- Parameters:
json
- the json map to validatecontext
- the context- Returns:
- validated json map
-
populate
public Map<String,Object> populate(Map<String,Object> json, Map<String,Object> context)
Description copied from interface:Repository
Populate the given json map with additional data.This method is called before returning the json data as response.
- Specified by:
populate
in interfaceRepository<T extends Model>
- Parameters:
json
- the json map to populatecontext
- the context- Returns:
- the json map itself
-
of
public static <U extends Model> JpaRepository<U> of(Class<U> type)
-
-