package org.springframework.data.jdbc.mapping;

import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.springframework.data.jdbc.repository.support.JdbcEntityInformation;
import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;

public class JdbcMappingContext extends
		AbstractMappingContext<JdbcPersistentEntityImpl<?>, JdbcPersistentProperty> {

	/**
	 * root entity 정보를 관리한다.
	 */
	Map<Class<?>, JdbcEntityInformation<?, Serializable>> map = new HashMap<Class<?>, JdbcEntityInformation<?, Serializable>>();
	
	Set<Class<?>> entitySet;
	
	public JdbcMappingContext(Set<Class<?>> initialEntitySet) {
		this.entitySet = initialEntitySet;
	}

	@Override
	protected <T> JdbcPersistentEntityImpl<?> createPersistentEntity(TypeInformation<T> typeInformation) {
		
		JdbcPersistentEntityImpl<T> jdbcPersistentEntityImpl = new JdbcPersistentEntityImpl<T>(typeInformation);
		return jdbcPersistentEntityImpl;
	}

	@Override
	protected JdbcPersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
			JdbcPersistentEntityImpl<?> owner, SimpleTypeHolder simpleTypeHolder) {
		
		JdbcPersistentPropertyImpl jdbcPersistentPropertyImpl = new JdbcPersistentPropertyImpl(field, descriptor, owner, simpleTypeHolder);
		return jdbcPersistentPropertyImpl;
	}

	public void addEntityInformation(Class<?> domainClass, JdbcEntityInformation<?, Serializable> information) {
		Assert.notNull(domainClass);
		Assert.notNull(information);
		map.put(domainClass, information);
	}
	
	public JdbcEntityInformation<?, Serializable> getEntityInformation(Class<?> domainClass) {
		Assert.notNull(domainClass);
		
		if (map.containsKey(domainClass)) {
			return map.get(domainClass);
		}
		
		throw new IllegalArgumentException(domainClass + " is not support.");
	}
}

@@ -198,31 +198,8 @@
 ap;%0D
-%0Aimport java.util.Set;%0D
 %0A%0D%0Ai
@@ -677,16 +677,24 @@
 %0A%09 */%0D%0A%09
+private 
 Map%3CClas
@@ -818,144 +818,8 @@
 %0A%09%0D%0A
-%09Set%3CClass%3C?%3E%3E entitySet;%0D%0A%09%0D%0A%09public JdbcMappingContext(Set%3CClass%3C?%3E%3E initialEntitySet) %7B%0D%0A%09%09this.entitySet = initialEntitySet;%0D%0A%09%7D%0D%0A%0D%0A
 %09@Ov
@@ -927,28 +927,24 @@
 rmation) %7B%0D%0A
-%09%09%0D%0A
 %09%09JdbcPersis
@@ -1273,20 +1273,16 @@
 der) %7B%0D%0A
-%09%09%0D%0A
 %09%09JdbcPe

remove Set attribute