Switch MongoDB samples to records.

See #606.
This commit is contained in:
Mark Paluch
2021-04-28 15:18:59 +02:00
parent b44dc3dea1
commit e565f33872
69 changed files with 395 additions and 555 deletions

View File

@@ -15,10 +15,6 @@
*/
package example.springdata.mongodb.schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.lang.Nullable;
@@ -26,14 +22,7 @@ import org.springframework.lang.Nullable;
/**
* @author Christoph Strobl
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document("star-wars")
class Jedi {
record Jedi(@Id String id, @Nullable String name, @Nullable String lastname, @Nullable Integer age) {
@Id String id;
@Nullable String name;
@Nullable String lastname;
@Nullable Integer age;
}

View File

@@ -74,7 +74,7 @@ public class DocumentValidation {
@Test
public void criteriaValidator() {
Validator validator = Validator.criteria( //
var validator = Validator.criteria( //
where("name").exists(true).ne(null).type(2) // non null String
.and("age").exists(true).ne(null).type(16).gte(0).lte(125)) // non null int between 0 and 125
;
@@ -116,7 +116,7 @@ public class DocumentValidation {
@Test
public void schemaValidator() {
Validator validator = Validator.schema(MongoJsonSchema.builder() //
var validator = Validator.schema(MongoJsonSchema.builder() //
.required("name", "age") //
.properties( //
string("name").minLength(1), //

View File

@@ -75,13 +75,13 @@ public class SchemaQuery {
@Test
public void criteriaValidator() {
Jedi luke = new Jedi("luke", "luke", "skywalker", 25);
Jedi yoda = new Jedi("yoda", "yoda", null, 900);
var luke = new Jedi("luke", "luke", "skywalker", 25);
var yoda = new Jedi("yoda", "yoda", null, 900);
mongoOps.save(luke);
mongoOps.save(yoda);
MongoJsonSchema schema = MongoJsonSchema.builder() //
var schema = MongoJsonSchema.builder() //
.required("name", "age") //
.properties( //
string("name").minLength(1), //