Sophie

Sophie

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

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="db4o Databases Replication" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>Simple Example	of db4o to db4o 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/db4o_databases_replication/simple_example.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../db4o_databases_replication.htm">db4o Databases Replication</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">Simple Example</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><a name="kanchor3"></a>Simple Example</h1>
        <p>A db4o-to-db4o replication is easy to use and easy to set up. There are only two steps required to get the replication started.</p>
        <p>First ensure that you have added the dRS-<span class="PrimaryArtefact">assembly</span> to your project. <a href="../getting_started.htm" target="" title="" alt="" class="MCXref">See "Getting Started"</a></p>
        <p>The replication process needs two things. An UUID for each object to identify it across multiple databases. Furthermore every object needs a version-number to detect updates.  By default db4o doesn't generate a UUID nor keeps timestamps. So you need to configure this explicitly:                      <![CDATA[ ]]></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>After this preparation you can store, retrieve and update normally. To start the replication-process open the two databases which take part in the replication. Then create an replication-session by passing the replication partners to the replication factory.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName);
IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName);

IReplicationProvider dektopReplicationProvider
    = new Db4oEmbeddedReplicationProvider(desktopDatabase);
IReplicationProvider mobileReplicationProvider
    = new Db4oEmbeddedReplicationProvider(mobileDatabase);

IReplicationSession replicationSession 
    = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider);
// set the replication-direction from the desktop database to the mobile database. 
replicationSession.SetDirection(replicationSession.ProviderA(), replicationSession.ProviderB());</pre>
            <div class="codesnippet-meta">Db4oReplicationExamples.cs: Prepare unidirectional replication
			<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">Dim desktopDatabase As IObjectContainer = OpenDatabase(DesktopDatabaseName)
Dim mobileDatabase As IObjectContainer = OpenDatabase(MobileDatabaseName)

Dim dektopReplicationProvider As IReplicationProvider _
    = New Db4oEmbeddedReplicationProvider(desktopDatabase)
Dim mobileReplicationProvider As IReplicationProvider _
    = New Db4oEmbeddedReplicationProvider(mobileDatabase)

Dim replicationSession As IReplicationSession _
    = Replication.Begin(dektopReplicationProvider, mobileReplicationProvider)
' set the replication-direction from the desktop database to the mobile database. 
replicationSession.SetDirection(replicationSession.ProviderA(), replicationSession.ProviderB())</pre>
            <div class="codesnippet-meta">Db4oReplicationExamples.vb: Prepare unidirectional replication
			<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>Now the system is ready for replication. First request all changes from a replication partner. The replication session will return all objects which have been created or updated since the last replication. Then iterate over the returned objects and replicate object by object.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">IObjectSet changes = replicationSession.ProviderA().ObjectsChangedSinceLastReplication();
foreach (object changedObject in changes)
{
    replicationSession.Replicate(changedObject);
}
replicationSession.Commit();</pre>
            <div class="codesnippet-meta">Db4oReplicationExamples.cs: One direction replication
			<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">Dim changes As IObjectSet = replicationSession.ProviderA().ObjectsChangedSinceLastReplication()
For Each changedObject As Object In changes
    replicationSession.Replicate(changedObject)
Next
replicationSession.Commit()</pre>
            <div class="codesnippet-meta">Db4oReplicationExamples.vb: One direction replication
			<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>To complete the replication, call commit on the replication session. This commit stores all changes in replication partners and finishes the running transactions. Furthermore it marks the objects as replicated to ensure that future replications only include the new changes. Without the commit call the replication-changes will be discarded! </p>
        <script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
        </script>
    </body>
</html>