Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 2e9c43658e374d290a2de15d25134ac8 > files > 1422

db4o-doc-8.0-1.fc15.i686.rpm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Advanced Replication Strategies" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Prepare Old Databases for Replication</title>
        <script type="text/javascript">/* <![CDATA[ */
window.onload = function(){
	var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf';
	ZeroClipboard.setMoviePath(pathToFlash);
			
	function bindToClipBord(element,content){
		var clip = new ZeroClipboard.Client();
		clip.setText(content);
		clip.glue(element);
	};
		
	if(location.protocol==='file:'){
		$('.copylink-marker').remove();
	} else{
			$('.copylink-marker').each(function(){
				var text = $(this).parent().parent().children('.prettyprint').html();
				$(this).hover(function(){
					bindToClipBord(this,text);
				},
				function(){});
			});	
	}		
	prettyPrint();	
};
                /* ]]> */</script>
        <link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
        <link href="../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" />
        <script src="../../Resources/Code/prettify.js">
        </script>
        <script src="../../Resources/Code/lang-vb.js">
        </script>
        <script src="../../Resources/Code/jquery.min.js">
        </script>
        <script src="../../Resources/Code/ZeroClipboard.js">
        </script>
        <script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
        </script>
    </head>
    <body>
        <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../index_CSH.html#db4o_replication_system_drs/advanced_replication_strategies/Prepare_old_databases_for_replication.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../advanced_replication_strategies.htm">Advanced Replication Strategies</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Prepare Old Databases for Replication</span>
        </div>
        <p>
            <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">');
				document.write("Direct Link");
			document.write('</a>');/*]]>*/</script>
        </p>
        <p>
        </p>
        <h1>Prepare Old Databases for Replication</h1>
        <p>Sometimes  replication is a new requirement for a existing application. Therefore existing databases have to be replicated. However the required UUIDs and timestamps haven't been enabled so far. How do you migrate the older databases to enable replication?</p>
        <p>The first step is to enable the UUIDs and timestamps. </p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">configuration.File.GenerateUUIDs = ConfigScope.Globally;
configuration.File.GenerateCommitTimestamps = true;</pre>
            <div class="codesnippet-meta">Db4oReplicationExamples.cs: Configure db4o to generate UUIDs and commit timestamps
			<div class="codedownload"><a href="../../CodeExamples/drs/db4o/Example-drs-db4o-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">configuration.File.GenerateUUIDs = ConfigScope.Globally
configuration.File.GenerateCommitTimestamps = True</pre>
            <div class="codesnippet-meta">Db4oReplicationExamples.vb: Configure db4o to generate UUIDs and commit timestamps
			<div class="codedownload"><a href="../../CodeExamples/drs/db4o/Example-drs-db4o-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <p>The next issue is that the all objects stored don't have a UUID nor a version numbers. The easiest way to have such a number is to load and update each object in the database. Because when you update a object the new configuration takes effect. </p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IList&lt;object&gt; allObjects = desktopDatabase.Query&lt;object&gt;();
foreach (object objectToUpdate in allObjects)
{
    desktopDatabase.Store(objectToUpdate);
}
desktopDatabase.Commit();</pre>
            <div class="codesnippet-meta">AdvancedReplicationExamples.cs: Updating all objects ensures that it has a UUID and timestamp
			<div class="codedownload"><a href="../../CodeExamples/drs/advanced/Example-drs-advanced-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim allObjects As IList(Of Object) = desktopDatabase.Query(Of Object)()
For Each objectToUpdate As Object In allObjects
    desktopDatabase.Store(objectToUpdate)
Next
desktopDatabase.Commit()</pre>
            <div class="codesnippet-meta">AdvancedReplicationExamples.vb: Updating all objects ensures that it has a UUID and timestamp
			<div class="codedownload"><a href="../../CodeExamples/drs/advanced/Example-drs-advanced-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <p>Updating all object is maybe not an option. It's also possible to do this during the first replication. First query the objects which are target of the replication. Then do the replication. When a object doesn't have a UUID yet, update the object to ensure it has an UUID. Make also sure that the update-depth is high enough so that child objects also have an UUID.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IReplicationSession replicationSession = Replication.Begin(desktopRelicationPartner, mobileRelicationPartner);
IList&lt;Car&gt; initialReplication = desktopDatabase.Query&lt;Car&gt;();

foreach (Car changedObjectOnDesktop in initialReplication)
{
    IObjectInfo infoAboutObject = desktopDatabase.Ext().GetObjectInfo(changedObjectOnDesktop);
    if (null == infoAboutObject.GetUUID())
    {
        desktopDatabase.Ext().Store(changedObjectOnDesktop, 2);
    }
    replicationSession.Replicate(changedObjectOnDesktop);
}
replicationSession.Commit();</pre>
            <div class="codesnippet-meta">AdvancedReplicationExamples.cs: Migrate on the fly
			<div class="codedownload"><a href="../../CodeExamples/drs/advanced/Example-drs-advanced-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <div class="codesnippet" MadCap:conditions="Primary.VB.NET">
            <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Dim replicationSession As IReplicationSession = _
    Replication.Begin(desktopDatabase, mobileDatabase)
Dim initialReplication As IList(Of Car) = desktopDatabase.Query(Of Car)()

For Each changedObjectOnDesktop As Car In initialReplication
    Dim infoAboutObject As IObjectInfo = desktopDatabase.Ext() _
        .GetObjectInfo(changedObjectOnDesktop)
    If infoAboutObject.GetUUID() Is Nothing Then
        desktopDatabase.Ext().Store(changedObjectOnDesktop, 2)
    End If
    replicationSession.Replicate(changedObjectOnDesktop)
Next
replicationSession.Commit()</pre>
            <div class="codesnippet-meta">AdvancedReplicationExamples.vb: Migrate on the fly
			<div class="codedownload"><a href="../../CodeExamples/drs/advanced/Example-drs-advanced-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div>
        </div>
        <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>