Overview
Installation
VTL reference
Configuration
Architecture
Java reference
Velosurf FAQ

Java Reference

Defining custom entity classes

You can easily use a custom instance class for an entity.

All you have to do is to specify its full qualified name in the 'class' attribute of the target entity in the configuration file. The class can be a POJO (Plain Old Java Object).

You can then decide to declare some of the getters or setters, or one of the insert(), update() or delete() methods if you want to specialize them, for instance to include some specific validation code.

It is also allowed to have your class inherit from velosurf.context.Instance, in case it will be directly used by Velosurf instead of being wrapped, which allows a more advanced customization.

Standalone usage

If you are not using the velocity-tools project, you can easily populate a Velocity context with a code as simple as this one:

import org.apache.velocity.Context;
import velosurf.standalone.Velosurf;
[...]

context.put("db",new Velosurf());

Some remarks, thought:

  • You should initialize Velosurf Logger if you want to log to somewhere else than System.err.

  • You must ensure that Velosurf will find its configuration file (velosurf.xml), according to this documentation.

Alternatively, you can handle yourself the initialization process:

    import velosurf.context.DBReference;
    import velosurf.sql.DBConnection;
    [...]
    // static initialisation (do it once)
    InputStream is = inServletContext.getResourceAsStream("./path/to/velosurf.xml");
    DBConnection connection = DBConnection.getInstance(is);
    [...]
    // context initialisation (for each new context)
    DBReference db = new DBReference(connection);
    context.put("db",db);

Javadoc

You can build the javadoc using the 'javadoc' ant target.

Using Velosurf from within Java

Velosurf can be used from Java as easily as from VTL.

It can be more convenient than using the jdbc classes and methods, especially if you want to re-use from Java the attributes you have defined in velosurf.xml.

Please note that to avoid sql connection timeouts, you should not declare Velosurf prepared statements as variables having a long lifecycle (like static members). You should only keep references to Velosurf connection objets on the long term (they do handle timeouts).