<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.eiffelroom.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>eiffelroom - Getting Started with Db4o for Eiffel - Comments</title>
 <link>http://www.eiffelroom.org/article/getting_started_with_db4o_for_eiffel</link>
 <description>Comments for &quot;Getting Started with Db4o for Eiffel&quot;</description>
 <language>en</language>
<item>
 <title>Prefixes for assemblies</title>
 <link>http://www.eiffelroom.org/article/getting_started_with_db4o_for_eiffel#comment-437</link>
 <description>&lt;p&gt;Thank you for your hint. I did not know about assembly-wide prefixes. I think it&#039;s a good alternative to resolve name clashes.&lt;/p&gt;

</description>
 <pubDate>Mon, 07 Apr 2008 01:32:07 -0700</pubDate>
 <dc:creator>ruihua</dc:creator>
 <guid isPermaLink="false">comment 437 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Looks Great</title>
 <link>http://www.eiffelroom.org/article/getting_started_with_db4o_for_eiffel#comment-436</link>
 <description>&lt;p&gt;One question, Ruihua. At step 7, instead of renaming individual classes, why didn&#039;t you just set assembly-wide prefixes &lt;code class=&quot;geshifilter eiffel&quot;&gt;DB4O_&lt;/code&gt; and &lt;code class=&quot;geshifilter eiffel&quot;&gt;REFLECTOR_&lt;/code&gt;?&lt;/p&gt;

</description>
 <pubDate>Fri, 04 Apr 2008 14:58:58 -0700</pubDate>
 <dc:creator>peter_gummer</dc:creator>
 <guid isPermaLink="false">comment 436 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Getting Started with Db4o for Eiffel</title>
 <link>http://www.eiffelroom.org/article/getting_started_with_db4o_for_eiffel</link>
 <description>&lt;p&gt;This page provides a step-by-step guide, showing you how to use db4o databases within Eiffel for .NET applications.&lt;/p&gt;


&lt;h4 id=&quot;toc0&quot;&gt;Step 1: Download Db4o Assembly&lt;/h4&gt;
 Because of a critical bug in the db4o assemblies before version &lt;a href=&quot;http://7.1.26&quot;&gt;7.1.26&lt;/a&gt; (see the issue report &amp;quot;&lt;a href=&quot;http://tracker.db4o.com/browse/COR-1086&quot;&gt;SODA queries return wrong query results for .NET interfaces&lt;/a&gt;&amp;quot;), it is important that you download a db4o version later than 7.1.26. Go to the &lt;a href=&quot;http://developer.db4o.com/files/default.aspx&quot;&gt;db4o download center&lt;/a&gt; to download a db4o assembly.
&lt;h4 id=&quot;toc1&quot;&gt;Step 2: Download Reflector for .NET Assembly&lt;/h4&gt;
 In the implementation we take advantage of the Reflector for .NET assembly to examine Eiffel for .NET assemblies. You can download the assembly from the &lt;a href=&quot;http://www.aisto.com/roeder/dotnet/&quot;&gt;project homepage&lt;/a&gt; or from &lt;a href=&quot;https://svn.origo.ethz.ch/defcon/source_code/references/Reflector.exe&quot;&gt;here&lt;/a&gt;.
&lt;h4 id=&quot;toc2&quot;&gt;Step 3: Download Source Code of Db4o for Eiffel&lt;/h4&gt;
 The project is implemented in Eiffel, and its source code is to be imported into your project. Here is the &lt;a href=&quot;http://www.eiffelroom.com/files/db4o_for_eiffel.zip&quot;&gt;source code&lt;/a&gt;.&lt;p&gt;After downloading the zip file, please extract the file and then move the &lt;code class=&quot;geshifilter&quot;&gt;db4o_for_eiffel&lt;/code&gt; directory to the directory in which your project will reside, say &lt;code class=&quot;geshifilter&quot;&gt;db4o_example&lt;/code&gt;.&lt;/p&gt;


