Car.cs /** Copyright (C) 2004 - 2008 Versant Inc. http://www.db4o.com */ using System; using Db4objects.Db4o.TA; using Db4objects.Db4o.Activation
; namespace Db4objects.Db4odoc.TP
.Rollback { public class Car : IActivatable { private string _model; private Pilot _pilot; /**//*activator registered for this class*/ [System.NonSerialized] public IActivator _activator; public Car(string model, Pilot pilot) { _model = model; _pilot = pilot; } // end Car /**//*Bind the class to the specified object container, create the activator*/ public void Bind(IActivator activator) { if (_activator == activator) { return; } if (activator != null && null != _activator) { throw new System.InvalidOperationException(); } _activator = activator; } // end Bind public void Activate(ActivationPurpose purpose) { if (_activator == null) return; _activator.Activate(purpose); } // end Activate public string Model { get { Activate(ActivationPurpose.Read); return _model; } set { Activate(ActivationPurpose.Write); _model = value; } } public Pilot Pilot { get { Activate(ActivationPurpose.Read); return _pilot; } set { Activate(ActivationPurpose.Write); _pilot = value; } } public void ChangePilot(String name, int id) { _pilot.Name = name; _pilot.Id.Change(id); } override public string ToString() { Activate(ActivationPurpose.Read); return string.Format("{0}[{1}]", _model, _pilot); } // end ToString } }
Car.vb ' Copyright (C) 2004 - 2008 Versant Inc. http://www.db4o.com Imports System Imports Db4objects.Db4o Imports Db4objects.Db4o.TA Imports Db4objects.Db4o.Activation Namespace Db4objects.Db4odoc.TP.Rollback Public Class Car Implements IActivatable Private _model As String Private _pilot As Pilot 'activator registered for this class <Transient()> _ Public _activator As IActivator Public Sub New(ByVal model As String, ByVal pilot As Pilot) _model = model _pilot = pilot End Sub ' end Car 'Bind the class to the specified object container, create the activator Public Sub Bind(ByVal activator As IActivator) Implements IActivatable.Bind If _activator Is activator Then Return End If If activator IsNot Nothing AndAlso _activator IsNot Nothing Then Throw New System.InvalidOperationException() End If _activator = activator End Sub ' end Bind Public Sub Activate(ByVal purpose As ActivationPurpose) _ Implements IActivatable.Activate If _activator Is Nothing Then Return End If _activator.Activate(purpose) End Sub ' end Activate Public Property Model() As String Get Activate(ActivationPurpose.Read) Return _model End Get Set(ByVal value As String) Activate(ActivationPurpose.Write) _model = value End Set End Property Public Property Pilot() As Pilot Get Activate(ActivationPurpose.Read) Return _pilot End Get Set(ByVal value As Pilot) Activate(ActivationPurpose.Write) _pilot = value End Set End Property Public Sub ChangePilot(ByVal name As String, ByVal id As Integer) _pilot.Name = name _pilot.Id.Change(id) End Sub Public Overloads Overrides Function ToString() As String Activate(ActivationPurpose.Read) Return String.Format("{0}[{1}]", _model, _pilot) End Function ' end ToString End Class End Namespace
Download example code: