|
25 | 25 |
|
26 | 26 | import java.io.Serializable; |
27 | 27 |
|
28 | | -/** PojoRepository is the central class for the Pojo Facade. It supports CRUD operations |
| 28 | +/** <p>PojoRepository is the central class for the Pojo Facade. It supports CRUD operations |
29 | 29 | * and search. Each PojoRepository instance operates on only one pojo class. Create new |
30 | | - * PojoRepository instances based on your custom pojo type like so: |
| 30 | + * PojoRepository instances based on your custom pojo type like so:</p> |
| 31 | + * |
31 | 32 | * <pre> public class MyClass { |
32 | | - * {@literal @}Id |
| 33 | + * {@literal @}Id |
33 | 34 | * public Integer getMyId() { |
34 | 35 | * ... |
35 | 36 | * } |
|
43 | 44 | * PojoRepository<MyClass, Integer> myClassRepo = |
44 | 45 | * client.newPojoRepository(MyClass.class, Integer.class);</pre> |
45 | 46 | * |
46 | | - * Where MyClass is your custom pojo type, and myId is the bean property of type Integer |
| 47 | + * <p>Where MyClass is your custom pojo type, and myId is the bean property of type Integer |
47 | 48 | * marked with the |
48 | 49 | * {@literal @}{@link Id Id annotation}. The |
49 | 50 | * {@literal @}Id annotation can be attached to a public field or a public getter or a |
50 | 51 | * public setter. The bean property marked with {@literal @}Id must be a native type or |
51 | 52 | * {@link java.io.Serializable} class and must contain an |
52 | 53 | * identifier value unique across all persisted instances of that |
53 | | - * type or the instance will overwrite the persisted instance with the same identifier. |
| 54 | + * type or the instance will overwrite the persisted instance with the same identifier.</p> |
| 55 | + * |
| 56 | + * <p>The current implementation of the Pojo Facade uses |
| 57 | + * <a href="https://github.com/FasterXML/jackson-databind/">Jackson databind</a> |
| 58 | + * for serialization and deserialization to and from json. Thus only classes which |
| 59 | + * can be serialized and deserialized directly by Jackson can be serialized by the |
| 60 | + * Pojo Facade. Every bean property including the one marked with {@literal @}Id |
| 61 | + * must either expose a public field or both a public getter and a public |
| 62 | + * setter. To test if your class can be directly serialized and deserialized |
| 63 | + * by Jackson, perform the following:</p> |
54 | 64 | * |
55 | | - * The current implementation of the Pojo Facade uses |
56 | | - * <a href="https://github.com/FasterXML/jackson-databind/">Jackson databind</a> for serialization |
57 | | - * and deserialization to json. Thus only classes which can be serialized and deserialized |
58 | | - * directly by Jackson can be serialized by the Pojo Facade. Every bean property |
59 | | - * including the one marked with {@literal @}Id must either expose a public field or both a public |
60 | | - * getter and a public setter. To test if your class can be directly serialized and |
61 | | - * deserialized by Jackson, perform the following: |
62 | 65 | * <pre> ObjectMapper objectMapper = new ObjectMapper(); |
63 | 66 | * String value = objectMapper.writeValueAsString(myObjectIn); |
64 | 67 | * MyClass myObjectOut = objectMapper.readValue(value, MyClass.class);</pre> |
65 | 68 | * |
66 | | - * If that works but the configured objectMapper in the Pojo Facade is different and not |
67 | | - * working, you can troubleshoot by directly accessing the objectMapper used by the Pojo |
68 | | - * Facade using an unsupported internal method attached to the current implementation: |
69 | | - * <a |
| 69 | + * <p>If that works but the configured objectMapper in the Pojo Facade is different and not |
| 70 | + * working, you can troubleshoot by directly accessing the objectMapper used by the Pojo |
| 71 | + * Facade using an unsupported internal method attached to the current implementation: |
| 72 | + * <a |
70 | 73 | * href="https://github.com/marklogic/java-client-api/blob/master/src/main/java/com/marklogic/client/impl/PojoRepositoryImpl.java" |
71 | | - * >com.marklogic.client.impl.PojoRepositoryImpl</a>. |
| 74 | + * >com.marklogic.client.impl.PojoRepositoryImpl</a>.</p> |
| 75 | + * |
72 | 76 | * <pre> ObjectMapper objectMapper = ((PojoRepositoryImpl) myClassRepo).getObjectMapper();</pre> |
73 | 77 | * |
74 | | - * If your class has properties which are classes (non-native types) they will be automatically |
75 | | - * serialized and deserialized, but cannot be written, read, or searched directly. If you |
76 | | - * wish to directly write, read, or search another class, create a new instance of |
77 | | - * PojoRepository specific to that class. |
| 78 | + * <p>Special handling is provided for bean properties of type |
| 79 | + * {@link java.util.Date Date} and {@link java.util.Calendar Calendar}. The |
| 80 | + * current implementation of Jackson ObjectMapper changes the timezone to UTC. |
| 81 | + * The serialized format is ISO 8601 format which is compatible with |
| 82 | + * xs:dateTime format and can therefore be indexed in the server by a path |
| 83 | + * range index of type dateTime. However, if you wish to query using a range |
| 84 | + * index, it is recommended that you modify serialization to remove the class |
| 85 | + * wrapper by adding a JsonTypeInfo annotation like so:</p> |
| 86 | + * |
| 87 | + * <pre> {@literal @}JsonTypeInfo(use=JsonTypeInfo.Id.NONE, include=JsonTypeInfo.As.EXTERNAL_PROPERTY) |
| 88 | + * public Calendar getMyDateTime();</pre> |
| 89 | + * |
| 90 | + * <p>That way you can query the field directly without needing to traverse the |
| 91 | + * java.util.GregorianCalendar type wrapper. By removing that wrapper, you can |
| 92 | + * create a query like this:</p> |
| 93 | + * |
| 94 | + * <pre> PojoQueryBuilder qb = pojoRepository.getQueryBuilder(); |
| 95 | + * PojoQueryDefinition query = qb.range("myDateTime", Operator.LT, Calendar.getInstance());</pre> |
| 96 | + * |
| 97 | + * <p>If your class has properties which are classes (non-native types) they |
| 98 | + * will be automatically serialized and deserialized, but can only be written, |
| 99 | + * read, or searched as properties of the parent instance. If you wish to |
| 100 | + * directly write, read, or search instances of another class, create and use |
| 101 | + * an instance of PojoRepository specific to that class.</p> |
78 | 102 | * |
79 | | - * Since PojoRepository stores in JSON format, which limits number precision to 15 |
80 | | - * significant digits (IEEE754 double precision), you will lose precision on numbers |
81 | | - * longer than 15 significant digits. If you desire larger numbers with no loss of |
82 | | - * precision, use Strings to persist those numbers. |
| 103 | + * <p>Since PojoRepository stores in JSON format, which limits number precision |
| 104 | + * to 15 significant digits (IEEE754 double precision), you will lose precision |
| 105 | + * on numbers longer than 15 significant digits. If you desire larger numbers |
| 106 | + * with no loss of precision, use Strings to persist those numbers.</p> |
83 | 107 | */ |
84 | 108 | public interface PojoRepository<T, ID extends Serializable> { |
85 | | - /** Get the value of the id field (the field marked with the {@literal @}Id |
| 109 | + /** Get the value of the id field (the field marked with the {@literal @}Id |
86 | 110 | * annotation). |
| 111 | + * |
| 112 | + * @param entity the entity instance from which you want to get the id value |
| 113 | + * |
| 114 | + * @return the id value for this entity of type ID |
87 | 115 | */ |
88 | 116 | public ID getId(T entity); |
89 | 117 |
|
|
0 commit comments