&lt;h4 id=&quot;toc3&quot;&gt;Step 4: Download EiffelStudio&lt;/h4&gt;
 It is common that Eiffel developers use EiffelStudio for developing Eiffel applications. You can download it from &lt;a href=&quot;https://www2.eiffel.com/download/&quot;&gt;Eiffel Software&lt;/a&gt; or from &lt;a href=&quot;http://eiffelstudio.origo.ethz.ch/download&quot;&gt;Origo&lt;/a&gt;.&lt;p&gt;The recommended version for Windows XP is EiffelStudio 6.1.6.9962, other versions of &lt;a href=&quot;http://6.1.x&quot;&gt;6.1.x&lt;/a&gt; seem to have problems with debugging Eiffel for .NET applications.&lt;/p&gt;


&lt;h4 id=&quot;toc4&quot;&gt;Step 5: Create an EiffelStudio Project&lt;/h4&gt;
 Until now you should have a project directory called &lt;code class=&quot;geshifilter&quot;&gt;db4o_example&lt;/code&gt; with the &lt;code class=&quot;geshifilter&quot;&gt;db4o_for_eiffel&lt;/code&gt; directory in it.&lt;p&gt;Start EiffelStudio, and in the pop-up window select “Microsoft .NET application” and then click “Create” (see screenshot).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.eiffelroom.com/files/es_create.JPG&quot; style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; width=&quot;500&quot; height=&quot;500&quot; alt=&quot;es_create.JPG&quot; /&gt; Click “Next &amp;gt;” to continue.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.eiffelroom.com/files/es_welcome.JPG&quot; style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; width=&quot;503&quot; height=&quot;400&quot; alt=&quot;es_welcome.JPG&quot; /&gt; In the next window specify the project name as &lt;code class=&quot;geshifilter&quot;&gt;db4o_example&lt;/code&gt; and the project location as the location of your &lt;code class=&quot;geshifilter&quot;&gt;db4o_example&lt;/code&gt; directory. Click “Next &amp;gt;”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.eiffelroom.com/files/es_name.JPG&quot; style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; width=&quot;503&quot; height=&quot;400&quot; alt=&quot;es_name.JPG&quot; /&gt; Configure the .NET application as shown in the following screenshot:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.eiffelroom.com/files/es_settings.JPG&quot; style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; width=&quot;541&quot; height=&quot;400&quot; alt=&quot;es_settings.JPG&quot; /&gt; Click “Finish” to generate and compile the project.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.eiffelroom.com/files/es_finish.JPG&quot; style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; width=&quot;541&quot; height=&quot;400&quot; alt=&quot;es_finish.JPG&quot; /&gt; 
&lt;h4 id=&quot;toc5&quot;&gt;Step 6: Add Assemblies to Your Project&lt;/h4&gt;
 In the “Clusters” panel right-click “Assemblies” and in the context-menu select “Add Assembly ...”. Then in the “Add Assembly” window specify the location of the db4o assembly &lt;code class=&quot;geshifilter&quot;&gt;Db4objects.Db4o.dll&lt;/code&gt; to import it into the project.&lt;/p&gt;

&lt;p&gt;Perform the same steps for the Reflector for .NET assembly &lt;code class=&quot;geshifilter&quot;&gt;Reflector.exe&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We also need the &lt;code class=&quot;geshifilter&quot;&gt;EiffelSoftware.Runtime&lt;/code&gt; assembly which can be selected in the “Add Assembly” window. 
&lt;h4 id=&quot;toc6&quot;&gt;Step 7: Rename Classes to Avoid Name Clashes&lt;/h4&gt;
 In Eiffel for .NET every class must have a unique class name, so we have to rename some classes in &lt;code class=&quot;geshifilter&quot;&gt;Db4objects.Db4o.dll&lt;/code&gt; and &lt;code class=&quot;geshifilter&quot;&gt;Reflector.exe&lt;/code&gt; to avoid name clashes.&lt;/p&gt;

