13.07.2015 Views

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

please define productname in your docbook file!• If a parameter is annotated with the @Value annotation, the given expression is evaluated and theresult is used as the parameter value.• If the Java type has a property whose name matches the given field of the input document, then it'sproperty information is used to select the appropriate constructor parameter to pass the input fieldvalue to. This works only if the parameter name information is present in the java .class files whichcan be achieved by compiling the source with debug information or using the new -parameterscommand-line switch for javac in Java 8.• Otherwise an MappingException will be thrown indicating that the given constructor parametercould not be bound.class OrderItem {@Id String id;int quantity;double unitPrice;OrderItem(String id, @Value("#root.qty ?: 0") int quantity, double unitPrice) {this.id = id;this.quantity = quantity;this.unitPrice = unitPrice;}}// getters/setters ommittedDBObject input = new BasicDBObject("id", "4711");input.put("unitPrice", 2.5);input.put("qty",5);OrderItem item = converter.read(OrderItem.class, input);NoteThe SpEL expression in the @Value annotation of the quantity parameter falls back to thevalue 0 if the given property path cannot be resolved.Additional examples for using the @PersistenceConstructor annotation can be found in theMappingMongoConverterUnitTests test suite.Compound IndexesCompound indexes are also supported. They are defined at the class level, rather than on indidvidualproperties.NoteCompound indexes are very important to improve the performance of queries that involve criteriaon multiple fieldsHere's an example that creates a compound index of lastName in ascending order and age indescending order:1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 84

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!