ENTITY
- entity typepublic abstract class AbstractManager<ENTITY> extends Object implements Manager<ENTITY>
Managers
.
This default implementation uses the plugged in
StreamSupplierComponent
and PersistenceComponent
to stream
over entities and make changes to them in the data store. It also installs
itself in the plugged in ManagerComponent
.
StreamSupplierComponent
,
PersistenceComponent
,
ManagerComponent
Modifier | Constructor and Description |
---|---|
protected |
AbstractManager() |
Modifier and Type | Method and Description |
---|---|
ENTITY |
persist(ENTITY entity)
Persists the provided entity to the underlying database and returns a
potentially updated entity.
|
Persister<ENTITY> |
persister()
Returns a
Persister that when its
Persister.apply(java.lang.Object) method is called, will produce
the same result as Manager.persist(java.lang.Object) |
ENTITY |
remove(ENTITY entity)
Removes the provided entity from the underlying database and returns the
provided entity instance.
|
Remover<ENTITY> |
remover()
Returns a
Remover that when its
Persister.apply(java.lang.Object) method is called, will produce
the same result as Manager.remove(java.lang.Object) |
Stream<ENTITY> |
stream()
Creates and returns a new
Stream over all entities in the
underlying database. |
ENTITY |
update(ENTITY entity)
Updates the provided entity in the underlying database and returns a
potentially updated entity.
|
Updater<ENTITY> |
updater()
Returns an
Updater that when its
Persister.apply(java.lang.Object) method is called, will produce
the same result as Manager.update(java.lang.Object) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
fields, findBackwardsBy, findBy, findByNullable, finderBackwardsBy, finderBy, finderByNullable, getEntityClass, getTableIdentifier, primaryKeyFields
public Stream<ENTITY> stream()
Manager
Stream
over all entities in the
underlying database. This is the main query API for Speedment.
This is an inexpensive O(1) operation that will complete in constant time regardless of the number of entities in the underlying database.
The returned stream is aware of its own pipeline and will optimize its own pipeline whenever it encounters a Terminal Operation so that it will only iterate over a minimum set of matching entities.
When a Terminal Operation is eventually called on the Stream
,
that execution time of the Terminal Operation will depend on the
optimized pipeline and the entities in the underlying database.
The Stream will be automatically
closed
after the Terminal
Operation is completed or if an Exception is thrown during the Terminal
Operation.
Some of the Terminal Operations are:
forEach(Consumer)
forEachOrdered(Consumer)
toArray()
toArray(IntFunction)
reduce(BinaryOperation
reduce(Object, BinaryOperator)
reduce(Object, BiFunction, BinaryOperator)
collect(Collector)
collect(Supplier, BiConsumer, BiConsumer)
min(Comparator)
min(Comparator)
count()
anyMatch(Predicate)
noneMatch(Predicate)
findFirst()
findAny()
iterator()
Any Terminating Operation may throw a SpeedmentException
if the
underlying database throws an Exception (e.g. an SqlException)
Because the Stream may short-circuit operations in the Stream pipeline,
methods having side-effects (like
peek(Consumer)
will
potentially be affected by the optimization.
Here are some examples of how the stream optimization might work:
stream
.filter(Hare.NAME.equal("Henry")
.collect(toList());
-> select * from hares where name='Henry'
stream.count();
-> select count(*) from hares
stream
.filter(Hare.NAME.equal("Henry")
.count();
-> select count(*) from hares where
name='Henry'
stream
.filter(Hare.NAME.equal("Henry")
.filter(Hare.AGE.greaterThan(5)
.count();
-> select count(*) from hares where
name ='Henry'
and
age > 5
stream
in interface Manager<ENTITY>
java.util.stream
,
Stream
public final ENTITY persist(ENTITY entity) throws SpeedmentException
Manager
SpeedmentException
is thrown.
It is unspecified if the returned updated entity is the same provided entity instance or another entity instance. It is erroneous to assume either, so you should use only the returned entity after the method has been called. However, it is guaranteed that the provided entity is untouched if an exception is thrown.
The fields of returned entity instance may differ from the provided entity fields due to auto generated column(s) or because of any other modification that the underlying database imposed on the persisted entity.
persist
in interface Manager<ENTITY>
entity
- to persistSpeedmentException
- if the underlying database throws an exception
(e.g. SQLException)public Persister<ENTITY> persister()
Manager
Persister
that when its
Persister.apply(java.lang.Object)
method is called, will produce
the same result as Manager.persist(java.lang.Object)
public final ENTITY update(ENTITY entity) throws SpeedmentException
Manager
SpeedmentException
is thrown.
It is unspecified if the returned updated entity is the same provided entity instance or another entity instance. It is erroneous to assume either, so you should use only the returned entity after the method has been called. However, it is guaranteed that the provided entity is untouched if an exception is thrown.
The fields of returned entity instance may differ from the provided entity fields due to auto generated column(s) or because of any other modification that the underlying database imposed on the persisted entity.
Entities are uniquely identified by their primary key(s).
update
in interface Manager<ENTITY>
entity
- to updateSpeedmentException
- if the underlying database throws an exception
(e.g. SQLException)public Updater<ENTITY> updater()
Manager
Updater
that when its
Persister.apply(java.lang.Object)
method is called, will produce
the same result as Manager.update(java.lang.Object)
public final ENTITY remove(ENTITY entity) throws SpeedmentException
Manager
SpeedmentException
is thrown.
Entities are uniquely identified by their primary key(s).
remove
in interface Manager<ENTITY>
entity
- to removeSpeedmentException
- if the underlying database throws an exception
(e.g. SQLException)public Remover<ENTITY> remover()
Manager
Remover
that when its
Persister.apply(java.lang.Object)
method is called, will produce
the same result as Manager.remove(java.lang.Object)
Copyright © 2016 Speedment, Inc.. All rights reserved.