DATACMNS-457 - MappingContext now provides information about managed types.
Added MappingContext.getManagedTypes() as well as ….hasPersistentEntity(Class) to access all types currently managed by the MappingContext and find out whether a type is managed by the context.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2012 by the original author(s).
|
||||
* Copyright 2011-2014 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -59,7 +59,7 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
*
|
||||
* @param E the concrete {@link PersistentEntity} type the {@link MappingContext} implementation creates
|
||||
* @param P the concrete {@link PersistentProperty} type the {@link MappingContext} implementation creates
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
|
||||
@@ -139,6 +139,15 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
return getPersistentEntity(ClassTypeInformation.from(type));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.context.MappingContext#hasPersistentEntityFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPersistentEntityFor(Class<?> type) {
|
||||
return type == null ? false : persistentEntities.containsKey(ClassTypeInformation.from(type));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.model.MappingContext#getPersistentEntity(org.springframework.data.util.TypeInformation)
|
||||
@@ -303,6 +312,23 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mapping.context.PersistentEntityAware#getManagedTypes()
|
||||
*/
|
||||
@Override
|
||||
public Collection<TypeInformation<?>> getManagedTypes() {
|
||||
|
||||
try {
|
||||
|
||||
read.lock();
|
||||
return Collections.unmodifiableSet(new HashSet<TypeInformation<?>>(persistentEntities.keySet()));
|
||||
|
||||
} finally {
|
||||
read.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the concrete {@link PersistentEntity} instance.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,6 +50,15 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
|
||||
*/
|
||||
E getPersistentEntity(Class<?> type);
|
||||
|
||||
/**
|
||||
* Returns whether the {@link MappingContext} currently contains a {@link PersistentEntity} for the type.
|
||||
*
|
||||
* @param type can be {@literal null}.
|
||||
* @return
|
||||
* @since 1.8
|
||||
*/
|
||||
boolean hasPersistentEntityFor(Class<?> type);
|
||||
|
||||
/**
|
||||
* Returns a {@link PersistentEntity} for the given {@link TypeInformation}. Will return {@literal null} for types
|
||||
* that are considered simple ones.
|
||||
@@ -87,4 +96,12 @@ public interface MappingContext<E extends PersistentEntity<?, P>, P extends Pers
|
||||
* @return the {@link PersistentPropertyPath} representing the given property path on the given type.
|
||||
*/
|
||||
PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath, Class<?> type);
|
||||
|
||||
/**
|
||||
* Returns the {@link TypeInformation}s for all {@link PersistentEntity}s in the {@link MappingContext}.
|
||||
*
|
||||
* @return all {@link TypeInformation}s for the {@link PersistentEntity}s in the {@link MappingContext}.
|
||||
* @since 1.8
|
||||
*/
|
||||
Collection<TypeInformation<?>> getManagedTypes();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user