ENTITY
- entity type for this Managerpublic interface Manager<ENTITY>
Modifier and Type | Method and Description |
---|---|
Stream<Field<ENTITY>> |
fields()
Returns a stream of the fields that every entity in this
Manager
contains. |
default <FK_ENTITY> |
findBackwardsBy(HasFinder<ENTITY,FK_ENTITY> fkField,
FK_ENTITY fkEntity)
Retrieves and returns a stream of matching entities that matches the
given a foreign key relation (foreign field and entity).
|
default <FK_ENTITY> |
findBy(HasFinder<FK_ENTITY,ENTITY> fkField,
FK_ENTITY fkEntity)
Retrieves and returns an Entity that matches the given a foreign key
relation (foreign field and entity).
|
default <FK_ENTITY> |
findByNullable(HasNullableFinder<FK_ENTITY,ENTITY> fkField,
FK_ENTITY fkEntity)
Retrieves and returns a stream of Entities (with one or zero elements)
that matches the given a foreign key relation (foreign field and entity).
|
default <FK_ENTITY> |
finderBackwardsBy(HasFinder<ENTITY,FK_ENTITY> fkField)
Returns a Function that, when it is applied, will produce an equivalent
result as if
findBackwardsBy(HasFinder, Object) was called. |
default <FK_ENTITY> |
finderBy(HasFinder<FK_ENTITY,ENTITY> fkField)
Returns a Function that, when it is applied, will produce an equivalent
result as if
finderByNullable(HasNullableFinder) was called. |
default <FK_ENTITY> |
finderByNullable(HasNullableFinder<FK_ENTITY,ENTITY> fkField)
Returns a Function that, when it is applied, will produce an equivalent
result as if
findByNullable(HasNullableFinder, Object) was
called. |
Class<ENTITY> |
getEntityClass()
Returns the entity class for this Manager.
|
TableIdentifier<ENTITY> |
getTableIdentifier()
Returns an identifier for the table that this
Manager handles
entities for. |
default 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 persist(java.lang.Object) |
Stream<Field<ENTITY>> |
primaryKeyFields()
Returns a stream of the fields that are included in the primary key of
the table represented by this
Manager . |
default 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(Object)
method is called, will produce the same result as remove(Object) |
Stream<ENTITY> |
stream()
Creates and returns a new
Stream over all entities in the
underlying data source (e.g database). |
default 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(Object)
method is called, will produce the same result as update(Object) |
TableIdentifier<ENTITY> getTableIdentifier()
Manager
handles
entities for.Class<ENTITY> getEntityClass()
Stream<Field<ENTITY>> fields()
Manager
contains.Stream<Field<ENTITY>> primaryKeyFields()
Manager
.Stream<ENTITY> stream()
Stream
over all entities in the
underlying data source (e.g database). This is the main query API for
Speedment.
The order in which elements are returned when the stream is eventually consumed is unspecified. The order may even change from one invocation to another. Thus, it is an error to assume any particular element order even though is might appear, for some stream sources, that there is a de-facto order.
If a deterministic order is required, then make sure to invoke the
Stream.sorted(java.util.Comparator)
method on the Stream
returned.
Mutable elements are not reused within the stream. More formally, there
are no pair of mutable stream elements e1
and
e2
such that e1 == e2
.
The Stream will never contain null
elements.
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 optionally 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
SpeedmentException
- if an error occurs during a Terminal Operation
(e.g. an SqlException is thrown by the underlying database)java.util.stream
,
Stream
default ENTITY persist(ENTITY entity) throws SpeedmentException
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.
entity
- to persistSpeedmentException
- if the underlying database throws an exception
(e.g. SQLException)Persister<ENTITY> persister()
Persister
that when its
Persister.apply(java.lang.Object)
method is called, will produce
the same result as persist(java.lang.Object)
default ENTITY update(ENTITY entity) throws SpeedmentException
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).
entity
- to updateSpeedmentException
- if the underlying database throws an exception
(e.g. SQLException)Updater<ENTITY> updater()
Updater
that when its Persister.apply(Object)
method is called, will produce the same result as update(Object)
default ENTITY remove(ENTITY entity) throws SpeedmentException
SpeedmentException
is thrown.
Entities are uniquely identified by their primary key(s).
entity
- to removeSpeedmentException
- if the underlying database throws an exception
(e.g. SQLException)Remover<ENTITY> remover()
Remover
that when its Persister.apply(Object)
method is called, will produce the same result as remove(Object)
default <FK_ENTITY> FindFrom<FK_ENTITY,ENTITY> finderBy(HasFinder<FK_ENTITY,ENTITY> fkField)
finderByNullable(HasNullableFinder)
was called.FK_ENTITY
- the type of the foreign entityfkField
- the foreign key fieldfinderByNullable(HasNullableFinder)
default <FK_ENTITY> ENTITY findBy(HasFinder<FK_ENTITY,ENTITY> fkField, FK_ENTITY fkEntity)
FK_ENTITY
- the type of the foreign entityfkField
- the foreign key fieldfkEntity
- the foreign key entitydefault <FK_ENTITY> Function<FK_ENTITY,Stream<ENTITY>> finderByNullable(HasNullableFinder<FK_ENTITY,ENTITY> fkField)
findByNullable(HasNullableFinder, Object)
was
called.FK_ENTITY
- the type of the foreign entityfkField
- the foreign key fieldfindByNullable(HasNullableFinder, Object)
default <FK_ENTITY> Stream<ENTITY> findByNullable(HasNullableFinder<FK_ENTITY,ENTITY> fkField, FK_ENTITY fkEntity)
FK_ENTITY
- the type of the foreign entityfkField
- the foreign key fieldfkEntity
- the foreign key entitydefault <FK_ENTITY> BackwardFinder<FK_ENTITY,ENTITY> finderBackwardsBy(HasFinder<ENTITY,FK_ENTITY> fkField)
findBackwardsBy(HasFinder, Object)
was called.FK_ENTITY
- the type of the foreign entityfkField
- the foreign key fieldfindBackwardsBy(HasFinder, Object)
default <FK_ENTITY> Stream<ENTITY> findBackwardsBy(HasFinder<ENTITY,FK_ENTITY> fkField, FK_ENTITY fkEntity)
FK_ENTITY
- the type of the foreign entityfkField
- the foreign key fieldfkEntity
- the foreign key entityCopyright © 2018 Speedment, Inc.. All rights reserved.