{"id":949,"date":"2010-01-15T00:52:09","date_gmt":"2010-01-14T23:52:09","guid":{"rendered":"http:\/\/www.gamlor.info\/wordpress\/?p=949"},"modified":"2021-03-11T09:45:22","modified_gmt":"2021-03-11T08:45:22","slug":"db4o-tools-for-adhoc-querying-and-modification","status":"publish","type":"post","link":"https:\/\/www.gamlor.info\/wordpress\/2010\/01\/db4o-tools-for-adhoc-querying-and-modification\/","title":{"rendered":"db4o: Tools For Adhoc Querying And Modification"},"content":{"rendered":"<p><a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-tools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-981\" title=\"db4o-tools\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-tools.png\" alt=\"\" width=\"300\" height=\"379\" srcset=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-tools.png 300w, https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-tools-237x300.png 237w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>Remember my <a href=\"?p=332\">very first post<\/a> about db4o? There I\u2019ve made the statement that the tool-support is very bad. Well I don\u2019t revise my opinion here. The situation is still bad compared to the relational database world. Mostly that&#8217;s because relational databases have a giant user base, are well known and have some common interfaces (JDBC, ODBC, etc).<\/p>\n<p>(All posts of this series: <a href=\"?p=620\">the basics<\/a>, <a href=\"?p=637\">activation<\/a>, <a href=\"?p=654\">object-identity<\/a>, <a href=\"?p=671\">transactions<\/a>, <a href=\"?p=695\">persistent classes<\/a>, <a href=\"?p=733\">single container concurrency<\/a>, <a href=\"?p=744\">Queries in Java, C# 2.0<\/a>, <a href=\"?p=779\">client-server concurrency<\/a>, <a href=\"?p=840\">transparent persistence<\/a>, <a href=\"?p=949\">adhoc query tools<\/a>)<\/p>\n<p>Now enough complaining. Only complaining doesn\u2019t help anyway!\u00a0 In this post I\u2019ll introduce two tools and show briefly, what you can do with them. Let\u2019s start:<\/p>\n<h4>ObjectManager Enterprise (OME)<\/h4>\n<p>This is a tool which <a href=\"http:\/\/developer.db4o.com\/Downloads.aspx\">comes bundled with db4o<\/a>. In the Java-Version it\u2019s a Eclipse-plugin. In the .NET-version it\u2019s a Visual Studio add-on.<\/p>\n<p>For the .NET-version there are installers in the \u2018ome2005\u2019 and \u2018ome2008\u2019-directory of the db4o-distribution. Pick the one which corresponds to your Visual Studio version and install it. After restarting Visual Studio, you\u2019ve a new buttons in you\u2019re toolbar and a new menu-point \u2018Tools\u2019-&gt;\u2019ObjectManager Enterprise\u2019.<\/p>\n<p>For the Java-Version there\u2019s a zip-file in the \u2018ome\u2019-directory of the db4o-distribution. Unzip it somewhere. Open Eclipse, go to \u2018Help\u2019-&gt;\u2019Install New Software\u2019. Click on \u2018Add\u2019, then \u2018Local\u2019 and choose the directory you\u2019ve unzipped the zip-file before. The click just through all the confirm-dialogs etc. Then restart Eclipse. Now there\u2019s a new menu-point \u2018OME\u2019 in Eclipse.<\/p>\n<p>Now you can connect to a db4o-database. Either you can connect to a running db4o-server or open a db4o-database-file directly.<\/p>\n<p><a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-ome.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-982 alignnone\" title=\"db4o-ome\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-ome.png\" alt=\"\" width=\"600\" height=\"481\" srcset=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-ome.png 600w, https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-ome-300x240.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h4>Queries with OME<\/h4>\n<p>Now in the OME you don\u2019t use a query-language for querying the database. This is quite a surprise. So how do you build queries then? You build then by drag and drop! On the left the OME shows a list of all known classes. When you expand such a class, you see the fields. Fields which are no primitives can be extended further. To build a query you choose a object-type, lets say \u2018Person\u2019. Then you expand the \u2018Person\u2019-class on the left, choose the fields you want to query and drag them into the \u2018Query-Builder&#8217;-window. After sticking the criterions together, you can run the query. Furthermore you also can update field of persisted data.<\/p>\n<p>Here a little screen-cast, which shows this:<br \/>\n<script type=\"text\/javascript\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/videosupport\/jwplayer.js\"><\/script><\/p>\n<div id=\"video-container\">Loading the screen-cast &#8230;<\/div>\n<p><script type=\"text\/javascript\"> \n    jwplayer(\"video-container\").setup({ \n        flashplayer: \"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/videosupport\/player.swf\", \n        file: \"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-ome-query.flv\", \n        height: 270, \n        width: 480 \n    }); \n<\/script> <\/p>\n<p><script type=\"text\/javascript\">\/\/ < ![CDATA[\n\/\/ < ![CDATA[\n\/\/ < ![CDATA[\nvar so = new SWFObject('wp-content\/uploads\/videosupport\/player-viral.swf','mpl','600','480','9');so.addParam('allowfullscreen','true');so.addParam('allowscriptaccess','always');so.addParam('wmode','opaque');\nso.addVariable('file','https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-ome-query.flv');\nso.addVariable('image','wp-content\/uploads\/2010\/01\/db4o-ome-query-preview.jpg');so.write('mediaspace');\n\/\/ ]]><\/script><\/p>\n<p>To get an overview of the OME-Features, you also <a href=\"http:\/\/db4o.blip.tv\/file\/720018\/\">might take a look at this screen-cast<\/a>.<\/p>\n<h4>LINQPad<\/h4>\n<p>Now I\u2019m not a fan of this visual query-building. I prefer a query-language. But db4o doesn\u2019t provide a language like SQL, but rather utilized the language of the platform. Now .NET brings a wonderful query-language, LINQ. And together with the excellent <a href=\"http:\/\/www.linqpad.net\/\">LINQPad<\/a> you can use it like a traditional SQL-console. However some preparation is required:<\/p>\n<ol>\n<li>We need to add the db4o-assemblies. LINQPad has no idea about db4o, therefore we need to include the db4o database engine. To achieve this, go to the \u2018Query\u2019-&gt;\u2019Advanced Query Properties\u2019. On the dialog, click on \u2018Add\u2026\u2019, then on \u2018Browse\u2026\u2019. Browse to the db4o-assemblies. Add the \u2018Db4objects.Db4o.dll\u2019, \u2018Db4objects.Db4o.Linq.dll\u2019, \u2018Cecil.FlowAnalysis.dll\u2019 and the \u2018Mono.Cecil.dll\u2019-assemblies. Keep the \u2018Advanced Query Properties\u2019-dialog open for the next step.<\/li>\n<li>In the \u2018Advanced Query Properties\u2019-dialog open again the \u2018Ad\u2026\u2019-dialog. Add you\u2019re assembly which contains the stored classes. We need the classes in order to write LINQ-Queries.<\/li>\n<li>In the \u2018Advanced Query Properties\u2019-dialog go the tab \u2018Additional Namespace Imports\u2019. Add there the db4o-namespaces:<br \/>\n<em>Db4objects.Db4o.Linq<br \/>\nDb4objects.Db4o<br \/>\n<\/em>Additional add the namespace of your stored classes, for example:<br \/>\n<em>MyProject.DomainModel<\/em><\/li>\n<li>Click on \u2018Set as default for new queries\u2019 so that you don\u2019t need to repeat the three steps above next time. Then we\u2019re done.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-linqpad.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-983 alignnone\" title=\"db4o-linqpad\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-linqpad.png\" alt=\"\" width=\"600\" height=\"347\" srcset=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-linqpad.png 600w, https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2010\/01\/db4o-linqpad-300x173.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h4>Queries with LINQPad<\/h4>\n<p>Now LINQPad is ready for db4o. Choose \u201cC# statements\u201d or \u201cVB statement\u201d in the language-chooser. Then you can write you\u2019re query like this:<\/p>\n<pre class=\"csharpcode\"><span class=\"kwrd\">using<\/span>(var db = Db4oEmbedded.OpenFile(<span class=\"str\">@\"C:\\file-path\\database-file.db4o\"<\/span>)){\r\n    var result = <span class=\"rem\">\/\/ query!!!<\/span>\r\n    result.Dump();\r\n}<\/pre>\n<p>For example:<\/p>\n<pre class=\"csharpcode\"><span class=\"kwrd\">using<\/span>(var db = Db4oEmbedded.OpenFile(<span class=\"str\">@\"C:\\Users\\Gamlor\\Desktop\\test.db4o\"<\/span>)){\r\n    var result = from Person p <span class=\"kwrd\">in<\/span> db\r\n                    <span class=\"kwrd\">where<\/span> p.FirstName.Contains(<span class=\"str\">\"Roman\"<\/span>)\r\n                    select <span class=\"kwrd\">new<\/span> {p.FirstName, p.LivesAt.Street, p.LivesAt.City.Name};\r\n    result.Dump();\r\n}<\/pre>\n<p>As you see, you just use normal C# code. So you can run any LINQ-Query on you\u2019re database.<\/p>\n<p>Update with LINQPad<\/p>\n<p>Well updating is also possible. LINQPad is nothing else than a C#-Console. So you just get the objects, change then and store the changes. For example:<\/p>\n<pre class=\"csharpcode\"><span class=\"kwrd\">using<\/span>(var db = Db4oEmbedded.OpenFile(<span class=\"str\">@\"C:\\Users\\Gamlor\\Desktop\\test.db4o\"<\/span>)){\r\n    var update = (from Person p <span class=\"kwrd\">in<\/span> db\r\n                    <span class=\"kwrd\">where<\/span> p.FirstName.Contains(<span class=\"str\">\"Roman\"<\/span>)\r\n                    select p).First();\r\n    update.FirstName = <span class=\"str\">\"Romanovski\"<\/span>;\r\n    db.Store(update);\r\n    update.Dump();\r\n}<\/pre>\n<h4>Some LINQPad-Tips<\/h4>\n<p>Since LINQPad doesn\u2019t know anything about db4o, but is only a interactive C#-console, you are responsible for db4o specific behavior. For example the <a href=\"?p=637\">activation-depth, update-depth<\/a> etc also apply within LINQPad. So for example when all properties of a nested object are null, it is might not activated yet.<\/p>\n<p>You might also write a little helper class library which you can use within LINQPad together with db4o.<\/p>\n<p>Since LINQPad is a popular tool, you certainly find more resources on the internet.<\/p>\n<h4>Conclusion<\/h4>\n<p>I\u2019ve introduced two tools for ad-hoc querying and modification of the db4o-database. The Object Manager with it\u2019s graphical query builder and LINQPad. Both are useful for inspecting the database.<\/p>\n<p>However I would like to see more powerful tools. When you know one, please tell me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Remember my very first post about db4o? There I\u2019ve made the statement that the tool-support is very bad. Well I don\u2019t revise my opinion here. The situation is still bad&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[126,150],"tags":[21,100],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/949"}],"collection":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/comments?post=949"}],"version-history":[{"count":23,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/949\/revisions"}],"predecessor-version":[{"id":3849,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/949\/revisions\/3849"}],"wp:attachment":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/media?parent=949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/categories?post=949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/tags?post=949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}