The fields of a schema define the allowed content for the properties of the documents having this schema.
Field Types
A standard set of XSD types are allowed in Nuxeo schemas, and are mapped to Java and storage types as follows:
XSD Type | Java Type |
---|---|
xsd:string | String |
xsd:normalizedString | String |
xsd:long | Long |
xsd:unsignedLong | Long |
xsd:integer | Long |
xsd:int | Long |
xsd:unsignedInt | Long |
xsd:positiveInteger | Long |
xsd:nonPositiveInteger | Long |
xsd:nonNegativeInteger | Long |
xsd:short | Long |
xsd:unsignedShort | Long |
xsd:double | Double |
xsd:float | Double |
xsd:decimal | Double |
xsd:datetime | Calendar |
xsd:date | Calendar |
xsd:time | Calendar |
xsd:boolean | Boolean |
Delta Updates
Since Nuxeo Platform 6.0 (NXP-15103) a new update model for Long
properties is available using DeltaLong
.
A DeltaLong
is stored as a Long
, but when used in the Java API to update a field (DocumentModel.setPropertyValue()
) it specifies that the update should be done as an increment at the storage level rather than as a replacement of the old value. This allows for concurrent updates that don't lose value.
The standard usage to add a value "count" to a property "myprop" is:
long count = 123;
Number oldValue = (Number) doc.getPropertyValue("myprop");
Number newValue = DeltaLong.deltaOrLong(oldValue, count);
doc.setPropertyValue("myprop", newValue);
DeltaLong.deltaOrLong(oldValue, count)
should be used in preference over new DeltaLong(oldValue, count)
because it can deal with the case where the old value is null
or already a DeltaLong
(the latter can happen if you're re-updating a property which hasn't been saved yet).
When using a SQL backend, this will emit code like:
UPDATE myschema SET myprop = myprop + 123 WHERE id = 'the-doc-id';
instead of:
UPDATE myschema SET myprop = 123 WHERE id = 'the-doc-id';
which you'll agree gives different results if two threads are executing it at the same time.
For a MongoDB backend, the update will be done using:
db.default.update(
{ "ecm:id": "the-doc-id" },
{ $inc: { "myprop": 123 } }
)
instead of :
db.default.update(
{ "ecm:id": "the-doc-id" },
{ "myprop": 123 }
)