Class JcrResourceUtil
java.lang.Object
org.apache.sling.jcr.resource.internal.helper.JcrResourceUtil
The
JcrResourceUtil class provides helper methods used
throughout this bundle.-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable javax.jcr.ValuecreateValue(@NotNull Object value, @NotNull javax.jcr.Session session) Creates aJCR Valuefor the given object with the given Session.static @NotNull javax.jcr.query.QueryResultHelper method to execute a JCR query.static @NotNull ObjecttoJavaObject(@NotNull javax.jcr.Property property) Converts the value(s) of a JCR Property to a corresponding Java Object.static @NotNull ObjecttoJavaObject(@NotNull javax.jcr.Value value) Converts a JCR Value to a corresponding Java Object
-
Method Details
-
query
@NotNull public static @NotNull javax.jcr.query.QueryResult query(@NotNull @NotNull javax.jcr.Session session, @NotNull @NotNull String query, @NotNull @NotNull String language) throws javax.jcr.RepositoryException Helper method to execute a JCR query.- Parameters:
session- the sessionquery- the querylanguage- the language- Returns:
- the query's result
- Throws:
javax.jcr.RepositoryException- if theQueryManagercannot be retrieved
-
toJavaObject
@NotNull public static @NotNull Object toJavaObject(@NotNull @NotNull javax.jcr.Value value) throws javax.jcr.RepositoryException Converts a JCR Value to a corresponding Java Object- Parameters:
value- the JCR Value to convert- Returns:
- the Java Object
- Throws:
javax.jcr.RepositoryException- if the value cannot be converted
-
toJavaObject
@NotNull public static @NotNull Object toJavaObject(@NotNull @NotNull javax.jcr.Property property) throws javax.jcr.RepositoryException Converts the value(s) of a JCR Property to a corresponding Java Object. If the property has multiple values the result is an array of Java Objects representing the converted values of the property.- Parameters:
property- the property to be converted to the corresponding Java Object- Returns:
- the Object resulting from the conversion
- Throws:
javax.jcr.RepositoryException- if the conversion cannot take place
-
createValue
@Nullable public static @Nullable javax.jcr.Value createValue(@NotNull @NotNull Object value, @NotNull @NotNull javax.jcr.Session session) throws javax.jcr.RepositoryException Creates aJCR Valuefor the given object with the given Session. Selects the thePropertyTypeaccording the instance of the object's Class- Parameters:
value- objectsession- to create value for- Returns:
- the value or null if not convertible to a valid PropertyType
- Throws:
javax.jcr.RepositoryException- in case of error, accessing the Repository
-