001package io.ebean.plugin;
002
003import io.ebean.Query;
004import io.ebean.config.dbplatform.IdType;
005import io.ebean.event.BeanFindController;
006import io.ebean.event.BeanPersistController;
007import io.ebean.event.BeanPersistListener;
008import io.ebean.event.BeanQueryAdapter;
009import io.ebeanservice.docstore.api.mapping.DocumentMapping;
010
011import java.util.Collection;
012import java.util.List;
013import java.util.function.Consumer;
014
015import javax.annotation.Nonnull;
016
017/**
018 * Information and methods on BeanDescriptors made available to plugins.
019 */
020public interface BeanType<T> {
021
022  /**
023   * Return the short name of the bean type.
024   */
025  @Nonnull
026  String getName();
027
028  /**
029   * Return the profileId of the bean type.
030   */
031  short getProfileId();
032
033  /**
034   * Return the full name of the bean type.
035   */
036  @Nonnull
037  String getFullName();
038
039  /**
040   * Return the class type this BeanDescriptor describes.
041   */
042  @Nonnull
043  Class<T> getBeanType();
044
045  /**
046   * Return the type bean for an OneToMany or ManyToOne or ManyToMany property.
047   */
048  BeanType<?> getBeanTypeAtPath(String propertyName);
049
050  /**
051   * Return all the properties for this bean type.
052   */
053  @Nonnull
054  Collection<? extends Property> allProperties();
055
056  /**
057   * Return the Id property.
058   */
059  Property getIdProperty();
060
061  /**
062   * Return the when modified property if there is one defined.
063   */
064  Property getWhenModifiedProperty();
065
066  /**
067   * Return the when created property if there is one defined.
068   */
069  Property getWhenCreatedProperty();
070
071  /**
072   * Return the Property to read values from a bean.
073   */
074  Property getProperty(String propertyName);
075
076  /**
077   * Return the ExpressionPath for a given property path.
078   * <p>
079   * This can return a property or nested property path.
080   * </p>
081   */
082  ExpressionPath getExpressionPath(String path);
083
084  /**
085   * Return true if the property is a valid known property or path for the given bean type.
086   */
087  boolean isValidExpression(String property);
088
089  /**
090   * Return true if bean caching is on for this bean type.
091   */
092  boolean isBeanCaching();
093
094  /**
095   * Return true if query caching is on for this bean type.
096   */
097  boolean isQueryCaching();
098
099  /**
100   * Clear the bean cache.
101   */
102  void clearBeanCache();
103
104  /**
105   * Clear the query cache.
106   */
107  void clearQueryCache();
108
109  /**
110   * Return true if the type is document store only.
111   */
112  boolean isDocStoreOnly();
113
114  /**
115   * Return the base table this bean type maps to.
116   */
117  String getBaseTable();
118
119  /**
120   * Create a new instance of the bean.
121   */
122  T createBean();
123
124  /**
125   * Return the bean id. This is the same as getBeanId() but without the generic type.
126   */
127  Object beanId(Object bean);
128
129  /**
130   * Return the id value for the given bean.
131   */
132  Object getBeanId(T bean);
133
134  /**
135   * Set the id value to the bean.
136   */
137  void setBeanId(T bean, Object idValue);
138
139  /**
140   * Return the bean persist controller.
141   */
142  BeanPersistController getPersistController();
143
144  /**
145   * Return the bean persist listener.
146   */
147  BeanPersistListener getPersistListener();
148
149  /**
150   * Return the beanFinder. Usually null unless overriding the finder.
151   */
152  BeanFindController getFindController();
153
154  /**
155   * Return the BeanQueryAdapter or null if none is defined.
156   */
157  BeanQueryAdapter getQueryAdapter();
158
159  /**
160   * Return the identity generation type.
161   */
162  IdType getIdType();
163
164  /**
165   * Return the sequence name associated to this entity bean type (if there is one).
166   */
167  String getSequenceName();
168
169  /**
170   * Return true if this bean type has doc store backing.
171   */
172  boolean isDocStoreMapped();
173
174  /**
175   * Return the DocumentMapping for this bean type.
176   * <p>
177   * This is the document structure and mapping options for how this bean type is mapped
178   * for the document store.
179   * </p>
180   */
181  DocumentMapping getDocMapping();
182
183  /**
184   * Return the doc store queueId for this bean type.
185   */
186  String getDocStoreQueueId();
187
188  /**
189   * Return the doc store support for this bean type.\
190   */
191  BeanDocType<T> docStore();
192
193  /**
194   * Add the discriminator value to the query if needed.
195   */
196  void addInheritanceWhere(Query<?> query);
197
198  /**
199   * Return the root bean type for an inheritance hierarchy.
200   */
201  BeanType<?> root();
202
203  /**
204   * Return true if this bean type has an inheritance hierarchy.
205   */
206  boolean hasInheritance();
207
208  /**
209   * Return true if this object is the root level object in its entity
210   * inheritance.
211   */
212  boolean isInheritanceRoot();
213
214  /**
215   * Returns all direct children of this beantype
216   */
217  List<BeanType<?>> getInheritanceChildren();
218
219  /**
220   * Returns the parent in inheritance hiearchy
221   */
222  BeanType<?> getInheritanceParent();
223
224  /**
225   * Visit all children recursively
226   * @param visitor
227   */
228  void visitAllInheritanceChildren(Consumer<BeanType<?>> visitor);
229
230  /**
231   * Return the discriminator column.
232   */
233  String getDiscColumn();
234
235  /**
236   * Create a bean given the discriminator value.
237   */
238  T createBeanUsingDisc(Object discValue);
239}