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

com.github.panchitoboy.common.ecb.Boundary Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package com.github.panchitoboy.common.ecb;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;
import javax.validation.Valid;
import org.slf4j.Logger;

public abstract class Boundary {

    @Inject
    public Boundary(InjectionPoint ip) {
        ParameterizedType type = (ParameterizedType) ip.getType();
        Class clazz = (Class) type.getActualTypeArguments()[0];
        this.entityClass = clazz;
    }

    @Inject
    protected Logger logger;

    protected final Class entityClass;

    protected Logger getLogger() {
        return logger;
    }

    public abstract Control getControl();

    public T find(Serializable id) {
        return getControl().findBy(id);
    }

    public List findAll() {
        return getControl().findAll();
    }

    public void create(@Valid T entity) {
        getControl().save(entity);
    }

    public void update(@Valid T entity) {
        getControl().save(entity);
    }

    public void remove(Serializable id) {
        T instance = find(id);
        getControl().attachAndRemove(instance);
    }

    public void remove(T instance) {
        getControl().attachAndRemove(instance);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy