/** * * @param entity * entity to inspect * @param prefix * optional prefix for fieldNames (@see * {@link #getIndexedEmbeddedFields(Class)} * @param declaredFields * @return String array containing all fieldNames of the given entity which * are annotated with {@link Field} to mark them indexable. */ private List<String> getIndexedFields(Class<?> entity, Optional<String> prefix) { List<String> fieldNames = new ArrayList<>(); for (Class<?> klass = entity; klass != null; klass = klass.getSuperclass()) { for (java.lang.reflect.Field field : klass.getDeclaredFields()) { if (field.getAnnotation(Field.class) != null) { fieldNames.add(prefix.isPresent() ? prefix.get() + "." + field.getName() : field.getName()); } else if (field.getAnnotation(IndexedEmbedded.class) != null) { fieldNames.addAll(getIndexedFields(field.getType(), Optional.of((prefix.isPresent() ? prefix.get() + "." : "") + field.getName()))); } } } return fieldNames; }
@IndexedEmbedded(prefix = ALL_OBJECTS_PREFIX, includePaths = {HistoryValue.REFERENCE}) public Set<HistoryValue> getAllObjects() { Set<HistoryValue> result = Sets.newLinkedHashSet(); for (HistoryValue value : new HistoryValue[] {mainObject, object1, object2, object3, object4}) { if (value != null) { result.add(value); } } return result; }
/** * @return disease disease to which given key perf. index belongs */ @ManyToOne(fetch = FetchType.LAZY, optional=false) @JoinColumn(name = "disease_id", nullable = false) @IndexedEmbedded public Disease getDisease() { return this.disease; }
@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; }
@IndexedEmbedded(includeEmbeddedObjectId = true, targetElement = Vendor.class) @ManyToMany @JoinTable(name = "Game_Vendor") @UpdateInfo(tableName = "Game_Vendor", idInfos = { @IdInfo(entity = Game.class, columns = @IdColumn(column = "Game_ID", columnType = ColumnType.LONG)), @IdInfo(entity = Vendor.class, columns = @IdColumn(column = "vendors_ID", columnType = ColumnType.LONG)) }) public List<Vendor> getVendors() { return vendors; }
/** * @return user's name */ @Embedded @IndexedEmbedded public Name getName() { return this.name; }
@Embedded @IndexedEmbedded public Address getAddress() { return address; }
@IndexedEmbedded public List<Transaction> getTransactions() { return this.transactions; }
/** * @return the producer */ @Embedded @IndexedEmbedded public Producer getProducer() { return producer; }
@IndexedEmbedded @ManyToMany public Set<Author> getAuthors() { return authors; }
@IndexedEmbedded(depth = 3, includeEmbeddedObjectId = true) @ContainedIn @OneToMany(cascade = CascadeType.ALL, mappedBy = "place") public Set<Sorcerer> getSorcerers() { return sorcerers; }
@IndexedEmbedded public Embedded getEmbedded() { return embedded; }
@IndexedEmbedded public List<Embedded2> getEmbedded2() { return embedded2; }
/** * @return the sorcerers */ @IndexedEmbedded(includeEmbeddedObjectId = true) public Set<Sorcerer> getSorcerers() { return sorcerers; }
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); } } }