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.foundation.*;
024:
025: class PendingClassInits {
026:
027: private final Transaction _systemTransaction;
028:
029: private Collection4 _pending = new Collection4();
030:
031: private Queue4 _members = new NonblockingQueue();
032: private Queue4 _statics = new NonblockingQueue();
033: private Queue4 _writes = new NonblockingQueue();
034: private Queue4 _inits = new NonblockingQueue();
035:
036: private boolean _running = false;
037:
038: PendingClassInits(Transaction systemTransaction) {
039: _systemTransaction = systemTransaction;
040: }
041:
042: void process(ClassMetadata newYapClass) {
043:
044: if (_pending.contains(newYapClass)) {
045: return;
046: }
047:
048: ClassMetadata ancestor = newYapClass.getAncestor();
049: if (ancestor != null) {
050: process(ancestor);
051: }
052:
053: _pending.add(newYapClass);
054:
055: _members.add(newYapClass);
056:
057: if (_running) {
058: return;
059: }
060:
061: _running = true;
062:
063: checkInits();
064:
065: _pending = new Collection4();
066:
067: _running = false;
068: }
069:
070: private void checkMembers() {
071: while (_members.hasNext()) {
072: ClassMetadata yc = (ClassMetadata) _members.next();
073: yc.addMembers(stream());
074: _statics.add(yc);
075: }
076: }
077:
078: private ObjectContainerBase stream() {
079: return _systemTransaction.container();
080: }
081:
082: private void checkStatics() {
083: checkMembers();
084: while (_statics.hasNext()) {
085: ClassMetadata yc = (ClassMetadata) _statics.next();
086: yc.storeStaticFieldValues(_systemTransaction, true);
087: _writes.add(yc);
088: checkMembers();
089: }
090: }
091:
092: private void checkWrites() {
093: checkStatics();
094: while (_writes.hasNext()) {
095: ClassMetadata yc = (ClassMetadata) _writes.next();
096: yc.setStateDirty();
097: yc.write(_systemTransaction);
098: _inits.add(yc);
099: checkStatics();
100: }
101: }
102:
103: private void checkInits() {
104: checkWrites();
105: while (_inits.hasNext()) {
106: ClassMetadata yc = (ClassMetadata) _inits.next();
107: yc.initConfigOnUp(_systemTransaction);
108: checkWrites();
109: }
110: }
111:
112: }
|