HHH-10863 Add a isCollectionElement() method to AbstractAttributeKey
It allows external libraries to test for the collection element marker
without being aware of the exact syntax used as it might change in the
future.
(cherry picked from commit 7f3a3bcbcc
)
This commit is contained in:
parent
8e64e3ac93
commit
af8ffdee8f
|
@ -12,6 +12,8 @@ import org.hibernate.internal.util.StringHelper;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractAttributeKey {
|
||||
private static final String COLLECTION_ELEMENT = "collection&&element";
|
||||
|
||||
private final AbstractAttributeKey parent;
|
||||
private final String property;
|
||||
private final String fullPath;
|
||||
|
@ -78,6 +80,13 @@ public abstract class AbstractAttributeKey {
|
|||
return parent == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the current property is a collection element marker
|
||||
*/
|
||||
public boolean isCollectionElement() {
|
||||
return COLLECTION_ELEMENT.equals( property );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getFullPath();
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.boot.model.source;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hibernate.boot.model.source.spi.AttributePath;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Guillaume Smet
|
||||
*/
|
||||
public class AttributePathTest {
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10863")
|
||||
public void testCollectionElement() {
|
||||
AttributePath attributePath = AttributePath.parse( "items.collection&&element.name" );
|
||||
|
||||
assertFalse( attributePath.isCollectionElement() );
|
||||
assertTrue( attributePath.getParent().isCollectionElement() );
|
||||
assertFalse( attributePath.getParent().getParent().isCollectionElement() );
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue