public class Elastic extends BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
mapper
used to communicate with Elasticsearch.Modifier and Type | Field and Description |
---|---|
protected sirius.kernel.health.Average |
callDuration |
protected Map<EntityDescriptor,Property> |
discriminatorTable |
protected boolean |
dockerDetected |
static ElasticFilterFactory |
FILTERS
Constains the factory used to generate filters for a
ElasticQuery . |
static String |
ID_FIELD
Contains the name of the ID field used by Elasticsearch
|
static sirius.kernel.health.Log |
LOG
Contains the logger used by everything related to Elasticsearch
|
protected sirius.kernel.async.Future |
readyFuture |
protected Map<EntityDescriptor,Property> |
routeTable |
mixing, VERSION
Constructor and Description |
---|
Elastic() |
Modifier and Type | Method and Description |
---|---|
BulkContext |
batch()
Creates a
batch context used for bulk updates. |
protected void |
createEntity(ElasticEntity entity,
EntityDescriptor ed)
Creates a new entity in the underlying database.
|
protected void |
deleteEntity(ElasticEntity entity,
boolean force,
EntityDescriptor ed)
Deletes the give entity from the database.
|
protected String |
determineId(ElasticEntity entity)
Determines the id of the entity.
|
protected String |
determineIndex(EntityDescriptor ed,
ElasticEntity entity)
Determines the index to use for the given entity.
|
protected String |
determineRouting(EntityDescriptor ed,
ElasticEntity entity)
Determines the routing value to be used for the given entity.
|
protected String |
determineTypeName(EntityDescriptor ed)
Determines the type name used for a given entity type.
|
protected String |
determineYearIndex(EntityDescriptor ed,
Object year)
Computes the effective index name for the given descriptor and year.
|
FilterFactory<ElasticConstraint> |
filters()
Returns the filter factory which is used by this mapper.
|
protected <E extends ElasticEntity> |
findEntity(E entity) |
protected <E extends ElasticEntity> |
findEntity(Object id,
EntityDescriptor ed,
Function<String,sirius.kernel.commons.Value> context)
Tries to find the entity with the given id.
|
LowLevelClient |
getLowLevelClient()
Provides access to the underlying low level client.
|
sirius.kernel.async.Future |
getReadyFuture()
Provides a future which is fulfilled once the Elasticsearch client is fully initialized.
|
boolean |
isConfigured()
Determines if an appropriate configuration is available (e.g. a host to connect to).
|
boolean |
isRouted(EntityDescriptor ed)
Determines if the entity of the given descriptor requires a routing value.
|
boolean |
isStoredPerYear(EntityDescriptor descriptor)
Determines if the given entity type is
stored per year . |
protected static ElasticEntity |
make(EntityDescriptor ed,
com.alibaba.fastjson.JSONObject obj)
Creates a new instance of the given entity type for the given data.
|
static ContextInfo |
routedBy(String value)
Provides a "routed by" context for
BaseMapper.find(Class, Object, ContextInfo...) . |
<E extends ElasticEntity> |
select(Class<E> type)
Creates a query for the given type.
|
protected boolean |
toJSON(EntityDescriptor ed,
ElasticEntity entity,
com.alibaba.fastjson.JSONObject data)
Transforms the given entity to JSON.
|
protected void |
updateDiscriminatorTable(EntityDescriptor ed,
Property p) |
protected void |
updateEntity(ElasticEntity entity,
boolean force,
EntityDescriptor ed)
Updates an existing entity in the underlying database.
|
protected void |
updateRouteTable(EntityDescriptor ed,
Property p) |
delete, find, findOrFail, forceDelete, hasValidationWarnings, override, performDelete, performUpdate, refreshOrFail, resolve, resolveOrFail, tryDelete, tryRefresh, tryUpdate, update, validate
public static final sirius.kernel.health.Log LOG
public static final ElasticFilterFactory FILTERS
ElasticQuery
.public static final String ID_FIELD
protected sirius.kernel.async.Future readyFuture
protected sirius.kernel.health.Average callDuration
protected Map<EntityDescriptor,Property> routeTable
protected Map<EntityDescriptor,Property> discriminatorTable
protected boolean dockerDetected
protected void updateRouteTable(EntityDescriptor ed, Property p)
protected void updateDiscriminatorTable(EntityDescriptor ed, Property p)
public sirius.kernel.async.Future getReadyFuture()
public LowLevelClient getLowLevelClient()
protected void createEntity(ElasticEntity entity, EntityDescriptor ed) throws Exception
BaseMapper
createEntity
in class BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
entity
- the entity to createed
- the descriptor of the entityException
- in case of an database error@Nullable protected String determineRouting(EntityDescriptor ed, ElasticEntity entity)
ed
- the entity descriptor of the entityentity
- the entity to fetch the routing value fromprotected void updateEntity(ElasticEntity entity, boolean force, EntityDescriptor ed) throws Exception
BaseMapper
updateEntity
in class BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
entity
- the entity to updateforce
- ture if the update is forced and optimistic locking must be disableded
- the descriptor of the entityException
- in case of an database errorprotected boolean toJSON(EntityDescriptor ed, ElasticEntity entity, com.alibaba.fastjson.JSONObject data)
entity
- the entity to transformed
- the descriptor of the entitydata
- the target JSON to fillprotected String determineId(ElasticEntity entity)
This will either return the stored ID or create a new one, if the entity is still new. If the entity is
stored per year
, the year will be prepended to the ID itself
to determine the index in determineIndex(EntityDescriptor, ElasticEntity)
.
entity
- the entity to determine the id forprotected String determineIndex(EntityDescriptor ed, ElasticEntity entity)
This will either be the relation name
or if the entity is
stored per year
, it will be determined by
determineYearIndex(EntityDescriptor, Object)
.
ed
- the descriptor of the entityentity
- the entity to determine the index forprotected String determineYearIndex(EntityDescriptor ed, Object year)
This will be ed.getRelationName() + "-" + year
ed
- the descriptor of the entityyear
- the year of the indexprotected String determineTypeName(EntityDescriptor ed)
ed
- the descriptor of the entityprotected void deleteEntity(ElasticEntity entity, boolean force, EntityDescriptor ed) throws Exception
BaseMapper
deleteEntity
in class BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
entity
- the entity to deleteforce
- true if the delete is forced and optimistic locking must be disableded
- the descriptor of the entityException
- in case of an database errorprotected static ElasticEntity make(EntityDescriptor ed, com.alibaba.fastjson.JSONObject obj)
ed
- the descriptor of the entity typeobj
- the JSON data to transformpublic static ContextInfo routedBy(String value)
BaseMapper.find(Class, Object, ContextInfo...)
.value
- the routing value to useprotected <E extends ElasticEntity> Optional<E> findEntity(Object id, EntityDescriptor ed, Function<String,sirius.kernel.commons.Value> context) throws Exception
BaseMapper
findEntity
in class BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
E
- the effective type of the entityid
- the id of the entity to finded
- the descriptor of the entity to findcontext
- the advanced search context which can be populated using ContextInfo
in
BaseMapper.find(Class, Object, ContextInfo...)
Exception
- in case of a database errorpublic boolean isRouted(EntityDescriptor ed)
ed
- the descriptor of the entity to checkprotected <E extends ElasticEntity> Optional<E> findEntity(E entity)
findEntity
in class BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
public BulkContext batch()
batch context
used for bulk updates.public boolean isConfigured()
public boolean isStoredPerYear(EntityDescriptor descriptor)
stored per year
.descriptor
- the descriptor of the entity typepublic <E extends ElasticEntity> ElasticQuery<E> select(Class<E> type)
BaseMapper
select
in class BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
E
- the generic type of entities to be returnedtype
- the type of entities to query for.public FilterFactory<ElasticConstraint> filters()
BaseMapper
filters
in class BaseMapper<ElasticEntity,ElasticConstraint,ElasticQuery<? extends ElasticEntity>>
Copyright © 2018. All rights reserved.