1717
1818import org .springframework .data .mapping .model .ConvertingPropertyAccessor ;
1919import org .springframework .lang .Nullable ;
20- import org .springframework .util .Assert ;
2120
2221/**
2322 * Domain service to allow accessing and setting {@link PersistentProperty}s of an entity. Usually obtained through
@@ -46,63 +45,6 @@ public interface PersistentPropertyAccessor<T> {
4645 */
4746 void setProperty (PersistentProperty <?> property , @ Nullable Object value );
4847
49- /**
50- * Sets the given value for the {@link PersistentProperty} pointed to by the given {@link PersistentPropertyPath}. The
51- * lookup of intermediate values must not yield {@literal null}.
52- *
53- * @param path must not be {@literal null} or empty.
54- * @param value can be {@literal null}.
55- * @since 2.1
56- * @deprecated since 2.3, use {@link PersistentPropertyPathAccessor#setProperty(PersistentPropertyPath, Object)}
57- * instead.
58- */
59- @ Deprecated
60- default void setProperty (PersistentPropertyPath <? extends PersistentProperty <?>> path , @ Nullable Object value ) {
61-
62- Assert .notNull (path , "PersistentPropertyPath must not be null" );
63- Assert .isTrue (!path .isEmpty (), "PersistentPropertyPath must not be empty" );
64-
65- PersistentProperty <? extends PersistentProperty <?>> leafProperty = path .getLeafProperty ();
66- PersistentPropertyPath <? extends PersistentProperty <?>> parentPath = path .getParentPath ();
67-
68- if (parentPath != null ) {
69-
70- PersistentProperty <? extends PersistentProperty <?>> parentProperty = parentPath .getLeafProperty ();
71-
72- if (parentProperty .isCollectionLike () || parentProperty .isMap ()) {
73- throw new MappingException (
74- "Cannot traverse collection or map intermediate %s" .formatted (parentPath .toDotPath ()));
75- }
76- }
77-
78- Object parent = parentPath == null ? getBean () : getProperty (parentPath );
79-
80- if (parent == null ) {
81-
82- String nullIntermediateMessage = "Cannot lookup property %s on null intermediate; Original path was: %s on %s" ;
83-
84- throw new MappingException (
85- String .format (nullIntermediateMessage , path .getParentPath (), path .toDotPath (),
86- getBean ().getClass ().getName ()));
87- }
88-
89- PersistentPropertyAccessor <?> accessor = parent == getBean () //
90- ? this //
91- : leafProperty .getOwner ().getPropertyAccessor (parent );
92-
93- accessor .setProperty (leafProperty , value );
94-
95- if (parentPath == null ) {
96- return ;
97- }
98-
99- Object bean = accessor .getBean ();
100-
101- if (bean != parent ) {
102- setProperty (parentPath , bean );
103- }
104- }
105-
10648 /**
10749 * Returns the value of the given {@link PersistentProperty} of the underlying bean instance.
10850 *
@@ -112,65 +54,6 @@ default void setProperty(PersistentPropertyPath<? extends PersistentProperty<?>>
11254 @ Nullable
11355 Object getProperty (PersistentProperty <?> property );
11456
115- /**
116- * Return the value pointed to by the given {@link PersistentPropertyPath}. If the given path is empty, the wrapped
117- * bean is returned.
118- *
119- * @param path must not be {@literal null}.
120- * @return
121- * @since 2.1
122- * @deprecated since 2.3, use {@link PersistentPropertyPathAccessor#getProperty(PersistentPropertyPath)} instead
123- */
124- @ Deprecated
125- @ Nullable
126- default Object getProperty (PersistentPropertyPath <? extends PersistentProperty <?>> path ) {
127- return getProperty (path , new TraversalContext ());
128- }
129-
130- /**
131- * Return the value pointed to by the given {@link PersistentPropertyPath}. If the given path is empty, the wrapped
132- * bean is returned. On each path segment value lookup, the resulting value is post-processed by handlers registered
133- * on the given {@link TraversalContext} context. This can be used to unwrap container types that are encountered
134- * during the traversal.
135- *
136- * @param path must not be {@literal null}.
137- * @param context must not be {@literal null}.
138- * @return
139- * @since 2.2
140- * @deprecated since 2.3, use
141- * {@link PersistentPropertyPathAccessor#getProperty(PersistentPropertyPath, org.springframework.data.mapping.AccessOptions.GetOptions)}
142- * instead.
143- */
144- @ Nullable
145- @ Deprecated
146- default Object getProperty (PersistentPropertyPath <? extends PersistentProperty <?>> path , TraversalContext context ) {
147-
148- Object bean = getBean ();
149- Object current = bean ;
150-
151- if (path .isEmpty ()) {
152- return bean ;
153- }
154-
155- for (PersistentProperty <?> property : path ) {
156-
157- if (current == null ) {
158-
159- String nullIntermediateMessage = "Cannot lookup property %s on null intermediate; Original path was: %s on %s" ;
160-
161- throw new MappingException (
162- String .format (nullIntermediateMessage , property , path .toDotPath (), bean .getClass ().getName ()));
163- }
164-
165- PersistentEntity <?, ? extends PersistentProperty <?>> entity = property .getOwner ();
166- PersistentPropertyAccessor <Object > accessor = entity .getPropertyAccessor (current );
167-
168- current = context .postProcess (property , accessor .getProperty (property ));
169- }
170-
171- return current ;
172- }
173-
17457 /**
17558 * Returns the underlying bean. The actual instance may change between
17659 * {@link #setProperty(PersistentProperty, Object)} calls.
0 commit comments