You are here: Basics Operations & Concepts > Update Concept > Transparent Persistence > Pilot

Pilot

Pilot.cs
/**//* Copyright (C) 2004 - 2008 Versant Inc. http://www.db4o.com */
using Db4objects.Db4o;
using Db4objects.Db4o.Activation;
using Db4objects.Db4o.TA;

namespace Db4objects.Db4odoc.TP.Rollback
 {
    public class Pilot : IActivatable
     {
        private string _name;
        private Id _id;

        [System.NonSerialized]
        IActivator _activator;

        public Pilot(string name, int id)
         {
            _name = name;
            _id = new Id(id);
        }

        // Bind the class to an object container
        public void Bind(IActivator activator)
         {
            if (_activator == activator)
             {
                return;
            }
            if (activator != null && null != _activator)
             {
                throw new System.InvalidOperationException();
            }
            _activator = activator;
        }

        // activate the object fields
        public void Activate(ActivationPurpose purpose)
         {
            if (_activator == null)
                return;
            _activator.Activate(purpose);
        }

        public Id Id
         {
            get
             {
                Activate(ActivationPurpose.Read);
                return _id;
            }
            set
             {
                Activate(ActivationPurpose.Write);
                _id = value;
            }
        }

        public string Name
         {
            get
             {
                // even simple string needs to be activated
                Activate(ActivationPurpose.Read);
                return _name;
            }
            set
             {
                Activate(ActivationPurpose.Write);
                _name = value;
            }
        }

        public override string ToString()
         {
            return string.Format("{0}[{1}]",Name, Id) ;
        }
    }

}

Pilot.vb
' Copyright (C) 2004 - 2008 Versant Inc. http://www.db4o.com 

Imports Db4objects.Db4o
Imports Db4objects.Db4o.Activation
Imports Db4objects.Db4o.TA

Namespace Db4objects.Db4odoc.TP.Rollback
    Public Class Pilot
        Implements IActivatable
        Private _name As String
        Private _id As Id

        <Transient()> _
        Private _activator As IActivator

        Public Sub New(ByVal name As String, ByVal id As Integer)
            _name = name
            _id = New Id(id)
        End Sub

        ' Bind the class to an object container
        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

        ' activate the object fields
        Public Sub Activate(ByVal purpose As ActivationPurpose) _ 
Implements IActivatable.Activate
            If _activator Is Nothing Then
                Return
            End If
            _activator.Activate(purpose)
        End Sub

        Public Property Id() As Id
            Get
                Activate(ActivationPurpose.Read)
                Return _id
            End Get
            Set(ByVal value As Id)
                Activate(ActivationPurpose.Write)
                _id = value
            End Set
        End Property

        Public Property Name()Property Name() As String
            Get
                ' even simple string needs to be activated
                Activate(ActivationPurpose.Read)
                Return _name
            End Get
            Set(ByVal value As String)
                Activate(ActivationPurpose.Write)
                _name = value
            End Set
        End Property

        Public Overloads Overrides Function ToString() As String
            Return String.Format("{0}[{1}]", Name, Id)
        End Function
    End Class

End Namespace

Download example code:

VB.NET c#