01: /*
02: * Copyright 2002-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.springframework.orm.jpa;
18:
19: import java.util.List;
20: import java.util.Map;
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 execute(JpaCallback action) throws DataAccessException;
53:
54: List executeFind(JpaCallback action) throws DataAccessException;
55:
56: <T> T find(Class<T> entityClass, Object id)
57: throws DataAccessException;
58:
59: <T> T getReference(Class<T> entityClass, Object id)
60: throws DataAccessException;
61:
62: boolean contains(Object entity) throws DataAccessException;
63:
64: void refresh(Object entity) throws DataAccessException;
65:
66: void persist(Object entity) throws DataAccessException;
67:
68: <T> T merge(T entity) throws DataAccessException;
69:
70: void remove(Object entity) throws DataAccessException;
71:
72: void flush() throws DataAccessException;
73:
74: List find(String queryString) throws DataAccessException;
75:
76: List find(String queryString, Object... values)
77: throws DataAccessException;
78:
79: List findByNamedParams(String queryString,
80: Map<String, ? extends Object> params)
81: throws DataAccessException;
82:
83: List findByNamedQuery(String queryName) throws DataAccessException;
84:
85: List findByNamedQuery(String queryName, Object... values)
86: throws DataAccessException;
87:
88: List findByNamedQueryAndNamedParams(String queryName,
89: Map<String, ? extends Object> params)
90: throws DataAccessException;
91:
92: }
|