Skip to content

Package: EntityManagerFactory

EntityManagerFactory

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model;
16:
17: import java.util.Map;
18:
19: import cz.cvut.kbss.jopa.model.metamodel.Metamodel;
20: import cz.cvut.kbss.jopa.model.query.Query;
21: import cz.cvut.kbss.jopa.sessions.Cache;
22:
23: public interface EntityManagerFactory {
24: /**
25: * Create a new application-managed EntityManager. This method returns a new
26: * EntityManager instance each time it is invoked. The isOpen method will
27: * return true on the returned instance.
28: *
29: * @return entity manager instance
30: * @throws IllegalStateException if the entity manager factory has been closed
31: */
32: EntityManager createEntityManager();
33:
34: /**
35: * Create a new EntityManager with the specified Map of properties. This
36: * method returns a new EntityManager instance each time it is invoked. The
37: * isOpen method will return true on the returned instance.
38: */
39: EntityManager createEntityManager(Map<String, String> map);
40:
41: // TODO JPA 2.0 getCriteriaBuilder
42:
43: /**
44: * Return an instance of Metamodel interface for access to the metamodel of
45: * the persistence unit.
46: *
47: * @return Metamodel instance
48: * @throws IllegalStateException if the entity manager factory has been closed
49: */
50: Metamodel getMetamodel();
51:
52: /**
53: * Close the factory, releasing any resources that it holds. After a factory
54: * instance is closed, all methods invoked on it will throw an
55: * IllegalStateException, except for isOpen, which will return false. Once
56: * an EntityManagerFactory has been closed, all its entity managers are
57: * considered to be in the closed state.
58: *
59: * @throws IllegalStateException if the entity manager factory has been closed
60: */
61: void close();
62:
63: /**
64: * Indicates whether the factory is open. Returns true until the factory has
65: * been closed.
66: *
67: * @return true if the entity manager is open
68: * @throws IllegalStateException if the entity manager factory has been closed
69: */
70: boolean isOpen();
71:
72: /**
73: * Get the properties and associated values that are in effect for the entity manager factory.
74: * <p>
75: * Changing the contents of the map does not change the configuration in effect.
76: *
77: * @return properties
78: * @throws IllegalStateException if the entity manager factory has been closed
79: */
80: Map<String, String> getProperties();
81:
82: /**
83: * Access the cache that is associated with the entity manager factory (the
84: * "second level cache").
85: *
86: * @return instance of the Cache interface
87: * @throws IllegalStateException if the entity manager factory has been closed
88: */
89: Cache getCache();
90:
91: /**
92: * Return interface providing access to utility methods for the persistence unit.
93: *
94: * @return {@code PersistenceUnitUtil} interface
95: * @throws IllegalStateException if the entity manager factory has been closed
96: */
97: PersistenceUnitUtil getPersistenceUnitUtil();
98:
99: /**
100: * Define the query or typed query as a named query such that future query objects can be
101: * created from it using the {@code createNamedQuery} method.
102: * Any configuration of the query object (except for actual parameter binding) in effect when the named query is
103: * added is retained as part of the named query definition. This includes configuration information such as max results
104: * and result set mapping information.
105: * <p>
106: * When the query is executed, information that can be set by means of the query APIs can be overridden.
107: * Information that is overridden does not affect the named query as registered with the entity manager factory,
108: * and thus does not affect subsequent query objects created from it by means of the {@code createNamedQuery} method.
109: * <p>
110: * If a named query of the same name has been previously defined, either statically via metadata or via this method,
111: * that query definition is replaced.
112: *
113: * @param name name for the query
114: * @param query {@code Query} or {@code TypedQuery} object
115: * @since JPA 2.1
116: */
117: void addNamedQuery(String name, Query query);
118: }