public class InstanceLoaderImpl<E extends Entity> extends java.lang.Object implements InstanceLoader<E>
InstanceLoader.PostLoadEvent<T extends Entity>, InstanceLoader.PreLoadEvent<T extends Entity>
Modifier and Type | Field and Description |
---|---|
protected Condition |
condition |
protected InstanceContainer<E> |
container |
protected DataContext |
dataContext |
protected java.util.function.Function<LoadContext<E>,E> |
delegate |
protected java.lang.Object |
entityId |
protected EventHub |
events |
protected boolean |
loadDynamicAttributes |
protected java.util.Map<java.lang.String,java.lang.Object> |
parameters |
protected java.lang.String |
query |
protected boolean |
softDeletion |
protected View |
view |
protected java.lang.String |
viewName |
Constructor and Description |
---|
InstanceLoaderImpl(org.springframework.context.ApplicationContext applicationContext) |
Modifier and Type | Method and Description |
---|---|
Subscription |
addPostLoadListener(java.util.function.Consumer<InstanceLoader.PostLoadEvent> listener)
Adds a listener to
InstanceLoader.PostLoadEvent . |
Subscription |
addPreLoadListener(java.util.function.Consumer<InstanceLoader.PreLoadEvent> listener)
Adds a listener to
InstanceLoader.PreLoadEvent . |
LoadContext<E> |
createLoadContext() |
Condition |
getCondition()
Returns the root condition which is used together with the query when loading entities.
|
InstanceContainer<E> |
getContainer()
Returns the container which accepts the loaded entity.
|
DataContext |
getDataContext()
Returns data context.
|
protected DataManager |
getDataManager() |
java.lang.Object |
getEntityId()
Returns id of the entity to load.
|
java.util.function.Function<LoadContext<E>,E> |
getLoadDelegate()
Returns a function which will be used to load data instead of standard implementation.
|
java.lang.Object |
getParameter(java.lang.String name)
Returns a query parameter by its name.
|
java.util.Map<java.lang.String,java.lang.Object> |
getParameters()
Returns the map of query parameters.
|
java.lang.String |
getQuery()
Returns the query which is used for loading entities.
|
View |
getView()
Returns the view which is used when loading.
|
protected ViewRepository |
getViewRepository() |
boolean |
isLoadDynamicAttributes()
Returns true if the entity's dynamic attributes are loaded.
|
boolean |
isSoftDeletion()
Returns true if the loader respects soft deletion, i.e.
|
void |
load()
Loads data to the connected container.
|
protected boolean |
needLoad() |
void |
removeParameter(java.lang.String name)
Removes a query parameter.
|
protected View |
resolveView() |
protected void |
sendPostLoadEvent(E entity) |
protected boolean |
sendPreLoadEvent(LoadContext<E> loadContext) |
void |
setCondition(Condition condition)
Sets the root condition which will be used together with the query when loading entities.
|
void |
setContainer(InstanceContainer<E> container)
Sets the container which accepts the loaded entity.
|
void |
setDataContext(DataContext dataContext)
Sets the data context for the loader.
|
void |
setEntityId(java.lang.Object entityId)
Sets the id of the entity to load.
|
void |
setLoadDelegate(java.util.function.Function<LoadContext<E>,E> delegate)
Sets a function which will be used to load data instead of standard implementation.
|
void |
setLoadDynamicAttributes(boolean loadDynamicAttributes)
Set to true to load the entity's dynamic attributes.
|
void |
setParameter(java.lang.String name,
java.lang.Object value)
Sets a query parameter.
|
void |
setParameters(java.util.Map<java.lang.String,java.lang.Object> parameters)
Sets the map of query parameters.
|
void |
setQuery(java.lang.String query)
Sets a query which will be used for loading entities.
|
void |
setSoftDeletion(boolean softDeletion)
Set to false if you want to load softly deleted instances too.
|
void |
setView(java.lang.String viewName)
Sets the name of the view which is used when loading.
|
void |
setView(View view)
Sets the view which is used when loading.
|
protected DataContext dataContext
protected InstanceContainer<E extends Entity> container
protected java.lang.String query
protected Condition condition
protected java.util.Map<java.lang.String,java.lang.Object> parameters
protected java.lang.Object entityId
protected boolean softDeletion
protected boolean loadDynamicAttributes
protected View view
protected java.lang.String viewName
protected java.util.function.Function<LoadContext<E extends Entity>,E extends Entity> delegate
protected EventHub events
public InstanceLoaderImpl(org.springframework.context.ApplicationContext applicationContext)
protected DataManager getDataManager()
protected ViewRepository getViewRepository()
@Nullable public DataContext getDataContext()
DataLoader
getDataContext
in interface DataLoader
public void setDataContext(DataContext dataContext)
DataLoader
setDataContext
in interface DataLoader
public void load()
DataLoader
load
in interface DataLoader
protected boolean needLoad()
public LoadContext<E> createLoadContext()
protected View resolveView()
protected boolean sendPreLoadEvent(LoadContext<E> loadContext)
protected void sendPostLoadEvent(E entity)
public InstanceContainer<E> getContainer()
InstanceLoader
getContainer
in interface DataLoader
getContainer
in interface InstanceLoader<E extends Entity>
public void setContainer(InstanceContainer<E> container)
InstanceLoader
setContainer
in interface InstanceLoader<E extends Entity>
public java.lang.String getQuery()
DataLoader
getQuery
in interface DataLoader
public void setQuery(java.lang.String query)
DataLoader
setQuery
in interface DataLoader
public Condition getCondition()
DataLoader
getCondition
in interface DataLoader
public void setCondition(Condition condition)
DataLoader
setCondition
in interface DataLoader
public java.util.Map<java.lang.String,java.lang.Object> getParameters()
DataLoader
getParameters
in interface DataLoader
public void setParameters(java.util.Map<java.lang.String,java.lang.Object> parameters)
DataLoader
setParameters
in interface DataLoader
public java.lang.Object getParameter(java.lang.String name)
DataLoader
getParameter
in interface DataLoader
public void setParameter(java.lang.String name, java.lang.Object value)
DataLoader
setParameter
in interface DataLoader
public void removeParameter(java.lang.String name)
DataLoader
removeParameter
in interface DataLoader
public java.lang.Object getEntityId()
InstanceLoader
getEntityId
in interface InstanceLoader<E extends Entity>
public void setEntityId(java.lang.Object entityId)
InstanceLoader
setEntityId
in interface InstanceLoader<E extends Entity>
public boolean isSoftDeletion()
DataLoader
isSoftDeletion
in interface DataLoader
public void setSoftDeletion(boolean softDeletion)
DataLoader
setSoftDeletion
in interface DataLoader
public boolean isLoadDynamicAttributes()
InstanceLoader
isLoadDynamicAttributes
in interface InstanceLoader<E extends Entity>
public void setLoadDynamicAttributes(boolean loadDynamicAttributes)
InstanceLoader
setLoadDynamicAttributes
in interface InstanceLoader<E extends Entity>
public java.util.function.Function<LoadContext<E>,E> getLoadDelegate()
InstanceLoader
getLoadDelegate
in interface InstanceLoader<E extends Entity>
public void setLoadDelegate(java.util.function.Function<LoadContext<E>,E> delegate)
InstanceLoader
setLoadDelegate
in interface InstanceLoader<E extends Entity>
public Subscription addPreLoadListener(java.util.function.Consumer<InstanceLoader.PreLoadEvent> listener)
InstanceLoader
InstanceLoader.PreLoadEvent
.
You can also add an event listener declaratively using a controller method annotated with Subscribe
:
@Subscribe(id = "fooDl", target = Target.DATA_LOADER) private void onFooDlPreLoad(InstanceLoader.PreLoadEvent event) { // handle event here }
addPreLoadListener
in interface InstanceLoader<E extends Entity>
listener
- listenerpublic Subscription addPostLoadListener(java.util.function.Consumer<InstanceLoader.PostLoadEvent> listener)
InstanceLoader
InstanceLoader.PostLoadEvent
.
You can also add an event listener declaratively using a controller method annotated with Subscribe
:
@Subscribe(id = "fooDl", target = Target.DATA_LOADER) private void onFooDlPostLoad(InstanceLoader.PostLoadEvent event) { // handle event here }
addPostLoadListener
in interface InstanceLoader<E extends Entity>
listener
- listenerpublic View getView()
InstanceLoader
getView
in interface InstanceLoader<E extends Entity>
public void setView(View view)
InstanceLoader
setView
in interface InstanceLoader<E extends Entity>
public void setView(java.lang.String viewName)
InstanceLoader
setView
in interface InstanceLoader<E extends Entity>