@Override public String toString() { StringBuilder builder = new StringBuilder(); for (Attribute<?, ?> attribute : attributes) { builder.append(attribute.getName()).append("."); } return builder.length() == 0 ? "" : builder.substring(0, builder.lastIndexOf(".")); } }
@Override public String renderTableExpression(RenderingContext renderingContext) { prepareAlias( renderingContext ); ( (FromImplementor) getParent() ).prepareAlias( renderingContext ); StringBuilder tableExpression = new StringBuilder(); tableExpression.append( getParent().getAlias() ) .append( '.' ) .append( getAttribute().getName() ) .append( " as " ) .append( getAlias() ); if ( suppliedJoinCondition != null ) { tableExpression.append( " with " ) .append( ( (PredicateImplementor) suppliedJoinCondition ).render( renderingContext ) ); } return tableExpression.toString(); }
@Override public String getPathIdentifier() { return getPathSource().getPathIdentifier() + "." + getAttribute().getName(); }
private <X> void registerAttribute(Class metamodelClass, Attribute<X, ?> attribute) { final String name = attribute.getName(); try {
/** * Return whether the given {@link From} contains a fetch declaration for the attribute with the given name. * * @param from the {@link From} to check for fetches. * @param attribute the attribute name to check. * @return */ private static boolean isAlreadyFetched(From<?, ?> from, String attribute) { for (Fetch<?, ?> fetch : from.getFetches()) { boolean sameName = fetch.getAttribute().getName().equals(attribute); if (sameName && fetch.getJoinType().equals(JoinType.LEFT)) { return true; } } return false; }
/** * Returns an existing join for the given attribute if one already exists or creates a new one if not. * * @param from the {@link From} to get the current joins from. * @param attribute the {@link Attribute} to look for in the current joins. * @return will never be {@literal null}. */ private static Join<?, ?> getOrCreateJoin(From<?, ?> from, String attribute) { for (Join<?, ?> join : from.getJoins()) { boolean sameName = join.getAttribute().getName().equals(attribute); if (sameName && join.getJoinType().equals(JoinType.LEFT)) { return join; } } return from.join(attribute, JoinType.LEFT); }
private static ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl> [] getPeopleAssignmentsJoins( Join<TaskImpl,PeopleAssignmentsImpl> peopleAssignJoin) { ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl> [] joins = new ListJoin[3]; for( Join<PeopleAssignmentsImpl,?> join : peopleAssignJoin.getJoins() ) { String joinFieldName = join.getAttribute().getName(); if( PeopleAssignmentsImpl_.businessAdministrators.getName().equals(joinFieldName) ) { joins[0] = (ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl>) join; } else if( PeopleAssignmentsImpl_.potentialOwners.getName().equals(joinFieldName) ) { joins[1] = (ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl>) join; } else if( PeopleAssignmentsImpl_.taskStakeholders.getName().equals(joinFieldName) ) { joins[2] = (ListJoin<PeopleAssignmentsImpl,OrganizationalEntityImpl>) join; } } if( joins[0] == null ) { joins[0] = peopleAssignJoin.join(PeopleAssignmentsImpl_.businessAdministrators, JoinType.LEFT); } if( joins[1] == null ) { joins[1] = peopleAssignJoin.join(PeopleAssignmentsImpl_.potentialOwners, JoinType.LEFT); } if( joins[2] == null ) { joins[2] = peopleAssignJoin.join(PeopleAssignmentsImpl_.taskStakeholders, JoinType.LEFT); } assert joins[0] != null : "Could not find business administrators join!"; assert joins[1] != null : "Could not find potential owners join!"; assert joins[2] != null : "Could not find task stakeholders join!"; return joins; }
toAttrJoinType = ((PluralAttribute) parentJoinAttr).getElementType().getJavaType(); } else { String joinName = parentJoinAttr.getDeclaringType().getJavaType().getSimpleName() + "." + parentJoinAttr.getName(); throw new IllegalStateException("Unknown attribute type encountered when trying to join " + joinName ); fieldParentJoin = grandparentJoin.join((SetAttribute) parentJoinAttr); } else { throw new IllegalStateException("Unknown attribute type encountered when trying to join" + parentJoinAttr.getName() );
private String [] createOriginalAndExpectedKeys(Attribute embeddedAttr, PluralAttribute listAttr) { String originalKey = embeddedAttr.getDeclaringType().getJavaType().getName() + "." + embeddedAttr.getName() + "." + listAttr.getName(); String copyKey = listAttr.getDeclaringType().getJavaType().getName() + "." + listAttr.getName(); String [] keys = { originalKey, copyKey }; return keys; }
jpaqlQuery.append( correlationRootAlias ) .append( '.' ) .append( correlationJoinImpl.getAttribute().getName() ) .append( " as " ) .append( correlationJoinImpl.getAlias() );
/** * Gets the column name. * * @param attribute * the attribute * @return the column name */ public String getColumnName(Attribute attribute) { return attribute.getName(); }
/** * @param attrib * @return */ QueryBuilder appendAttribute(Attribute attrib) { this.builder.append("."); this.builder.append(attrib.getName()); return this; }
public MetamodelUtilAttribute(Attribute<?,?> singularAttrib) { this(singularAttrib.getName(), singularAttrib.isAssociation()); }
QueryBuilder appendOrdering(Order orderAttribute) { DefaultPath expression = (DefaultPath) orderAttribute.getExpression(); Attribute attrib = expression.getAttribute(); Attribute embedAttribute = expression.getEmbeddedAttribute(); String fieldName = null; this.builder.append("."); if (embedAttribute != null) { fieldName = embedAttribute.getName(); this.builder.append(fieldName); this.builder.append("."); } this.builder.append(attrib.getName()); SortOrder order = ((QueryOrder) orderAttribute).getOrder(); this.builder.append(Constants.SPACE); this.builder.append(order.name()); return this; }
public static void onJPAColumnMapping(final EntityType entityType, EntityMetadata entityMetadata) { Set<Attribute> attributes = entityType.getAttributes(); Iterator<Attribute> iter = attributes.iterator(); while (iter.hasNext()) { Attribute attribute = iter.next(); // jpa column mapping is for non id columns only. if (!entityMetadata.getIdAttribute().equals(attribute)) { entityMetadata.addJPAColumnMapping(((AbstractAttribute) attribute).getJPAColumnName(), attribute.getName()); } } entityMetadata.setEntityType(entityType); }
/** * @param alias * @param expr */ private void appendValueClause(final String alias, Expression expr) { ConditionalOperator condition = ((ComparisonPredicate) expr).getCondition(); DefaultPath path = (DefaultPath) ((ComparisonPredicate) expr).getLhs(); Object value = ((ComparisonPredicate) expr).getRhs(); this.builder.append(alias); this.builder.append("."); if (path.getEmbeddedAttribute() != null) { this.builder.append(path.getEmbeddedAttribute().getName()); this.builder.append("."); } this.builder.append(path.getAttribute().getName()); this.builder.append(Constants.SPACE); this.builder.append(conditions.get(condition)); this.builder.append(Constants.SPACE); appendValue(value, isStringLiteral(((AbstractAttribute) path.getAttribute()).getBindableJavaType(), value)); this.builder.append(Constants.SPACE); }
/** * Checks if is string property. * * @param m * the m * @param fieldName * the field name * @return true, if is string property */ private boolean isStringProperty(EntityType entityType, Attribute attribute) { String discriminatorColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn(); if (attribute.getName().equals(discriminatorColumn)) { return true; } return attribute != null ? ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(String.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Character.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(char.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(Date.class) || ((AbstractAttribute) attribute).getBindableJavaType().isAssignableFrom(java.util.Date.class) : false; } }
private String getActualColumnName(Attribute attribute) { if (attribute instanceof DefaultSingularAttribute) { DefaultSingularAttribute dsAttribute = (DefaultSingularAttribute) attribute; if (dsAttribute.isId()) { return "_id"; } else { return dsAttribute.getJPAColumnName(); } } else if (attribute instanceof AbstractAttribute) { return ((AbstractAttribute) attribute).getJPAColumnName(); } else { return attribute.getName(); } }
/** * @param alias * @param expr * @param btw */ private void appendBTValueClause(final String alias, Expression expr, BetweenPredicate btw) { DefaultPath path = (DefaultPath) expr; this.builder.append(alias); this.builder.append("."); this.builder.append(path.getAttribute().getName()); this.builder.append(Constants.SPACE); this.builder.append(conditions.get(btw.getCondition())); this.builder.append(Constants.SPACE); appendValue(btw.getLower(), isStringLiteral(((AbstractAttribute) path.getAttribute()).getBindableJavaType(), btw.getLower())); this.builder.append(Constants.SPACE); this.builder.append("AND"); this.builder.append(Constants.SPACE); appendValue(btw.getUpper(), isStringLiteral(((AbstractAttribute) path.getAttribute()).getBindableJavaType(), btw.getUpper())); }