@DBRef private Product product; private BigDecimal price;
/** * Returns whether the property shall be resolved lazily. * * @param property must not be {@literal null}. * @return */ private boolean isLazyDbRef(MongoPersistentProperty property) { return property.getDBRef() != null && property.getDBRef().lazy(); }
/** * Creates a {@link DBRef} instance for the given {@link org.springframework.data.mongodb.core.mapping.DBRef} * annotation, {@link MongoPersistentEntity} and id. * * @param annotation will never be {@literal null}. * @param entity will never be {@literal null}. * @param id will never be {@literal null}. * @return */ default DBRef createDbRef(@Nullable org.springframework.data.mongodb.core.mapping.DBRef annotation, MongoPersistentEntity<?> entity, Object id) { if (annotation != null && StringUtils.hasText(annotation.db())) { return new DBRef(annotation.db(), entity.getCollection(), id); } return new DBRef(entity.getCollection(), id); }
public class Order extends AbstractDocument { @DBRef private Customer customer; private Address billingAddress;
private static void potentiallyAssertDBRefTargetType(MongoPersistentProperty persistentProperty) { if (persistentProperty.isDbReference() && persistentProperty.getDBRef().lazy()) { if (persistentProperty.isArray() || Modifier.isFinal(persistentProperty.getActualType().getModifiers())) { throw new MappingException(String.format( "Invalid lazy DBRef property for %s. Found %s which must not be an array nor a final class.", persistentProperty.getField(), persistentProperty.getActualType())); } } }
/** * Creates a {@link DBRef} instance for the given {@link org.springframework.data.mongodb.core.mapping.DBRef} * annotation, {@link MongoPersistentEntity} and id. * * @param annotation will never be {@literal null}. * @param entity will never be {@literal null}. * @param id will never be {@literal null}. * @return */ default DBRef createDbRef(@Nullable org.springframework.data.mongodb.core.mapping.DBRef annotation, MongoPersistentEntity<?> entity, Object id) { if (annotation != null && StringUtils.hasText(annotation.db())) { return new DBRef(annotation.db(), entity.getCollection(), id); } return new DBRef(entity.getCollection(), id); }
private String owner; private String lineOfBusiness; @DBRef private List<Component> components = new ArrayList<>();
@Nullable @SuppressWarnings("unchecked") public <T> T getPropertyValue(MongoPersistentProperty property) { if (property.isDbReference() && property.getDBRef().lazy()) { Object rawRefValue = accessor.get(property); if (rawRefValue == null) { return null; } DbRefResolverCallback callback = new DefaultDbRefResolverCallback(accessor.getDocument(), path, evaluator, MappingMongoConverter.this); DBRef dbref = rawRefValue instanceof DBRef ? (DBRef) rawRefValue : null; return (T) dbRefResolver.resolveDbRef(property, dbref, callback, dbRefProxyHandler); } return super.getPropertyValue(property); } }
private String id; @DBRef(lazy = true) private User user;
/** * Returns whether the property shall be resolved lazily. * * @param property must not be {@literal null}. * @return */ private boolean isLazyDbRef(MongoPersistentProperty property) { return property.getDBRef() != null && property.getDBRef().lazy(); }
/** * A convenience class for a StatefulDocument. This Class ensures read-only behavior for the State * field * * @author Andrew Hall * */ public abstract class StatefulDocument { /** * State field is managed by StatefulJ. * */ @State @DBRef private StateDocument state; public StateDocument getStateDocument() { return state; } }
private static void potentiallyAssertDBRefTargetType(MongoPersistentProperty persistentProperty) { if (persistentProperty.isDbReference() && persistentProperty.getDBRef().lazy()) { if (persistentProperty.isArray() || Modifier.isFinal(persistentProperty.getActualType().getModifiers())) { throw new MappingException(String.format( "Invalid lazy DBRef property for %s. Found %s which must not be an array nor a final class.", persistentProperty.getField(), persistentProperty.getActualType())); } } }
@DBRef private User author;
@Nullable @SuppressWarnings("unchecked") public <T> T getPropertyValue(MongoPersistentProperty property) { if (property.isDbReference() && property.getDBRef().lazy()) { Object rawRefValue = accessor.get(property); if (rawRefValue == null) { return null; } DbRefResolverCallback callback = new DefaultDbRefResolverCallback(accessor.getDocument(), path, evaluator, MappingMongoConverter.this); DBRef dbref = rawRefValue instanceof DBRef ? (DBRef) rawRefValue : null; return (T) dbRefResolver.resolveDbRef(property, dbref, callback, dbRefProxyHandler); } return super.getPropertyValue(property); } }
private int socialSecurityNumber; @DBRef private List<Account> accounts;
/** * Returns whether the property shall be resolved lazily. * * @param property must not be {@literal null}. * @return */ private boolean isLazyDbRef(MongoPersistentProperty property) { return property.getDBRef() != null && property.getDBRef().lazy(); }