EntityManagerInterface.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM;
  20. use BadMethodCallException;
  21. use DateTimeInterface;
  22. use Doctrine\Common\EventManager;
  23. use Doctrine\DBAL\Connection;
  24. use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
  25. use Doctrine\ORM\Proxy\ProxyFactory;
  26. use Doctrine\ORM\Query\Expr;
  27. use Doctrine\ORM\Query\FilterCollection;
  28. use Doctrine\ORM\Query\ResultSetMapping;
  29. use Doctrine\Persistence\ObjectManager;
  30. /**
  31. * EntityManager interface
  32. *
  33. * @method Mapping\ClassMetadata getClassMetadata($className)
  34. */
  35. interface EntityManagerInterface extends ObjectManager
  36. {
  37. /**
  38. * Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.
  39. *
  40. * @return Cache|null
  41. */
  42. public function getCache();
  43. /**
  44. * Gets the database connection object used by the EntityManager.
  45. *
  46. * @return Connection
  47. */
  48. public function getConnection();
  49. /**
  50. * Gets an ExpressionBuilder used for object-oriented construction of query expressions.
  51. *
  52. * Example:
  53. *
  54. * <code>
  55. * $qb = $em->createQueryBuilder();
  56. * $expr = $em->getExpressionBuilder();
  57. * $qb->select('u')->from('User', 'u')
  58. * ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));
  59. * </code>
  60. *
  61. * @return Expr
  62. */
  63. public function getExpressionBuilder();
  64. /**
  65. * Starts a transaction on the underlying database connection.
  66. *
  67. * @return void
  68. */
  69. public function beginTransaction();
  70. /**
  71. * Executes a function in a transaction.
  72. *
  73. * The function gets passed this EntityManager instance as an (optional) parameter.
  74. *
  75. * {@link flush} is invoked prior to transaction commit.
  76. *
  77. * If an exception occurs during execution of the function or flushing or transaction commit,
  78. * the transaction is rolled back, the EntityManager closed and the exception re-thrown.
  79. *
  80. * @param callable $func The function to execute transactionally.
  81. *
  82. * @return mixed The non-empty value returned from the closure or true instead.
  83. */
  84. public function transactional($func);
  85. /**
  86. * Commits a transaction on the underlying database connection.
  87. *
  88. * @return void
  89. */
  90. public function commit();
  91. /**
  92. * Performs a rollback on the underlying database connection.
  93. *
  94. * @return void
  95. */
  96. public function rollback();
  97. /**
  98. * Creates a new Query object.
  99. *
  100. * @param string $dql The DQL string.
  101. *
  102. * @return Query
  103. */
  104. public function createQuery($dql = '');
  105. /**
  106. * Creates a Query from a named query.
  107. *
  108. * @param string $name
  109. *
  110. * @return Query
  111. */
  112. public function createNamedQuery($name);
  113. /**
  114. * Creates a native SQL query.
  115. *
  116. * @param string $sql
  117. * @param ResultSetMapping $rsm The ResultSetMapping to use.
  118. *
  119. * @return NativeQuery
  120. */
  121. public function createNativeQuery($sql, ResultSetMapping $rsm);
  122. /**
  123. * Creates a NativeQuery from a named native query.
  124. *
  125. * @param string $name
  126. *
  127. * @return NativeQuery
  128. */
  129. public function createNamedNativeQuery($name);
  130. /**
  131. * Create a QueryBuilder instance
  132. *
  133. * @return QueryBuilder
  134. */
  135. public function createQueryBuilder();
  136. /**
  137. * Gets a reference to the entity identified by the given type and identifier
  138. * without actually loading it, if the entity is not yet loaded.
  139. *
  140. * @param string $entityName The name of the entity type.
  141. * @param mixed $id The entity identifier.
  142. *
  143. * @return object|null The entity reference.
  144. *
  145. * @throws ORMException
  146. *
  147. * @template T
  148. * @psalm-param class-string<T> $entityName
  149. * @psalm-return ?T
  150. */
  151. public function getReference($entityName, $id);
  152. /**
  153. * Gets a partial reference to the entity identified by the given type and identifier
  154. * without actually loading it, if the entity is not yet loaded.
  155. *
  156. * The returned reference may be a partial object if the entity is not yet loaded/managed.
  157. * If it is a partial object it will not initialize the rest of the entity state on access.
  158. * Thus you can only ever safely access the identifier of an entity obtained through
  159. * this method.
  160. *
  161. * The use-cases for partial references involve maintaining bidirectional associations
  162. * without loading one side of the association or to update an entity without loading it.
  163. * Note, however, that in the latter case the original (persistent) entity data will
  164. * never be visible to the application (especially not event listeners) as it will
  165. * never be loaded in the first place.
  166. *
  167. * @param string $entityName The name of the entity type.
  168. * @param mixed $identifier The entity identifier.
  169. *
  170. * @return object|null The (partial) entity reference.
  171. */
  172. public function getPartialReference($entityName, $identifier);
  173. /**
  174. * Closes the EntityManager. All entities that are currently managed
  175. * by this EntityManager become detached. The EntityManager may no longer
  176. * be used after it is closed.
  177. *
  178. * @return void
  179. */
  180. public function close();
  181. /**
  182. * Creates a copy of the given entity. Can create a shallow or a deep copy.
  183. *
  184. * @deprecated 2.7 This method is being removed from the ORM and won't have any replacement
  185. *
  186. * @param object $entity The entity to copy.
  187. * @param bool $deep FALSE for a shallow copy, TRUE for a deep copy.
  188. *
  189. * @return object The new entity.
  190. *
  191. * @throws BadMethodCallException
  192. */
  193. public function copy($entity, $deep = false);
  194. /**
  195. * Acquire a lock on the given entity.
  196. *
  197. * @param object $entity
  198. * @param int $lockMode
  199. * @param int|DateTimeInterface|null $lockVersion
  200. *
  201. * @return void
  202. *
  203. * @throws OptimisticLockException
  204. * @throws PessimisticLockException
  205. */
  206. public function lock($entity, $lockMode, $lockVersion = null);
  207. /**
  208. * Gets the EventManager used by the EntityManager.
  209. *
  210. * @return EventManager
  211. */
  212. public function getEventManager();
  213. /**
  214. * Gets the Configuration used by the EntityManager.
  215. *
  216. * @return Configuration
  217. */
  218. public function getConfiguration();
  219. /**
  220. * Check if the Entity manager is open or closed.
  221. *
  222. * @return bool
  223. */
  224. public function isOpen();
  225. /**
  226. * Gets the UnitOfWork used by the EntityManager to coordinate operations.
  227. *
  228. * @return UnitOfWork
  229. */
  230. public function getUnitOfWork();
  231. /**
  232. * Gets a hydrator for the given hydration mode.
  233. *
  234. * This method caches the hydrator instances which is used for all queries that don't
  235. * selectively iterate over the result.
  236. *
  237. * @deprecated
  238. *
  239. * @param string|int $hydrationMode
  240. *
  241. * @return AbstractHydrator
  242. */
  243. public function getHydrator($hydrationMode);
  244. /**
  245. * Create a new instance for the given hydration mode.
  246. *
  247. * @param string|int $hydrationMode
  248. *
  249. * @return AbstractHydrator
  250. *
  251. * @throws ORMException
  252. */
  253. public function newHydrator($hydrationMode);
  254. /**
  255. * Gets the proxy factory used by the EntityManager to create entity proxies.
  256. *
  257. * @return ProxyFactory
  258. */
  259. public function getProxyFactory();
  260. /**
  261. * Gets the enabled filters.
  262. *
  263. * @return FilterCollection The active filter collection.
  264. */
  265. public function getFilters();
  266. /**
  267. * Checks whether the state of the filter collection is clean.
  268. *
  269. * @return bool True, if the filter collection is clean.
  270. */
  271. public function isFiltersStateClean();
  272. /**
  273. * Checks whether the Entity Manager has filters.
  274. *
  275. * @return bool True, if the EM has a filter collection.
  276. */
  277. public function hasFilters();
  278. }