2011/01/16 - Apache ObJectRelationalBridge has been retired.

For more information, please explore the Attic.


Coding Standards

This document describes a list of coding conventions that are required for code submissions to the project. By default, the coding conventions for most Open Source Projects should follow the existing coding conventions in the code that you are working on. For example, if the bracket is on the same line as the if statement, then you should write all your code to have that convention.

If you commit code that does not follow these conventions, you are responsible for also fixing your own code.

Below is a list of coding conventions that are specific to OJB, everything else not specificially mentioned here should follow the official Sun Java Coding Conventions.

1. Brackets should begin and end on a new line and should exist even for one line statements. Examples:

        if (foo)
            // code here

            // code here
        catch (Exception bar)
            // code here
            // code here

        while (true)
            // code here

2. Though it's considered okay to include spaces inside parens, the preference is to not include them. Both of the following are okay:

        if (foo)


        if ( foo )

3. Use 4 space indent. NO tabs. Period. We understand that many developers like to use tabs, but the fact of the matter is that in a distributed development environment where diffs are sent to the mailing lists by both developers and the version control system (which sends commit log messages), the use tabs makes it impossible to preserve legibility.

In Emacs-speak, this translates to the following command:

        (setq-default tab-width 4 indent-tabs-mode nil)

4. Unix linefeeds for all .java source code files. Other platform specific files should have the platform specific linefeeds.

5. JavaDoc MUST exist on all methods. If your code modifications use an existing class/method/variable which lacks JavaDoc, it is required that you add it. This will improve the project as a whole.

6. The ASF license MUST be placed at the top of each and every file.

7. All .java files should have a @version tag with CVS Id keyword expansion, like the one below.

        @version $Id: code-standards.xml 365208 2005-12-14 01:19:23Z arminw $


To add the keyword to a new file, either use $Id: code-standards.xml 365208 2005-12-14 01:19:23Z arminw $ or copy an existing expanded id-string from another file (all the parameters will be replaced by CVS). Just watch out not to type $Id $, since that extra space will signal to CVS that keyword expansion already took place.

8. Import statements must be fully qualified for clarity.

        import java.util.ArrayList;
        import java.util.Hashtable;

        import org.apache.foo.Bar;
        import org.apache.bar.Foo;

And not

        import java.util.*;
        import org.apache.foo.*;
        import org.apache.bar.*;

Emacs/XEmacs users might appreciate the following in their .emacs file.

        (defun apache-db-mode ()
          "The Java mode specialization for Apache DB projects."
          (if (not (assoc "apache-db" c-style-alist))
              ;; Define the Apache DB cc-mode style.
              (c-add-style "apache-db" '("java" (indent-tabs-mode . nil))))

          (c-set-style "apache-db")
          (c-set-offset 'substatement-open 0 nil)
          (setq mode-name "Apache DB")

          ;; Turn on syntax highlighting when X is running.
          (if (boundp 'window-system)
              (progn (setq font-lock-support-mode 'lazy-lock-mode)
                     (font-lock-mode t))))

        ;; Activate Apache DB-mode for JDE.
        (if (fboundp 'jde-mode)
            (add-hook 'jde-mode-hook 'apache-db-mode)
          (add-hook 'java-mode-hook 'apache-db-mode))

Thanks for your cooperation.

by Jon S. Stevens, Jason van Zyl