1 21 package com.db4o; 22 23 import com.db4o.foundation.*; 24 25 class PendingClassInits { 26 27 private final Transaction _systemTransaction; 28 29 private Collection4 _pending = new Collection4(); 30 31 private Queue4 _members = new Queue4(); 32 private Queue4 _statics = new Queue4(); 33 private Queue4 _writes = new Queue4(); 34 private Queue4 _inits = new Queue4(); 35 36 private boolean _running = false; 37 38 PendingClassInits(Transaction systemTransaction){ 39 _systemTransaction = systemTransaction; 40 } 41 42 void process(YapClass newYapClass) { 43 44 if(_pending.contains(newYapClass)) { 45 return; 46 } 47 48 YapClass ancestor = newYapClass.getAncestor(); 49 if (ancestor != null) { 50 process(ancestor); 51 } 52 53 _pending.add(newYapClass); 54 55 _members.add(newYapClass); 56 57 58 if(_running) { 59 return; 60 } 61 62 _running = true; 63 64 checkInits(); 65 66 _pending = new Collection4(); 67 68 _running = false; 69 } 70 71 72 private void checkMembers() { 73 while(_members.hasNext()) { 74 YapClass yc = (YapClass)_members.next(); 75 yc.addMembers(stream()); 76 _statics.add(yc); 77 } 78 } 79 80 private YapStream stream() { 81 return _systemTransaction.stream(); 82 } 83 84 private void checkStatics() { 85 checkMembers(); 86 while(_statics.hasNext()) { 87 YapClass yc = (YapClass)_statics.next(); 88 yc.storeStaticFieldValues(_systemTransaction, true); 89 _writes.add(yc); 90 checkMembers(); 91 } 92 } 93 94 private void checkWrites() { 95 checkStatics(); 96 while(_writes.hasNext()) { 97 YapClass yc = (YapClass)_writes.next(); 98 yc.setStateDirty(); 99 yc.write(_systemTransaction); 100 _inits.add(yc); 101 checkStatics(); 102 } 103 } 104 105 private void checkInits() { 106 checkWrites(); 107 while(_inits.hasNext()) { 108 YapClass yc = (YapClass)_inits.next(); 109 yc.initConfigOnUp(_systemTransaction); 110 checkWrites(); 111 } 112 } 113 114 115 } 116 | Popular Tags |