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

org.xblackcat.sjpu.storage.impl.AMappableMethodBuilder Maven / Gradle / Ivy

Go to download

Service for generating DB access logic in simple way via interfaces and annotations

There is a newer version: 2.0
Show newest version
package org.xblackcat.sjpu.storage.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xblackcat.sjpu.skel.IMethodBuilder;
import org.xblackcat.sjpu.storage.consumer.IRowSetConsumer;
import org.xblackcat.sjpu.storage.typemap.TypeMapper;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * 19.12.13 16:50
 *
 * @author xBlackCat
 */
public abstract class AMappableMethodBuilder implements IMethodBuilder {
    protected final Log log = LogFactory.getLog(getClass());
    protected final TypeMapper typeMapper;
    protected final Map, Class> rowSetConsumers;
    private final Class annClass;

    public AMappableMethodBuilder(
            Class annClass,
            TypeMapper typeMapper,
            Map, Class> rowSetConsumers
    ) {
        this.typeMapper = typeMapper;
        this.rowSetConsumers = rowSetConsumers;
        this.annClass = annClass;
    }

    protected Class hasRowSetConsumer(Class returnType, Class realReturnType) {
        for (Map.Entry, Class> e : rowSetConsumers.entrySet()) {
            if (returnType.equals(e.getKey()) && !realReturnType.isAssignableFrom(e.getKey())) {
                return e.getValue();
            }
        }

        return null;
    }

    @Override
    public Class getAnnotationClass() {
        return annClass;
    }

    protected A getAnnotation(Method m) {
        return m.getAnnotation(getAnnotationClass());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy