Coverage Report - net.admin4j.jdbc.driver.DriverContextRegistry
 
Classes in this File Line Coverage Branch Coverage Complexity
DriverContextRegistry
82%
14/17
100%
6/6
2
DriverContextRegistry$1
N/A
N/A
2
DriverContextRegistry$DriverSettings
100%
2/2
N/A
2
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.jdbc.driver;
 15  
 
 16  
 import java.util.Map;
 17  
 import java.util.concurrent.ConcurrentHashMap;
 18  
 import java.util.concurrent.atomic.AtomicBoolean;
 19  
 
 20  
 import net.admin4j.deps.commons.lang3.Validate;
 21  
 import net.admin4j.util.annotate.PackageRestrictions;
 22  
 
 23  
 /**
 24  
  * Registry for JDBC drivers that are currently being proxied.
 25  
  * @author D. Ashmore
 26  
  * @since 1.0.1
 27  
  */
 28  
 @PackageRestrictions({"net.admin4j","java","javax"})
 29  0
 public class DriverContextRegistry {
 30  
     
 31  6
     private static Map<DriverContext, DriverSettings> registryMap = new ConcurrentHashMap<DriverContext, DriverSettings>();
 32  
     
 33  
     public static boolean hasSettings(DriverContext context) {
 34  
         Validate.notNull(context, "Null DriverContext not allowed.");
 35  0
         return registryMap.containsKey(context);
 36  
     }
 37  
     
 38  
     public static boolean isTrackExecutionStacks(DriverContext context) {
 39  
         Validate.notNull(context, "Null DriverContext not allowed.");
 40  180132
         boolean answer = true;
 41  
         
 42  180132
         DriverSettings settings = registryMap.get(context);
 43  180132
         if (settings != null && !settings.trackExecutionStacks.get()) {
 44  90006
             answer = false;
 45  
         }
 46  
         
 47  180132
         return answer;
 48  
     }
 49  
     
 50  
     public static void setTrackExecutionStacks(DriverContext context, boolean setting) {
 51  
         Validate.notNull(context, "Null DriverContext not allowed.");
 52  
         
 53  6
         synchronized (registryMap) {
 54  6
             DriverSettings settings = registryMap.get(context);
 55  6
             if (settings == null) {
 56  3
                 settings = new DriverSettings();
 57  3
                 registryMap.put(context, settings);
 58  
             }
 59  6
             settings.trackExecutionStacks.set(setting);
 60  6
         }
 61  6
     }
 62  
     
 63  0
     private static class DriverSettings {
 64  3
         public AtomicBoolean trackExecutionStacks = new AtomicBoolean(true);
 65  
     }
 66  
 
 67  
 }