How to write a new RdbAdapter for my database ?

  1. Fill the user.properties files with information do access the database
  2. Try the BasicRdbAdapter for your data base and note the list failed tests.
     ant test -Dtest.name=adapter


  3. Write a class respecting this pattern for its name: org.objectweb.jorm.rdb.adapter.<database name>Adapter where <database name> is the name of your database and the first letter is upper. This class should extend the BasicRdbAdapter class and overide the methods which fail.
    For example in postgres the BIGINT sql type does not exist. But the INT8 sql type must be used. Then the PostgresAdapter overides the method getSqlType(PType, boolean, int, int) such as the following example:

    package org.objectweb.jorm.mapper.rdb.adapter;
    
    import org.objectweb.jorm.api.PExceptionProtocol;
    import org.objectweb.jorm.api.PException;
    import org.objectweb.jorm.type.api.PType;
    
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Connection;
    
    /**
     * Defines a RdbAdapter for the PostgreSQL database.
     */
    public class PostgresAdapter extends BasicRdbAdapter {
    
    	public PostgresAdapter() {
    		super("postgres");
    	}
    
    	public String getSqlType(PType pt, boolean usedInPK, int size, int scale) throws PExceptionProtocol {
    		if (pt == null) {
    			throw new PExceptionProtocol("No Sql Type name associated to a null PType");
    		}
    		switch (pt.getTypeCode()) {
    		case PType.TYPECODE_LONG:
    		case PType.TYPECODE_OBJLONG:
    			return "INT8";
    		default:
    			return super.getSqlType(pt, usedInPK, size, scale);
    		}
    	}
    }
    We advice you to take a look on the existing RdbAdapter, and in the javadoc of the RdbAdapter interface.


  4. Change the adapter.classname in the user.properties with the name of your adapter to test
  5. Test your adapter and modify it until the test works fine.
     ant test -Dtest.name=adapter


  6. When your adapter works fine, send it to jorm list in order to be integrated into the CVS version.

If you have questions about the RdbAdapter, contact the JORM team.