import entity graph parsing test cases
This commit is contained in:
parent
06605956f9
commit
233b8daffb
|
@ -16,7 +16,7 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.graph.AbstractEntityGraphTest;
|
import org.hibernate.orm.test.loading.entitygraph.parser.AbstractEntityGraphTest;
|
||||||
import org.hibernate.graph.GraphParser;
|
import org.hibernate.graph.GraphParser;
|
||||||
import org.hibernate.graph.EntityGraphs;
|
import org.hibernate.graph.EntityGraphs;
|
||||||
import org.hibernate.graph.GraphSemantic;
|
import org.hibernate.graph.GraphSemantic;
|
||||||
|
|
|
@ -39,17 +39,30 @@ RPAREN: ')';
|
||||||
/**
|
/**
|
||||||
* In this grammar, basically any string since we (atm) have no keywords
|
* In this grammar, basically any string since we (atm) have no keywords
|
||||||
*/
|
*/
|
||||||
NAME : NAME_START ( NAME_CONTINUATION )*;
|
ATTR_NAME : ATTR_NAME_START NAME_CONTINUATION*;
|
||||||
|
|
||||||
fragment NAME_START
|
TYPE_NAME : TYPE_NAME_START NAME_CONTINUATION*;
|
||||||
: '_'
|
|
||||||
|
fragment NON_ALPHANUM_EXTENTION
|
||||||
|
: '_'
|
||||||
| '$'
|
| '$'
|
||||||
| 'a'..'z'
|
|
||||||
// HHH-558 : Allow unicode chars in identifiers
|
// HHH-558 : Allow unicode chars in identifiers
|
||||||
//| '\u0080'..'\ufffe'
|
//| '\u0080'..'\ufffe'
|
||||||
;
|
;
|
||||||
|
|
||||||
|
fragment ATTR_NAME_START
|
||||||
|
: NON_ALPHANUM_EXTENTION
|
||||||
|
| 'a'..'z'
|
||||||
|
;
|
||||||
|
|
||||||
|
fragment TYPE_NAME_START
|
||||||
|
: NON_ALPHANUM_EXTENTION
|
||||||
|
| 'A'..'Z'
|
||||||
|
;
|
||||||
|
|
||||||
fragment NAME_CONTINUATION
|
fragment NAME_CONTINUATION
|
||||||
: NAME_START
|
: NON_ALPHANUM_EXTENTION
|
||||||
|
| 'a'..'z'
|
||||||
|
| 'A'..'Z'
|
||||||
| '0'..'9'
|
| '0'..'9'
|
||||||
;
|
;
|
||||||
|
|
|
@ -33,15 +33,15 @@ attributeList
|
||||||
;
|
;
|
||||||
|
|
||||||
attributeNode
|
attributeNode
|
||||||
: attributePath (subGraph)?
|
: attributePath subGraph?
|
||||||
;
|
;
|
||||||
|
|
||||||
attributePath
|
attributePath
|
||||||
: NAME attributeQualifier?
|
: ATTR_NAME attributeQualifier?
|
||||||
;
|
;
|
||||||
|
|
||||||
attributeQualifier
|
attributeQualifier
|
||||||
: DOT NAME
|
: DOT ATTR_NAME
|
||||||
;
|
;
|
||||||
|
|
||||||
subGraph
|
subGraph
|
||||||
|
@ -49,5 +49,5 @@ subGraph
|
||||||
;
|
;
|
||||||
|
|
||||||
subType
|
subType
|
||||||
: NAME
|
: TYPE_NAME
|
||||||
;
|
;
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class GraphParser extends GraphLanguageParserBaseVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AttributeNodeImplementor visitAttributeNode(GraphLanguageParser.AttributeNodeContext ctx) {
|
public AttributeNodeImplementor visitAttributeNode(GraphLanguageParser.AttributeNodeContext ctx) {
|
||||||
final String attributeName = ctx.attributePath().NAME().getText();
|
final String attributeName = ctx.attributePath().ATTR_NAME().getText();
|
||||||
|
|
||||||
final SubGraphGenerator subGraphCreator;
|
final SubGraphGenerator subGraphCreator;
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public class GraphParser extends GraphLanguageParserBaseVisitor {
|
||||||
subGraphCreator = PathQualifierType.VALUE.getSubGraphCreator();
|
subGraphCreator = PathQualifierType.VALUE.getSubGraphCreator();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final String qualifierName = ctx.attributePath().attributeQualifier().NAME().getText();
|
final String qualifierName = ctx.attributePath().attributeQualifier().ATTR_NAME().getText();
|
||||||
|
|
||||||
if ( PARSING_LOGGER.isDebugEnabled() ) {
|
if ( PARSING_LOGGER.isDebugEnabled() ) {
|
||||||
PARSING_LOGGER.debugf(
|
PARSING_LOGGER.debugf(
|
||||||
|
|
|
@ -117,7 +117,7 @@ public abstract class AbstractManagedType<J>
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public PersistentAttribute<? super J,?> getAttribute(String name) {
|
public PersistentAttribute<? super J,?> getAttribute(String name) {
|
||||||
final PersistentAttribute attribute = findAttribute( name );
|
final PersistentAttribute attribute = findAttribute( name );
|
||||||
checkNotNull( "Attribute ", attribute, name );
|
checkNotNull( "Attribute", attribute, name );
|
||||||
return attribute;
|
return attribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ public abstract class AbstractManagedType<J>
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public PersistentAttribute<J,?> getDeclaredAttribute(String name) {
|
public PersistentAttribute<J,?> getDeclaredAttribute(String name) {
|
||||||
PersistentAttribute attr = findDeclaredAttribute( name );
|
PersistentAttribute attr = findDeclaredAttribute( name );
|
||||||
checkNotNull( "Attribute ", attr, name );
|
checkNotNull( "Attribute", attr, name );
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ public abstract class AbstractManagedType<J>
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SingularPersistentAttribute<? super J, ?> getSingularAttribute(String name) {
|
public SingularPersistentAttribute<? super J, ?> getSingularAttribute(String name) {
|
||||||
SingularPersistentAttribute attribute = findSingularAttribute( name );
|
SingularPersistentAttribute attribute = findSingularAttribute( name );
|
||||||
checkNotNull( "SingularAttribute ", attribute, name );
|
checkNotNull( "SingularAttribute", attribute, name );
|
||||||
return attribute;
|
return attribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ public abstract class AbstractManagedType<J>
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SingularAttribute<J, ?> getDeclaredSingularAttribute(String name) {
|
public SingularAttribute<J, ?> getDeclaredSingularAttribute(String name) {
|
||||||
final SingularAttribute attr = findDeclaredSingularAttribute( name );
|
final SingularAttribute attr = findDeclaredSingularAttribute( name );
|
||||||
checkNotNull( "SingularAttribute ", attr, name );
|
checkNotNull( "SingularAttribute", attr, name );
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class DomainModelHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// first, try to find it by name directly..
|
// first, try to find it by name directly..
|
||||||
ManagedDomainType<S> subManagedType = jpaMetamodel.entity( subTypeName );
|
ManagedDomainType<S> subManagedType = jpaMetamodel.resolveHqlEntityReference( subTypeName );
|
||||||
if ( subManagedType != null ) {
|
if ( subManagedType != null ) {
|
||||||
return subManagedType;
|
return subManagedType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,17 +4,17 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.loading.entitygraph.parser;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.AttributeNode;
|
import javax.persistence.AttributeNode;
|
||||||
import javax.persistence.EntityGraph;
|
import javax.persistence.EntityGraph;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Subgraph;
|
import javax.persistence.Subgraph;
|
||||||
|
|
||||||
|
import org.hibernate.graph.GraphParser;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public abstract class AbstractEntityGraphTest extends BaseEntityManagerFunctiona
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
return new Class[]{ GraphParsingTestEntity.class, GraphParsingTestSubentity.class };
|
return new Class[]{ GraphParsingTestEntity.class, GraphParsingTestSubEntity.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> RootGraphImplementor<T> parseGraph(Class<T> entityType, String graphString) {
|
protected <T> RootGraphImplementor<T> parseGraph(Class<T> entityType, String graphString) {
|
||||||
|
@ -104,3 +104,4 @@ public abstract class AbstractEntityGraphTest extends BaseEntityManagerFunctiona
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.loading.entitygraph.parser;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -15,6 +15,7 @@ import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Subgraph;
|
import javax.persistence.Subgraph;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
import org.hibernate.graph.GraphParser;
|
||||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||||
|
@ -191,7 +192,7 @@ public class EntityGraphParserTest extends AbstractEntityGraphTest {
|
||||||
//
|
//
|
||||||
// return type.isAssignableFrom( entityPersister.getMappedClass() );
|
// return type.isAssignableFrom( entityPersister.getMappedClass() );
|
||||||
|
|
||||||
RootGraphImplementor<GraphParsingTestEntity> graph = parseGraph( "linkToOne(name, description), linkToOne(GraphParsingTestSubentity: sub)" );
|
RootGraphImplementor<GraphParsingTestEntity> graph = parseGraph( "linkToOne(name, description), linkToOne(GraphParsingTestSubEntity: sub)" );
|
||||||
assertNotNull( graph );
|
assertNotNull( graph );
|
||||||
|
|
||||||
List<AttributeNodeImplementor<?>> attrs = graph.getAttributeNodeImplementors();
|
List<AttributeNodeImplementor<?>> attrs = graph.getAttributeNodeImplementors();
|
||||||
|
@ -204,7 +205,7 @@ public class EntityGraphParserTest extends AbstractEntityGraphTest {
|
||||||
|
|
||||||
assertNullOrEmpty( linkToOneNode.getKeySubgraphs() );
|
assertNullOrEmpty( linkToOneNode.getKeySubgraphs() );
|
||||||
|
|
||||||
final SubGraphImplementor subGraph = linkToOneNode.getSubGraphMap().get( GraphParsingTestSubentity.class );
|
final SubGraphImplementor subGraph = linkToOneNode.getSubGraphMap().get( GraphParsingTestSubEntity.class );
|
||||||
assertNotNull( subGraph );
|
assertNotNull( subGraph );
|
||||||
|
|
||||||
assertBasicAttributes( subGraph, "sub" );
|
assertBasicAttributes( subGraph, "sub" );
|
||||||
|
@ -215,12 +216,12 @@ public class EntityGraphParserTest extends AbstractEntityGraphTest {
|
||||||
EntityManager entityManager = getOrCreateEntityManager();
|
EntityManager entityManager = getOrCreateEntityManager();
|
||||||
RootGraphImplementor<GraphParsingTestEntity> graph = ( (SessionImplementor) entityManager ).createEntityGraph(
|
RootGraphImplementor<GraphParsingTestEntity> graph = ( (SessionImplementor) entityManager ).createEntityGraph(
|
||||||
GraphParsingTestEntity.class );
|
GraphParsingTestEntity.class );
|
||||||
final SubGraphImplementor<GraphParsingTestSubentity> subGraph = graph.addSubGraph(
|
final SubGraphImplementor<GraphParsingTestSubEntity> subGraph = graph.addSubGraph(
|
||||||
"linkToOne",
|
"linkToOne",
|
||||||
GraphParsingTestSubentity.class
|
GraphParsingTestSubEntity.class
|
||||||
);
|
);
|
||||||
|
|
||||||
assertEquals( subGraph.getGraphedType().getJavaType(), GraphParsingTestSubentity.class );
|
assertEquals( subGraph.getGraphedType().getJavaType(), GraphParsingTestSubEntity.class );
|
||||||
|
|
||||||
final AttributeNodeImplementor<Object> subTypeAttrNode = subGraph.addAttributeNode( "sub" );
|
final AttributeNodeImplementor<Object> subTypeAttrNode = subGraph.addAttributeNode( "sub" );
|
||||||
assert subTypeAttrNode != null;
|
assert subTypeAttrNode != null;
|
|
@ -4,11 +4,13 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.loading.entitygraph.parser;
|
||||||
|
|
||||||
import javax.persistence.EntityGraph;
|
import javax.persistence.EntityGraph;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
import org.hibernate.graph.EntityGraphs;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
|
@ -1,7 +1,6 @@
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.loading.entitygraph.parser;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
|
@ -11,7 +10,7 @@ import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
@Entity
|
@Entity( name = "GraphParsingTestEntity" )
|
||||||
public class GraphParsingTestEntity {
|
public class GraphParsingTestEntity {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -79,4 +78,4 @@ public class GraphParsingTestEntity {
|
||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
package org.hibernate.graph;
|
package org.hibernate.orm.test.loading.entitygraph.parser;
|
||||||
|
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
@Entity
|
@Entity( name = "GraphParsingTestSubEntity" )
|
||||||
public class GraphParsingTestSubentity extends GraphParsingTestEntity {
|
public class GraphParsingTestSubEntity extends GraphParsingTestEntity {
|
||||||
|
|
||||||
private String sub;
|
private String sub;
|
||||||
|
|
||||||
|
@ -17,4 +17,4 @@ public class GraphParsingTestSubentity extends GraphParsingTestEntity {
|
||||||
this.sub = sub;
|
this.sub = sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue