KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > jpa > JpaOperations


1 /*
2  * Copyright 2002-2006 the original author or authors.
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
17 package org.springframework.orm.jpa;
18
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.springframework.dao.DataAccessException;
23
24 /**
25  * Interface that specifies a basic set of JPA operations,
26  * implemented by {@link JpaTemplate}. Not often used, but a useful
27  * option to enhance testability, as it can easily be mocked or stubbed.
28  *
29  * <p>Defines <code>JpaTemplate</code>'s data access methods that mirror
30  * various {@link javax.persistence.EntityManager} methods. Users are
31  * strongly encouraged to read the JPA <code>EntityManager</code>
32  * javadocs for details on the semantics of those methods.
33  *
34  * <p>Note that lazy loading will just work with an open JPA
35  * <code>EntityManager</code>, either within a managed transaction or within
36  * {@link org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter}/
37  * {@link org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor}.
38  * Furthermore, some operations just make sense within transactions,
39  * for example: <code>flush</code>, <code>clear</code>.
40  *
41  * @author Juergen Hoeller
42  * @since 2.0
43  * @see JpaTemplate
44  * @see javax.persistence.EntityManager
45  * @see JpaTransactionManager
46  * @see JpaDialect
47  * @see org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
48  * @see org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor
49  */

50 public interface JpaOperations {
51
52     Object JavaDoc execute(JpaCallback action) throws DataAccessException;
53
54     List JavaDoc executeFind(JpaCallback action) throws DataAccessException;
55
56     <T> T find(Class JavaDoc<T> entityClass, Object JavaDoc id) throws DataAccessException;
57
58     <T> T getReference(Class JavaDoc<T> entityClass, Object JavaDoc id) throws DataAccessException;
59
60     boolean contains(Object JavaDoc entity) throws DataAccessException;
61
62     void refresh(Object JavaDoc entity) throws DataAccessException;
63
64     void persist(Object JavaDoc entity) throws DataAccessException;
65
66     <T> T merge(T entity) throws DataAccessException;
67
68     void remove(Object JavaDoc entity) throws DataAccessException;
69
70     void flush() throws DataAccessException;
71
72     List JavaDoc find(String JavaDoc queryString) throws DataAccessException;
73
74     List JavaDoc find(String JavaDoc queryString, Object JavaDoc... values) throws DataAccessException;
75
76     List JavaDoc findByNamedParams(String JavaDoc queryString, Map JavaDoc<String JavaDoc,? extends Object JavaDoc> params) throws DataAccessException;
77
78     List JavaDoc findByNamedQuery(String JavaDoc queryName) throws DataAccessException;
79
80     List JavaDoc findByNamedQuery(String JavaDoc queryName, Object JavaDoc... values) throws DataAccessException;
81
82     List JavaDoc findByNamedQueryAndNamedParams(String JavaDoc queryName, Map JavaDoc<String JavaDoc,? extends Object JavaDoc> params) throws DataAccessException;
83
84 }
85
Popular Tags