dot.setJoinType( hibernateJoinType ); // Tell the dot node about the join type. dot.setFetch( fetch ); dot.resolve( true, false, alias == null ? null : alias.getText() ); if ( dot.getDataType() != null && dot.getDataType().isComponentType() ) { if ( dot.getDataType().isAnyType() ) { throw new SemanticException( "An AnyType attribute cannot be join fetched" ); dot.getLhs().getFromElement(), dot.getPropertyPath(), alias == null ? null : alias.getText(), null, false ); fromElement = factory.createComponentJoin( (CompositeType) dot.getDataType() ); fromElement = dot.getImpliedJoin(); fromElement.setAllPropertyFetch( propertyFetch != null );
private void dereferenceEntityIdentifier(String propertyName, DotNode dotParent) { // special shortcut for id properties, skip the join! // this must only occur at the _end_ of a path expression if ( LOG.isDebugEnabled() ) { LOG.debugf( "dereferenceShortcut() : property %s in %s does not require a join.", propertyName, getFromElement().getClassName() ); } setPropertyNameAndPath( dotParent ); // Set the unresolved path in this node and the parent. initText(); // Set the text for the parent. if ( dotParent != null ) { dotParent.dereferenceType = DereferenceType.IDENTIFIER; dotParent.setText( getText() ); dotParent.columns = getColumns(); } }
boolean isSizeProperty = getNextSibling() != null && CollectionProperties.isAnyCollectionProperty( getNextSibling().getText() ); QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection( role ); String propName = getPath(); FromClause currentFromClause = getWalker().getCurrentFromClause(); FromElement lhsFromElement = getLhs().getFromElement(); while ( lhsFromElement != null && ComponentJoin.class.isInstance( lhsFromElement ) ) { lhsFromElement = lhsFromElement.getOrigin(); if ( getWalker().getStatementType() != SqlTokenTypes.SELECT ) { if ( isFromElementUpdateOrDeleteRoot( lhsFromElement ) ) { if ( getWalker().getStatementType() != SqlTokenTypes.INSERT ) { final Queryable persister = lhsFromElement.getQueryable(); if ( persister.isMultiTable() ) { columns = getFromElement().toColumns( lhsTableName, propertyPath, false, true ); propName, classAlias, getColumns(), implicitJoin ); setImpliedJoin( elem ); setFromElement( elem ); // This 'dot' expression now refers to the resulting from element.
public void resolveIndex(AST parent) throws SemanticException { if ( isResolved() ) { return; } Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type. dereferenceCollection( (CollectionType) propertyType, true, true, null, parent ); }
private Type prepareLhs() throws SemanticException { FromReferenceNode lhs = getLhs(); lhs.prepareForDot( propertyName ); return getDataType(); }
public void resolve(boolean generateJoin, boolean implicitJoin, String classAlias, AST parent, AST parentPredicate) throws SemanticException { if ( isResolved() ) { return; Type propertyType = prepareLhs(); // Prepare the left hand side and get the data type. DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfClassEntityTypeSelector( getLhs().getPath() ); getWalker().getLiteralProcessor().lookupConstant( this ); checkLhsIsNotCollection(); dereferenceComponent( parent ); initText(); checkLhsIsNotCollection(); dereferenceEntity( (EntityType) propertyType, implicitJoin, classAlias, generateJoin, parent, parentPredicate ); initText(); checkLhsIsNotCollection(); dereferenceCollection( (CollectionType) propertyType, implicitJoin, false, classAlias, parent ); checkLhsIsNotCollection(); initText(); setResolved();
"dereferenceEntityJoin() : generating join for %s in %s (%s) parent = %s", propertyName, getFromElement().getClassName(), classAlias == null ? "<no alias>" : classAlias, ASTUtil.getDebugString( parent ) String tableAlias = getAliasGenerator().createName( associatedEntityName ); String[] joinColumns = getColumns(); String joinPath = getPath(); if ( impliedJoin && getWalker().isInFrom() ) { joinType = getWalker().getImpliedJoinType(); FromClause currentFromClause = getWalker().getCurrentFromClause(); FromElement elem = currentFromClause.findJoinByPath( joinPath ); boolean useFoundFromElement = found && canReuse( classAlias, elem ); FromElement lhsFromElement = getLhs().getFromElement(); while ( lhsFromElement != null && ComponentJoin.class.isInstance( lhsFromElement ) ) { lhsFromElement = lhsFromElement.getOrigin(); String lhsTableAlias = getLhs().getFromElement().getTableAlias(); joinSequence = getSessionFactoryHelper() .createJoinSequence( impliedJoin, propertyType, tableAlias, joinType, polyJoinColumns ); joinSequence = getSessionFactoryHelper()
if ( getWalker().isShallowQuery() || getWalker().getCurrentFromClause().isSubQuery() ) { resolve( false, true ); resolve( true, false ); Type type = getDataType(); if ( type.isEntityType() ) { FromElement fromElement = getFromElement(); fromElement.setIncludeSubclasses( true ); // Tell the destination fromElement to 'includeSubclasses'. if ( useThetaStyleImplicitJoins ) { FromReferenceNode lhs = getLhs(); while ( lhs != null ) { checkSubclassOrSuperclassPropertyReference( lhs, lhs.getNextSibling().getText() ); lhs = (FromReferenceNode) lhs.getFirstChild();
node.setFirstChild( null ); if ( value instanceof String ) { node.setType( SqlTokenTypes.QUOTED_STRING ); node.setType( SqlTokenTypes.QUOTED_STRING ); node.setType( SqlTokenTypes.NUM_INT ); node.setType( SqlTokenTypes.NUM_INT ); node.setType( SqlTokenTypes.NUM_INT ); node.setType( SqlTokenTypes.NUM_LONG ); node.setType( SqlTokenTypes.NUM_DOUBLE ); node.setType( SqlTokenTypes.NUM_FLOAT ); node.setType( SqlTokenTypes.CONSTANT ); throw new QueryException( QueryTranslator.ERROR_CANNOT_DETERMINE_TYPE + node.getText() ); node.setText( literalType.objectToSQLString( value, dialect ) ); throw new QueryException( QueryTranslator.ERROR_CANNOT_FORMAT_LITERAL + node.getText(), e ); node.setDataType( type ); node.setResolvedConstant( text );
@Override protected AST lookupProperty(AST dot, boolean root, boolean inSelect) throws SemanticException { DotNode dotNode = (DotNode) dot; FromReferenceNode lhs = dotNode.getLhs(); AST rhs = lhs.getNextSibling(); LOG.debugf( "lookupProperty() %s => %s(%s)", dotNode.getPath(), rhs.getText(), lhs.getPath() dotNode.setFirstChild( f ); dotNode.resolveFirstChild(); return dotNode;
private void dereferenceEntity(EntityType entityType, boolean implicitJoin, String classAlias, boolean generateJoin, AST parent) throws SemanticException { checkForCorrelatedSubquery( "dereferenceEntity" ); final boolean joinIsNeeded; if ( isDotNode( parent ) ) { joinIsNeeded = generateJoin && !isReferenceToPrimaryKey( parentAsDotNode.propertyName, entityType ); else if ( ! getWalker().isSelectStatement() ) { joinIsNeeded = getWalker().getCurrentStatementType() == SqlTokenTypes.SELECT && getWalker().isInFrom(); joinIsNeeded = generateJoin && ( !getWalker().isInSelect() || !getWalker().isShallowQuery() ); joinIsNeeded = generateJoin || ( getWalker().isInSelect() || getWalker().isInFrom() ); dereferenceEntityJoin( classAlias, entityType, implicitJoin, parent ); dereferenceEntityIdentifier( property, parentAsDotNode );
AST parent, AST parentPredicate) throws SemanticException { checkForCorrelatedSubquery( "dereferenceEntity" ); final boolean joinIsNeeded; if ( isDotNode( parent ) ) { joinIsNeeded = generateJoin && !isPropertyEmbeddedInJoinProperties( parentAsDotNode.propertyName ); else if ( !getWalker().isSelectStatement() ) { joinIsNeeded = getWalker().getCurrentStatementType() == SqlTokenTypes.SELECT && getWalker().isInFrom(); joinIsNeeded = generateJoin && ( !getWalker().isInSelect() || !getWalker().isShallowQuery() ); joinIsNeeded = generateJoin || ( getWalker().isInSelect() || getWalker().isInFrom() ); dereferenceEntityJoin( classAlias, entityType, implicitJoin, parent ); dereferenceEntityIdentifier( property, parentAsDotNode );
private boolean resolveAsNakedComponentPropertyRefLHS(DotNode parent) { FromElement fromElement = locateSingleFromElement(); if (fromElement == null) { return false; } Type componentType = getNakedPropertyType(fromElement); if ( componentType == null ) { throw new QueryException( "Unable to resolve path [" + parent.getPath() + "], unexpected token [" + getOriginalText() + "]" ); } if (!componentType.isComponentType()) { throw new QueryException("Property '" + getOriginalText() + "' is not a component. Use an alias to reference associations or collections."); } Type propertyType; String propertyPath = getText() + "." + getNextSibling().getText(); try { // check to see if our "propPath" actually // represents a property on the persister propertyType = fromElement.getPropertyType(getText(), propertyPath); } catch (Throwable t) { // assume we do *not* refer to a property on the given persister return false; } setFromElement(fromElement); parent.setPropertyPath(propertyPath); parent.setDataType(propertyType); return true; }
private String[] getColumns() throws QueryException { if ( columns == null ) { // Use the table fromElement and the property name to get the array of column names. String tableAlias = getLhs().getFromElement().getTableAlias(); columns = getFromElement().toColumns( tableAlias, propertyPath, false ); } return columns; }
/** * Returns the full path of the node. * * @return the full path of the node. */ @Override public String getPath() { if ( path == null ) { FromReferenceNode lhs = getLhs(); if ( lhs == null ) { path = getText(); } else { SqlNode rhs = (SqlNode) lhs.getNextSibling(); path = lhs.getPath() + "." + rhs.getOriginalText(); } } return path; }
/** * Resolves the left hand side of the DOT. * * @throws SemanticException */ @Override public void resolveFirstChild() throws SemanticException { FromReferenceNode lhs = (FromReferenceNode) getFirstChild(); SqlNode property = (SqlNode) lhs.getNextSibling(); // Set the attributes of the property reference expression. String propName = property.getText(); propertyName = propName; // If the uresolved property path isn't set yet, just use the property name. if ( propertyPath == null ) { propertyPath = propName; } // Resolve the LHS fully, generate implicit joins. Pass in the property name so that the resolver can // discover foreign key (id) properties. lhs.resolve( true, true, null, this ); setFromElement( lhs.getFromElement() ); // The 'from element' that the property is in. checkSubclassOrSuperclassPropertyReference( lhs, propName ); }
@Override public String getDisplayText() { StringBuilder buf = new StringBuilder(); FromElement fromElement = getFromElement(); buf.append( "{propertyName=" ).append( propertyName ); buf.append( ",dereferenceType=" ).append( getWalker().getASTPrinter().getTokenTypeName( dereferenceType ) ); buf.append( ",propertyPath=" ).append( propertyPath ); buf.append( ",path=" ).append( getPath() ); if ( fromElement != null ) { buf.append( ",tableAlias=" ).append( fromElement.getTableAlias() ); buf.append( ",className=" ).append( fromElement.getClassName() ); buf.append( ",classAlias=" ).append( fromElement.getClassAlias() ); } else { buf.append( ",no from element" ); } buf.append( '}' ); return buf.toString(); }
@Override public Statement resolve(DotNode dotNode) { final Type dataType = dotNode.getDataType(); Class<?> requestedType = dataType.getReturnedClass(); throw new UnsupportedOperationException("Can't resolve " + dotNode.getText() + ": Components are not implemented yet in JPQL expressions"); Bool.notEquals(Stmt.loadVariable("candidate").invoke("get", dotNode.getPropertyPath()).invoke("isNull"), null), Stmt.loadLiteral(null), Stmt.loadVariable("entityManager").invoke("find", Stmt.invokeStatic(Key.class, "fromJsonObject", Stmt.loadVariable("entityManager"), Stmt.loadVariable("candidate").invoke("get", dotNode.getPropertyPath()).invoke("isObject"), false), Stmt.loadStatic(Collections.class, "EMPTY_MAP"))); throw new UnsupportedOperationException("Can't resolve " + dotNode.getText() + ": Collections are not implemented yet in JPQL expressions"); Stmt.loadVariable("candidate").invoke("get", dotNode.getPropertyPath()), requestedType);
final SqlNode rhs = (SqlNode) lhs.getNextSibling(); final String propertyPath = lhs.getPropertyPath(); Set<String> temp = new HashSet<String>();
@Override public Statement resolve(DotNode dotNode) { Class<?> lhsType = dotNode.getLhs().getDataType().getReturnedClass(); // ensure the attribute is available as a field of the comparator String attrVarName = dotNode.getPath().replace('.', '_') + "_attr"; if (containingClass != null && !generatedClassVariables.contains(attrVarName)) { generatedClassVariables.add(attrVarName); containingClass.privateField(attrVarName, ErraiAttribute.class) .modifiers(Modifier.Final) .initializesWith( Stmt.nestedCall(new StringStatement("entityManager.getMetamodel()", MetaClassFactory.get(ErraiMetamodel.class))) .invoke("entity", Stmt.loadLiteral(lhsType)) .invoke("getAttribute", dotNode.getPropertyPath())) .finish(); } // XXX need a StringStatement here because codegen can't see fields of anonymous inner classes. (ERRAI-363) return Stmt.nestedCall(new StringStatement(attrVarName, MetaClassFactory.get(ErraiAttribute.class))) .invoke("get", Stmt.loadVariable(variableName)); } }