Search in sources :

Example 11 with ExtensionMethod

use of org.jdbi.v3.core.extension.ExtensionMethod in project jdbi by jdbi.

the class ConstantHandleSupplier method invokeInContext.

@Override
public <V> V invokeInContext(ExtensionMethod extensionMethod, ConfigRegistry config, Callable<V> task) throws Exception {
    ExtensionMethod oldExtensionMethod = handle.getExtensionMethod();
    try {
        handle.setExtensionMethod(extensionMethod);
        ConfigRegistry oldConfig = handle.getConfig();
        try {
            handle.setConfig(config);
            return task.call();
        } finally {
            handle.setConfig(oldConfig);
        }
    } finally {
        handle.setExtensionMethod(oldExtensionMethod);
    }
}
Also used : ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod)

Example 12 with ExtensionMethod

use of org.jdbi.v3.core.extension.ExtensionMethod in project jdbi by jdbi.

the class TestSqlObjectMethodBehavior method setUp.

@Before
public void setUp() throws Exception {
    HandleSupplier handleSupplier = new HandleSupplier() {

        @Override
        public ConfigRegistry getConfig() {
            return new ConfigRegistry();
        }

        @Override
        public Handle getHandle() {
            throw new UnsupportedOperationException();
        }

        @Override
        public <V> V invokeInContext(ExtensionMethod extensionMethod, ConfigRegistry config, Callable<V> task) throws Exception {
            return task.call();
        }
    };
    SqlObjectFactory factory = new SqlObjectFactory();
    dao = factory.attach(UselessDao.class, handleSupplier);
    anotherDao = factory.attach(UselessDao.class, handleSupplier);
}
Also used : ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) HandleSupplier(org.jdbi.v3.core.extension.HandleSupplier) ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Callable(java.util.concurrent.Callable) Before(org.junit.Before)

Aggregations

ExtensionMethod (org.jdbi.v3.core.extension.ExtensionMethod)12 Test (org.junit.Test)9 ConfigRegistry (org.jdbi.v3.core.config.ConfigRegistry)2 Timed (com.codahale.metrics.annotation.Timed)1 Method (java.lang.reflect.Method)1 Callable (java.util.concurrent.Callable)1 HandleSupplier (org.jdbi.v3.core.extension.HandleSupplier)1 Before (org.junit.Before)1