&lt;p&gt;Click “Project” in the menu bar and select “Project settings ...”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.eiffelroom.com/files/es_project.JPG&quot; style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; width=&quot;595&quot; height=&quot;437&quot; alt=&quot;es_project.JPG&quot; /&gt; In the “Project Settings” window, navigate to the “db4objects.db4o” item in the left panel, then in the right panel click inside the cell next to “Renaming”. A window for editing renaming then pops up. Rename &lt;code class=&quot;geshifilter&quot;&gt;PREDICATE&lt;/code&gt; as &lt;code class=&quot;geshifilter&quot;&gt;DB4O_PREDICATE&lt;/code&gt; and rename &lt;code class=&quot;geshifilter&quot;&gt;FIELD_INFO&lt;/code&gt; as &lt;code class=&quot;geshifilter&quot;&gt;DB4O_FIELD_INFO&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://www.eiffelroom.com/files/es_renaming.JPG&quot; style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; width=&quot;300&quot; height=&quot;200&quot; alt=&quot;es_renaming.JPG&quot; /&gt; Similar for the &lt;code class=&quot;geshifilter&quot;&gt;Reflector.exe&lt;/code&gt; assembly, rename &lt;code class=&quot;geshifilter&quot;&gt;ASSEMBLY&lt;/code&gt; as &lt;code class=&quot;geshifilter&quot;&gt;REFLECTOR_ASSEMBLY&lt;/code&gt; and rename &lt;code class=&quot;geshifilter&quot;&gt;ICONFIGURATION&lt;/code&gt; as &lt;code class=&quot;geshifilter&quot;&gt;REFLECTOR_ICONFIGURATION&lt;/code&gt;. 
&lt;h4 id=&quot;toc7&quot;&gt;Step 8: Configure Db4o Databases for Eiffel Applications&lt;/h4&gt;
 Before storing and querying for Eiffel objects in db4o databases, we have to install &lt;code class=&quot;geshifilter&quot;&gt;POINTER_TRANSLATOR&lt;/code&gt;, which is done in the class &lt;code class=&quot;geshifilter&quot;&gt;EIFFEL_CONFIGURATION&lt;/code&gt;. Add the &lt;code class=&quot;geshifilter&quot;&gt;init&lt;/code&gt; method in the &lt;code class=&quot;geshifilter&quot;&gt;APPLICATION&lt;/code&gt; class and call it in the root procedure &lt;code class=&quot;geshifilter&quot;&gt;make&lt;/code&gt;. &lt;pre class=&quot;geshifilter&quot;&gt;init is
        -- Set global database configuration.
    local
        eiffel_configuration: EIFFEL_CONFIGURATION
    do
        create eiffel_configuration.configure
    end

make is
        -- Run application.
    do
        init
        --store
        --retrieve_qbe
        --retrieve_soda
        --retrieve_nq
    end&lt;/pre&gt; 
&lt;h4 id=&quot;toc8&quot;&gt;Step 9: Open and Close a Db4o Database&lt;/h4&gt;
 To open and close a db4o database, add the following features to class &lt;code class=&quot;geshifilter&quot;&gt;APPLICATION&lt;/code&gt;: &lt;pre class=&quot;geshifilter&quot;&gt;feature  -- Database control

    db: IOBJECT_CONTAINER

    database_file: STRING is &quot;eiffel.db4o&quot;

    open_database is
            -- Open `db&#039; of `database_file&#039;.
        do
            db := {DB_4O_FACTORY}.open_file(database_file)
        end

    close_database is
            -- Close `db&#039;.
        local
            closed: BOOLEAN
        do
            closed := db.close
        end&lt;/pre&gt; 
&lt;h4 id=&quot;toc9&quot;&gt;Step 10: Store Eiffel Objects&lt;/h4&gt;
 Suppose we have a class &lt;code class=&quot;geshifilter&quot;&gt;PARALLELOGRAM&lt;/code&gt; with two attributes &lt;code class=&quot;geshifilter&quot;&gt;height1&lt;/code&gt; and &lt;code class=&quot;geshifilter&quot;&gt;height2&lt;/code&gt;: &lt;pre class=&quot;geshifilter&quot;&gt;class
    PARALLELOGRAM

create
    make

feature {NONE}  -- Initialization

    make(h1: INTEGER; h2: INTEGER) is
            -- Initialize `height1&#039; with `h1&#039;,
            -- `height2&#039; with `h2&#039;.
        require
            h1_positive: h1 &gt; 0
            h2_positive: h2 &gt; 0
        do
            height1 := h1
            height2 := h2
        end

