private DefaultArangoTypeMapper(final String typeKey, final ArangoTypeAliasAccessor accessor, final MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext, final List<? extends TypeInformationMapper> additionalMappers) { Assert.notNull(accessor, "Accessor must not be null!"); Assert.notNull(additionalMappers, "AdditionalMappers must not be null!"); final List<TypeInformationMapper> mappers = new ArrayList<>(additionalMappers.size() + 1); if (mappingContext != null) { mappers.add(new MappingContextTypeInformationMapper(mappingContext)); } mappers.addAll(additionalMappers); this.mappers = Collections.unmodifiableList(mappers); this.accessor = accessor; this.typeCache = new ConcurrentHashMap<>(16, 0.75f, 4); this.typeKey = typeKey; }
/** * Creates a {@link MappingContextTypeInformationMapper} from the given {@link MappingContext}. Inspects all * {@link PersistentEntity} instances for alias information and builds a {@link Map} of aliases to types from it. * * @param mappingContext must not be {@literal null}. */ public MappingContextTypeInformationMapper(MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext) { Assert.notNull(mappingContext, "MappingContext must not be null!"); this.typeMap = new ConcurrentHashMap<>(); this.mappingContext = mappingContext; for (PersistentEntity<?, ?> entity : mappingContext.getPersistentEntities()) { verify(entity.getTypeInformation().getRawTypeInformation(), entity.getTypeAlias()); } }
public Object createAliasFor(TypeInformation<?> type) { Object key = typeMap.get(type); if (key != null) { return key; } PersistentEntity<?, ?> entity = mappingContext.getPersistentEntity(type); if (entity == null) { return null; } Object alias = entity.getTypeAlias(); safelyAddToCache(type, alias); return alias; }
public Alias createAliasFor(TypeInformation<?> type) { return typeMap.computeIfAbsent(type.getRawTypeInformation(), key -> { PersistentEntity<?, ?> entity = mappingContext.getPersistentEntity(key); if (entity == null || entity.getTypeAlias() == null) { return Alias.NONE; } return verify(key, entity.getTypeAlias()); }); }
/** * Creates a {@link MappingContextTypeInformationMapper} from the given {@link MappingContext}. Inspects all * {@link PersistentEntity} instances for alias information and builds a {@link Map} of aliases to types from it. * * @param mappingContext must not be {@literal null}. */ public MappingContextTypeInformationMapper(MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext) { Assert.notNull(mappingContext); this.typeMap = new HashMap<TypeInformation<?>, Object>(); this.mappingContext = mappingContext; for (PersistentEntity<?, ?> entity : mappingContext.getPersistentEntities()) { safelyAddToCache(entity.getTypeInformation(), entity.getTypeAlias()); } }
private DefaultArangoTypeMapper(final String typeKey, final ArangoTypeAliasAccessor accessor, final MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext, final List<? extends TypeInformationMapper> additionalMappers) { Assert.notNull(accessor, "Accessor must not be null!"); Assert.notNull(additionalMappers, "AdditionalMappers must not be null!"); final List<TypeInformationMapper> mappers = new ArrayList<>(additionalMappers.size() + 1); if (mappingContext != null) { mappers.add(new MappingContextTypeInformationMapper(mappingContext)); } mappers.addAll(additionalMappers); this.mappers = Collections.unmodifiableList(mappers); this.accessor = accessor; this.typeCache = new ConcurrentHashMap<>(16, 0.75f, 4); this.typeKey = typeKey; }
/** * Creates a new {@link DefaultTypeMapper} using the given {@link TypeAliasAccessor}, {@link MappingContext} and * additional {@link TypeInformationMapper}s. Will register a {@link MappingContextTypeInformationMapper} before the * given additional mappers. * * @param accessor must not be {@literal null}. * @param mappingContext * @param additionalMappers must not be {@literal null}. */ public DefaultTypeMapper(TypeAliasAccessor<S> accessor, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext, List<? extends TypeInformationMapper> additionalMappers) { Assert.notNull(accessor); Assert.notNull(additionalMappers); List<TypeInformationMapper> mappers = new ArrayList<TypeInformationMapper>(additionalMappers.size() + 1); if (mappingContext != null) { mappers.add(new MappingContextTypeInformationMapper(mappingContext)); } mappers.addAll(additionalMappers); this.mappers = Collections.unmodifiableList(mappers); this.accessor = accessor; }
mappers.add(new MappingContextTypeInformationMapper(mappingContext));