@ContainedIn @ManyToOne(cascade = CascadeType.ALL) @JoinTable(name = "Place_Sorcerer") @UpdateInfo(tableName = "Place_Sorcerer", updateTableName = "PlaceSorcererUpdatesHsearch", updateTableIdColumn = "updateid", updateTableEventTypeColumn = "eventCase", idInfos = { @IdInfo(entity = Place.class, columns = @IdColumn(column = "Place_ID", updateTableColumn = "placefk", columnType = ColumnType.INTEGER)), @IdInfo(entity = Sorcerer.class, columns = @IdColumn(column = "Sorcerer_ID", updateTableColumn = "sorcererfk", columnType = ColumnType.INTEGER)) }) @IndexedEmbedded(includeEmbeddedObjectId = true) public Place getPlace() { return place; }
private void parse(EntityType<?> curEntType, Class<?> cameFrom, Set<EntityType<?>> visited) { // just to make sure we don't handle an entity twice: if ( visited.contains( curEntType ) ) { return; } Map<Class<? extends Annotation>, Set<Attribute<?, ?>>> attributeForAnnotationType = buildAttributeForAnnotationType( curEntType ); Function<Object, Object> toRoot; // first of all, lets build the parentAccessor for this entity if ( visited.size() > 0 ) { // don't do this for the first entity Set<Attribute<?, ?>> cameFromAttributes = attributeForAnnotationType.getOrDefault( ContainedIn.class, new HashSet<>() ).stream() .filter( (attribute) -> { Class<?> entityTypeClass = getEntityTypeClass( attribute ); return entityTypeClass.equals( cameFrom ); } ).collect( Collectors.toSet() ); if ( cameFromAttributes.size() != 1 ) { throw new IllegalArgumentException( "entity: " + curEntType.getJavaType() + " has not exactly 1 @ContainedIn for each Index-parent specified" ); } Attribute<?, ?> toParentAttribute = cameFromAttributes.iterator().next(); toRoot = (object) -> { Object parentOfThis = member( toParentAttribute.getJavaMember(), object ); return parentOfThis; }; } // and do the recursion this.doRecursion( attributeForAnnotationType, curEntType, visited ); }
@IndexedEmbedded(depth = 3, includeEmbeddedObjectId = true) @ContainedIn @OneToMany(cascade = CascadeType.ALL, mappedBy = "place") public Set<Sorcerer> getSorcerers() { return sorcerers; }
@ContainedIn public TopLevel getTopLevel() { return this.topLevel; }
@ContainedIn public Embedded getEmbedded() { return embedded; }
@ManyToMany(targetEntity = Game.class) @ContainedIn public List<Game> getGames() { return games; }
/** * @return the place */ @ContainedIn public Place getPlace() { return place; }
void register(final Class< ? extends BaseDO< ? >> clazz) { final Field[] fields = clazz.getDeclaredFields(); for (final Field field : fields) { if (field.isAnnotationPresent(IndexedEmbedded.class) == true || field.isAnnotationPresent(ContainedIn.class) == true) { Class< ? > embeddedClass = field.getType(); boolean setOrCollection = false; if (Set.class.isAssignableFrom(embeddedClass) == true || Collection.class.isAssignableFrom(embeddedClass) == true) { // Please use @ContainedIn. final Type type = field.getGenericType(); if (type instanceof ParameterizedType) { final Type actualTypeArgument = ((ParameterizedType) type).getActualTypeArguments()[0]; if (actualTypeArgument instanceof Class) { embeddedClass = (Class< ? >) actualTypeArgument; setOrCollection = true; } } } if (BaseDO.class.isAssignableFrom(embeddedClass) == false) { // Only BaseDO objects are supported. continue; } final String name = field.getName(); final Entry entry = new Entry(clazz, name, setOrCollection); List<Entry> list = map.get(embeddedClass); if (list == null) { list = new ArrayList<Entry>(); @SuppressWarnings("unchecked") final Class< ? extends BaseDO< ? >> embeddedBaseDOClass = (Class< ? extends BaseDO< ? >>) embeddedClass; map.put(embeddedBaseDOClass, list); } else { for (final Entry e : list) { if (entry.equals(e) == true) { log.warn("Entry already registerd: " + entry); } } } list.add(entry); } } }