feature  -- Access

    height1: INTEGER
    height2: INTEGER

end&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;To store some &lt;code class=&quot;geshifilter&quot;&gt;PARALLELOGRAM&lt;/code&gt; objects we can write &lt;pre class=&quot;geshifilter&quot;&gt;store is
    local
        closed: BOOLEAN
    do
        open_database
        db.store(create {PARALLELOGRAM}.make(10, 30))
        db.store(create {PARALLELOGRAM}.make(20, 40))
        close_database
    rescue
        if (db /= Void) then
            closed := db.close
        end
    end&lt;/pre&gt; 
&lt;h4 id=&quot;toc10&quot;&gt;Step 11: Retrieve Eiffel Objects&lt;/h4&gt;
 Db4o supplies three querying mechanisms: Query-By-Example, SODA Query API and Native Queries. 
&lt;h5 id=&quot;toc11&quot;&gt;Query-By-Example&lt;/h5&gt;
 The following query uses Query-By-Example to retrieve all the &lt;code class=&quot;geshifilter&quot;&gt;PARALLELOGRAM&lt;/code&gt; objects whose &lt;code class=&quot;geshifilter&quot;&gt;height1&lt;/code&gt; is equal to 10 and &lt;code class=&quot;geshifilter&quot;&gt;height2&lt;/code&gt; is equal to 30: &lt;pre class=&quot;geshifilter&quot;&gt;retrieve_qbe is
    local
        template: PARALLELOGRAM
        resultos: IOBJECT_SET
        closed: BOOLEAN
    do
        open_database
        create template.make(10, 30)
        resultos := db.query_by_example(template)
        printos(resultos)
        close_database
    rescue
        if (db /= Void) then
            closed := db.close
        end
    end&lt;/pre&gt; where &lt;code class=&quot;geshifilter&quot;&gt;printos&lt;/code&gt; outputs the &lt;code class=&quot;geshifilter&quot;&gt;PARALLELOGRAM&lt;/code&gt; objects in the query result to the console: &lt;pre class=&quot;geshifilter&quot;&gt;printos(os: IOBJECT_SET) is
    local
        p: PARALLELOGRAM
    do
        from
        until not os.has_next
        loop
            p ?= os.next
            if (p /= Void) then
                io.put_string(&quot;Parallelogram (&quot; + p.height1.out + &quot;, &quot; + p.height2.out + &quot;)&quot;)
                io.put_new_line
            end
        end
end&lt;/pre&gt; 
&lt;h5 id=&quot;toc12&quot;&gt;SODA Query API&lt;/h5&gt;
 To retrieve all &lt;code class=&quot;geshifilter&quot;&gt;PARALLELOGRAM&lt;/code&gt; objects whose &lt;code class=&quot;geshifilter&quot;&gt;height1&lt;/code&gt; is greater than 10, you can write the following SODA query: &lt;pre class=&quot;geshifilter&quot;&gt;retrieve_soda is
    local
        query: QUERY
        constraint, subconstraint: CONSTRAINT
        resultos: IOBJECT_SET
        closed: BOOLEAN
    do
        open_database
        create query.make_from_query(db.query)
        constraint := query.constrain({PARALLELOGRAM})
        subconstraint := query.descend(&quot;height1&quot;, {PARALLELOGRAM}).constrain(10).greater
        resultos := query.execute
        printos(resultos)
        close_database
    rescue
        if (db /= Void) then
            closed := db.close
        end
    end&lt;/pre&gt; 
