📄 ozoneobject.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: OzoneObject.java,v 1.15 2003/12/06 20:59:44 per_nyfelt Exp $package org.ozoneDB;import org.ozoneDB.core.ObjectContainer;import org.ozoneDB.core.ObjectID;import org.xml.sax.ContentHandler;import org.xml.sax.SAXException;/** * This class can be extended to build actual database objects. It provides a * default implementation of the {@link OzoneCompatible} interface. * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.15 $Date: 2003/12/06 20:59:44 $ */public class OzoneObject implements OzoneCompatible { final static long serialVersionUID = 3171995582505722338L; transient ObjectContainer container = null; public int hashCode() { return container.id().hashCode(); } public synchronized void setContainer(ObjectContainer _container) { container = _container; } public OzoneProxy self() { if (container == null) { throw new RuntimeException("The object of class " + this.getClass().getName() + " is not (yet) associated to a database container."); } return container.ozoneProxy(); } public ObjectContainer container() { if (container == null) { throw new RuntimeException("The object of class " + this.getClass().getName() + " is not (yet) associated to a database container."); } return container; } /** * Retrieves a handle to a specific instance of an OzoneObject. A handle is * the externalizeable equivalent of OzoneProxy. The purpose of handles is to enable * detached systems (such as web interfaces) that are not able to use OzoneProxy * objects directly a means to access specific objects where object naming is not * practical or convenient. A handle is valid for the lifetime of * the OzoneObject it references. Unlike OzoneProxy, retrieving a handle on an * object does nothing to guarantee its existence. While the handle is valid * for the lifetime of the object it refers to, that object's lifetime may * be shorter than the handle's. * <br><br> * The resultant string representation will be composed * entirely of alphanumeric characters [A-Z], [a-z], and [0-9]; as such, * it can safely and reliably be used in URLs without need for escaping. * */ public String getHandle() { if (container == null) { throw new RuntimeException("The object of class " + this.getClass().getName() + " is not (yet) associated to a database container."); } return container.id().toString(); } /** * @deprecated use getHandle() */ public String handle() { return getHandle(); } public OzoneInterface database() { if (container == null) { return CurrentDatabase.get(); } return container.database(); } public String toString() { return "OzoneObject, ID: " + (container != null ? container.id().toString() : "null"); } /** * This default implementation of the onCreate() method does nothing. */ public void onCreate() { } /** * This method will be automaticly called immediately after this object is * loaded (deserialized) from storage. * This default implementation of the onActivate() method does nothing. */ public void onActivate() { //System.out.println("[OzoneObject] - onActivate called for " + getClass().getName()); } /** Calling this tells the OzoneDatabase to upgrade the locking of this OzoneObject (more precisely: of this {@link ObjectContainer}) to write-locking if it is not already write locked. After calling this, you may safely change members if the Object. <DIV> Note that calling this method currently should only be done from {@link #onActivate}, though it may be possible to call it from any user method. </DIV> <DIV> Please do not override this method. We reserve the right to make it final. </DIV> <DIV> Some specifics on the implementation: Require write locking upgrades the locking of this object to write-locking, if it was not already write-locked. If the upgrade is not possible, because other transactions also read-locked this object, this method waits until this is complete. If a deadlock happens, this method may throw a TransactionError due to that deadlock. In this case, the transaction is retried, which means that calling {@link #onActivate()} is retried. So it is guaranteed that write-locking is established after this call. </DIV> */ protected void requireWriteLocking() { container.requireWriteLocking(); } /** * This method will be automaticly called immediately before this object is * stored (serialized) to storage. */ public void onPassivate() { //System.out.println("[OzoneObject] - onPassivate called for " + getClass().getName()); } /** * This default implementation of the onDelete() method does nothing. */ public void onDelete() { } // This Method is not needed anymore, because it is only used in ClassicStore /** * This default implementation of the size() method. It returns just -1 to * signal that a default value should be used. * public int size() throws Exception { return -1; } */ /** * This default implementation of the toSAX() method. It returns just false * to signal that a default value should be used. */ public boolean toXML(ContentHandler ch) throws SAXException { return false; } public void deleteRecursive() { throw new RuntimeException("deleteRecursive() is not implemented yet."); } /** Returns the ObjectID of the represented ozone object. ObjectIDs are equal for equal ozone objects and different for different ozone objects. They are comparable, so that ozone objects may use {@link org.ozoneDB.core.ObjectID#compareTo(Object)} in comparison functions. <p> Currently, ObjectID exposes other methods than {@link org.ozoneDB.core.ObjectID#equals(Object)} and {@link org.ozoneDB.core.ObjectID#compareTo(Object)}. However, they should not be used, as ObjectIDs should be, apart from this method, opaque. </p> @return the ObjectID of the represented ozone object */ public ObjectID getObjectID() { return container.id(); } /** * Returns wether or not the passed object is equal to this object. Two ozone * objects are considered equal when their object ids are equal. * If you pass on OzoneObject, its <code>getObjectID()</code> will be called * and compared with <code>this.getObjectID()</code>. The same goes for * <code>OzoneProxy</code> instances. * * @param o the object to test for equality */ public boolean equals(Object o) { // as we normally only pass proxies and not the actual object itself // the next 2 tests will probably never return true, but are included // for completeness if (o == this) { return true; } else if (o instanceof OzoneObject && getObjectID().equals(((OzoneObject) o).getObjectID())) { return true; } else { return o instanceof OzoneProxy && getObjectID().equals(((OzoneProxy) o).getObjectID()); } } }// :indentSize=4:tabSize=4:noTabs=true:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -