@Override public void setText(String s) { // for some reason the antlr.CommonAST initialization routines force // this method to get called twice. The first time with an empty string if ( StringHelper.isNotEmpty( s ) ) { constantExpression = s; constantValue = ReflectHelper.getConstantValue( s, factory ); heuristicType = factory.getTypeResolver().heuristicType( constantValue.getClass().getName() ); super.setText( s ); } }
private void handleDotStructure(AST dotStructureRoot) { final String expression = ASTUtil.getPathText( dotStructureRoot ); final Object constant = ReflectHelper.getConstantValue( expression, factory ); if ( constant != null ) { dotStructureRoot.setFirstChild( null ); dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT ); dotStructureRoot.setText( expression ); } } }
@Test public void test_getConstantValue_simpleAlias_non_conventional() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( false ); Object value = ReflectHelper.getConstantValue( "alias.b", sessionFactoryImplementorMock); assertNull(value); verify(classLoaderServiceMock, times(1)).classForName( eq( "alias" ) ); }
@Test public void test_getConstantValue_simpleAlias() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( true ); Object value = ReflectHelper.getConstantValue( "alias.b", sessionFactoryImplementorMock); assertNull(value); verify(classLoaderServiceMock, never()).classForName( anyString() ); }
@Test public void test_getConstantValue_outerEnum() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( true ); when( classLoaderServiceMock.classForName( "javax.persistence.FetchType" ) ).thenReturn( (Class) FetchType.class ); Object value = ReflectHelper.getConstantValue( "javax.persistence.FetchType.LAZY", sessionFactoryImplementorMock); assertEquals( FetchType.LAZY, value ); verify(classLoaderServiceMock, times(1)).classForName( eq("javax.persistence.FetchType") ); }
@Test public void test_getConstantValue_nestedAlias() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( true ); Object value = ReflectHelper.getConstantValue( "alias.b.c", sessionFactoryImplementorMock); assertNull(value); verify(classLoaderServiceMock, never()).classForName( anyString() ); }
@Test public void test_getConstantValue_constant_digits() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( true ); when( classLoaderServiceMock.classForName( "org.hibernate.internal.util.hib3rnat3.C0nst4nts३" ) ).thenReturn( (Class) C0nst4nts३.class ); Object value = ReflectHelper.getConstantValue( "org.hibernate.internal.util.hib3rnat3.C0nst4nts३.ABC_DEF", sessionFactoryImplementorMock); assertEquals( C0nst4nts३.ABC_DEF, value ); verify(classLoaderServiceMock, times(1)).classForName( eq("org.hibernate.internal.util.hib3rnat3.C0nst4nts३") ); }
@Test public void test_getConstantValue_nestedAlias_non_conventional() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( false ); Object value = ReflectHelper.getConstantValue( "alias.b.c", sessionFactoryImplementorMock); assertNull(value); verify(classLoaderServiceMock, times(1)).classForName( eq( "alias.b" ) ); }
@Test public void test_getConstantValue_enumClass() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( true ); when( classLoaderServiceMock.classForName( "org.hibernate.internal.util.ReflectHelperTest$Status" ) ).thenReturn( (Class) Status.class ); Object value = ReflectHelper.getConstantValue( "org.hibernate.internal.util.ReflectHelperTest$Status", sessionFactoryImplementorMock); assertNull(value); verify(classLoaderServiceMock, never()).classForName( eq("org.hibernate.internal.util") ); }
@Test public void test_getConstantValue_nestedEnum() { when( sessionFactoryOptionsMock.isConventionalJavaConstants() ).thenReturn( true ); when( classLoaderServiceMock.classForName( "org.hibernate.internal.util.ReflectHelperTest$Status" ) ).thenReturn( (Class) Status.class ); Object value = ReflectHelper.getConstantValue( "org.hibernate.internal.util.ReflectHelperTest$Status.ON", sessionFactoryImplementorMock); assertEquals( ON, value ); verify(classLoaderServiceMock, times(1)).classForName( eq("org.hibernate.internal.util.ReflectHelperTest$Status") ); }
if ( token.indexOf( '.' ) > -1 && ( constant = ReflectHelper.getConstantValue( token, q.getFactory() ) ) != null ) { Type type;
public void lookupConstant(DotNode node) throws SemanticException { String text = ASTUtil.getPathText( node ); Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports( text ); if ( persister != null ) { // the name of an entity class final String discrim = persister.getDiscriminatorSQLValue(); node.setDataType( persister.getDiscriminatorType() ); if ( InFragment.NULL.equals( discrim ) || InFragment.NOT_NULL.equals( discrim ) ) { throw new InvalidPathException( "subclass test not allowed for null or not null discriminator: '" + text + "'" ); } // the class discriminator value setSQLValue( node, text, discrim ); } else { Object value = ReflectHelper.getConstantValue( text, walker.getSessionFactoryHelper().getFactory() ); if ( value == null ) { throw new InvalidPathException( "Invalid path: '" + text + "'" ); } setConstantValue( node, text, value ); } }
@Override public void setText(String s) { // for some reason the antlr.CommonAST initialization routines force // this method to get called twice. The first time with an empty string if ( StringHelper.isNotEmpty( s ) ) { constantExpression = s; constantValue = ReflectHelper.getConstantValue( s ); heuristicType = factory.getTypeResolver().heuristicType( constantValue.getClass().getName() ); super.setText( s ); } }
@Override public void setText(String s) { // for some reason the antlr.CommonAST initialization routines force // this method to get called twice. The first time with an empty string if ( StringHelper.isNotEmpty( s ) ) { constantExpression = s; constantValue = ReflectHelper.getConstantValue( s ); heuristicType = factory.getTypeResolver().heuristicType( constantValue.getClass().getName() ); super.setText( s ); } }
private void handleDotStructure(AST dotStructureRoot) { String expression = ASTUtil.getPathText( dotStructureRoot ); Object constant = ReflectHelper.getConstantValue( expression ); if ( constant != null ) { dotStructureRoot.setFirstChild( null ); dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT ); dotStructureRoot.setText( expression ); } } }
private void handleDotStructure(AST dotStructureRoot) { String expression = ASTUtil.getPathText( dotStructureRoot ); Object constant = ReflectHelper.getConstantValue( expression ); if ( constant != null ) { dotStructureRoot.setFirstChild( null ); dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT ); dotStructureRoot.setText( expression ); } } }
public void lookupConstant(DotNode node) throws SemanticException { String text = ASTUtil.getPathText( node ); Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports( text ); if ( persister != null ) { // the name of an entity class final String discrim = persister.getDiscriminatorSQLValue(); node.setDataType( persister.getDiscriminatorType() ); if (InFragment.NULL.equals(discrim) || InFragment.NOT_NULL.equals(discrim)) throw new InvalidPathException( "subclass test not allowed for null or not null discriminator: '" + text + "'"); setSQLValue(node, text, discrim); // the class discriminator value } else { Object value = ReflectHelper.getConstantValue( text ); if (value == null) throw new InvalidPathException("Invalid path: '" + text + "'"); setConstantValue(node, text, value); } }
public void lookupConstant(DotNode node) throws SemanticException { String text = ASTUtil.getPathText( node ); Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports( text ); if ( persister != null ) { // the name of an entity class final String discrim = persister.getDiscriminatorSQLValue(); node.setDataType( persister.getDiscriminatorType() ); if (InFragment.NULL.equals(discrim) || InFragment.NOT_NULL.equals(discrim)) throw new InvalidPathException( "subclass test not allowed for null or not null discriminator: '" + text + "'"); setSQLValue(node, text, discrim); // the class discriminator value } else { Object value = ReflectHelper.getConstantValue( text ); if (value == null) throw new InvalidPathException("Invalid path: '" + text + "'"); setConstantValue(node, text, value); } }
if ( token.indexOf( '.' ) > -1 && ( constant = ReflectHelper.getConstantValue( token ) ) != null ) { Type type;
if ( token.indexOf( '.' ) > -1 && ( constant = ReflectHelper.getConstantValue( token ) ) != null ) { Type type;