- java.lang.Object
-
- io.ebean.BeanFinder<I,T>
-
- io.ebean.BeanRepository<I,T>
-
- Type Parameters:
I- The ID typeT- The Bean type
@NonNullApi public abstract class BeanRepository<I,T> extends BeanFinder<I,T>
Provides find and persist functionality for use with "Dependency Injection style" use of Ebean.Extend the BeanRepository with additional finder and persisting methods as needed by the application. The intention is to keep all the related logic together, for example, all the persisting and finding logic for Customer would be in CustomerRepository.
{@code
-
-
Field Summary
-
Fields inherited from class io.ebean.BeanFinder
database, server, type
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBeanRepository(Class<T> type, Database database)Create with the given bean type and Database instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandelete(T bean)Delete this bean.intdeleteAll(Collection<T> beans)Delete all the beans in the collection.booleandeletePermanent(T bean)Delete a bean permanently without soft delete.voidinsert(T bean)Insert this entity.voidmarkAsDirty(T bean)Marks the entity bean as dirty.voidmarkPropertyUnset(T bean, String propertyName)Mark the property as unset or 'not loaded'.voidmerge(T bean)Merge this entity using the default merge options.voidmerge(T bean, MergeOptions options)Merge this entity using the specified merge options.voidrefresh(T bean)Refreshes this entity from the database.voidsave(T bean)Insert or update this entity depending on its state.intsaveAll(Collection<T> beans)Save all the beans in the collection.voidupdate(T bean)Update this entity.-
Methods inherited from class io.ebean.BeanFinder
currentTransaction, db, db, deleteById, findAll, findById, findByIdOrEmpty, flush, nativeSql, query, query, ref, updateQuery
-
-
-
-
Constructor Detail
-
BeanRepository
protected BeanRepository(Class<T> type, Database database)
Create with the given bean type and Database instance.Typically users would extend BeanRepository rather than BeanFinder.
{@code- Parameters:
type- The bean typedatabase- The Database instance typically created via Spring factory or equivalent
-
-
Method Detail
-
markAsDirty
public void markAsDirty(T bean)
Marks the entity bean as dirty.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);- See Also:
Database.markAsDirty(Object)
-
markPropertyUnset
public void markPropertyUnset(T bean, String propertyName)
Mark the property as unset or 'not loaded'.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);- Parameters:
propertyName- the name of the property on the bean to be marked as 'unset'
-
save
public void save(T bean)
Insert or update this entity depending on its state.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.
- See Also:
Database.save(Object)
-
saveAll
public int saveAll(Collection<T> beans)
Save all the beans in the collection.
-
update
public void update(T bean)
Update this entity.- See Also:
Database.update(Object)
-
insert
public void insert(T bean)
Insert this entity.- See Also:
Database.insert(Object)
-
delete
public boolean delete(T bean)
Delete this 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.
- See Also:
Database.delete(Object)
-
deleteAll
public int deleteAll(Collection<T> beans)
Delete all the beans in the collection.
-
deletePermanent
public boolean deletePermanent(T bean)
Delete a bean permanently without soft delete.This is used when the bean contains a
@SoftDeleteproperty and we want to perform a hard/permanent delete.- See Also:
Database.deletePermanent(Object)
-
merge
public void merge(T bean)
Merge this entity using the default merge 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.
- See Also:
Database.merge(Object)
-
merge
public void merge(T bean, MergeOptions options)
Merge this entity using the specified merge 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.
- See Also:
Database.merge(Object, MergeOptions)
-
refresh
public void refresh(T bean)
Refreshes this entity from the database.- See Also:
Database.refresh(Object)
-
-