I
- The ID typeT
- The Bean typepublic abstract class BeanRepository<I,T> extends BeanFinder<I,T>
@Repository
public class CustomerRepository extends BeanRepository<Long,Customer> {
@Inject
public CustomerRepository(EbeanServer server) {
super(Customer.class, server);
}
// ... add customer specific finders and persist logic
public List<Customer> findByName(String nameStart) {
return query().where()
.istartsWith("name", nameStart)
.findList();
}
}
Modifier and Type | Method and Description |
---|---|
boolean |
delete(T bean)
Delete this bean.
|
int |
deleteAll(Collection<T> beans)
Delete all the beans in the collection.
|
boolean |
deletePermanent(T bean)
Delete a bean permanently without soft delete.
|
void |
insert(T bean)
Insert this entity.
|
void |
markAsDirty(T bean)
Marks the entity bean as dirty.
|
void |
markPropertyUnset(T bean,
String propertyName)
Mark the property as unset or 'not loaded'.
|
void |
merge(T bean)
Merge this entity using the default merge options.
|
void |
merge(T bean,
MergeOptions options)
Merge this entity using the specified merge options.
|
void |
refresh(T bean)
Refreshes this entity from the database.
|
void |
save(T bean)
Insert or update this entity depending on its state.
|
int |
saveAll(Collection<T> bean)
Save all the beans in the collection.
|
void |
update(T bean)
Update this entity.
|
currentTransaction, db, db, deleteById, findAll, findById, findByIdOrEmpty, flush, ref
public void markAsDirty(T bean)
This is used so that when a bean that is otherwise unmodified is updated the version property is updated.
An unmodified bean that is saved or updated is normally skipped and this marks the bean as dirty so that it is not skipped.
Customer customer = customerRepository.byId(id);
// mark the bean as dirty so that a save() or update() will
// increment the version property
customerRepository.markAsDirty(customer);
customerRepository.save(customer);
Database.markAsDirty(Object)
public void markPropertyUnset(T bean, String propertyName)
This would be used to specify a property that we did not wish to include in a stateless update.
// populate an entity bean from JSON or whatever
Customer customer = ...;
// mark the email property as 'unset' so that it is not
// included in a 'stateless update'
customerRepository.markPropertyUnset(customer, "email");
customerRepository.update(customer);
propertyName
- the name of the property on the bean to be marked as 'unset'public void save(T bean)
Ebean will detect if this is a new bean or a previously fetched bean and perform either an insert or an update based on that.
Database.save(Object)
public int saveAll(Collection<T> bean)
public void update(T bean)
Database.update(Object)
public void insert(T bean)
Database.insert(Object)
public boolean delete(T bean)
This will return true if the bean was deleted successfully or JDBC batch is being used.
If there is no current transaction one will be created and committed for you automatically.
If the Bean does not have a version property (or loaded version property) and the bean does not exist then this returns false indicating that nothing was deleted. Note that, if JDBC batch mode is used then this always returns true.
Database.delete(Object)
public int deleteAll(Collection<T> beans)
public boolean deletePermanent(T bean)
This is used when the bean contains a @SoftDelete
property and we
want to perform a hard/permanent delete.
Database.deletePermanent(Object)
public void merge(T bean)
Ebean will detect if this is a new bean or a previously fetched bean and perform either an insert or an update based on that.
Database.merge(Object)
public void merge(T bean, MergeOptions options)
Ebean will detect if this is a new bean or a previously fetched bean and perform either an insert or an update based on that.
Database.merge(Object, MergeOptions)
public void refresh(T bean)
Database.refresh(Object)
Copyright © 2019. All rights reserved.