001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.bo; 017 018import org.kuali.rice.core.api.mo.common.GloballyUnique; 019import org.kuali.rice.core.api.mo.common.Versioned; 020 021import java.util.Collection; 022import java.util.List; 023import java.util.UUID; 024 025/** 026 * Declares a common interface for all {@link BusinessObject} classes which can have their 027 * state persisted. A business object which is persistable defines some additional methods 028 * which allow for various operations to be executed that relate to the persistent nature of 029 * the business object. A persistable business object also has some additional data 030 * attributes which include the version number, the object id, and the extension. 031 * 032 * <p>The version number indicates the version of the business object when it was retrieved 033 * from persistent storage. This allows for services to check this version number 034 * during persistence operations to prevent silent overwrites of business object state. 035 * These kinds of scenarios might arise as a result of concurrent modification to the business 036 * object in the persistent store (i.e. two web application users updating the same record 037 * in a database). The kind of check which would be performed using the version number is commonly 038 * referred to as "optimistic locking". 039 * 040 * <p>The object id represents a globally unique identifier for the business object. In practice, 041 * this can be used by other portions of the system to link to persistable business objects which 042 * might be stored in different locations or even different persistent data stores. In general, it 043 * is not the responsibility of the client who implements a persistable business object to handle 044 * generating this value. The framework will handle this automatically at the point in time when 045 * the business object is persisted. If the client does need to do this themselves, however, care 046 * should be taken that an appropriate globally unique value generator algorithm is used 047 * (such as the one provided by {@link UUID}). 048 * 049 * <p>The extension object is primarily provided for the purposes of allowing implementer 050 * customization of the business object without requiring the original business object to be 051 * modified. The additional {@link PersistableBusinessObjectExtension} which is linked with the 052 * parent business object can contain additional data attributes and methods. The framework will 053 * automatically request that this extension object be persisted when the parent business object 054 * is persisted. This is generally the most useful in cases where an application is defining 055 * business objects that will be used in redistributable software packages (such as the 056 * actual Kuali Foundation projects themselves). If using the framework for the purposes 057 * of implementing an internal application, the use of a business object extensions 058 * is likely unnecessary. 059 * 060 * @author Kuali Rice Team (rice.collab@kuali.org) 061 */ 062public interface PersistableBusinessObject extends BusinessObject, Versioned, GloballyUnique { 063 064 /** 065 * Sets the business object's version number. It is rarely advisable 066 * for client code to manually set this value as the framework should 067 * generally handle the management of version numbers internally. 068 * 069 * @param versionNumber the version number to set on this business object 070 */ 071 public void setVersionNumber(Long versionNumber); 072 073 /** 074 * Sets the unique identifier for the object 075 * 076 * @param objectId 077 */ 078 public void setObjectId(String objectId); 079 080 public PersistableBusinessObjectExtension getExtension(); 081 082 public void setExtension(PersistableBusinessObjectExtension extension); 083 084 /** 085 * @see BusinessObject#refresh() 086 */ 087 public abstract void refreshNonUpdateableReferences(); 088 089 /** 090 * This method is used to refresh a reference object that hangs off of a document. For example, if the attribute's keys were 091 * updated for a reference object, but the reference object wasn't, this method would go out and retrieve the reference object. 092 * 093 * @param referenceObjectName 094 */ 095 public abstract void refreshReferenceObject(String referenceObjectName); 096 097 /** 098 * If this method is not implemented appropriately for PersistableBusinessObject with collections, then PersistableBusinessObject with collections will not persist deletions correctly. 099 * Elements that have been deleted will reappear in the DB after retrieval. 100 * 101 * @return List of collections which need to be monitored for changes by OJB 102 */ 103 public List<Collection<PersistableBusinessObject>> buildListOfDeletionAwareLists(); 104 105 /** 106 * Returns the boolean indicating whether this record is a new record of a maintenance document collection. 107 * Used to determine whether the record can be deleted on the document. 108 */ 109 public boolean isNewCollectionRecord(); 110 111 /** 112 * Sets the boolean indicating this record is a new record of a maintenance document collection. 113 * Used to determine whether the record can be deleted on the document. 114 */ 115 public void setNewCollectionRecord(boolean isNewCollectionRecord); 116 117 /** 118 * Hook to link in any editable user fields. 119 */ 120 public void linkEditableUserFields(); 121 122 123 124}