diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index d1378a5df..3e7bfaf28 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -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 + * @author Jon Brisbin * @author Oliver Gierke */ public abstract class AbstractMappingContext, P extends PersistentProperty

> @@ -139,6 +139,15 @@ public abstract class AbstractMappingContext 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> getManagedTypes() { + + try { + + read.lock(); + return Collections.unmodifiableSet(new HashSet>(persistentEntities.keySet())); + + } finally { + read.unlock(); + } + } + /** * Creates the concrete {@link PersistentEntity} instance. * diff --git a/src/main/java/org/springframework/data/mapping/context/MappingContext.java b/src/main/java/org/springframework/data/mapping/context/MappingContext.java index 0d5ea6d2c..b6277cb6f 100644 --- a/src/main/java/org/springframework/data/mapping/context/MappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/MappingContext.java @@ -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, 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, P extends Pers * @return the {@link PersistentPropertyPath} representing the given property path on the given type. */ PersistentPropertyPath

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> getManagedTypes(); } diff --git a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java index db49b59f0..75b16ca36 100644 --- a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java +++ b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 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. @@ -15,6 +15,8 @@ */ package org.springframework.data.mapping.context; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; import static org.mockito.Mockito.*; import java.beans.PropertyDescriptor; @@ -27,6 +29,7 @@ import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PropertyHandler; import org.springframework.data.mapping.model.BasicPersistentEntity; import org.springframework.data.mapping.model.SimpleTypeHolder; +import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; /** @@ -36,6 +39,35 @@ import org.springframework.data.util.TypeInformation; */ public class AbstractMappingContextIntegrationTests> { + /** + * @see DATACMNS-457 + */ + @Test + public void returnsManagedType() { + + SampleMappingContext context = new SampleMappingContext(); + context.setInitialEntitySet(Collections.singleton(Person.class)); + context.initialize(); + + assertThat(context.getManagedTypes(), hasItem(ClassTypeInformation.from(Person.class))); + } + + /** + * @see DATACMNS-457 + */ + @Test + public void indicatesManagedType() { + + SampleMappingContext context = new SampleMappingContext(); + context.setInitialEntitySet(Collections.singleton(Person.class)); + context.initialize(); + + assertThat(context.hasPersistentEntityFor(Person.class), is(true)); + } + + /** + * @see DATACMNS-65 + */ @Test public void foo() throws InterruptedException { @@ -56,7 +88,7 @@ public class AbstractMappingContextIntegrationTests() { public void doWithPersistentProperty(T persistentProperty) { try { - Thread.sleep(1000); + Thread.sleep(250); } catch (InterruptedException e) { throw new RuntimeException(e); } @@ -66,7 +98,7 @@ public class AbstractMappingContextIntegrationTests