cancel
Showing results for 
Search instead for 
Did you mean: 

APS - How to override DbSqlSessionFactory properly?

vikash_patel
Star Contributor
Star Contributor

I am using Alfresco Process Services 24.2 Spring version - 6.1.5

I have overridden DbSqlSessionFactory in my custom code using below code CustomDbSqlSessionFactory

 

 

package com.activiti.extension.bean.extension.db;

import lombok.RequiredArgsConstructor;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.db.DbSqlSessionFactory;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.Session;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.stereotype.Component;

import java.sql.SQLException;

@Component
@RequiredArgsConstructor
public class CustomDbSqlSessionFactory extends DbSqlSessionFactory {

    private final ObjectFactory<CustomDbSqlSession> dbSqlSession;

    
    public Session openSession(CommandContext commandContext) {
        return super.openSession(commandContext);
    }

}

 

 

And CustomDbSqlSession

 

 

package com.activiti.extension.bean.extension.db;

import org.activiti.engine.impl.db.DbSqlSession;
import org.activiti.engine.impl.persistence.entity.Entity;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

import static java.util.stream.Collectors.toList;
import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE;

@Slf4j
@Component
@Scope(SCOPE_PROTOTYPE)
public class CustomDbSqlSession extends DbSqlSession {

    public CustomDbSqlSession(CustomDbSqlSessionFactory dbSqlSessionFactory, CustomEntityCache entityCache) {
        super(dbSqlSessionFactory, entityCache);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    
    public List selectListWithRawParameter(String statement, Object parameter, int firstResult, int maxResults) {
        return super.selectListWithRawParameter(statement, parameter, firstResult, maxResults);

    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    
    public List selectListWithRawParameterWithoutFilter(String statement, Object parameter, int firstResult, int maxResults) {
       return super.selectListWithRawParameterWithoutFilter(statement, parameter, firstResult, maxResults);

    }

    
    protected void flushRegularInsert(Entity persistentObject, Class<? extends Entity> clazz) {
        super.flushRegularInsert(persistentObject, clazz);
    }

    
    protected void flushBulkInsert(Collection<Entity> persistentObjectList, Class<? extends Entity> clazz) {
        super.flushBulkInsert(persistentObjectList, clazz);
    }

    
    protected void flushUpdates() {
        super.flushUpdates();
    }
}

 

 

I am able to compile and create build, After deploying changes to APS I am able to create and execute process . But in CustomDbSqlSession class, I have overridden few DbSqlSession's methods and that are not getting executed. I tried by adding logs and debuggers in Intellij Idea it seems flow is not executing in custom overridden method, it's calling the default DbSqlSession's method.

I wanted to execute the CustomDbSqlSession's overridden methods.

if I changes openSession method to below code then the overridden method of CustomDbSqlSession is getting executed, but due to that I am getting CommandContext error and not able to start the process,

@Override
public Session openSession() {
return dbSqlSession.getObject();
}

Can anyone please help here?

0 REPLIES 0