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