1 package org.apache.ojb.broker.core; 2 3 17 18 import org.apache.ojb.broker.Identity; 19 import org.apache.ojb.broker.MtoNImplementor; 20 import org.apache.ojb.broker.ManageableCollection; 21 import org.apache.ojb.broker.PBKey; 22 import org.apache.ojb.broker.PBListener; 23 import org.apache.ojb.broker.PBState; 24 import org.apache.ojb.broker.PersistenceBroker; 25 import org.apache.ojb.broker.PersistenceBrokerEvent; 26 import org.apache.ojb.broker.PBLifeCycleEvent; 27 import org.apache.ojb.broker.PBStateEvent; 28 import org.apache.ojb.broker.PersistenceBrokerException; 29 import org.apache.ojb.broker.TransactionAbortedException; 30 import org.apache.ojb.broker.TransactionInProgressException; 31 import org.apache.ojb.broker.TransactionNotInProgressException; 32 import org.apache.ojb.broker.IdentityFactory; 33 import org.apache.ojb.broker.PersistenceBrokerInternal; 34 import org.apache.ojb.broker.accesslayer.ConnectionManagerIF; 35 import org.apache.ojb.broker.accesslayer.JdbcAccess; 36 import org.apache.ojb.broker.accesslayer.StatementManagerIF; 37 import org.apache.ojb.broker.accesslayer.RelationshipPrefetcherFactory; 38 import org.apache.ojb.broker.accesslayer.sql.SqlGenerator; 39 import org.apache.ojb.broker.cache.ObjectCache; 40 import org.apache.ojb.broker.core.proxy.ProxyFactory; 41 import org.apache.ojb.broker.metadata.ClassDescriptor; 42 import org.apache.ojb.broker.metadata.DescriptorRepository; 43 import org.apache.ojb.broker.query.Query; 44 import org.apache.ojb.broker.util.BrokerHelper; 45 import org.apache.ojb.broker.util.ObjectModification; 46 import org.apache.ojb.broker.util.configuration.Configuration; 47 import org.apache.ojb.broker.util.configuration.ConfigurationException; 48 import org.apache.ojb.broker.util.sequence.SequenceManager; 49 50 import java.util.Collection ; 51 import java.util.Enumeration ; 52 import java.util.Iterator ; 53 54 60 public class DelegatingPersistenceBroker implements PersistenceBrokerInternal, PBState 61 { 62 protected PersistenceBrokerInternal m_broker; 63 64 public DelegatingPersistenceBroker(PersistenceBrokerInternal broker) 65 { 66 this.m_broker = broker; 67 } 68 69 73 protected PersistenceBrokerInternal getBroker() 74 { 75 if (m_broker != null) 76 { 77 return m_broker; 78 } 79 else 80 { 81 throw new IllegalStateException ( 82 "This PersistenceBroker instance is already closed and no longer useable." + 83 " It's not possible to re-use a closed instance."); 84 } 85 86 } 87 88 92 public PersistenceBrokerInternal getDelegate() 93 { 94 return this.m_broker; 95 } 96 97 public void setDelegate(PersistenceBrokerInternal broker) 98 { 99 this.m_broker = broker; 100 } 101 102 117 public PersistenceBroker getInnermostDelegate() 118 { 119 PersistenceBroker broker = this.m_broker; 120 while (broker != null && broker instanceof DelegatingPersistenceBroker) 121 { 122 broker = ((DelegatingPersistenceBroker) broker).getDelegate(); 123 if (this == broker) 124 { 125 return null; 126 } 127 } 128 return broker; 129 } 130 131 public boolean isManaged() 132 { 133 return m_broker.isManaged(); 134 } 135 136 public void setManaged(boolean managed) 137 { 138 m_broker.setManaged(managed); 139 } 140 141 public QueryReferenceBroker getReferenceBroker() 142 { 143 return m_broker.getReferenceBroker(); 144 } 145 146 public void checkRefreshRelationships(Object obj, Identity oid, ClassDescriptor cld) 147 { 148 m_broker.checkRefreshRelationships(obj, oid, cld); 149 } 150 151 public RelationshipPrefetcherFactory getRelationshipPrefetcherFactory() 152 { 153 return m_broker.getRelationshipPrefetcherFactory(); 154 } 155 156 public void store(Object obj, Identity oid, ClassDescriptor cld, boolean insert, boolean ignoreReferences) 157 { 158 m_broker.store(obj, oid, cld, insert, ignoreReferences); 159 } 160 161 public void delete(Object obj, boolean ignoreReferences) throws PersistenceBrokerException 162 { 163 m_broker.delete(obj, ignoreReferences); 164 } 165 166 public boolean isInTransaction() throws PersistenceBrokerException 167 { 168 return m_broker != null && getBroker().isInTransaction(); 169 } 170 171 public boolean isClosed() 172 { 173 return m_broker == null || getBroker().isClosed(); 174 } 175 176 public void setClosed(boolean closed) 177 { 178 ((PBState) getBroker()).setClosed(closed); 179 } 180 181 public void beginTransaction() 182 throws TransactionInProgressException, TransactionAbortedException 183 { 184 getBroker().beginTransaction(); 185 } 186 187 public void commitTransaction() 188 throws TransactionNotInProgressException, TransactionAbortedException 189 { 190 getBroker().commitTransaction(); 191 } 192 193 public void abortTransaction() throws TransactionNotInProgressException 194 { 195 getBroker().abortTransaction(); 196 } 197 198 public boolean close() 199 { 200 return getBroker().close(); 201 } 202 203 public SqlGenerator serviceSqlGenerator() 204 { 205 return getBroker().serviceSqlGenerator(); 206 } 207 208 public JdbcAccess serviceJdbcAccess() 209 { 210 return getBroker().serviceJdbcAccess(); 211 } 212 213 public void delete(Object obj) throws PersistenceBrokerException 214 { 215 getBroker().delete(obj); 216 } 217 218 public void store(Object obj) throws PersistenceBrokerException 219 { 220 getBroker().store(obj); 221 } 222 223 public void store(Object obj, 224 ObjectModification modification) throws PersistenceBrokerException 225 { 226 getBroker().store(obj, modification); 227 } 228 229 public PBKey getPBKey() 230 { 231 return getBroker().getPBKey(); 232 } 233 234 public void removeFromCache(Object obj) throws PersistenceBrokerException 235 { 236 getBroker().removeFromCache(obj); 237 } 238 239 public void clearCache() throws PersistenceBrokerException 240 { 241 getBroker().clearCache(); 242 } 243 244 public DescriptorRepository getDescriptorRepository() 245 { 246 return getBroker().getDescriptorRepository(); 247 } 248 249 public void removeAllListeners() throws PersistenceBrokerException 250 { 251 getBroker().removeAllListeners(); 252 } 253 254 public void removeAllListeners(boolean permanent) throws PersistenceBrokerException 255 { 256 getBroker().removeAllListeners(permanent); 257 } 258 259 public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException 260 { 261 getBroker().retrieveReference(pInstance, pAttributeName); 262 } 263 264 public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException 265 { 266 getBroker().retrieveAllReferences(pInstance); 267 } 268 269 public ConnectionManagerIF serviceConnectionManager() 270 { 271 return getBroker().serviceConnectionManager(); 272 } 273 274 public StatementManagerIF serviceStatementManager() 275 { 276 return getBroker().serviceStatementManager(); 277 } 278 279 public SequenceManager serviceSequenceManager() 280 { 281 return getBroker().serviceSequenceManager(); 282 } 283 284 public BrokerHelper serviceBrokerHelper() 285 { 286 return getBroker().serviceBrokerHelper(); 287 } 288 289 public ObjectCache serviceObjectCache() 290 { 291 return getBroker().serviceObjectCache(); 292 } 293 294 public IdentityFactory serviceIdentity() 295 { 296 return getBroker().serviceIdentity(); 297 } 298 299 public void fireBrokerEvent(PersistenceBrokerEvent event) 300 { 301 getBroker().fireBrokerEvent(event); 302 } 303 304 public void fireBrokerEvent(PBLifeCycleEvent event) 305 { 306 getBroker().fireBrokerEvent(event); 307 } 308 309 public void fireBrokerEvent(PBStateEvent event) 310 { 311 getBroker().fireBrokerEvent(event); 312 } 313 314 public void addListener(PBListener listener) throws PersistenceBrokerException 315 { 316 getBroker().addListener(listener); 317 } 318 319 public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException 320 { 321 getBroker().addListener(listener, permanent); 322 } 323 324 public void removeListener(PBListener listener) throws PersistenceBrokerException 325 { 326 } 328 329 public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException 330 { 331 return getBroker().getTopLevelClass(clazz); 332 } 333 334 public boolean hasClassDescriptor(Class clazz) 335 { 336 return getBroker().hasClassDescriptor(clazz); 337 } 338 339 public ClassDescriptor getClassDescriptor(Class clazz) throws PersistenceBrokerException 340 { 341 return getBroker().getClassDescriptor(clazz); 342 } 343 344 public Enumeration getPKEnumerationByQuery(Class primaryKeyClass, 345 Query query) throws PersistenceBrokerException 346 { 347 return getBroker().getPKEnumerationByQuery(primaryKeyClass, query); 348 } 349 350 public Object getObjectByQuery(Query query) throws PersistenceBrokerException 351 { 352 return getBroker().getObjectByQuery(query); 353 } 354 355 public Object getObjectByIdentity(Identity id) throws PersistenceBrokerException 356 { 357 return getBroker().getObjectByIdentity(id); 358 } 359 360 public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException 361 { 362 return getBroker().getReportQueryIteratorByQuery(query); 363 } 364 365 public Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException 366 { 367 return getBroker().getIteratorByQuery(query); 368 } 369 370 public ManageableCollection getCollectionByQuery(Class collectionClass, Query query) 371 throws PersistenceBrokerException 372 { 373 return getBroker().getCollectionByQuery(collectionClass, query); 374 } 375 376 public int getCount(Query query) throws PersistenceBrokerException 377 { 378 return getBroker().getCount(query); 379 } 380 381 public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException 382 { 383 return getBroker().getCollectionByQuery(query); 384 } 385 386 public void configure(Configuration pConfig) throws ConfigurationException 387 { 388 getBroker().configure(pConfig); 389 } 390 391 public org.odbms.Query query() 392 { 393 return getBroker().query(); 394 } 395 396 public void deleteByQuery(Query query) throws PersistenceBrokerException 397 { 398 getBroker().deleteByQuery(query); 399 } 400 401 404 public void deleteMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException 405 { 406 getBroker().deleteMtoNImplementor(m2nImpl); 407 } 408 409 412 public void addMtoNImplementor(MtoNImplementor m2nImpl) throws PersistenceBrokerException 413 { 414 getBroker().addMtoNImplementor(m2nImpl); 415 } 416 417 public ProxyFactory getProxyFactory() 418 { 419 return getBroker().getProxyFactory(); 420 } 421 422 public Object createProxy(Class proxyClass, Identity realSubjectsIdentity) { 423 return getBroker().createProxy(proxyClass, realSubjectsIdentity); 424 } 425 426 427 428 429 } 430 | Popular Tags |