NF9.1 OSGi New Model Factory

From iDempiere en

Feature: OSGi New Model Factory

Goal: Development

Developer: Hengsin (talk)

Description: Implement a new model factory base class that's backed by Map and Lambda functional object.

Usage:
With following model class:

public class MyTest extends X_Test {
    /**
    * 
    */
    private static final long serialVersionUID = 2010413233032792416L;
    
    public MyTest(Properties ctx, int Test_ID, String trxName) {
	super(ctx, Test_ID, trxName);
    }
    
    public MyTest(Properties ctx, ResultSet rs, String trxName) {
	super(ctx, rs, trxName);
    }				
}

Developer can use one of the following approach:

1. At plugin Activator start method, register the model class.

public void start(BundleContext context) throws Exception {
    var factory = Core.getMappedModelFactory();
    factory.addMapping(MyTest.Table_Name, () -> MyTest.class, 
          (id, trxName) -> new MyTest(Env.getCtx(), id, trxName), 
          (rs, trxName) -> new MyTest(Env.getCtx(), rs, trxName));
}

2. Create an osgi component, at the bind method for the IMappedModelFactory service.

public void bindService(IMappedModelFactory factory) {
    factory.addMapping(MyTest.Table_Name, () -> MyTest.class, 
          (id, trxName) -> new MyTest(Env.getCtx(), id, trxName), 
          (rs, trxName) -> new MyTest(Env.getCtx(), rs, trxName));
}

3. Create a subclass of MappedModelFactory, register as IModelFactory service (DO NOT register as IMappedModelFactory service).

public class MyFactory extends MappedModelFactory {	
    public MyFactory() {
        addMapping(MyTest.Table_Name, () -> MyTest.class, 
            (id, trxName) -> new MyTest(Env.getCtx(), id, trxName), 
            (rs, trxName) -> new MyTest(Env.getCtx(), rs, trxName));
    }		
}

Technical Info: IDEMPIERE-4675

Cookies help us deliver our services. By using our services, you agree to our use of cookies.