| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| HibernateRepository |
|
| 1.0;1 |
| 1 | /** | |
| 2 | * Copyright (C) 2013 Matthias Langer | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 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 | package at.ipsquare.commons.hibernate; | |
| 17 | ||
| 18 | import java.io.Closeable; | |
| 19 | ||
| 20 | import org.hibernate.Session; | |
| 21 | import org.hibernate.Transaction; | |
| 22 | ||
| 23 | import at.ipsquare.commons.core.interfaces.ExecutionError; | |
| 24 | import at.ipsquare.commons.core.interfaces.UnitOfWork; | |
| 25 | import at.ipsquare.commons.core.interfaces.UnitOfWorkExecutor; | |
| 26 | ||
| 27 | /** | |
| 28 | * Wraps our Hibernate repository. | |
| 29 | * | |
| 30 | * <h4>Notes:</h4> | |
| 31 | * <ul> | |
| 32 | * <li>Implementations of this interface can be expected to be thread save.</li> | |
| 33 | * </ul> | |
| 34 | * | |
| 35 | * @author Matthias Langer | |
| 36 | * @since 2.0.0 | |
| 37 | */ | |
| 38 | public interface HibernateRepository extends UnitOfWorkExecutor, Closeable | |
| 39 | { | |
| 40 | /** | |
| 41 | * Executes the given {@link UnitOfWork} within a single transaction. | |
| 42 | * | |
| 43 | * <h4>Notes:</h4> | |
| 44 | * <ul> | |
| 45 | * <li>If you need more fine grained transaction management, you can do so by manipulating {@link #currentSession()} accordingly.</li> | |
| 46 | * <li>Implementations of this class can be expected to be thread save; executing multiple units of work concurrently is save.</li> | |
| 47 | * <li> | |
| 48 | * It is not an error to execute a {@link UnitOfWork} while another {@link UnitOfWork} is already executing. However note that | |
| 49 | * when doing so the {@link Session} or the current {@link Transaction} is not modified. | |
| 50 | * </li> | |
| 51 | * </ul> | |
| 52 | * | |
| 53 | * @param work a {@link UnitOfWork} that should be executed. | |
| 54 | * @return the result of the {@link UnitOfWork}. | |
| 55 | * | |
| 56 | * @throws ExecutionError if {@link UnitOfWork#execute()} throws an exception. | |
| 57 | */ | |
| 58 | <T> T executeUnitOfWork(UnitOfWork<T> work); | |
| 59 | ||
| 60 | /** | |
| 61 | * Returns the currently open session for this thread. | |
| 62 | * | |
| 63 | * @throws IllegalStateException if no {@link UnitOfWork} is currently executing in this thread. | |
| 64 | */ | |
| 65 | Session currentSession(); | |
| 66 | ||
| 67 | /** | |
| 68 | * Closes the repository (all acquired resources are released). | |
| 69 | */ | |
| 70 | @Override | |
| 71 | void close(); | |
| 72 | ||
| 73 | /** | |
| 74 | * Returns true if the repository is closed. | |
| 75 | */ | |
| 76 | boolean isClosed(); | |
| 77 | } |