Movatterモバイル変換


[0]ホーム

URL:


7.1.5 Adding and Writing Properties

To add new properties or change the values of existing properties of a node we use thesetProperty methods ofNode:

javax.jcr.
Node

Property

setProperty(String name,
Value value)

Sets the specified (single value) property of this node to the specifiedvalue. If the property does not yet exist, it is created. The property type of the property will be that specified by the node type of this node.

If the property type of the suppliedValue object is different from that required, then a best-effort conversion is attempted. If the conversion fails, aValueFormatException is thrown. If another error occurs, aRepositoryException is thrown.

If the node type of this node does not indicate a specific property type, then the property type of the suppliedValue object is used and if the property already exists (has previously been set) it assumes both the new value and new property type.

If the property is multi-valued, aValueFormatException is thrown.

Passing anull as the second parameter removes the property. It is equivalent to callingremove on theProperty object itself. For example,N.setProperty("P", (Value)null) would remove property called"P" of the node inN.

To save the addition or removal of a property, asave call must be performed that includes the parent of the property in its scope: that is, asave on either the session, this node, or an ancestor of this node. To save a change to an existing property, asave call that includes that property in its scope is required. This means that in addition to the above-mentionedsave options, asave on the changed property itself will also work.

AConstraintViolationException will be thrown either immediately (by this method), or onsave, if the change would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

AVersionException will be thrown either immediately (by this method), or onsave, ifthis node is versionable and checked-in or is non-versionable but its nearest versionable ancestor is checked-in. Implementations may differ on when this validation is performed.

ALockException will be thrown either immediately (by this method), or onsave, if a lock prevents the setting of the property. Implementations may differ on when this validation is performed.

ARepositoryException is thrown if another error occurs.

Property

setProperty(String name, Value[] values)

Sets the specified (multi-value) property to the specified array of values. If the property does not yet exist, it is created. Same as

setProperty(String name, Value value)

except that an array ofValue objects is assigned instead of a singleValue.

The property type of the property will be that specified by the node type of this node. If the property type of the suppliedValue objects is different from that required, then a best-effort conversion is attempted. If the conversion fails, aValueFormatException is thrown. AllValue objects in the array must be of the same type, otherwise aValueFormatException is thrown. If the property is not multi-valued then aValueFormatException is also thrown. If another error occurs, aRepositoryException is thrown.

If the node type of this node does not indicate a specific property type, then the property type of the suppliedValue objects is used and if the property already exists it assumes both the new values and the new property type.

Passing anull as the second parameter removes the property. It is equivalent to calling remove on theProperty object itself. For example,N.setProperty("P", (Value[])null) would remove property called"P" of the node inN.

Note that this is different from passing an array that containsnull elements. In such a case, the array is compacted by removing thenulls. The resulting set of values of the property never containsnulls. However, the set may be empty:N.setProperty("P", new Value[]{null}) would set the property to the empty set of values.

To save the addition or removal of a property, asave call must be performed that includes the parent of the property in its scope: that is, asave on either the session, this node, or an ancestor of this node. To save a change to an existing property, asave call that includes that property in its scope is required. This means that in addition to the above-mentionedsave options, asave on the changed property itself will also work.

AConstraintViolationException will be thrown either immediately (by this method), or onsave, if the change would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

AVersionException will be thrown either immediately (by this method), or onsave, ifthis node is versionable and checked-in or is non-versionable but its nearest versionable ancestor is checked-in. Implementations may differ on when this validation is performed.

ALockException will be thrown either immediately (by this method), or onsave, if a lock prevents the setting of the property. Implementations may differ on when this validation is performed.

ARepositoryException is thrown if another error occurs.

Property

setProperty(String name,
Value[] values,
int type)

Sets the specified (multi-value) property to the specified array of values. If the property does not yet exist, it is created. The type of the property is determined by thetype parameter specified.

If the property type of the suppliedValue objects is different from that specified, then a best-effort conversion is attempted. If the conversion fails, aValueFormatException is thrown.

If the property already exists it assumes both the new values and the new property type.

AllValue objects in the array must be of the same type, otherwise aValueFormatException is thrown. If the property is not multi-valued then aValueFormatException is also thrown. If another error occurs, aRepositoryException is thrown.

Passing anull as the second parameter removes the property. It is equivalent to calling remove on theProperty object itself. For example,N.setProperty("P", (Value[])null, type) would remove property called"P" of the node inN.

Note that this is different from passing an array that containsnull elements. In such a case, the array is compacted by removing thenulls. The resulting set of values of the property never containsnulls. However, the set may be empty:N.setProperty("P", new Value[]{null}, type) would set the property to the empty set of values.

To save the addition or removal of a property, asave call must be performed that includes the parent of the property in its scope: that is, asave on either the session, this node, or an ancestor of this node. To save a change to an existing property, asave call that includes that property in its scope is required. This means that in addition to the above-mentionedsave options, asave on the changed property itself will also work.

AConstraintViolationException will be thrown either immediately (by this method), or onsave, if the change would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

AVersionException will be thrown either immediately (by this method), or onsave, ifthis node is versionable and checked-in or is non-versionable but its nearest versionable ancestor is checked-in. Implementations may differ on when this validation is performed.