&lt;h5 id=&quot;toc13&quot;&gt;Native Queries&lt;/h5&gt;
 You should first define a class, say &lt;code class=&quot;geshifilter&quot;&gt;PARALLELOGRAM_PREDICATE&lt;/code&gt;, which inherits from &lt;code class=&quot;geshifilter&quot;&gt;DB4O_PREDICATE&lt;/code&gt; and implements the &lt;code class=&quot;geshifilter&quot;&gt;match&lt;/code&gt; method. The &lt;code class=&quot;geshifilter&quot;&gt;match&lt;/code&gt; method defines whether a candidate object is to be included in the query result or not. &lt;pre class=&quot;geshifilter&quot;&gt;class
    PARALLELOGRAM_PREDICATE

inherit
    DB4O_PREDICATE

feature
    match(p: PARALLELOGRAM): BOOLEAN is
        do
            Result := p.height1 &gt; 10
        end

end&lt;/pre&gt; Then you can pass a &lt;code class=&quot;geshifilter&quot;&gt;PARALLELOGRAM_PREDICATE&lt;/code&gt; instance to the &lt;code class=&quot;geshifilter&quot;&gt;IOBJECT_CONTAINER.query&lt;/code&gt; method to get the query result: &lt;pre class=&quot;geshifilter&quot;&gt;retrieve_nq is
    local
        resultos: IOBJECT_SET
        closed: BOOLEAN
    do
        open_database
        resultos := db.query(create {PARALLELOGRAM_PREDICATE})
        printos(resultos)
        close_database
    rescue
        if (db /= Void) then
            closed := db.close
        end
    end&lt;/pre&gt; Note that you have to run the finalized system to have Native Queries run without exceptions. 
&lt;h4 id=&quot;toc14&quot;&gt;Step 12: What’s Next&lt;/h4&gt;
 To ensure a correct way of working with db4o databases within Eiffel applications, you may need to read the &lt;a href=&quot;http://www.eiffelroom.com/files/db4o_for_eiffel_manual.pdf&quot;&gt;User&#039;s and Developer&#039;s Manual&lt;/a&gt;. Furthermore, we suggest you to download and try out this advanced &lt;a href=&quot;http://www.eiffelroom.com/files/db4o_for_eiffel_example.zip&quot;&gt;example project&lt;/a&gt; when you are reading the manual.&lt;/p&gt;

&lt;p&gt;For further advanced features of db4o, such as transaction and concurrency control, maintenance, client-server mode, etc. please visit the &lt;a href=&quot;http://developer.db4o.com/Resources/&quot;&gt;db4o documentation page&lt;/a&gt;.&lt;/p&gt;

</description>
 <comments>http://www.eiffelroom.org/article/getting_started_with_db4o_for_eiffel#comments</comments>
 <category domain="http://www.eiffelroom.org/taxonomy/term/3">Tutorial</category>
 <category domain="http://www.eiffelroom.org/taxonomy/term/7">Beginner</category>
 <category domain="http://www.eiffelroom.org/tag/db4o">db4o</category>
 <category domain="http://www.eiffelroom.org/tag/eiffel_for_net">Eiffel for .NET</category>
 <category domain="http://www.eiffelroom.org/tag/object_oriented_database">object-oriented database</category>
 <category domain="http://www.eiffelroom.org/tag/oodbms">OODBMS</category>
 <enclosure url="http://www.eiffelroom.org/files/es_create.JPG" length="41984" type="image/jpeg" />
 <pubDate>Fri, 04 Apr 2008 05:52:02 -0700</pubDate>
 <dc:creator>ruihua</dc:creator>
 <guid isPermaLink="false">274 at http://www.eiffelroom.org</guid>
</item>
</channel>
</rss>
