Click here to Skip to main content
15,798,739 members
Articles / Desktop Programming / Windows Forms


Rate me:
Please Sign up or sign in to vote.
4.61/5 (25 votes)
24 Apr 2012CPOL5 min read 133.2K   17.8K   98   10
A project for managing the digital books (HTML, DOCX, ODF, PDF, EPUB, TXT, etc.) of the user using db4o

Screenshot 1

Image 1

Screenshot 2

Image 2

Screenshot 3

Image 3


BookStore is a digital book management system, written in C# and targeting the .NET Framework 2.0 on the Windows OS. It uses the db4o fully object-oriented database management system for the storing and querying of books.

The application allows the user to store all of its digital books (CHM, HTML, DOCX, PDF, EPUB, ODF, RTF, TXT, etc.) in a central single-file database repository, without the need to keep the books as individual files and folders on the disc, thus reducing disc fragmentation and easing content cohesion and portability (by copying the books database to a memory stick, for example).

The books to be imported can be either file-based books (such as a single PDF document) or folder-based books (such as a website offline copy). Books can be loaded one-at-a-time or many-at-once (bulk-load). Once imported, each book can be displayed or deleted.

Each book stored in the system is characterized by 5 attributes:

  • Title
  • Set of authors
  • Set of tags
  • Publishing house
  • Year of publishing

The user can then query a particular set of books, based upon a combination of the aforementioned attributes. The querying system contains two layers:

  • An inter-category layer - The corresponding query types are AND queries (for which the query result must satisfy each selected category) and OR queries (for which the query result satisfies at least one of the designated categories)
  • An intra-category layer - the related query types are AND queries (only in the case of multiple selection availability, meaning the set of authors and set of tags) and OR queries. The semantics for these query types are similar to the inter-category queries.

The application supports multi-user access on the same PC, as each user can have its own database, without any interference with the data of other users. Also, since the user is able to select the application's working folders, the solution can be run by any user, irrespective of its privileges on the system.

The Underlying DBMS

At the start of the application's development, I looked into small-footprint programmable open-source database management systems available. I found two potential candidates: SQLite and db4o. Due to an interest in dabbling into an OODBMS for research purposes, I chose db4o.

Object-oriented databases have attracted considerable interest due to their promise to completely remove the disparity between the object-oriented data model and the entity-relationship model, called impedance mismatch.

These databases expose means through which objects can be queried and stored using the same model that it employed by the application’s programming language. Another way of putting it would be saying that an OODBMS extends the programming language with transparently persistent data, concurrency control, data recovery, associative queries and other capabilities. Object-oriented databases have bindings to most modern programming languages and platforms, including C++, Java, .NET, Perl, Python, Objective-C and Visual Basic. 

Impedance Mismatch

The impedance mismatch is a collection of technical and conceptual difficulties, often encountered when a relational (SQL) database management system is being used in an object-oriented application.

It relates to aspects of information hiding, inheritance and polymorphism, syntax and semantics, as well as security features.

The diagram below reveals the usage of the composite design pattern. A Book contains an IDiscEntry, which can be either a File or a Folder. A Folder can contain many IDiscEntrys, those, of course, being files or folders. A File contains one or many Buffers, which are used to read / write data from / to disc using contiguous memory blocks. If a file is small, it may require only one Buffer object, but if its size is great it could use many such objects.

Image 4

As the relational databases world does not have an approximate correspondent to the inheritance relation of the object-oriented world, modeling this concept into a SQL-compliant database is a painful, full of compromises experience, as shown next.

Image 5

The db4o Solution

db4o provides a simple uniform interface for storing new objects and updating existing objects: objectContainer.Store(myObject). The object is stored anew or updated up to a specifically-defined update depth inside the object graph.

There are three methods for querying objects in db4o. Two of them use a declarative syntax, while the third is based on navigational semantics. The table underneath reveals the querying options in db4o.

Image 6

