Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.skife.jdbi.v2.sqlobject;
 
 
 import java.util.Set;
 
 class OnDemandHandleDing implements HandleDing
    private final IDBI dbi;
    private final ThreadLocal<LocalDingthreadDing = new ThreadLocal<LocalDing>();
    {
        this. = dbi;
    }
    public Handle getHandle()
    {
        if (.get() == null) {
            .set(new LocalDing(.open()));
        }
        return .get().getHandle();
    }
    public void retain(String name)
    {
        getHandle(); // need to ensure the local ding has been created as this is called before getHandle sometimes.
        .get().retain(name);
    }
    public void release(String name)
    {
        LocalDing ding = .get();
        if (ding == null) {
            return;
        }
        ding.release(name);
    }
    class LocalDing implements HandleDing {
        private final Set<Stringretentions = new HashSet<String>();
        private final Handle handle;
        public LocalDing(Handle handle)
        {
            this. = handle;
        }
        public Handle getHandle()
        {
            return ;
        }
        public void release(String name)
        {
            .remove(name);
            if (.isEmpty()) {
                .set(null);
                .close();
            }
        }
        public void retain(String name)
        {
            .add(name);
        }
    }
New to GrepCode? Check out our FAQ X