ALockException will be thrown either immediately (by this method), or onsave, if a lock prevents the setting of the property. Implementations may differ on when this validation is performed.

ARepositoryException is thrown if another error occurs.

Property

setProperty(String name, String[] values)

Sets the specified property to the specified array of values. Same as

setProperty(String name, Value[] values)

except that the values are specified asString objects instead ofValue objects.

Property

setProperty(String name,
String[] values,
int type)

Sets the specified property to the specified array of values and to the specified type. Same as

setProperty(String name,
Value[] values,
int type)

except that the values are specified asString objects instead ofValue objects.

Property

setProperty(String name,
Value value,
int type)

Sets the specified (single-value) property to the specified value. If the property does not yet exist, it is created. The type of the property is determined by thetype parameter specified.

If the property type of the suppliedValue object is different from that required, then a best-effort conversion is attempted. If the conversion fails, aValueFormatException is thrown.

If the property is not single-valued then aValueFormatException is also thrown.

If the property already exists it assumes both the new value and the new property type.

Passing anull as the second parameter removes the property. It is equivalent to callingremove on theProperty object itself. For example,N.setProperty("P", (Value)null, type) would remove property called"P" of the node inN.

To save the addition or removal of a property, asave call must be performed that includes the parent of the property in its scope: that is, asave on either the session, this node, or an ancestor of this node. To save a change to an existing property, asave call that includes that property in its scope is required. This means that in addition to the above-mentionedsave options, asave on the changed property itself will also work.

AConstraintViolationException will be thrown either immediately (by this method), or onsave, if the change would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

AVersionException will be thrown either immediately (by this method), or onsave, ifthis node is versionable and checked-in or is non-versionable but its nearest versionable ancestor is checked-in. Implementations may differ on when this validation is performed.

ALockException will be thrown either immediately (by this method), or onsave, if a lock prevents the setting of the property. Implementations may differ on when this validation is performed.

If another error occurs, aRepositoryException is thrown.

Property

setProperty(String name,
String value,
int type)

Sets the specified property to the specified value. Same as

setProperty(String name,
Value value,
int type)

except that the value is specified as aString object instead of aValue object.

Property

setProperty(String name, String value)

setProperty(String name, InputStream value)

setProperty(String name, boolean value)

setProperty(String name, Calendar value)

setProperty(String name, double value)

setProperty(String name, long value)

setProperty(String name, Node value)

Sets the specified property to the specified value. In the context of these methods, each Java typeimplies a particular property type. The correspondence is:

String: PropertyType.STRING

InputStream: PropertyType.BINARY

boolean: PropertyType.BOOLEAN

Calendar: PropertyType.DATE

double: PropertyType.DOUBLE

long: PropertyType.LONG

Node: PropertyType.REFERENCE

In the case of the signature that takes aNode, theREFERENCE property in question is set torefer to the supplied node (see6.2.5.4Reference).

The property type of the property being set is determined by the node type of this node. If this property type is something other than that implied by the (Java) type of the passed value, a best-effort conversion is attempted. If the conversion fails, aValueFormatException is thrown. If the property is multi-valued, aValueFormatException is also thrown. If another error occurs, aRepositoryException is thrown.

If the node type ofthis node does not specify a particular property type for the property being set then the property type implied by the (Java) type of the passed value is used and if the property already exists (has previously been set) it assumes both the new value and new type.

Passing anull as the second parameter removes the property. It is equivalent to callingremove on theProperty object itself. For example,N.setProperty("P", (Calendar)null) would remove property called"P" of the node inN. Obviously, anull cannot be passed to the signatures that take the primitive typesboolean,long ordouble.

To save the addition or removal of a property, asave call must be performed that includes the parent of the property in its scope: that is, asave on either the session, this node, or an ancestor of this node. To save a change to an existing property, asave call that includes that property in its scope is required. This means that in addition to the above-mentionedsave options, asave on the changed property itself will also work.

To create a property ofPropertyType.NAME orPropertyType.PATH an explicit type must be specified using a three-argument signature.

AConstraintViolationException will be thrown either immediately (by this method), or onsave, if the change would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.

AVersionException will be thrown either immediately (by this method), or onsave, ifthis node is versionable and checked-in or is non-versionable but its nearest versionable ancestor is checked-in. Implementations may differ on when this validation is performed.

ALockException will be thrown either immediately (by this method), or onsave, if a lock prevents the setting of the property. Implementations may differ on when this validation is performed.

ARepositoryException is thrown if another error occurs.


To change the value of a property that has already been retrieved you can also use thesetValue methods in theProperty Interface itself:

javax.jcr.
Property

void

setValue(Value value)

setValue(Value[] values)

setValue(String value)

setValue(String[] values)

setValue(InputStream value)

setValue(double value)

setValue(long value)

setValue(Calendar value)

setValue(boolean value)

setValue(Node node)

Sets the value of thisProperty to the specified value. The behavior of these methods is identical with their correspondingNode.setProperty signature.


[8]ページ先頭

©2009-2025 Movatter.jp