/** * @author neo */ @Data @AllArgsConstructor @NoArgsConstructor @Document(collection = "first_mongo") public class PrimaryMongoObject { @Id private String id; private String value; @Override public String toString() { return "PrimaryMongoObject{" + "id='" + id + '\'' + ", value='" + value + '\'' + '}'; } }
/** * Creates a new {@link BasicMongoPersistentEntity} with the given {@link TypeInformation}. Will default the * collection name to the entities simple type name. * * @param typeInformation must not be {@literal null}. */ public BasicMongoPersistentEntity(TypeInformation<T> typeInformation) { super(typeInformation, MongoPersistentPropertyComparator.INSTANCE); Class<?> rawType = typeInformation.getType(); String fallback = MongoCollectionUtils.getPreferredCollectionName(rawType); if (this.isAnnotationPresent(Document.class)) { Document document = this.getRequiredAnnotation(Document.class); this.collection = StringUtils.hasText(document.collection()) ? document.collection() : fallback; this.language = StringUtils.hasText(document.language()) ? document.language() : ""; this.expression = detectExpression(document); } else { this.collection = fallback; this.language = ""; this.expression = null; } }
/** * An entity to represent a customer. * * @author Oliver Gierke */ @Data @Document public class Customer { private String id, firstname, lastname; private Address address; /** * Creates a new {@link Customer} with the given firstname and lastname. * * @param firstname must not be {@literal null} or empty. * @param lastname must not be {@literal null} or empty. */ public Customer(String firstname, String lastname) { Assert.hasText(firstname, "Firstname must not be null or empty!"); Assert.hasText(lastname, "Lastname must not be null or empty!"); this.firstname = firstname; this.lastname = lastname; } }
/** * Sample user class. * * @author Mark Paluch * @author Oliver Gierke */ @Getter @RequiredArgsConstructor @Document(collection = "contacts") public class Person extends Contact { private final String firstname, lastname; private final Integer age; }
/** * Returns a SpEL {@link Expression} frór the collection String expressed in the given {@link Document} annotation if * present or {@literal null} otherwise. Will also return {@literal null} it the collection {@link String} evaluates * to a {@link LiteralExpression} (indicating that no subsequent evaluation is necessary). * * @param document can be {@literal null} * @return */ @Nullable private static Expression detectExpression(Document document) { String collection = document.collection(); if (!StringUtils.hasText(collection)) { return null; } Expression expression = PARSER.parseExpression(document.collection(), ParserContext.TEMPLATE_EXPRESSION); return expression instanceof LiteralExpression ? null : expression; }
/** * @author Christoph Strobl */ @Data @Document(collection = "starbucks") public class Store { String id; String name; String street; String city; /** * {@code location} is stored in GeoJSON format. * * <pre> * <code> * { * "type" : "Point", * "coordinates" : [ x, y ] * } * </code> * </pre> */ GeoJsonPoint location; }
/** * Sample contact class. * * @author Mark Paluch * @author Oliver Gierke */ @Getter @RequiredArgsConstructor @Document(collection = "contacts") public class Relative extends Contact { private final String firstname, lastname; private final Integer age; }
/** * Returns a SpEL {@link Expression} frór the collection String expressed in the given {@link Document} annotation if * present or {@literal null} otherwise. Will also return {@literal null} it the collection {@link String} evaluates * to a {@link LiteralExpression} (indicating that no subsequent evaluation is necessary). * * @param document can be {@literal null} * @return */ @Nullable private static Expression detectExpression(Document document) { String collection = document.collection(); if (!StringUtils.hasText(collection)) { return null; } Expression expression = PARSER.parseExpression(document.collection(), ParserContext.TEMPLATE_EXPRESSION); return expression instanceof LiteralExpression ? null : expression; }
/** * @author Oliver Gierke */ @Document(collection = "contacts") @EqualsAndHashCode @ToString public abstract class Contact { private @Getter ObjectId id; }
/** * Creates a new {@link BasicMongoPersistentEntity} with the given {@link TypeInformation}. Will default the * collection name to the entities simple type name. * * @param typeInformation must not be {@literal null}. */ public BasicMongoPersistentEntity(TypeInformation<T> typeInformation) { super(typeInformation, MongoPersistentPropertyComparator.INSTANCE); Class<?> rawType = typeInformation.getType(); String fallback = MongoCollectionUtils.getPreferredCollectionName(rawType); if (this.isAnnotationPresent(Document.class)) { Document document = this.getRequiredAnnotation(Document.class); this.collection = StringUtils.hasText(document.collection()) ? document.collection() : fallback; this.language = StringUtils.hasText(document.language()) ? document.language() : ""; this.expression = detectExpression(document); } else { this.collection = fallback; this.language = ""; this.expression = null; } }
/** * @author neo */ @Data @AllArgsConstructor @NoArgsConstructor @Document(collection = "second_mongo") public class SecondaryMongoObject { @Id private String id; private String value; @Override public String toString() { return "SecondaryMongoObject{" + "id='" + id + '\'' + ", value='" + value + '\'' + '}'; } }
@Document public class OrderEvent extends BaseEntity implements Serializable {