Transactional support is not a feature that is dependent on the type of DBMS used. db4o makes transactional support available to the client programmer, as revealed in the subsequent example.

Address address = new Address("Teodor Mihali St.", "Cluj-Napoca", "Romania");
Person person = new Person("Mihnea Radulescu", address);

     // Opens the database file and creates a new instance of the
     // IObjectContainer interface.
     IObjectContainer db = Db4oFactory.OpenFile("Persons.yap");

     // Stores the new person.

     // Commits the transaction.

catch (Exception)
     // Rolls the transaction back, in case of failures.

     // Closes the database.

Application Details

The application contains around 55 types (mostly classes), organized into 5 namespaces:

  • DataAccess - Types relevant to the interaction with the db4o database management system
  • DiscAccess - Classes for reading the book file content from disc, persisting it to the database and writing the book files to disc for displaying
  • RegistryAccess - A single class used for storing per-user database location and temporary folder path
  • BookEntities - Application business-logic classes, exposing the book data and meta-data, as well as the book querying engine
  • BookStoreGUI - Windows Forms GUI functionality types (Form, UserControl and TabPage classes)

The application developed is a well-chosen example of using the strengths of OODBMS’ in real-world scenarios. It manages the storage, visualization and tag-based querying of the digital books of the user by allowing the viewing of the content of books already stored, deleting existing books, searching for books based upon a criterion or combination of criteria and adding new books to the application's database. It benefits from object-oriented persistence features in terms of natural and straightforward development, as well as performance opportunities.

Also, as collateral db4o-related benefits to implementing the required functionality of the application, I:

  • created a uniform fully transactional wrapper to updating and querying in db4o (DataAccess namespace)
  • added the means to store and retrieve an external file (BLOB) of any size, by repeatedly accessing buffer-size database-controlled sections of the file (DiscAccess namespace)

Source Code and Application Download

The complete source code of the BookStore application (a Google Code project) can be accessed here. If one is only interested in the binaries, they can be downloaded from this link.

I would gladly welcome contributions and feedback to this BookStore.NET open-source (GPL v3) project, being interested in particular in a Mono port of this project.


  • [1] The Microsoft Developer Network (MSDN) pages


  • Version 0.1 - Initial submission - 09/03/2010
  • Version 0.2 - Updated content, sources and binaries - 21/09/2011
  • Version 0.3 - Reengineered code with significant bug fixes - 24/04/2012 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Comments and Discussions

QuestionUse with Mysql database Pin
Member 1069993925-Mar-14 22:32
Member 1069993925-Mar-14 22:32 
AnswerRe: Use with Mysql database Pin
User 691845420-May-14 8:59
User 691845420-May-14 8:59 
GeneralThank You! Pin
Member 81289586-Feb-14 12:55
Member 81289586-Feb-14 12:55 
QuestionHow can i add data into database? Pin
Member 1022658415-Oct-13 15:51
Member 1022658415-Oct-13 15:51 
AnswerRe: How can i add data into database? Pin
User 69184541-Nov-13 7:40
User 69184541-Nov-13 7:40 
QuestionGreat work! Pin
rizomatosa16-Nov-12 2:31
rizomatosa16-Nov-12 2:31 
Very interesting work! Now i'm thinking to use this code with another db (probably sqlite) because i need to use sql data that were already saved in other relational db. Have you some suggestions ? Which strategy would you adopt? Or is there some simple method to import external sql relational data into your schema db?
AnswerRe: Great work! Pin
User 691845416-Nov-12 5:18
User 691845416-Nov-12 5:18 
GeneralMy vote of 5 Pin
ErmanBelegu14-Jun-12 23:16
ErmanBelegu14-Jun-12 23:16 
BugFirst couple of pictures are missing Pin
Slacker00724-Apr-12 0:29
professionalSlacker00724-Apr-12 0:29 
GeneralRe: First couple of pictures are missing Pin
User 691845424-Apr-12 0:33
User 691845424-Apr-12 0:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.