Using Annotations

This topic applies to Java version only

JDK1.5 platform introduced new metadata feature called annotations. Annotations allow programmers to decorate Java code with their attributes, which can be used afterwards for automatic code generation, documentation, security checking etc. Annotations do not directly affect program semantics, but they do affect the way programs are treated by tools and libraries, which can in turn affect the semantics of the running program.

Annotations can make your code cleaner, protecting you from common errors (using deprecated API, typos in overriding methods) and taking part of you work.

You can use annotations to affect db4o behavior. At present we provide only one annotation:

@Indexed

This annotation can be applied to class fields

Car.java
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02 03package com.db4odoc.annotations; 04 05import com.db4o.config.annotations.Indexed; 06 07 08public class Car { 09 @Indexed 10 private String model; 11 private int year; 12}

and its functionality is equivalent to the db4o configurations setting:

Db4o.configure().objectClass(clazz).objectField("fieldName").indexed(true)