T
- the type of bean classpublic class JpaRepository<T extends Model> extends Object implements Repository<T>
Repository
.Modifier and Type | Field and Description |
---|---|
protected Class<T> |
modelClass |
Modifier | Constructor and Description |
---|---|
protected |
JpaRepository(Class<T> modelClass) |
Modifier and Type | Method and Description |
---|---|
Query<T> |
all()
Get the
Query instance of the managed domain class. |
<U extends T> |
all(Class<U> type)
Get the
Query 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.
|
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> |
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.
|
public List<Property> fields()
Repository
fields
in interface Repository<T extends Model>
Property
public Query<T> all()
Repository
Query
instance of the managed domain class.all
in interface Repository<T extends Model>
Query
public <U extends T> Query<U> all(Class<U> type)
Query
instance of the given type.U
- type of the model classtype
- the subtype of the managed model class.Query
public T create(Map<String,Object> values)
Repository
create
in interface Repository<T extends Model>
values
- the default valuespublic T copy(T entity, boolean deep)
Repository
copy
in interface Repository<T extends Model>
entity
- the entity bean to copydeep
- whether to create a deep copypublic T find(Long id)
Repository
find
in interface Repository<T extends Model>
id
- the record idpublic T save(T entity)
Repository
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.
save
in interface Repository<T extends Model>
entity
- the entity object to savepublic void persist(T entity)
entity
- the entity instanceEntityManager.persist(Object)
public T merge(T entity)
entity
- the entity instanceEntityManager.merge(Object)
public void remove(T entity)
Repository
remove
in interface Repository<T extends Model>
entity
- the entity objectpublic void refresh(T entity)
refresh
in interface Repository<T extends Model>
entity
- the entity instanceEntityManager.refresh(Object)
public void flush()
flush
in interface Repository<T extends Model>
EntityManager.flush()
public Map<String,Object> validate(Map<String,Object> json, Map<String,Object> context)
Repository
This method is called before the json map is converted to model object.
validate
in interface Repository<T extends Model>
json
- the json map to validatecontext
- the contextpublic Map<String,Object> populate(Map<String,Object> json, Map<String,Object> context)
Repository
This method is called before returning the json data as response.
populate
in interface Repository<T extends Model>
json
- the json map to populatecontext
- the contextpublic static <U extends Model> JpaRepository<U> of(Class<U> type)