All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.curs.celesta.java.JCallContext Maven / Gradle / Ivy

There is a newer version: 6.1.12
Show newest version
package ru.curs.celesta.java;

import ru.curs.celesta.CallContext;
import ru.curs.celesta.CelestaException;
import ru.curs.celesta.dbutils.BasicDataAccessor;

import java.util.HashMap;

public class JCallContext extends CallContext<
        JCallContext, JSessionContext, Class, BasicDataAccessor
        > {

    private final HashMap, BasicDataAccessor> dataAccessorsCache = new HashMap<>();

    public JCallContext(JCallContextBuilder contextBuilder) {
        super(contextBuilder);
    }

    @Override
    public JCallContext getCopy() {
        return null;
    }

    @Override
    public BasicDataAccessor create(Class dataAccessorClass) {
        BasicDataAccessor result = dataAccessorsCache.computeIfAbsent(dataAccessorClass,
                aClass -> {
                    try {
                        return dataAccessorClass.getDeclaredConstructor(CallContext.class)
                                .newInstance(this);
                    } catch (Exception e) {
                        throw new CelestaException(e);
                    }
                });

        result.clear();
        return result;
    }

    @Override
    public void removeFromCache(BasicDataAccessor dataAccessor) {
        dataAccessorsCache.remove(dataAccessor.getClass());
    }

    @Override
    public CallContextBuilder getBuilder() {
        return builder();
    }

    public static JCallContextBuilder builder() {
        return new JCallContextBuilder();
    }

    public static final class JCallContextBuilder extends CallContext.CallContextBuilder {
        @Override
        protected JCallContextBuilder getThis() {
            return this;
        }

        @Override
        public JCallContext createCallContext() {
            return new JCallContext(this);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy