Skip to content

Package: EntityManagerFactory

EntityManagerFactory

Coverage

1: /**
2: * Copyright (C) 2020 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 cz.cvut.kbss.jopa.exceptions.OWLPersistenceException;
18: import cz.cvut.kbss.jopa.model.metamodel.Metamodel;
19: import cz.cvut.kbss.jopa.model.query.Query;
20: import cz.cvut.kbss.jopa.sessions.Cache;
21:
22: import java.util.Map;
23:
24: public interface EntityManagerFactory {
25: /**
26: * Create a new application-managed EntityManager. This method returns a new
27: * EntityManager instance each time it is invoked. The isOpen method will
28: * return true on the returned instance.
29: *
30: * @return entity manager instance
31: * @throws IllegalStateException if the entity manager factory has been closed
32: */
33: EntityManager createEntityManager();
34:
35: /**
36: * Create a new EntityManager with the specified Map of properties. This
37: * method returns a new EntityManager instance each time it is invoked. The
38: * isOpen method will return true on the returned instance.
39: *
40: * @param map properties for entity manager
41: * @return entity manager instance
42: */
43: EntityManager createEntityManager(Map<String, String> map);
44:
45: // TODO JPA 2.0 getCriteriaBuilder
46:
47: /**
48: * Return an instance of Metamodel interface for access to the metamodel of
49: * the persistence unit.
50: *
51: * @return Metamodel instance
52: * @throws IllegalStateException if the entity manager factory has been closed
53: */
54: Metamodel getMetamodel();
55:
56: /**
57: * Close the factory, releasing any resources that it holds. After a factory
58: * instance is closed, all methods invoked on it will throw an
59: * IllegalStateException, except for isOpen, which will return false. Once
60: * an EntityManagerFactory has been closed, all its entity managers are
61: * considered to be in the closed state.
62: *
63: * @throws IllegalStateException if the entity manager factory has been closed
64: */
65: void close();
66:
67: /**
68: * Indicates whether the factory is open. Returns true until the factory has
69: * been closed.
70: *
71: * @return true if the entity manager is open
72: * @throws IllegalStateException if the entity manager factory has been closed
73: */
74: boolean isOpen();
75:
76: /**
77: * Get the properties and associated values that are in effect for the entity manager factory.
78: * <p>
79: * Changing the contents of the map does not change the configuration in effect.
80: *
81: * @return properties
82: * @throws IllegalStateException if the entity manager factory has been closed
83: */
84: Map<String, String> getProperties();
85:
86: /**
87: * Access the cache that is associated with the entity manager factory (the
88: * "second level cache").
89: *
90: * @return instance of the Cache interface
91: * @throws IllegalStateException if the entity manager factory has been closed
92: */
93: Cache getCache();
94:
95: /**
96: * Return interface providing access to utility methods for the persistence unit.
97: *
98: * @return {@code PersistenceUnitUtil} interface
99: * @throws IllegalStateException if the entity manager factory has been closed
100: */
101: PersistenceUnitUtil getPersistenceUnitUtil();
102:
103: /**
104: * Define the query or typed query as a named query such that future query objects can be created from it using the
105: * {@code createNamedQuery} method. Any configuration of the query object (except for actual parameter binding) in
106: * effect when the named query is added is retained as part of the named query definition. This includes
107: * configuration information such as max results and result set mapping information.
108: * <p>
109: * When the query is executed, information that can be set by means of the query APIs can be overridden. Information
110: * that is overridden does not affect the named query as registered with the entity manager factory, and thus does
111: * not affect subsequent query objects created from it by means of the {@code createNamedQuery} method.
112: * <p>
113: * If a named query of the same name has been previously defined, either statically via metadata or via this method,
114: * that query definition is replaced.
115: *
116: * @param name name for the query
117: * @param query {@code Query} or {@code TypedQuery} object
118: * @since JPA 2.1
119: */
120: void addNamedQuery(String name, Query query);
121:
122: /**
123: * Return an object of the specified type to allow access to the provider-specific API. If the provider's
124: * EntityManagerFactory implementation does not support the specified class, the {@link OWLPersistenceException} is
125: * thrown.
126: *
127: * @param cls The class of the object to be returned. This can be also an implementation of the underlying driver
128: * @return an instance of the specified class
129: * @throws OWLPersistenceException If the provider does not support the specified class
130: */
131: <T> T unwrap(Class<T> cls);
132: }