Car

Car.cs
01/* Copyright (C) 2004 - 2008 db4objects Inc. http://www.db4o.com */ 02using System; 03using Db4objects.Db4o.TA; 04using Db4objects.Db4o.Activation; 05 06namespace Db4objects.Db4odoc.TP.Rollback 07{ 08 public class Car : IActivatable 09 { 10 private string _model; 11 private Pilot _pilot; 12 /*activator registered for this class*/ 13 [System.NonSerialized] 14 public IActivator _activator; 15 16 17 public Car(string model, Pilot pilot) 18 { 19 _model = model; 20 _pilot = pilot; 21 } 22 // end Car 23 24 /*Bind the class to the specified object container, create the activator*/ 25 public void Bind(IActivator activator) 26 { 27 if (_activator == activator) 28 { 29 return; 30 } 31 if (activator != null && null != _activator) 32 { 33 throw new System.InvalidOperationException(); 34 } 35 _activator = activator; 36 } 37 // end Bind 38 39 public void Activate(ActivationPurpose purpose) 40 { 41 if (_activator == null) 42 return; 43 _activator.Activate(purpose); 44 } 45 // end Activate 46 47 public string Model 48 { 49 get 50 { 51 Activate(ActivationPurpose.Read); 52 return _model; 53 } 54 set 55 { 56 Activate(ActivationPurpose.Write); 57 _model = value; 58 } 59 } 60 61 public Pilot Pilot 62 { 63 get 64 { 65 Activate(ActivationPurpose.Read); 66 return _pilot; 67 } 68 set 69 { 70 Activate(ActivationPurpose.Write); 71 _pilot = value; 72 } 73 } 74 75 public void ChangePilot(String name, int id) 76 { 77 _pilot.Name = name; 78 _pilot.Id.Change(id); 79 } 80 81 override public string ToString() 82 { 83 Activate(ActivationPurpose.Read); 84 return string.Format("{0}[{1}]", _model, _pilot); 85 } 86 // end ToString 87 } 88}
Car.vb
01' Copyright (C) 2004 - 2008 db4objects Inc. http://www.db4o.com 02 03Imports System 04Imports Db4objects.Db4o 05Imports Db4objects.Db4o.TA 06Imports Db4objects.Db4o.Activation 07 08Namespace Db4objects.Db4odoc.TP.Rollback 09 Public Class Car 10 Implements IActivatable 11 Private _model As String 12 Private _pilot As Pilot 13 'activator registered for this class 14 15 <Transient()> _ 16 Public _activator As IActivator 17 18 19 Public Sub New(ByVal model As String, ByVal pilot As Pilot) 20 _model = model 21 _pilot = pilot 22 End Sub 23 ' end Car 24 25 'Bind the class to the specified object container, create the activator 26 27 Public Sub Bind(ByVal activator As IActivator) Implements IActivatable.Bind 28 If _activator Is activator Then 29 Return 30 End If 31 If activator IsNot Nothing AndAlso _activator IsNot Nothing Then 32 Throw New System.InvalidOperationException() 33 End If 34 _activator = activator 35 End Sub 36 ' end Bind 37 38 Public Sub Activate(ByVal purpose As ActivationPurpose) Implements IActivatable.Activate 39 If _activator Is Nothing Then 40 Return 41 End If 42 _activator.Activate(purpose) 43 End Sub 44 ' end Activate 45 46 Public Property Model() As String 47 Get 48 Activate(ActivationPurpose.Read) 49 Return _model 50 End Get 51 Set(ByVal value As String) 52 Activate(ActivationPurpose.Write) 53 _model = value 54 End Set 55 End Property 56 57 Public Property Pilot() As Pilot 58 Get 59 Activate(ActivationPurpose.Read) 60 Return _pilot 61 End Get 62 Set(ByVal value As Pilot) 63 Activate(ActivationPurpose.Write) 64 _pilot = value 65 End Set 66 End Property 67 68 Public Sub ChangePilot(ByVal name As String, ByVal id As Integer) 69 _pilot.Name = name 70 _pilot.Id.Change(id) 71 End Sub 72 73 Public Overloads Overrides Function ToString() As String 74 Activate(ActivationPurpose.Read) 75 Return String.Format("{0}[{1}]", _model, _pilot) 76 End Function 77 ' end ToString 78 End Class 79End Namespace