1. First GlanceBefore diving straight into the first source code samples let's get you familiar with some basics.1.1. The db4o engineThe db4o object database engine consists of one single core jar file. In addition you may want to use client/server library or optional components. You may also get it all in a single jar "db4o-all":db4o-8.0-core-java5.jar is built for Java JDK 5 and JDK 6 If you intend to use client/server version of db4o you will additionally need the client/server library : db4o-8.0-cs-java5.jar Some advanced functionality such as cluster support, platform-specific IO adapters, statistic tools etc can be added by including the db4o optional library: db4o-8.0-optional-java5.jar You can also get all of the above in a single jar: db4o-8.0-all-java5.jar 1.2. InstallationIf you add one of the above db4o-*.jar files to your CLASSPATH db4o is installed. For beginners it is recommended to use "db4o-all" library to avoid confusion with the location of certain classes. In case you work with an integrated development environment like Eclipse you would copy the db4o-*.jar to the /lib/ folder under your project and add db4o to your project as a library.1.3. Object Manager Enterprise installationObject Manager Enterprise (OME) is an object browser for db4o databases. OME installation can be found in /ome folder of the distribution. The zip file in this folder contains the Eclipse plugin version of OME.To install the plugin, you need to have a version of Eclipse >= 3.3 installed. Unzip the file to a folder of your choice. Then open Eclipse, select 'Help' -> 'Software Updates...' -> 'Available Software' from the menu. Choose 'Add Site...' -> 'Local...' and select the unzipped folder. Follow the Eclipse Update Manager instructions for the OME feature from here on. The actual menu structure may vary over Eclipse versions. (The above applies to Eclipse 3.4 Ganymede.) When in doubt, please refer to the Eclipse documentation on Software Updates. Alternatively, you can install the plugin manually by simply copying the contents of the 'plugins' and 'features' folders from the unzipped folder to the corresponding subfolders in the root folder of your Eclipse installation. 1.4. API OverviewDo not forget the API documentation while reading through this tutorial. It provides an organized view of the API, looking from a java package perspective and you may find related functionality to the theme you are currently reading up on.For starters, the java packages com.db4o and com.db4o.query are all that you need to worry about. com.db4o The com.db4o java package contains almost all of the functionality you will commonly need when using db4o. Two objects of note are com.db4o.Db4oEmbedded, and the com.db4o.ObjectContainer interface. The com.db4o.Db4o factory is your starting point. Static methods in this class allow you to open a database file and create an initial configuration. For client/server environment you will need to use com.db4o.cs.Db4oClientServer factory class to start a server, or connect to an existing server, but this will be discussed later , start a server, or connect to an existing server. The most important interface, and the one that you will be using 99% of the time is com.db4o.ObjectContainer: This is your db4o database. - An ObjectContainer can either be a database in single-user mode or a client connection to a db4o server. - Every ObjectContainer owns one transaction. All work is transactional. When you open an ObjectContainer, you are in a transaction, when you commit() or rollback(), the next transaction is started immediately. - Every ObjectContainer maintains it's own references to stored and instantiated objects. In doing so, it manages object identities, and is able to achieve a high level of performance. - ObjectContainers are intended to be kept open as long as you work against them. When you close an ObjectContainer, all database references to objects in RAM will be discarded. com.db4o.ext In case you wonder why you only see very few methods in an ObjectContainer, here is why: The db4o interface is supplied in two steps in two java packages, com.db4o and com.db4o.ext for the following reasons: - It's easier to get started, because the important methods are emphasized. - It will be easier for other products to copy the basic db4o interface. - It is an example of how a lightweight version of db4o could look. Every com.db4o.ObjectContainer object is also an com.db4o.ext.ExtObjectContainer. You can cast it to ExtObjectContainer or you can use the method to get to the advanced features. com.db4o.config The com.db4o.config java package contains types and classes necessary to configure db4o. The objects and interfaces within are discussed in the Configuration section. com.db4o.query The com.db4o.query java package contains the Predicate class to construct Native Queries. The Native Query interface is the primary db4o querying interface and should be preferred over the Soda Query API. |