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

nl._42.jarb.constraint.metadata.database.CachingBeanMetadataRepository Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
/*
 * (C) 2013 42 bv (www.42.nl). All rights reserved.
 */
package nl._42.jarb.constraint.metadata.database;

import java.util.HashMap;
import java.util.Map;

import nl._42.jarb.utils.bean.PropertyReference;

/**
 * Caching bean metadata repository.
 *
 * @author Jeroen van Schagen
 * @since Feb 11, 2014
 */
public class CachingBeanMetadataRepository implements BeanMetadataRepository {
    
    private final Map caches = new HashMap();

    private final BeanMetadataRepository delegate;

    public CachingBeanMetadataRepository(BeanMetadataRepository delegate) {
        this.delegate = delegate;
    }

    @Override
    public ColumnMetadata getColumnMetadata(PropertyReference propertyReference) {
        ColumnMetadata columnMetadata = caches.get(propertyReference);
        if (columnMetadata == null) {
            columnMetadata = delegate.getColumnMetadata(propertyReference);
            caches.put(propertyReference, columnMetadata);
        }
        return columnMetadata;
    }
    
    @Override
    public boolean isEmbeddable(Class propertyType) {
        return delegate.isEmbeddable(propertyType);
    }
    
    public void evictAll() {
        caches.clear();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy