1 /***************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 ****************************************************************/ 19 20 package org.apache.cayenne; 21 22 import java.io.Serializable; 23 24 /** 25 * Provides a level of indirection for property value access, most often used for deferred 26 * faulting of to-one relationships. A ValueHolder abstracts how a property value is 27 * obtained (fetched from DB, etc.), thus simplifying design of an object that uses it. 28 * <p> 29 * Here is an example of a bean property implemented using ValueHolder: 30 * </p> 31 * 32 * <pre> 33 * protected ValueHolder someProperty; 34 * 35 * public SomeClass getSomeProperty() { 36 * return (SomeClass) somePropertyHolder.getValue(SomeClass.class); 37 * } 38 * 39 * public void setSomeProperty(SomeClass newValue) { 40 * somePropertyHolder.setValue(SomeClass.class, newValue); 41 * } 42 * </pre> 43 * 44 * @since 1.2 45 * @author Andrus Adamchik 46 */ 47 public interface ValueHolder extends Serializable { 48 49 /** 50 * Returns an object stored by this ValueHolder. 51 */ 52 Object getValue() throws CayenneRuntimeException; 53 54 /** 55 * Retrieves ValueHolder value without triggering fault resolution. 56 */ 57 Object getValueDirectly() throws CayenneRuntimeException; 58 59 /** 60 * Sets an object stored by this ValueHolder. 61 * 62 * @param value a new value of the ValueHolder. 63 * @return a previous value saved in the ValueHolder. 64 */ 65 Object setValue(Object value) throws CayenneRuntimeException; 66 67 /** 68 * Sets ValueHolder vaue without triggering fault resolution. 69 */ 70 Object setValueDirectly(Object value) throws CayenneRuntimeException; 71 72 /** 73 * Returns true if the internal value is not yet resolved. 74 */ 75 boolean isFault(); 76 77 /** 78 * Turns a ValueHolder into a fault. 79 */ 80 void invalidate(); 81 } 82