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

de.zalando.sprocwrapper.proxy.SProcProxyBuilder Maven / Gradle / Ivy

Go to download

Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces including automatic object serialization and deserialization (using typemapper and convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types such as enums and hstore.

There is a newer version: 2.0.0
Show newest version
package de.zalando.sprocwrapper.proxy;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.zalando.sprocwrapper.dsprovider.DataSourceProvider;

/**
 * @author jmussler
 */
public class SProcProxyBuilder {

    private static SProcServiceAnnotationHandler sProcServiceAnnotationHandler = new SProcServiceAnnotationHandler();
    private static SProcCallHandler sProcCallHandler = new SProcCallHandler();

    private static final Logger LOG = LoggerFactory.getLogger(SProcProxyBuilder.class);

    private SProcProxyBuilder() {
        // utility class: private constructor
    }

    @SuppressWarnings("unchecked")
    public static  T build(final DataSourceProvider d, final Class c) {
        final SProcProxy proxy = new SProcProxy(d, c.getName());


        try {
            SProcServiceAnnotationHandler.HandlerResult handlerResult = sProcServiceAnnotationHandler.handle(c);
            Map spMap = sProcCallHandler.handle(c, handlerResult);
            for (Method method : spMap.keySet()) {
                StoredProcedure storedProcedure = spMap.get(method);
                LOG.debug("{} registering {}", c.getSimpleName(), storedProcedure);
                proxy.addStoredProcedure(method, storedProcedure);
            }
        } catch (IllegalArgumentException ex) {
            return null;
        }
        return (T) java.lang.reflect.Proxy.newProxyInstance(c.getClassLoader(), new Class[]{c}, proxy);

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy