001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal;
022:
023: import com.db4o.ext.*;
024:
025: /**
026: * @exclude
027: */
028: public class StoredClassImpl implements StoredClass {
029:
030: private final Transaction _transaction;
031:
032: private final ClassMetadata _classMetadata;
033:
034: public StoredClassImpl(Transaction transaction,
035: ClassMetadata classMetadata) {
036: if (classMetadata == null) {
037: throw new IllegalArgumentException();
038: }
039: _transaction = transaction;
040: _classMetadata = classMetadata;
041: }
042:
043: public long[] getIDs() {
044: return _classMetadata.getIDs(_transaction);
045: }
046:
047: public String getName() {
048: return _classMetadata.getName();
049: }
050:
051: public StoredClass getParentStoredClass() {
052: ClassMetadata parentClassMetadata = _classMetadata
053: .getAncestor();
054: if (parentClassMetadata == null) {
055: return null;
056: }
057: return new StoredClassImpl(_transaction, parentClassMetadata);
058: }
059:
060: public StoredField[] getStoredFields() {
061: StoredField[] fieldMetadata = _classMetadata.getStoredFields();
062: StoredField[] storedFields = new StoredField[fieldMetadata.length];
063: for (int i = 0; i < fieldMetadata.length; i++) {
064: storedFields[i] = new StoredFieldImpl(_transaction,
065: (FieldMetadata) fieldMetadata[i]);
066: }
067: return storedFields;
068: }
069:
070: public boolean hasClassIndex() {
071: return _classMetadata.hasClassIndex();
072: }
073:
074: // TODO: Write test case.
075: public void rename(String newName) {
076: _classMetadata.rename(newName);
077: }
078:
079: public StoredField storedField(String name, Object type) {
080: FieldMetadata fieldMetadata = (FieldMetadata) _classMetadata
081: .storedField(name, type);
082: if (fieldMetadata == null) {
083: return null;
084: }
085: return new StoredFieldImpl(_transaction, fieldMetadata);
086: }
087:
088: public int hashCode() {
089: return _classMetadata.hashCode();
090: }
091:
092: public boolean equals(Object obj) {
093: if (obj == null) {
094: return false;
095: }
096: if (getClass() != obj.getClass()) {
097: return false;
098: }
099: return _classMetadata
100: .equals(((StoredClassImpl) obj)._classMetadata);
101: }
102:
103: }
|