/** * Reserved for internal use. A static factory method to generate a map of property names to {@link PropertyPair} * instances for the specified class type. Checks if the cache is enabled and if so tries to get the property pairs * from it. Otherwise, uses reflection to find pairs of getter and setter methods that are annotated with * {@link StoreAs} with a common property name, or of the form <code>get<em>PropertyName</em></code> and * <code>set<em>PropertyName</em></code>, with a common type for the getter return value and the setter parameter, * and stores the methods and the property name for each pair found in a map for use in serializing and * deserializing entity data. If the cache is enabled and the mapping was not present, adds it to the cache. * * @param clazzType * The class type to check for matching getter and setter methods with a common return and parameter * type, respectively. */ protected static HashMap<String, PropertyPair> generatePropertyPairs(final Class<?> clazzType) { if (!TableServiceEntity.isReflectedEntityCacheDisabled()) { HashMap<String, PropertyPair> props = new HashMap<String, PropertyPair>(); props = TableServiceEntity.getReflectedEntityCache().get(clazzType); if (props == null) { props = PropertyPair.generatePropertyPairsHelper(clazzType); TableServiceEntity.getReflectedEntityCache().put(clazzType, props); } return props; } else { return PropertyPair.generatePropertyPairsHelper(clazzType); } }
/** * Reserved for internal use. A static factory method to generate a map of property names to {@link PropertyPair} * instances for the specified class type. Checks if the cache is enabled and if so tries to get the property pairs * from it. Otherwise, uses reflection to find pairs of getter and setter methods that are annotated with * {@link StoreAs} with a common property name, or of the form <code>get<em>PropertyName</em></code> and * <code>set<em>PropertyName</em></code>, with a common type for the getter return value and the setter parameter, * and stores the methods and the property name for each pair found in a map for use in serializing and * deserializing entity data. If the cache is enabled and the mapping was not present, adds it to the cache. * * @param clazzType * The class type to check for matching getter and setter methods with a common return and parameter * type, respectively. */ protected static HashMap<String, PropertyPair> generatePropertyPairs(final Class<?> clazzType) { if (!TableServiceEntity.isReflectedEntityCacheDisabled()) { HashMap<String, PropertyPair> props = new HashMap<String, PropertyPair>(); props = TableServiceEntity.getReflectedEntityCache().get(clazzType); if (props == null) { props = PropertyPair.generatePropertyPairsHelper(clazzType); TableServiceEntity.getReflectedEntityCache().put(clazzType, props); } return props; } else { return PropertyPair.generatePropertyPairsHelper(clazzType); } }
@Test public void testPropertyCacheDisable() { try { TableServiceEntity.getReflectedEntityCache().put(this.getClass(), new HashMap<String, PropertyPair>()); TableServiceEntity.setReflectedEntityCacheDisabled(true); assertEquals(true, TableServiceEntity.isReflectedEntityCacheDisabled()); assertTrue(TableServiceEntity.getReflectedEntityCache().isEmpty()); TableServiceEntity.setReflectedEntityCacheDisabled(false); assertEquals(false, TableServiceEntity.isReflectedEntityCacheDisabled()); } finally { TableServiceEntity.setReflectedEntityCacheDisabled(false); } }