|
Lines 52-637
Link Here
|
| 52 |
* |
52 |
* |
| 53 |
* @author gyorke |
53 |
* @author gyorke |
| 54 |
* @since TopLink Essentials - JPA 1.0 |
54 |
* @since TopLink Essentials - JPA 1.0 |
| 55 |
* |
55 |
* |
| 56 |
* 03/19/2009-2.0 Michael O'Brien |
56 |
* 03/19/2009-2.0 Michael O'Brien - 266912: JPA 2.0 Metamodel API (part |
| 57 |
* - 266912: JPA 2.0 Metamodel API (part of the JSR-317 EJB 3.1 Criteria API) |
57 |
* of the JSR-317 EJB 3.1 Criteria API) |
| 58 |
*/ |
58 |
*/ |
| 59 |
public class EntityManagerFactoryImpl implements EntityManagerFactory, PersistenceUnitUtil { |
59 |
public class EntityManagerFactoryImpl implements EntityManagerFactory, PersistenceUnitUtil { |
| 60 |
/** Reference to Cache Interface. */ |
60 |
/** Reference to Cache Interface. */ |
| 61 |
protected Cache myCache; |
61 |
protected Cache myCache; |
| 62 |
/** Reference to the ServerSession for this deployment. */ |
62 |
/** Reference to the ServerSession for this deployment. */ |
| 63 |
protected volatile ServerSession serverSession; |
63 |
protected volatile ServerSession serverSession; |
| 64 |
/** EntityManagerSetupImpl that deployed this factory. */ |
64 |
/** EntityManagerSetupImpl that deployed this factory. */ |
| 65 |
protected EntityManagerSetupImpl setupImpl; |
65 |
protected EntityManagerSetupImpl setupImpl; |
| 66 |
/** Stores if closed has been called. */ |
66 |
/** Stores if closed has been called. */ |
| 67 |
protected boolean isOpen = true; |
67 |
protected boolean isOpen = true; |
| 68 |
/** Persistence unit properties from create factory. */ |
68 |
/** Persistence unit properties from create factory. */ |
| 69 |
protected Map properties; |
69 |
protected Map properties; |
| 70 |
|
70 |
|
| 71 |
/** |
71 |
/** |
| 72 |
* INTERNAL: |
72 |
* INTERNAL: The following properties passed to createEMF cached and |
| 73 |
* The following properties passed to createEMF cached and processed on the emf directly. |
73 |
* processed on the emf directly. None of these properties processed during |
| 74 |
* None of these properties processed during predeploy or deploy. |
74 |
* predeploy or deploy. |
| 75 |
**/ |
75 |
**/ |
| 76 |
protected static final Set<String> supportedNonServerSessionProperties = PersistenceUnitProperties.getSupportedNonServerSessionProperties(); |
76 |
protected static final Set<String> supportedNonServerSessionProperties = PersistenceUnitProperties.getSupportedNonServerSessionProperties(); |
| 77 |
|
|
|
| 78 |
/** |
| 79 |
* Default join existing transaction property, allows reading through write |
| 80 |
* connection. |
| 81 |
*/ |
| 82 |
protected boolean beginEarlyTransaction; |
| 83 |
|
77 |
|
| 84 |
/** Default property, allows flush before query to be avoided. */ |
78 |
/** |
| 85 |
protected FlushModeType flushMode = FlushModeType.AUTO; |
79 |
* Default join existing transaction property, allows reading through write |
|
|
80 |
* connection. |
| 81 |
*/ |
| 82 |
protected boolean beginEarlyTransaction; |
| 86 |
|
83 |
|
| 87 |
/** Default property, allows weak unit of work references. */ |
84 |
/** Default property, allows flush before query to be avoided. */ |
| 88 |
protected ReferenceMode referenceMode = ReferenceMode.HARD; |
85 |
protected FlushModeType flushMode = FlushModeType.AUTO; |
| 89 |
|
86 |
|
| 90 |
/** |
87 |
/** Default property, allows weak unit of work references. */ |
| 91 |
* Default property to avoid resuming unit of work if going to be closed on |
88 |
protected ReferenceMode referenceMode = ReferenceMode.HARD; |
| 92 |
* commit anyway. |
|
|
| 93 |
*/ |
| 94 |
protected boolean closeOnCommit; |
| 95 |
|
89 |
|
| 96 |
/** |
90 |
/** |
| 97 |
* Default property to avoid discover new objects in unit of work if |
91 |
* Default property to avoid resuming unit of work if going to be closed on |
| 98 |
* application always uses persist. |
92 |
* commit anyway. |
| 99 |
*/ |
93 |
*/ |
| 100 |
protected boolean persistOnCommit = true; |
94 |
protected boolean closeOnCommit; |
| 101 |
|
95 |
|
| 102 |
/** |
96 |
/** |
| 103 |
* Default FlashClearCache mode to be used. Relevant only in case call to |
97 |
* Default property to avoid discover new objects in unit of work if |
| 104 |
* flush method followed by call to clear method. |
98 |
* application always uses persist. |
| 105 |
* |
99 |
*/ |
| 106 |
* @see org.eclipse.persistence.config.FlushClearCache |
100 |
protected boolean persistOnCommit = true; |
| 107 |
*/ |
|
|
| 108 |
protected String flushClearCache = FlushClearCache.DEFAULT; |
| 109 |
|
101 |
|
| 110 |
/** Default to determine if does-exist should be performed on persist. */ |
102 |
/** |
| 111 |
protected boolean shouldValidateExistence; |
103 |
* Default FlashClearCache mode to be used. Relevant only in case call to |
| 112 |
protected boolean commitWithoutPersistRules; |
104 |
* flush method followed by call to clear method. |
|
|
105 |
* |
| 106 |
* @see org.eclipse.persistence.config.FlushClearCache |
| 107 |
*/ |
| 108 |
protected String flushClearCache = FlushClearCache.DEFAULT; |
| 113 |
|
109 |
|
| 114 |
/** |
110 |
/** Default to determine if does-exist should be performed on persist. */ |
| 115 |
* Will return an instance of the Factory. Should only be called by |
111 |
protected boolean shouldValidateExistence; |
| 116 |
* EclipseLink. |
112 |
protected boolean commitWithoutPersistRules; |
| 117 |
* |
|
|
| 118 |
* @param serverSession |
| 119 |
*/ |
| 120 |
public EntityManagerFactoryImpl(ServerSession serverSession) { |
| 121 |
this.serverSession = serverSession; |
| 122 |
processProperties(serverSession.getProperties()); |
| 123 |
} |
| 124 |
|
113 |
|
| 125 |
public EntityManagerFactoryImpl(EntityManagerSetupImpl setupImpl, Map properties) { |
114 |
/** |
| 126 |
this.setupImpl = setupImpl; |
115 |
* Will return an instance of the Factory. Should only be called by |
| 127 |
this.properties = properties; |
116 |
* EclipseLink. |
| 128 |
} |
117 |
* |
|
|
118 |
* @param serverSession |
| 119 |
*/ |
| 120 |
public EntityManagerFactoryImpl(ServerSession serverSession) { |
| 121 |
this.serverSession = serverSession; |
| 122 |
processProperties(serverSession.getProperties()); |
| 123 |
} |
| 129 |
|
124 |
|
| 130 |
/** |
125 |
public EntityManagerFactoryImpl(EntityManagerSetupImpl setupImpl, Map properties) { |
| 131 |
* INTERNAL: Returns the ServerSession that the Factory will be using and |
126 |
this.setupImpl = setupImpl; |
| 132 |
* initializes it if it is not available. This method makes use of the |
127 |
this.properties = properties; |
| 133 |
* partially constructed session stored in our setupImpl and completes its |
128 |
} |
| 134 |
* construction |
|
|
| 135 |
*/ |
| 136 |
public ServerSession getServerSession() { |
| 137 |
if (this.serverSession == null) { |
| 138 |
// PERF: Avoid synchronization. |
| 139 |
synchronized (this) { |
| 140 |
// DCL ok as isLoggedIn is volatile boolean, set after login is |
| 141 |
// complete. |
| 142 |
if (this.serverSession == null) { |
| 143 |
ClassLoader realLoader = setupImpl.getPersistenceUnitInfo().getClassLoader(); |
| 144 |
// splitProperties[0] contains supportedNonServerSessionProperties; [1] - all the rest. |
| 145 |
Map[] splitProperties = EntityManagerFactoryProvider.splitSpecifiedProperties(properties, supportedNonServerSessionProperties); |
| 146 |
// keep only non server session properties - the rest will be either cached in the server session or ignored |
| 147 |
properties = splitProperties[0]; |
| 148 |
Map serverSessionProperties = splitProperties[1]; |
| 149 |
// the call top setupImpl.deploy() finishes the session |
| 150 |
// creation |
| 151 |
ServerSession tempServerSession = setupImpl.deploy(realLoader, serverSessionProperties); |
| 152 |
// discard all but non server session properties from server session properties. |
| 153 |
Map tempProperties = EntityManagerFactoryProvider.keepSpecifiedProperties(tempServerSession.getProperties(), supportedNonServerSessionProperties); |
| 154 |
// properties override server session properties |
| 155 |
Map propertiesToProcess = EntityManagerFactoryProvider.mergeMaps(properties, tempProperties); |
| 156 |
processProperties(propertiesToProcess); |
| 157 |
this.serverSession = tempServerSession; |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
return this.serverSession; |
| 162 |
} |
| 163 |
|
129 |
|
| 164 |
/** |
130 |
/** |
| 165 |
* Closes this factory, releasing any resources that might be held by this |
131 |
* INTERNAL: Returns the ServerSession that the Factory will be using and |
| 166 |
* factory. After invoking this method, all methods on the instance will |
132 |
* initializes it if it is not available. This method makes use of the |
| 167 |
* throw an {@link IllegalStateException}, except for {@link #isOpen}, which |
133 |
* partially constructed session stored in our setupImpl and completes its |
| 168 |
* will return <code>false</code>. |
134 |
* construction |
| 169 |
*/ |
135 |
*/ |
| 170 |
public synchronized void close() { |
136 |
public ServerSession getServerSession() { |
| 171 |
verifyOpen(); |
137 |
if (this.serverSession == null) { |
| 172 |
isOpen = false; |
138 |
// PERF: Avoid synchronization. |
| 173 |
// Do not invalidate the metaModel field |
139 |
synchronized (this) { |
|
|
140 |
// DCL ok as isLoggedIn is volatile boolean, set after login is |
| 141 |
// complete. |
| 142 |
if (this.serverSession == null) { |
| 143 |
ClassLoader realLoader = setupImpl.getPersistenceUnitInfo().getClassLoader(); |
| 144 |
// splitProperties[0] contains |
| 145 |
// supportedNonServerSessionProperties; [1] - all the rest. |
| 146 |
Map[] splitProperties = EntityManagerFactoryProvider.splitSpecifiedProperties(properties, supportedNonServerSessionProperties); |
| 147 |
// keep only non server session properties - the rest will |
| 148 |
// be either cached in the server session or ignored |
| 149 |
properties = splitProperties[0]; |
| 150 |
Map serverSessionProperties = splitProperties[1]; |
| 151 |
// the call top setupImpl.deploy() finishes the session |
| 152 |
// creation |
| 153 |
ServerSession tempServerSession = setupImpl.deploy(realLoader, serverSessionProperties); |
| 154 |
// discard all but non server session properties from server |
| 155 |
// session properties. |
| 156 |
Map tempProperties = EntityManagerFactoryProvider.keepSpecifiedProperties(tempServerSession.getProperties(), supportedNonServerSessionProperties); |
| 157 |
// properties override server session properties |
| 158 |
Map propertiesToProcess = EntityManagerFactoryProvider.mergeMaps(properties, tempProperties); |
| 159 |
processProperties(propertiesToProcess); |
| 160 |
this.serverSession = tempServerSession; |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
return this.serverSession; |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Closes this factory, releasing any resources that might be held by this |
| 169 |
* factory. After invoking this method, all methods on the instance will |
| 170 |
* throw an {@link IllegalStateException}, except for {@link #isOpen}, which |
| 171 |
* will return <code>false</code>. |
| 172 |
*/ |
| 173 |
public synchronized void close() { |
| 174 |
verifyOpen(); |
| 175 |
isOpen = false; |
| 176 |
// Do not invalidate the metaModel field |
| 174 |
// (a reopened emf will re-populate the same metaModel) |
177 |
// (a reopened emf will re-populate the same metaModel) |
| 175 |
// (a new persistence unit will generate a new metaModel) |
178 |
// (a new persistence unit will generate a new metaModel) |
| 176 |
if (setupImpl != null) { |
179 |
if (setupImpl != null) { |
| 177 |
// 260511 null check so that closing a EM |
180 |
// 260511 null check so that closing a EM |
| 178 |
// created from the constructor no longer throws a NPE |
181 |
// created from the constructor no longer throws a NPE |
| 179 |
setupImpl.undeploy(); |
182 |
setupImpl.undeploy(); |
| 180 |
} |
183 |
} |
| 181 |
} |
184 |
} |
| 182 |
|
185 |
|
| 183 |
/** |
186 |
/** |
| 184 |
* Indicates whether or not this factory is open. Returns <code>true</code> |
187 |
* Indicates whether or not this factory is open. Returns <code>true</code> |
| 185 |
* until a call to {@link #close} is made. |
188 |
* until a call to {@link #close} is made. |
| 186 |
*/ |
189 |
*/ |
| 187 |
public boolean isOpen() { |
190 |
public boolean isOpen() { |
| 188 |
return isOpen; |
191 |
return isOpen; |
| 189 |
} |
192 |
} |
| 190 |
|
193 |
|
| 191 |
/** |
194 |
/** |
| 192 |
* PUBLIC: Returns an EntityManager for this deployment. |
195 |
* PUBLIC: Returns an EntityManager for this deployment. |
| 193 |
*/ |
196 |
*/ |
| 194 |
public EntityManager createEntityManager() { |
197 |
public EntityManager createEntityManager() { |
| 195 |
return createEntityManagerImpl(null); |
198 |
return createEntityManagerImpl(null); |
| 196 |
} |
199 |
} |
| 197 |
|
200 |
|
| 198 |
/** |
201 |
/** |
| 199 |
* PUBLIC: Returns an EntityManager for this deployment. |
202 |
* PUBLIC: Returns an EntityManager for this deployment. |
| 200 |
*/ |
203 |
*/ |
| 201 |
public EntityManager createEntityManager(Map properties) { |
204 |
public EntityManager createEntityManager(Map properties) { |
| 202 |
return createEntityManagerImpl(properties); |
205 |
return createEntityManagerImpl(properties); |
| 203 |
} |
206 |
} |
| 204 |
|
207 |
|
| 205 |
protected EntityManagerImpl createEntityManagerImpl(Map properties) { |
208 |
protected EntityManagerImpl createEntityManagerImpl(Map properties) { |
| 206 |
verifyOpen(); |
209 |
verifyOpen(); |
| 207 |
ServerSession session = getServerSession(); |
210 |
ServerSession session = getServerSession(); |
| 208 |
if (!session.isLoggedIn()) { |
211 |
if (!session.isLoggedIn()) { |
| 209 |
// PERF: Avoid synchronization. |
212 |
// PERF: Avoid synchronization. |
| 210 |
synchronized (session) { |
213 |
synchronized (session) { |
| 211 |
// DCL ok as isLoggedIn is volatile boolean, set after login is |
214 |
// DCL ok as isLoggedIn is volatile boolean, set after login is |
| 212 |
// complete. |
215 |
// complete. |
| 213 |
if (!session.isLoggedIn()) { |
216 |
if (!session.isLoggedIn()) { |
| 214 |
session.login(); |
217 |
session.login(); |
| 215 |
} |
218 |
} |
| 216 |
} |
219 |
} |
| 217 |
} |
220 |
} |
| 218 |
return new EntityManagerImpl(this, properties); |
221 |
return new EntityManagerImpl(this, properties); |
| 219 |
} |
222 |
} |
| 220 |
|
223 |
|
| 221 |
protected void verifyOpen() { |
224 |
protected void verifyOpen() { |
| 222 |
if (!this.isOpen) { |
225 |
if (!this.isOpen) { |
| 223 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
226 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
| 224 |
} |
227 |
} |
| 225 |
} |
228 |
} |
| 226 |
|
229 |
|
| 227 |
protected void finalize() throws Throwable { |
230 |
protected void finalize() throws Throwable { |
| 228 |
if (isOpen()) { |
231 |
if (isOpen()) { |
| 229 |
close(); |
232 |
close(); |
| 230 |
} |
233 |
} |
| 231 |
} |
234 |
} |
| 232 |
|
235 |
|
| 233 |
/** |
236 |
/** |
| 234 |
* The method return user defined property passed in from |
237 |
* The method return user defined property passed in from |
| 235 |
* EntityManagerFactory. |
238 |
* EntityManagerFactory. |
| 236 |
*/ |
239 |
*/ |
| 237 |
public Object getProperty(String name) { |
240 |
public Object getProperty(String name) { |
| 238 |
if (name == null) { |
241 |
if (name == null) { |
| 239 |
return null; |
242 |
return null; |
| 240 |
} |
243 |
} |
| 241 |
if(properties != null) { |
244 |
if (properties != null) { |
| 242 |
Object value = properties.get(name); |
245 |
Object value = properties.get(name); |
| 243 |
if(value != null) { |
246 |
if (value != null) { |
| 244 |
return value; |
247 |
return value; |
| 245 |
} |
248 |
} |
| 246 |
} |
249 |
} |
| 247 |
return getServerSession().getProperty(name); |
250 |
return getServerSession().getProperty(name); |
| 248 |
} |
251 |
} |
| 249 |
|
252 |
|
| 250 |
/** |
253 |
/** |
| 251 |
* Process all EntityManager properties. This allows all EntityManager |
254 |
* Process all EntityManager properties. This allows all EntityManager |
| 252 |
* properties specified in the persistence.xml, factory properties, or |
255 |
* properties specified in the persistence.xml, factory properties, or |
| 253 |
* System properties to be preprocessed. This save the cost of processing |
256 |
* System properties to be preprocessed. This save the cost of processing |
| 254 |
* these properties each time an EntityManager is created, which can add |
257 |
* these properties each time an EntityManager is created, which can add |
| 255 |
* considerable overhead to both performance and concurrency as System |
258 |
* considerable overhead to both performance and concurrency as System |
| 256 |
* properties are a Hashtable and synchronized. |
259 |
* properties are a Hashtable and synchronized. ATTENTION: If you add a new |
| 257 |
* ATTENTION: |
260 |
* property to be processed in this method please also add the property's |
| 258 |
* If you add a new property to be processed in this method please also add |
261 |
* name to PersistenceUnitProperties.supportedNonServerSessionProperties |
| 259 |
* the property's name to PersistenceUnitProperties.supportedNonServerSessionProperties |
262 |
*/ |
| 260 |
*/ |
263 |
protected void processProperties(Map properties) { |
| 261 |
protected void processProperties(Map properties) { |
264 |
String beginEarlyTransactionProperty = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.JOIN_EXISTING_TRANSACTION, properties, this.serverSession, true); |
| 262 |
String beginEarlyTransactionProperty = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.JOIN_EXISTING_TRANSACTION, properties, this.serverSession, true); |
265 |
if (beginEarlyTransactionProperty != null) { |
| 263 |
if (beginEarlyTransactionProperty != null) { |
266 |
this.beginEarlyTransaction = "true".equalsIgnoreCase(beginEarlyTransactionProperty); |
| 264 |
this.beginEarlyTransaction = "true".equalsIgnoreCase(beginEarlyTransactionProperty); |
267 |
} |
| 265 |
} |
268 |
String referenceMode = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, properties, this.serverSession, true); |
| 266 |
String referenceMode = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_REFERENCE_MODE, properties, this.serverSession, true); |
269 |
if (referenceMode != null) { |
| 267 |
if (referenceMode != null) { |
270 |
this.referenceMode = ReferenceMode.valueOf(referenceMode); |
| 268 |
this.referenceMode = ReferenceMode.valueOf(referenceMode); |
271 |
} |
| 269 |
} |
272 |
String flushMode = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_FLUSH_MODE, properties, this.serverSession, true); |
| 270 |
String flushMode = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_FLUSH_MODE, properties, this.serverSession, true); |
273 |
if (flushMode != null) { |
| 271 |
if (flushMode != null) { |
274 |
this.flushMode = FlushModeType.valueOf(flushMode); |
| 272 |
this.flushMode = FlushModeType.valueOf(flushMode); |
275 |
} |
| 273 |
} |
276 |
String closeOnCommit = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT, properties, this.serverSession, true); |
| 274 |
String closeOnCommit = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_CLOSE_ON_COMMIT, properties, this.serverSession, true); |
277 |
if (closeOnCommit != null) { |
| 275 |
if (closeOnCommit != null) { |
278 |
this.closeOnCommit = "true".equalsIgnoreCase(closeOnCommit); |
| 276 |
this.closeOnCommit = "true".equalsIgnoreCase(closeOnCommit); |
279 |
} |
| 277 |
} |
280 |
String persistOnCommit = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_PERSIST_ON_COMMIT, properties, this.serverSession, true); |
| 278 |
String persistOnCommit = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_PERSIST_ON_COMMIT, properties, this.serverSession, true); |
281 |
if (persistOnCommit != null) { |
| 279 |
if (persistOnCommit != null) { |
282 |
this.persistOnCommit = "true".equalsIgnoreCase(persistOnCommit); |
| 280 |
this.persistOnCommit = "true".equalsIgnoreCase(persistOnCommit); |
283 |
} |
| 281 |
} |
|
|
| 282 |
String commitWithoutPersist = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_COMMIT_WITHOUT_PERSIST_RULES, properties, this.serverSession, true); |
284 |
String commitWithoutPersist = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.PERSISTENCE_CONTEXT_COMMIT_WITHOUT_PERSIST_RULES, properties, this.serverSession, true); |
| 283 |
if (commitWithoutPersist != null) { |
285 |
if (commitWithoutPersist != null) { |
| 284 |
this.commitWithoutPersistRules = "true".equalsIgnoreCase(commitWithoutPersist); |
286 |
this.commitWithoutPersistRules = "true".equalsIgnoreCase(commitWithoutPersist); |
| 285 |
} |
287 |
} |
| 286 |
String shouldValidateExistence = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.VALIDATE_EXISTENCE, properties, this.serverSession, true); |
288 |
String shouldValidateExistence = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.VALIDATE_EXISTENCE, properties, this.serverSession, true); |
| 287 |
if (shouldValidateExistence != null) { |
289 |
if (shouldValidateExistence != null) { |
| 288 |
this.shouldValidateExistence = "true".equalsIgnoreCase(shouldValidateExistence); |
290 |
this.shouldValidateExistence = "true".equalsIgnoreCase(shouldValidateExistence); |
| 289 |
} |
291 |
} |
| 290 |
String flushClearCache = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.FLUSH_CLEAR_CACHE, properties, this.serverSession, true); |
292 |
String flushClearCache = PropertiesHandler.getPropertyValueLogDebug(EntityManagerProperties.FLUSH_CLEAR_CACHE, properties, this.serverSession, true); |
| 291 |
if (flushClearCache != null) { |
293 |
if (flushClearCache != null) { |
| 292 |
this.flushClearCache = flushClearCache; |
294 |
this.flushClearCache = flushClearCache; |
| 293 |
} |
295 |
} |
| 294 |
} |
296 |
} |
| 295 |
|
297 |
|
| 296 |
/** |
298 |
/** |
| 297 |
* Return default join existing transaction property, allows reading through |
299 |
* Return default join existing transaction property, allows reading through |
| 298 |
* write connection. |
300 |
* write connection. |
| 299 |
*/ |
301 |
*/ |
| 300 |
public boolean getBeginEarlyTransaction() { |
302 |
public boolean getBeginEarlyTransaction() { |
| 301 |
return beginEarlyTransaction; |
303 |
return beginEarlyTransaction; |
| 302 |
} |
304 |
} |
| 303 |
|
305 |
|
| 304 |
/** |
306 |
/** |
| 305 |
* Set default join existing transaction property, allows reading through |
307 |
* Set default join existing transaction property, allows reading through |
| 306 |
* write connection. |
308 |
* write connection. |
| 307 |
*/ |
309 |
*/ |
| 308 |
public void setBeginEarlyTransaction(boolean beginEarlyTransaction) { |
310 |
public void setBeginEarlyTransaction(boolean beginEarlyTransaction) { |
| 309 |
this.beginEarlyTransaction = beginEarlyTransaction; |
311 |
this.beginEarlyTransaction = beginEarlyTransaction; |
| 310 |
} |
312 |
} |
| 311 |
|
313 |
|
| 312 |
/** |
314 |
/** |
| 313 |
* Return default property, allows flush before query to be avoided. |
315 |
* Return default property, allows flush before query to be avoided. |
| 314 |
*/ |
316 |
*/ |
| 315 |
public FlushModeType getFlushMode() { |
317 |
public FlushModeType getFlushMode() { |
| 316 |
return flushMode; |
318 |
return flushMode; |
| 317 |
} |
319 |
} |
| 318 |
|
320 |
|
| 319 |
/** |
321 |
/** |
| 320 |
* Set default property, allows flush before query to be avoided. |
322 |
* Set default property, allows flush before query to be avoided. |
| 321 |
*/ |
323 |
*/ |
| 322 |
public void setFlushMode(FlushModeType flushMode) { |
324 |
public void setFlushMode(FlushModeType flushMode) { |
| 323 |
this.flushMode = flushMode; |
325 |
this.flushMode = flushMode; |
| 324 |
} |
326 |
} |
| 325 |
|
327 |
|
| 326 |
/** |
328 |
/** |
| 327 |
* Return default property, allows weak unit of work references. |
329 |
* Return default property, allows weak unit of work references. |
| 328 |
*/ |
330 |
*/ |
| 329 |
public ReferenceMode getReferenceMode() { |
331 |
public ReferenceMode getReferenceMode() { |
| 330 |
return referenceMode; |
332 |
return referenceMode; |
| 331 |
} |
333 |
} |
| 332 |
|
334 |
|
| 333 |
/** |
335 |
/** |
| 334 |
* Set default property, allows weak unit of work references. |
336 |
* Set default property, allows weak unit of work references. |
| 335 |
*/ |
337 |
*/ |
| 336 |
public void setReferenceMode(ReferenceMode referenceMode) { |
338 |
public void setReferenceMode(ReferenceMode referenceMode) { |
| 337 |
this.referenceMode = referenceMode; |
339 |
this.referenceMode = referenceMode; |
| 338 |
} |
340 |
} |
| 339 |
|
341 |
|
| 340 |
/** |
342 |
/** |
| 341 |
* Return default property to avoid resuming unit of work if going to be |
343 |
* Return default property to avoid resuming unit of work if going to be |
| 342 |
* closed on commit anyway. |
344 |
* closed on commit anyway. |
| 343 |
*/ |
345 |
*/ |
| 344 |
public boolean getCloseOnCommit() { |
346 |
public boolean getCloseOnCommit() { |
| 345 |
return closeOnCommit; |
347 |
return closeOnCommit; |
| 346 |
} |
348 |
} |
| 347 |
|
349 |
|
| 348 |
/** |
350 |
/** |
| 349 |
* Set default property to avoid resuming unit of work if going to be closed |
351 |
* Set default property to avoid resuming unit of work if going to be closed |
| 350 |
* on commit anyway. |
352 |
* on commit anyway. |
| 351 |
*/ |
353 |
*/ |
| 352 |
public void setCloseOnCommit(boolean closeOnCommit) { |
354 |
public void setCloseOnCommit(boolean closeOnCommit) { |
| 353 |
this.closeOnCommit = closeOnCommit; |
355 |
this.closeOnCommit = closeOnCommit; |
| 354 |
} |
356 |
} |
| 355 |
|
357 |
|
| 356 |
/** |
358 |
/** |
| 357 |
* Return default property to avoid discover new objects in unit of work if |
359 |
* Return default property to avoid discover new objects in unit of work if |
| 358 |
* application always uses persist. |
360 |
* application always uses persist. |
| 359 |
*/ |
361 |
*/ |
| 360 |
public boolean getPersistOnCommit() { |
362 |
public boolean getPersistOnCommit() { |
| 361 |
return persistOnCommit; |
363 |
return persistOnCommit; |
| 362 |
} |
364 |
} |
| 363 |
|
365 |
|
| 364 |
/** |
366 |
/** |
| 365 |
* Return interface providing access to utility methods |
367 |
* Return interface providing access to utility methods for the persistence |
| 366 |
* for the persistence unit. |
368 |
* unit. |
|
|
369 |
* |
| 367 |
* @return PersistenceUnitUtil interface |
370 |
* @return PersistenceUnitUtil interface |
| 368 |
* @throws IllegalStateException if the entity manager factory |
371 |
* @throws IllegalStateException |
| 369 |
* has been closed. |
372 |
* if the entity manager factory has been closed. |
| 370 |
*/ |
373 |
*/ |
| 371 |
public PersistenceUnitUtil getPersistenceUnitUtil(){ |
374 |
public PersistenceUnitUtil getPersistenceUnitUtil() { |
| 372 |
return this; |
375 |
return this; |
| 373 |
} |
376 |
} |
| 374 |
|
377 |
|
| 375 |
/** |
378 |
/** |
| 376 |
* Set default property to avoid discover new objects in unit of work if |
379 |
* Set default property to avoid discover new objects in unit of work if |
| 377 |
* application always uses persist. |
380 |
* application always uses persist. |
| 378 |
*/ |
381 |
*/ |
| 379 |
public void setPersistOnCommit(boolean persistOnCommit) { |
382 |
public void setPersistOnCommit(boolean persistOnCommit) { |
| 380 |
this.persistOnCommit = persistOnCommit; |
383 |
this.persistOnCommit = persistOnCommit; |
| 381 |
} |
384 |
} |
| 382 |
|
385 |
|
| 383 |
/** |
386 |
/** |
| 384 |
* Return default property to avoid discover new objects in unit of work if application always uses persist. |
387 |
* Return default property to avoid discover new objects in unit of work if |
|
|
388 |
* application always uses persist. |
| 385 |
*/ |
389 |
*/ |
| 386 |
public boolean getCommitWithoutPersistRules() { |
390 |
public boolean getCommitWithoutPersistRules() { |
| 387 |
return commitWithoutPersistRules; |
391 |
return commitWithoutPersistRules; |
| 388 |
} |
392 |
} |
| 389 |
|
393 |
|
| 390 |
/** |
394 |
/** |
| 391 |
* Set default property to avoid discover new objects in unit of work if application always uses persist. |
395 |
* Set default property to avoid discover new objects in unit of work if |
|
|
396 |
* application always uses persist. |
| 392 |
*/ |
397 |
*/ |
| 393 |
public void setCommitWithoutPersistRules(boolean commitWithoutPersistRules) { |
398 |
public void setCommitWithoutPersistRules(boolean commitWithoutPersistRules) { |
| 394 |
this.commitWithoutPersistRules = commitWithoutPersistRules; |
399 |
this.commitWithoutPersistRules = commitWithoutPersistRules; |
| 395 |
} |
400 |
} |
|
|
401 |
|
| 396 |
/** |
402 |
/** |
| 397 |
* Return the default FlashClearCache mode to be used. |
403 |
* Return the default FlashClearCache mode to be used. Relevant only in case |
| 398 |
* Relevant only in case call to flush method followed by call to clear method. |
404 |
* call to flush method followed by call to clear method. |
| 399 |
* @see org.eclipse.persistence.config.FlushClearCache |
405 |
* |
| 400 |
*/ |
406 |
* @see org.eclipse.persistence.config.FlushClearCache |
| 401 |
public String getFlushClearCache() { |
407 |
*/ |
| 402 |
return flushClearCache; |
408 |
public String getFlushClearCache() { |
| 403 |
} |
409 |
return flushClearCache; |
|
|
410 |
} |
| 404 |
|
411 |
|
| 405 |
/** |
412 |
/** |
| 406 |
* Set the default FlashClearCache mode to be used. Relevant only in case |
413 |
* Set the default FlashClearCache mode to be used. Relevant only in case |
| 407 |
* call to flush method followed by call to clear method. |
414 |
* call to flush method followed by call to clear method. |
| 408 |
* |
415 |
* |
| 409 |
* @see org.eclipse.persistence.config.FlushClearCache |
416 |
* @see org.eclipse.persistence.config.FlushClearCache |
| 410 |
*/ |
417 |
*/ |
| 411 |
public void setFlushClearCache(String flushClearCache) { |
418 |
public void setFlushClearCache(String flushClearCache) { |
| 412 |
this.flushClearCache = flushClearCache; |
419 |
this.flushClearCache = flushClearCache; |
| 413 |
} |
420 |
} |
| 414 |
|
421 |
|
| 415 |
/** |
422 |
/** |
| 416 |
* Return the default to determine if does-exist should be performed on |
423 |
* Return the default to determine if does-exist should be performed on |
| 417 |
* persist. |
424 |
* persist. |
| 418 |
*/ |
425 |
*/ |
| 419 |
public boolean shouldValidateExistence() { |
426 |
public boolean shouldValidateExistence() { |
| 420 |
return shouldValidateExistence; |
427 |
return shouldValidateExistence; |
| 421 |
} |
428 |
} |
| 422 |
|
429 |
|
| 423 |
/** |
430 |
/** |
| 424 |
* Set the default to determine if does-exist should be performed on |
431 |
* Set the default to determine if does-exist should be performed on |
| 425 |
* persist. |
432 |
* persist. |
| 426 |
*/ |
433 |
*/ |
| 427 |
public void setShouldValidateExistence(boolean shouldValidateExistence) { |
434 |
public void setShouldValidateExistence(boolean shouldValidateExistence) { |
| 428 |
this.shouldValidateExistence = shouldValidateExistence; |
435 |
this.shouldValidateExistence = shouldValidateExistence; |
| 429 |
} |
436 |
} |
| 430 |
|
437 |
|
| 431 |
public Cache getCache() { |
438 |
public Cache getCache() { |
| 432 |
verifyOpen(); |
439 |
verifyOpen(); |
| 433 |
if (myCache == null) { |
440 |
if (myCache == null) { |
| 434 |
ServerSession session = this.getServerSession(); |
441 |
ServerSession session = this.getServerSession(); |
| 435 |
myCache = new CacheImpl(this, session.getIdentityMapAccessor()); |
442 |
myCache = new CacheImpl(this, session.getIdentityMapAccessor()); |
| 436 |
} |
443 |
} |
| 437 |
return myCache; |
444 |
return myCache; |
| 438 |
} |
445 |
} |
| 439 |
|
446 |
|
| 440 |
/** |
447 |
/** |
| 441 |
* @see javax.persistence.EntityManagerFactory#getProperties() |
448 |
* @see javax.persistence.EntityManagerFactory#getProperties() |
| 442 |
* @since Java Persistence API 2.0 |
449 |
* @since Java Persistence API 2.0 |
| 443 |
*/ |
450 |
*/ |
| 444 |
public Map<String, Object> getProperties() { |
451 |
public Map<String, Object> getProperties() { |
| 445 |
if(!this.isOpen()) { |
452 |
if (!this.isOpen()) { |
| 446 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
453 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
| 447 |
} |
454 |
} |
| 448 |
return Collections.unmodifiableMap(EntityManagerFactoryProvider.mergeMaps(properties, this.getServerSession().getProperties())); |
455 |
return Collections.unmodifiableMap(EntityManagerFactoryProvider.mergeMaps(properties, this.getServerSession().getProperties())); |
| 449 |
} |
456 |
} |
| 450 |
|
457 |
|
| 451 |
/** |
458 |
/** |
| 452 |
* @see javax.persistence.EntityManagerFactory#getCriteriaBuilder() |
459 |
* @see javax.persistence.EntityManagerFactory#getCriteriaBuilder() |
| 453 |
* @since Java Persistence 2.0 |
460 |
* @since Java Persistence 2.0 |
| 454 |
*/ |
461 |
*/ |
| 455 |
public CriteriaBuilder getCriteriaBuilder() { |
462 |
public CriteriaBuilder getCriteriaBuilder() { |
| 456 |
return new CriteriaBuilderImpl(this.getMetamodel()); |
463 |
return new CriteriaBuilderImpl(this.getMetamodel()); |
| 457 |
} |
464 |
} |
| 458 |
|
465 |
|
| 459 |
/** |
466 |
/** |
| 460 |
* Return an instance of Metamodel interface for access to the |
467 |
* Return an instance of Metamodel interface for access to the metamodel of |
| 461 |
* metamodel of the persistence unit. |
468 |
* the persistence unit. |
|
|
469 |
* |
| 462 |
* @return Metamodel instance |
470 |
* @return Metamodel instance |
| 463 |
* @throws IllegalStateException if the entity manager factory has |
471 |
* @throws IllegalStateException |
| 464 |
* been closed. |
472 |
* if the entity manager factory has been closed. |
| 465 |
* @see javax.persistence.EntityManagerFactory#getMetamodel() |
473 |
* @see javax.persistence.EntityManagerFactory#getMetamodel() |
| 466 |
* @since Java Persistence 2.0 |
474 |
* @since Java Persistence 2.0 |
| 467 |
*/ |
475 |
*/ |
| 468 |
public Metamodel getMetamodel() { |
476 |
public Metamodel getMetamodel() { |
| 469 |
if(!this.isOpen()) { |
477 |
if (!this.isOpen()) { |
| 470 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
478 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
| 471 |
} |
479 |
} |
| 472 |
return this.setupImpl.getMetamodel(); |
480 |
return this.setupImpl.getMetamodel(); |
| 473 |
} |
481 |
} |
| 474 |
|
482 |
|
| 475 |
/** |
483 |
/** |
| 476 |
* INTERNAL: |
484 |
* INTERNAL: Convenience function to allow us to reset the Metamodel in the |
| 477 |
* Convenience function to allow us to reset the Metamodel |
485 |
* possible case that we want to regenerate it. This function is outside of |
| 478 |
* in the possible case that we want to regenerate it. |
486 |
* the JPA 2.0 specification. |
| 479 |
* This function is outside of the JPA 2.0 specification. |
487 |
* |
| 480 |
* @param aMetamodel |
488 |
* @param aMetamodel |
| 481 |
* @since Java Persistence 2.0 |
489 |
* @since Java Persistence 2.0 |
| 482 |
*/ |
490 |
*/ |
| 483 |
public void setMetamodel(Metamodel aMetamodel) { |
491 |
public void setMetamodel(Metamodel aMetamodel) { |
| 484 |
if(!this.isOpen()) { |
492 |
if (!this.isOpen()) { |
| 485 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
493 |
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager_factory")); |
| 486 |
} |
494 |
} |
| 487 |
this.setupImpl.setMetamodel(aMetamodel); |
495 |
this.setupImpl.setMetamodel(aMetamodel); |
| 488 |
} |
496 |
} |
| 489 |
|
497 |
|
| 490 |
/** |
498 |
/** |
| 491 |
* Determine the load state of a given persistent attribute |
499 |
* Determine the load state of a given persistent attribute of an entity |
| 492 |
* of an entity belonging to the persistence unit. |
500 |
* belonging to the persistence unit. |
| 493 |
* @param entity containing the attribute |
501 |
* |
| 494 |
* @param attributeName name of attribute whose load state is |
502 |
* @param entity |
| 495 |
* to be determined |
503 |
* containing the attribute |
| 496 |
* @return false if entity's state has not been loaded or |
504 |
* @param attributeName |
| 497 |
* if the attribute state has not been loaded, otherwise true |
505 |
* name of attribute whose load state is to be determined |
|
|
506 |
* @return false if entity's state has not been loaded or if the attribute |
| 507 |
* state has not been loaded, otherwise true |
| 498 |
*/ |
508 |
*/ |
| 499 |
public boolean isLoaded(Object entity, String attributeName){ |
509 |
public boolean isLoaded(Object entity, String attributeName) { |
| 500 |
if (EntityManagerFactoryImpl.isLoaded(entity, attributeName, serverSession).equals(Boolean.valueOf(true))){ |
510 |
if (EntityManagerFactoryImpl.isLoaded(entity, attributeName, serverSession).equals(Boolean.valueOf(true))) { |
| 501 |
return true; |
511 |
return true; |
| 502 |
} |
512 |
} |
| 503 |
return false; |
513 |
return false; |
| 504 |
} |
514 |
} |
| 505 |
|
515 |
|
| 506 |
/** |
516 |
/** |
| 507 |
* Determine the load state of an entity belonging to the |
517 |
* Determine the load state of an entity belonging to the persistence unit. |
| 508 |
* persistence unit. |
518 |
* This method can be used to determine the load state of an entity passed |
| 509 |
* This method can be used to determine the load state |
519 |
* as a reference. An entity is considered loaded if all attributes for |
| 510 |
* of an entity passed as a reference. An entity is |
520 |
* which FetchType EAGER has been specified have been loaded. The |
| 511 |
* considered loaded if all attributes for which FetchType |
521 |
* isLoaded(Object, String) method should be used to determine the load |
| 512 |
* EAGER has been specified have been loaded. |
522 |
* state of an attribute. Not doing so might lead to unintended loading of |
| 513 |
* The isLoaded(Object, String) method should be used to |
523 |
* state. |
| 514 |
* determine the load state of an attribute. |
524 |
* |
| 515 |
* Not doing so might lead to unintended loading of state. |
525 |
* @param entity |
| 516 |
* @param entity whose load state is to be determined |
526 |
* whose load state is to be determined |
| 517 |
* @return false if the entity has not been loaded, else true. |
527 |
* @return false if the entity has not been loaded, else true. |
| 518 |
*/ |
528 |
*/ |
| 519 |
public boolean isLoaded(Object entity){ |
529 |
public boolean isLoaded(Object entity) { |
| 520 |
if (EntityManagerFactoryImpl.isLoaded(entity, serverSession).equals(Boolean.valueOf(true))){ |
530 |
if (EntityManagerFactoryImpl.isLoaded(entity, serverSession).equals(Boolean.valueOf(true))) { |
| 521 |
return true; |
531 |
return true; |
| 522 |
} |
532 |
} |
| 523 |
return false; |
533 |
return false; |
| 524 |
} |
534 |
} |
| 525 |
|
535 |
|
| 526 |
/** |
536 |
/** |
| 527 |
* Returns the id of the entity. |
537 |
* Returns the id of the entity. A generated id is not guaranteed to be |
| 528 |
* A generated id is not guaranteed to be available until after |
538 |
* available until after the database insert has occurred. Returns null if |
| 529 |
* the database insert has occurred. |
539 |
* the entity does not yet have an id |
| 530 |
* Returns null if the entity does not yet have an id |
540 |
* |
| 531 |
* @param entity |
541 |
* @param entity |
| 532 |
* @return id of the entity |
542 |
* @return id of the entity |
| 533 |
* @throws IllegalStateException if the entity is found not to be |
543 |
* @throws IllegalStateException |
| 534 |
* an entity. |
544 |
* if the entity is found not to be an entity. |
| 535 |
*/ |
545 |
*/ |
| 536 |
public Object getIdentifier(Object entity){ |
546 |
public Object getIdentifier(Object entity) { |
| 537 |
return EntityManagerFactoryImpl.getIdentifier(entity, serverSession); |
547 |
return EntityManagerFactoryImpl.getIdentifier(entity, serverSession); |
| 538 |
} |
548 |
} |
| 539 |
|
549 |
|
| 540 |
/** |
550 |
/** |
| 541 |
* Determine the load state of a given persistent attribute |
551 |
* Determine the load state of a given persistent attribute of an entity |
| 542 |
* of an entity belonging to the persistence unit. |
552 |
* belonging to the persistence unit. |
| 543 |
* @param entity containing the attribute |
553 |
* |
| 544 |
* @param attributeName name of attribute whose load state is |
554 |
* @param entity |
| 545 |
* to be determined |
555 |
* containing the attribute |
| 546 |
* @return false if entity's state has not been loaded or |
556 |
* @param attributeName |
| 547 |
* if the attribute state has not been loaded, otherwise true |
557 |
* name of attribute whose load state is to be determined |
|
|
558 |
* @return false if entity's state has not been loaded or if the attribute |
| 559 |
* state has not been loaded, otherwise true |
| 548 |
*/ |
560 |
*/ |
| 549 |
public static Boolean isLoaded(Object entity, String attributeName, AbstractSession session){ |
561 |
public static Boolean isLoaded(Object entity, String attributeName, AbstractSession session) { |
| 550 |
ClassDescriptor descriptor = session.getDescriptor(entity); |
562 |
ClassDescriptor descriptor = session.getDescriptor(entity); |
| 551 |
if (descriptor == null){ |
563 |
if (descriptor == null) { |
| 552 |
return null; |
564 |
return null; |
| 553 |
} |
565 |
} |
| 554 |
DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeName); |
566 |
DatabaseMapping mapping = descriptor.getMappingForAttributeName(attributeName); |
| 555 |
if (mapping == null){ |
567 |
if (mapping == null) { |
| 556 |
return null; |
568 |
return null; |
| 557 |
} |
569 |
} |
| 558 |
return isLoaded(entity, attributeName, mapping); |
570 |
return isLoaded(entity, attributeName, mapping); |
| 559 |
} |
571 |
} |
| 560 |
|
572 |
|
| 561 |
/** |
573 |
/** |
| 562 |
* Check whether a named attribute on a given entity with a given mapping has been loaded. |
574 |
* Check whether a named attribute on a given entity with a given mapping |
|
|
575 |
* has been loaded. |
| 563 |
* |
576 |
* |
| 564 |
* This method will check the valueholder or indirect collection for LAZY ForeignReferenceMappings |
577 |
* This method will check the valueholder or indirect collection for LAZY |
| 565 |
* to see if has been instantiated and otherwise check the fetch group. |
578 |
* ForeignReferenceMappings to see if has been instantiated and otherwise |
|
|
579 |
* check the fetch group. |
| 580 |
* |
| 566 |
* @param entity |
581 |
* @param entity |
| 567 |
* @param attributeName |
582 |
* @param attributeName |
| 568 |
* @param mapping |
583 |
* @param mapping |
| 569 |
* @return |
584 |
* @return |
| 570 |
*/ |
585 |
*/ |
| 571 |
public static boolean isLoaded(Object entity, String attributeName, DatabaseMapping mapping){ |
586 |
public static boolean isLoaded(Object entity, String attributeName, DatabaseMapping mapping) { |
| 572 |
if (mapping.isForeignReferenceMapping()){ |
587 |
if (mapping.isForeignReferenceMapping()) { |
| 573 |
if (((ForeignReferenceMapping)mapping).isLazy()){ |
588 |
if (((ForeignReferenceMapping) mapping).isLazy()) { |
| 574 |
Object value = mapping.getAttributeValueFromObject(entity); |
589 |
Object value = mapping.getAttributeValueFromObject(entity); |
| 575 |
IndirectionPolicy policy = ((ForeignReferenceMapping)mapping).getIndirectionPolicy(); |
590 |
IndirectionPolicy policy = ((ForeignReferenceMapping) mapping).getIndirectionPolicy(); |
| 576 |
return policy.objectIsInstantiated(value); |
591 |
return policy.objectIsInstantiated(value); |
| 577 |
} |
592 |
} |
| 578 |
} |
593 |
} |
| 579 |
|
594 |
|
| 580 |
if (entity instanceof FetchGroupTracker){ |
595 |
if (entity instanceof FetchGroupTracker) { |
| 581 |
return ((FetchGroupTracker)entity)._persistence_isAttributeFetched(attributeName); |
596 |
return ((FetchGroupTracker) entity)._persistence_isAttributeFetched(attributeName); |
| 582 |
} else { |
597 |
} else { |
| 583 |
return true; |
598 |
return true; |
| 584 |
} |
599 |
} |
| 585 |
} |
600 |
} |
| 586 |
|
601 |
|
| 587 |
/** |
602 |
/** |
| 588 |
* Determine the load state of an entity belonging to the |
603 |
* Determine the load state of an entity belonging to the persistence unit. |
| 589 |
* persistence unit. |
604 |
* This method can be used to determine the load state of an entity passed |
| 590 |
* This method can be used to determine the load state |
605 |
* as a reference. An entity is considered loaded if all attributes for |
| 591 |
* of an entity passed as a reference. An entity is |
606 |
* which FetchType EAGER has been specified have been loaded. The |
| 592 |
* considered loaded if all attributes for which FetchType |
607 |
* isLoaded(Object, String) method should be used to determine the load |
| 593 |
* EAGER has been specified have been loaded. |
608 |
* state of an attribute. Not doing so might lead to unintended loading of |
| 594 |
* The isLoaded(Object, String) method should be used to |
609 |
* state. |
| 595 |
* determine the load state of an attribute. |
610 |
* |
| 596 |
* Not doing so might lead to unintended loading of state. |
611 |
* @param entity |
| 597 |
* @param entity whose load state is to be determined |
612 |
* whose load state is to be determined |
| 598 |
* @return false if the entity has not been loaded, else true. |
613 |
* @return false if the entity has not been loaded, else true. |
| 599 |
*/ |
614 |
*/ |
| 600 |
public static Boolean isLoaded(Object entity, AbstractSession session){ |
615 |
public static Boolean isLoaded(Object entity, AbstractSession session) { |
| 601 |
ClassDescriptor descriptor = session.getDescriptor(entity); |
616 |
ClassDescriptor descriptor = session.getDescriptor(entity); |
| 602 |
if (descriptor == null){ |
617 |
if (descriptor == null) { |
| 603 |
return null; |
618 |
return null; |
| 604 |
} |
619 |
} |
| 605 |
List<DatabaseMapping> mappings = descriptor.getMappings(); |
620 |
List<DatabaseMapping> mappings = descriptor.getMappings(); |
| 606 |
Iterator<DatabaseMapping> i = mappings.iterator(); |
621 |
Iterator<DatabaseMapping> i = mappings.iterator(); |
| 607 |
while (i.hasNext()){ |
622 |
while (i.hasNext()) { |
| 608 |
DatabaseMapping mapping = i.next(); |
623 |
DatabaseMapping mapping = i.next(); |
| 609 |
if (!mapping.isLazy() && !isLoaded(entity, mapping.getAttributeName(), mapping)){ |
624 |
if (!mapping.isLazy() && !isLoaded(entity, mapping.getAttributeName(), mapping)) { |
| 610 |
return false; |
625 |
return false; |
| 611 |
} |
626 |
} |
| 612 |
} |
627 |
} |
| 613 |
return true; |
628 |
return true; |
| 614 |
} |
629 |
} |
| 615 |
|
630 |
|
| 616 |
/** |
631 |
/** |
| 617 |
* Returns the id of the entity. |
632 |
* Returns the id of the entity. A generated id is not guaranteed to be |
| 618 |
* A generated id is not guaranteed to be available until after |
633 |
* available until after the database insert has occurred. Returns null if |
| 619 |
* the database insert has occurred. |
634 |
* the entity does not yet have an id |
| 620 |
* Returns null if the entity does not yet have an id |
635 |
* |
| 621 |
* @param entity |
636 |
* @param entity |
| 622 |
* @return id of the entity |
637 |
* @return id of the entity |
| 623 |
* @throws IllegalStateException if the entity is found not to be |
638 |
* @throws IllegalStateException |
| 624 |
* an entity. |
639 |
* if the entity is found not to be an entity. |
| 625 |
*/ |
640 |
*/ |
| 626 |
public static Object getIdentifier(Object entity, AbstractSession session){ |
641 |
public static Object getIdentifier(Object entity, AbstractSession session) { |
| 627 |
ClassDescriptor descriptor = session.getDescriptor(entity); |
642 |
ClassDescriptor descriptor = session.getDescriptor(entity); |
| 628 |
if (descriptor == null){ |
643 |
if (descriptor == null) { |
| 629 |
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("jpa_persistence_util_non_persistent_class ", new Object[]{entity})); |
644 |
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("jpa_persistence_util_non_persistent_class ", new Object[] { entity })); |
| 630 |
} |
645 |
} |
| 631 |
if (descriptor.getCMPPolicy() != null){ |
646 |
if (descriptor.getCMPPolicy() != null) { |
| 632 |
return descriptor.getCMPPolicy().createPrimaryKeyInstance(entity, session); |
647 |
return descriptor.getCMPPolicy().createPrimaryKeyInstance(entity, session); |
| 633 |
} else { |
648 |
} else { |
| 634 |
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("jpa_persistence_util_non_persistent_class ", new Object[]{entity})); |
649 |
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("jpa_persistence_util_non_persistent_class ", new Object[] { entity })); |
| 635 |
} |
650 |
} |
| 636 |
} |
651 |
} |
| 637 |
|
652 |
|