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

com.github.lontime.extcopper.container.AbstractPersistentEngineContainer Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.github.lontime.extcopper.container;

import com.github.lontime.base.commonj.utils.LoggerHelper;
import com.github.lontime.extcopper.common.ProcessingEngineWrapper;
import com.github.lontime.extcopper.configuration.OptionResolver;
import com.github.lontime.extcopper.configuration.PersitenceOption;
import com.github.lontime.extcopper.impl.DefaultRdbmsEngineFactory;
import org.copperengine.core.DependencyInjector;
import org.copperengine.core.audit.BatchingAuditTrail;
import org.copperengine.core.audit.ScottyAuditTrailQueryEngine;
import org.copperengine.core.persistent.PersistentScottyEngine;
import org.copperengine.core.util.PojoDependencyInjector;

/**
 * AbstractPersistentEngineContainer.
 * @author lontime
 * @since 1.0
 */
public abstract class AbstractPersistentEngineContainer implements  EngineContainer {

    private PersistentScottyEngine processingEngine;

    private BatchingAuditTrail batchingAuditTrail;

    private ScottyAuditTrailQueryEngine auditTrailQueryEngine;

    private PersitenceOption option;

    private DependencyInjector dependencyInjector;

    public AbstractPersistentEngineContainer() {
        this.dependencyInjector = new PojoDependencyInjector();
        this.option = OptionResolver.getInstance().getPersitenceOption();
    }

    @Override
    public void setDependencyInjector(DependencyInjector dependencyInjector) {
        this.dependencyInjector = dependencyInjector;
    }

    @Override
    public void initialize() {
        if (option == null) {
            return;
        }
        initializeInternal();
    }

    protected void initializeInternal() {
        final DefaultRdbmsEngineFactory factory = new DefaultRdbmsEngineFactory(option, dependencyInjector);
        this.processingEngine = factory.getEngine();
        this.auditTrailQueryEngine = factory.getScottyAuditTrailQueryEngine();
        this.batchingAuditTrail = factory.getAuditTrail();
    }

    @Override
    public void start() {
        if (this.processingEngine != null) {
            this.processingEngine.startup();
        }
        if (this.batchingAuditTrail != null) {
            try {
                this.batchingAuditTrail.startup();
            } catch (Exception e) {
                LoggerHelper.warnv(e, "start error");
            }
        }
    }

    @Override
    public void stop() {
        if (this.processingEngine != null) {
            this.processingEngine.shutdown();
        }
    }

    @Override
    public ProcessingEngineWrapper getEngine() {
        return ProcessingEngineWrapper.from(this.processingEngine);
    }

    @Override
    public BatchingAuditTrail getBatchingAuditTrail() {
        return batchingAuditTrail;
    }

    @Override
    public ScottyAuditTrailQueryEngine getAuditTrailQueryEngine() {
        return auditTrailQueryEngine;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy