Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Mapper |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright 2003-2004 The Apache Software Foundation. | |
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.apache.commons.mapper; | |
18 | ||
19 | import java.util.Collection; | |
20 | ||
21 | /** | |
22 | * A Mapper is responsible for mapping domain objects to a persistent data store. | |
23 | * By removing this functionality from the domain objects, the backend | |
24 | * datastore implementation is allowed to change without affecting any domain | |
25 | * objects. Examples of Mapper implementations include JdbcMapper, EjbMapper, | |
26 | * and JdoMapper which store data using their respective technologies. | |
27 | * <p> | |
28 | * Additionally, Mappers decouple your application from the underlying mapping | |
29 | * technology. You might use JdbcMappers for a small website and then migrate | |
30 | * to EjbMappers as the site grows without your application code changing. | |
31 | * <p> | |
32 | * Mapper implementations should not use instance variables to maintain state | |
33 | * because they will be run in a multi-threaded environment. The MapperFactory | |
34 | * will return the same instance of a Mapper every time it's requested. Mappers | |
35 | * should use local method variables and method parameters to maintain thread | |
36 | * safety. | |
37 | * <p> | |
38 | * Mapper is equivalent to the concept of a data access object (DAO). | |
39 | * | |
40 | * @see MapperFactory | |
41 | */ | |
42 | public interface Mapper { | |
43 | ||
44 | /** | |
45 | * Create the given object in a persistent data store. The | |
46 | * Mapper should document what type of Object is expected. | |
47 | * @return Object the created object's unique id. | |
48 | * @throws MapperException | |
49 | * @throws UnsupportedOperationException if this mapper doesn't support this | |
50 | * method. | |
51 | */ | |
52 | Object create(Object object) throws MapperException; | |
53 | ||
54 | /** | |
55 | * Find the given Object based on its unique identifier. This could be a primary | |
56 | * key for relational database backends or an ID field in an XML file for XML | |
57 | * implementations. The Mapper should document what type of object is | |
58 | * expected and what type it returns. | |
59 | * @param id An Object that represents a unique ID or a container for | |
60 | * composite key values. | |
61 | * @return Object a single object with the given id or null if none found | |
62 | * @throws MapperException | |
63 | * @throws UnsupportedOperationException if this mapper doesn't support this | |
64 | * method. | |
65 | */ | |
66 | Object findByUniqueId(Object id) throws MapperException; | |
67 | ||
68 | /** | |
69 | * Remove an object from the data store. | |
70 | * @throws MapperException | |
71 | * @throws UnsupportedOperationException if this mapper doesn't support this | |
72 | * method. | |
73 | */ | |
74 | void delete(Object object) throws MapperException; | |
75 | ||
76 | /** | |
77 | * Update the given object in the data store. | |
78 | * @throws MapperException | |
79 | * @throws UnsupportedOperationException if this mapper doesn't support this | |
80 | * method. | |
81 | */ | |
82 | void update(Object object) throws MapperException; | |
83 | ||
84 | /** | |
85 | * Returns a Collection of all objects for the given mapper. | |
86 | * @throws MapperException | |
87 | * @throws UnsupportedOperationException if this mapper doesn't support this | |
88 | * method. | |
89 | */ | |
90 | Collection findAllObjects() throws MapperException; | |
91 | ||
92 | } |