001package com.avaje.ebean.plugin;
002
003import com.avaje.ebean.config.dbplatform.IdType;
004import com.avaje.ebean.event.BeanFindController;
005import com.avaje.ebean.event.BeanPersistController;
006import com.avaje.ebean.event.BeanPersistListener;
007import com.avaje.ebean.event.BeanQueryAdapter;
008import com.avaje.ebeaninternal.api.SpiQuery;
009import com.avaje.ebeanservice.docstore.api.mapping.DocumentMapping;
010
011import java.util.Collection;
012
013/**
014 * Information and methods on BeanDescriptors made available to plugins.
015 */
016public interface BeanType<T> {
017
018  /**
019   * Return the short name of the bean type.
020   */
021  String getName();
022
023  /**
024   * Return the full name of the bean type.
025   */
026  String getFullName();
027
028  /**
029   * Return the class type this BeanDescriptor describes.
030   */
031  Class<T> getBeanType();
032
033  /**
034   * Return the type bean for an OneToMany or ManyToOne or ManyToMany property.
035   */
036  BeanType<?> getBeanTypeAtPath(String propertyName);
037
038  /**
039   * Return all the properties for this bean type.
040   */
041  Collection<? extends Property> allProperties();
042
043  /**
044   * Return the Id property.
045   */
046  Property getIdProperty();
047
048  /**
049   * Return the when modified property if there is one defined.
050   */
051  Property getWhenModifiedProperty();
052
053  /**
054   * Return the when created property if there is one defined.
055   */
056  Property getWhenCreatedProperty();
057
058  /**
059   * Return the Property to read values from a bean.
060   */
061  Property getProperty(String propertyName);
062
063  /**
064   * Return the ExpressionPath for a given property path.
065   * <p>
066   * This can return a property or nested property path.
067   * </p>
068   */
069  ExpressionPath getExpressionPath(String path);
070
071  /**
072   * Return true if the property is a valid known property or path for the given bean type.
073   */
074  boolean isValidExpression(String property);
075
076  /**
077   * Return the base table this bean type maps to.
078   */
079  String getBaseTable();
080
081  /**
082   * Create a new instance of the bean.
083   */
084  T createBean();
085
086  /**
087   * Return the bean id. This is the same as getBeanId() but without the generic type.
088   */
089  Object beanId(Object bean);
090
091  /**
092   * Return the id value for the given bean.
093   */
094  Object getBeanId(T bean);
095
096  /**
097   * Set the id value to the bean.
098   */
099  void setBeanId(T bean, Object idValue);
100
101  /**
102   * Return the bean persist controller.
103   */
104  BeanPersistController getPersistController();
105
106  /**
107   * Return the bean persist listener.
108   */
109  BeanPersistListener getPersistListener();
110
111  /**
112   * Return the beanFinder. Usually null unless overriding the finder.
113   */
114  BeanFindController getFindController();
115
116  /**
117   * Return the BeanQueryAdapter or null if none is defined.
118   */
119  BeanQueryAdapter getQueryAdapter();
120
121  /**
122   * Return the identity generation type.
123   */
124  IdType getIdType();
125
126  /**
127   * Return the sequence name associated to this entity bean type (if there is one).
128   */
129  String getSequenceName();
130
131  /**
132   * Return true if this bean type has doc store backing.
133   */
134  boolean isDocStoreMapped();
135
136  /**
137   * Return the DocumentMapping for this bean type.
138   * <p>
139   * This is the document structure and mapping options for how this bean type is mapped
140   * for the document store.
141   * </p>
142   */
143  DocumentMapping getDocMapping();
144
145  /**
146   * Return the doc store queueId for this bean type.
147   */
148  String getDocStoreQueueId();
149
150  /**
151   * Return the doc store support for this bean type.\
152   */
153  BeanDocType<T> docStore();
154
155  /**
156   * Add the discriminator value to the query if needed.
157   */
158  void addInheritanceWhere(SpiQuery<?> query);
159
160  /**
161   * Return the root bean type for an inheritance hierarchy.
162   */
163  BeanType<?> root();
164
165  /**
166   * Return true if this bean type has an inheritance hierarchy.
167   */
168  boolean hasInheritance();
169
170  /**
171   * Return the discriminator column.
172   */
173  String getDiscColumn();
174
175  /**
176   * Create a bean given the discriminator value.
177   */
178  T createBeanUsingDisc(Object discValue);
179}