1 /** 2 * Copyright (C) 2005-2009 Alfresco Software Limited. 3 * 4 * This file is part of the Spring Surf Extension project. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * 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, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.springframework.extensions.surf; 20 21 import java.util.Map; 22 23 import org.springframework.extensions.surf.exception.ModelObjectPersisterException; 24 25 /** 26 * @author muzquiano 27 */ 28 public interface ModelObjectPersister 29 { 30 /** 31 * Initializes the persister by preloading the object cache 32 * 33 * @param context the persistence context 34 */ 35 public void init(ModelPersistenceContext context); 36 37 /** 38 * Resets the persister, clearing cache and starting anew. 39 */ 40 public void reset(); 41 42 /** 43 * Returns a unique id for this persister 44 * 45 * If this persister is wrapped around a ClassPath store, 46 * a LocalFileSystem store or a Repository store, this will return 47 * the value provided getBasePath() 48 * 49 * If this is wrapped around a RemoteStore, this will return the 50 * AVM Store ID to which this persister is bound 51 * 52 * @return 53 */ 54 public String getId(); 55 56 /** 57 * Gets an object from persisted storage by id 58 * 59 * @param context 60 * @param objectTypeId 61 * @param objectId 62 * 63 * @return object instance 64 */ 65 public ModelObject getObject(ModelPersistenceContext context, String objectTypeId, String objectId) 66 throws ModelObjectPersisterException; 67 68 /** 69 * Saves an object to persisted storage 70 * 71 * @param context 72 * @param object 73 * 74 * @return whether the object was saved 75 */ 76 public boolean saveObject(ModelPersistenceContext context, ModelObject object) 77 throws ModelObjectPersisterException; 78 79 /** 80 * Removes an object from persisted storage 81 * 82 * @param context 83 * @param object 84 * 85 * @return whether the object was removed 86 */ 87 public boolean removeObject(ModelPersistenceContext context, ModelObject object) 88 throws ModelObjectPersisterException; 89 90 /** 91 * Removes an object from persisted storage 92 * 93 * @param context 94 * @param objectTypeId 95 * @param objectId 96 * 97 * @return whether the object was removed 98 */ 99 public boolean removeObject(ModelPersistenceContext context, String objectTypeId, String objectId) 100 throws ModelObjectPersisterException; 101 102 /** 103 * Checks whether the given object is persisted 104 * 105 * @param context 106 * @param object 107 * 108 * @return whether the object is persisted 109 */ 110 public boolean hasObject(ModelPersistenceContext context, ModelObject object) 111 throws ModelObjectPersisterException; 112 113 /** 114 * Checks whether an object with the given path is persisted 115 * 116 * @param context 117 * @param objectTypeId 118 * @param objectId 119 * 120 * @return whether the object is persisted 121 */ 122 public boolean hasObject(ModelPersistenceContext context, String objectTypeId, String objectId) 123 throws ModelObjectPersisterException; 124 125 /** 126 * Creates a new object 127 * 128 * @param context 129 * @param objectTypeId 130 * @param objectId 131 * 132 * @return the object 133 */ 134 public ModelObject newObject(ModelPersistenceContext context, String objectTypeId, String objectId) 135 throws ModelObjectPersisterException; 136 137 /** 138 * Returns a map of all of the objects referenced by this persister. 139 * <p> 140 * In general, this is a very expensive call and should be avoided. Each object 141 * descriptor referenced by the persister is loaded into the model object cache. 142 * 143 * @param context 144 * @param objectTypeId 145 * 146 * @return Map of object IDs to ModelObject instances 147 * 148 * @throws ModelObjectException 149 */ 150 public Map<String, ModelObject> getAllObjects(ModelPersistenceContext context, String objectTypeId) 151 throws ModelObjectPersisterException; 152 153 /** 154 * Returns a map of all of the objects referenced by this persister filtered by 155 * the given ID filter. 156 * <p> 157 * In general, this is an expensive call but less expensive than getAllObjects(). 158 * Each object descriptor referenced by the persister found using the filter is 159 * loaded into the model object cache. 160 * 161 * @param context 162 * @param objectTypeId 163 * @param objectIdPattern 164 * 165 * @return Map of object IDs to ModelObject instances 166 * 167 * @throws ModelObjectException 168 */ 169 public Map<String, ModelObject> getAllObjectsByFilter(ModelPersistenceContext context, String objectTypeId, String objectIdPattern) 170 throws ModelObjectPersisterException; 171 172 /** 173 * Returns the timestamp of the given object in the underlying store 174 * 175 * @param context 176 * @param objectTypeId 177 * @param objectId 178 * @return 179 * @throws ModelObjectPersisterException 180 */ 181 public long getTimestamp(ModelPersistenceContext context, String objectTypeId, String objectId) 182 throws ModelObjectPersisterException; 183 184 /** 185 * Indicates whether this persisted is currently enabled. 186 * Disabled persisters continue to work but do not modify data. 187 * 188 * @return flag 189 */ 190 public boolean isEnabled(); 191 }