/
IObject.java
133 lines (119 loc) · 4.29 KB
/
IObject.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* ome.model.IObject
*
* Copyright 2006 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*/
package ome.model;
import java.io.Serializable;
import java.util.Set;
import ome.conditions.ApiUsageException;
import ome.model.internal.Details;
import ome.model.internal.GraphHolder;
import ome.util.Filterable;
import ome.util.Validation;
/**
* central model interface. All entities that the backend can persist to the DB
* implement this interface. (Note: value objects like
* {@link ome.model.internal.Details} get saved to the DB, but only embedded in
* other entites.
*
* @author Josh Moore <a
* href="mailto:josh.moore@gmx.de">josh.moore@gmx.de</a>
* @version 3.0
* @since 3.0
* @author josh
*
*/
public interface IObject extends Filterable, Serializable {
/**
* primary key of this object. Before the session is flushed, this value
* <em>may be</em> null.
*
* @return Long primary key. May be null.
*/
public Long getId();
/**
* usually unneeded. Ids are managed by the backend.
*
* @param id
* Long value for this id.
*/
public void setId(Long id);
// ~ Security
// =========================================================================
/**
* Value (i.e. not entity) which is available on all rows in the database.
* Low-level "details" such as security, ownership, auditing are managed
* here.
*
* When setting values on {@link Details}, it is important to realize that
* most of the values are managed by the backend and may be replaced. For
* example, a user does not have permission to change the owner of an
* object, not even when owned by that user.
*
* To replace all of the values from an existing {@link Details} instance,
* use {@link Details#copy(Details)} or {@link Details#shallowCopy(Details)}
*/
public Details getDetails();
// ~ Lifecycle
// =========================================================================
/**
* transient field (not stored in the DB) which specifies whether this
* object has been loaded from the DB or is only a wrapper around the ID.
*/
public boolean isLoaded();
/**
* set the loaded field to false, and set all non-ID fields to null.
* Subsequent calls to all accessors other than getId/setId will throw an
* ApiUsageException
*
* @throws ApiUsageException
*/
public void unload() throws ApiUsageException;
// ~ Validation
// =========================================================================
/**
* calls the class-specific validator for this instance and returns the
* value from {@link Validation#isValid()}
*/
public boolean isValid();
/**
* calls the class-specific validator for this instance and returns the
* {@link Validation} object.
*
* @return Validation collecting parameter.
*/
public Validation validate();
// ~ For dynamic/generic programming
// =========================================================================
/**
* retrieves a value from this instance. Values for <code>field</code>
* which match a field of this instance will be delegated to the accessors.
* Otherwise, values will be retrieved from a lazy-loaded map filled by
* calls to {@link #putAt(String, Object)}
*/
public Object retrieve(String field);
/**
* stores a value in this instance. Values for <code>field</code> which
* match a field of this instance will be delegated to the accessors.
* Otherwise, values will be stored in a lazy-loaded map.
*
* @param field
* Field name
* @param value
* Any object to be stored.
*/
public void putAt(String field, Object value);
/** returns a Set of field names that belong to this class */
public Set fields();
// ~ Graph information
// =========================================================================
/**
* retrieves the {@link GraphHolder} for this entity. If the GraphHolder has
* not been actively set, a new one will be instatiated.
*
* @return Non-null GraphHolder
*/
public GraphHolder getGraphHolder();
}