001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.collectable;
025:
026: public class LogObjectDbImpl extends CollectableDbImpl implements
027: LogObject {
028: protected long m_time;
029: protected LogStore m_logStore;
030:
031: public static long getSynchronizedLocalTime() {
032: return org.myoodb.core.IdentifierManager
033: .getSynchronizedLocalTime();
034: }
035:
036: public LogObjectDbImpl() {
037: m_time = -1;
038: m_logStore = null;
039: }
040:
041: public void onDelete() {
042: if (m_logStore != null) {
043: m_logStore.removeLogObject(this );
044: }
045: }
046:
047: public Comparable getKey() {
048: return (Long) getTime();
049: }
050:
051: // XXX: one should ensure that each log time is unique ( see LogStore )
052: public void setTime(long time) {
053: if ((m_time != -1) && (m_logStore != null)) {
054: throw new org.myoodb.exception.PermissionException(
055: "Object already in Store");
056: }
057:
058: m_time = time;
059: }
060:
061: public long getTime() {
062: return m_time;
063: }
064:
065: public void setLogStore(LogStore logStore) {
066: m_logStore = logStore;
067: }
068:
069: public LogStore getLogStore() {
070: return m_logStore;
071: }
072:
073: public int hashCode() {
074: return (int) m_time;
075: }
076:
077: public boolean equals(Object obj) {
078: if (this == obj) {
079: return true;
080: } else if (obj instanceof Long) {
081: return getTime() == ((Long) obj).longValue();
082: } else if (obj instanceof LogObject) {
083: return getTime() == (((LogObject) obj).getTime());
084: } else {
085: return false;
086: }
087: }
088:
089: public int compareTo(Object obj) {
090: if (obj instanceof Long) {
091: return ((Long) getTime()).compareTo((Long) obj);
092: } else if (obj instanceof LogObject) {
093: long diff = getTime() - ((LogObject) obj).getTime();
094: return diff > 0 ? 1 : diff < 0 ? -1 : 0;
095: } else {
096: return -1;
097: }
098: }
099:
100: public String toString() {
101: return "LogObject: " + getTime();
102: }
103: }
|