1 /* Copyright (C) 2004 - 2009 Versant Inc. http://www.db4o.com */ 2 3 using Db4objects.Db4o.Internal; 4 using Db4objects.Db4o.Internal.Activation; 5 6 namespace Db4objects.Db4o.Internal.Activation 7 { 8 public abstract class FixedUpdateDepth : IUpdateDepth 9 { 10 private int _depth; 11 12 private bool _tpMode = false; 13 FixedUpdateDepth(int depth)14 public FixedUpdateDepth(int depth) 15 { 16 _depth = depth; 17 } 18 TpMode(bool tpMode)19 public virtual void TpMode(bool tpMode) 20 { 21 _tpMode = tpMode; 22 } 23 TpMode()24 public virtual bool TpMode() 25 { 26 return _tpMode; 27 } 28 SufficientDepth()29 public virtual bool SufficientDepth() 30 { 31 return _depth > 0; 32 } 33 Negative()34 public virtual bool Negative() 35 { 36 // should never happen? 37 return _depth < 0; 38 } 39 ToString()40 public override string ToString() 41 { 42 return GetType().FullName + ": " + _depth; 43 } 44 Adjust(ClassMetadata clazz)45 public virtual IUpdateDepth Adjust(ClassMetadata clazz) 46 { 47 if (clazz.CascadesOnDeleteOrUpdate()) 48 { 49 return AdjustDepthToBorders().Descend(); 50 } 51 return Descend(); 52 } 53 IsBroaderThan(Db4objects.Db4o.Internal.Activation.FixedUpdateDepth other)54 public virtual bool IsBroaderThan(Db4objects.Db4o.Internal.Activation.FixedUpdateDepth 55 other) 56 { 57 return _depth > other._depth; 58 } 59 60 // TODO code duplication in fixed activation/update depth AdjustDepthToBorders()61 public virtual Db4objects.Db4o.Internal.Activation.FixedUpdateDepth AdjustDepthToBorders 62 () 63 { 64 return ForDepth(DepthUtil.AdjustDepthToBorders(_depth)); 65 } 66 AdjustUpdateDepthForCascade(bool isCollection)67 public virtual IUpdateDepth AdjustUpdateDepthForCascade(bool isCollection) 68 { 69 int minimumUpdateDepth = isCollection ? 2 : 1; 70 if (_depth < minimumUpdateDepth) 71 { 72 return ForDepth(minimumUpdateDepth); 73 } 74 return this; 75 } 76 Descend()77 public virtual IUpdateDepth Descend() 78 { 79 return ForDepth(_depth - 1); 80 } 81 Equals(object other)82 public override bool Equals(object other) 83 { 84 if (this == other) 85 { 86 return true; 87 } 88 if (other == null || GetType() != other.GetType()) 89 { 90 return false; 91 } 92 return _depth == ((Db4objects.Db4o.Internal.Activation.FixedUpdateDepth)other)._depth; 93 } 94 GetHashCode()95 public override int GetHashCode() 96 { 97 return _depth; 98 } 99 ForDepth( int depth)100 protected abstract Db4objects.Db4o.Internal.Activation.FixedUpdateDepth ForDepth( 101 int depth); 102 CanSkip(ObjectReference arg1)103 public abstract bool CanSkip(ObjectReference arg1); 104 } 105 } 106