01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.gps.device.jpa;
18:
19: import javax.persistence.EntityManager;
20: import javax.persistence.EntityManagerFactory;
21: import javax.persistence.PersistenceException;
22:
23: /**
24: * An <code>EntityManager<code> wrapper allows controlling the creation and destruction of JPA
25: * <code>EntityManager</code>s, as well as any transactions control (such as JPA resource local
26: * <code>EntityTransaction<code>).
27: * <p>
28: * Used by {@link JpaGpsDevice} when performing the index operation.
29: *
30: * @author kimchy
31: */
32: public interface EntityManagerWrapper {
33:
34: /**
35: * Sets up the entity manager wrapper with the <code>EntityManagerFactory</code>.
36: *
37: * @param entityManagerFactory The <code>EntityManagerFactory</code> the wrapper will use
38: */
39: void setUp(EntityManagerFactory entityManagerFactory);
40:
41: /**
42: * Opens the warpper for a session of reading enteties for indexing.
43: */
44: void open() throws JpaGpsDeviceException, PersistenceException;
45:
46: /**
47: * Returns the <code>EntityManager</code> opened by the wrapper open operation.
48: *
49: * @return The current <code>EntityManager</code>
50: * @throws IllegalStateException If not called between the open and close* operations
51: */
52: EntityManager getEntityManager() throws IllegalStateException;
53:
54: /**
55: * Closes the current <code>EntityManager</code>, commiting the transaction if necessary.
56: *
57: * @throws JpaGpsDeviceException
58: */
59: void close() throws JpaGpsDeviceException, PersistenceException;
60:
61: /**
62: * Closes the current <code>EntityManager</code>, rollback the transaction if necessary.
63: *
64: * @throws JpaGpsDeviceException
65: */
66: void closeOnError() throws JpaGpsDeviceException,
67: PersistenceException;
68:
69: /**
70: * Creates a new instance of this entity manager wrapper for multi threaded usage.
71: */
72: EntityManagerWrapper newInstance();
73: }
|