Sophie

Sophie

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

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="Basics Operations &amp; Concepts|ACID Properties And Transactions" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem">
    <head><title>db4o Transactions</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#basics/acid_and_transactions/db4o_tx_basics.htm" style="">Open topic with navigation</a>
        </p>
        <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../basics.htm">Basics Operations &amp; Concepts</a><span class="MCBreadcrumbsDivider"> &gt; </span><a class="MCBreadcrumbsLink" href="../acid_and_transactions.htm">ACID Properties And Transactions</a><span class="MCBreadcrumbsDivider"> &gt; </span><span class="MCBreadcrumbs">db4o Transactions</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="kanchor22"></a>db4o Transactions</h1>
        <p>All db4o operations are transactional and there's always a transaction running. Each object container has its own transaction running. The transaction is started implicitly. </p>
        <p>You can commit the transaction at any time.&#160;When the commit-call returns, all changes are made persistent. </p>
        <h2>Commit A Transactions</h2>
        <p>In order to commit a transaction, you need to call the commit-method. This will make all changes of the current transaction persistent. When the commit call is finished, everything is safely stored. If something goes wrong during the commit-operation or the commit-operation is interrupted (power-off, crash etc) the database has the state of either before or after the commit-call. </p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">container.Store(new Pilot("John"));
container.Store(new Pilot("Joanna"));

container.Commit();</pre>
            <div class="codesnippet-meta">Transactions.cs: Commit changes
			<div class="codedownload"><a href="../../CodeExamples/transactions/Example-Code-transactions-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">container.Store(New Pilot("John"))
container.Store(New Pilot("Joanna"))

container.Commit()</pre>
            <div class="codesnippet-meta">Transactions.vb: Commit changes
			<div class="codedownload"><a href="../../CodeExamples/transactions/Example-Code-transactions-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>
        <h2>Rollback A Transaction</h2>
        <p>Of course you also can rollback a transaction. Just call rollback on the object container. </p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">container.Store(new Pilot("John"));
container.Store(new Pilot("Joanna"));

container.Rollback();</pre>
            <div class="codesnippet-meta">Transactions.cs: Rollback changes
			<div class="codedownload"><a href="../../CodeExamples/transactions/Example-Code-transactions-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">container.Store(New Pilot("John"))
container.Store(New Pilot("Joanna"))

container.Rollback()</pre>
            <div class="codesnippet-meta">Transactions.vb: Rollback changes
			<div class="codedownload"><a href="../../CodeExamples/transactions/Example-Code-transactions-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>Note that when you rollback the changes, db4o won't rollback the objects in memory. All objects in memory will keep the state. If you want to make sure that objects in memory have the same state as in the database, you need to refresh the objects.</p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">Pilot pilot = container.Query&lt;Pilot&gt;()[0];
pilot.Name = "New Name";
container.Store(pilot);
container.Rollback();

// use refresh to return the in memory objects back
// to the state in the database.
container.Ext().Refresh(pilot, int.MaxValue);</pre>
            <div class="codesnippet-meta">Transactions.cs: Refresh objects after rollback
			<div class="codedownload"><a href="../../CodeExamples/transactions/Example-Code-transactions-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 pilot As Pilot = container.Query(Of Pilot)()(0)
pilot.Name = "New Name"
container.Store(pilot)
container.Rollback()

' use refresh to return the in memory objects back
' to the state in the database.
container.Ext().Refresh(pilot, Integer.MaxValue)</pre>
            <div class="codesnippet-meta">Transactions.vb: Refresh objects after rollback
			<div class="codedownload"><a href="../../CodeExamples/transactions/Example-Code-transactions-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>
        <h2>Implicit Commits</h2>
        <p>db4o commits implicitly when you close the object-container. The assumption is that normally you want to make the changes persistent when you close the object container. That's why it commits automatically. When you want to prevent this you should rollback the transaction before closing the container,</p>
        <h2>Multiple Concurrent Transactions</h2>
        <p>db4o transactions are always bound to their object container. When you want multiple concurrent transactions, you need to open multiple object containers. You can easily do this with the open session method. <a href="../../advanced_topics/session_containers.htm" target="" title="" alt="" class="MCXref" xrefformat="See &quot;{paratext}&quot;">See "Session Containers"</a></p>
        <p>Note that in this mode, db4o uses the read committed isolation. <a href="isolation.htm" target="" title="" alt="" class="MCXref" xrefformat="See &quot;{paratext}&quot;">See "Isolation"</a></p>
        <div class="codesnippet" MadCap:conditions="Primary.c#">
            <pre class="prettyprint" xml:space="preserve">using (IObjectContainer rootContainer = Db4oEmbedded.OpenFile(DatabaseFileName))
{
    // open the db4o-session. For example at the beginning for a web-request
    using (IObjectContainer session = rootContainer.Ext().OpenSession())
    {
        // do the operations on the session-container
        session.Store(new Person("Joe"));
    }
}</pre>
            <div class="codesnippet-meta">Db4oSessions.cs: Session object container
			<div class="codedownload"><a href="../../CodeExamples/container/sessions/Example-container-sessions-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">Using rootContainer As IObjectContainer = Db4oEmbedded.OpenFile(DatabaseFileName)
    ' open the db4o-session. For example at the beginning for a web-request
    Using session As IObjectContainer = rootContainer.Ext().OpenSession()
        ' do the operations on the session-container
        session.Store(New Person("Joe"))
    End Using
End Using</pre>
            <div class="codesnippet-meta">Db4oSessions.vb: Session object container
			<div class="codedownload"><a href="../../CodeExamples/container/sessions/Example-container-sessions-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>