if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) { query = new ReadAllQuery(type.getJavaType()); List<org.eclipse.persistence.expressions.Expression> list = ((FromImpl) this.roots.iterator().next()).findJoinFetches();
if (singularAttType.getPersistenceType().equals(PersistenceType.ENTITY)) {
this.managedTypes.put(descriptorJavaType, managedType); if (managedType.getPersistenceType().equals(PersistenceType.ENTITY)) { this.entities.put(descriptorJavaType, (EntityTypeImpl<?>) managedType); if (managedType.getPersistenceType().equals(PersistenceType.EMBEDDABLE)) { this.embeddables.put(descriptorJavaType, (EmbeddableTypeImpl<?>) managedType);
if (((PluralAttribute) attribute).getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) { join = new BasicCollectionJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) { this.queryResult = ResultType.ENTITY; // this will be a selection item in a report query } else {
node = this.currentNode.anyOf(assoc.getName()); if (assoc.getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { if (assoc.getCollectionType().equals(CollectionType.COLLECTION)) { fetch = new BasicCollectionJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) assoc).getBindableJavaType(), node, (Bindable) assoc, jt);
private void addPrimaryKey(MetadataFactory mf, Metamodel model, EntityType<?> entity, Table entityTable) throws TranslatorException { if (entity.getIdType().getPersistenceType().equals(PersistenceType.BASIC)) { SingularAttribute<?, ?> pkattr = entity.getId(entity.getIdType().getJavaType()); addColumn(mf, pkattr.getName(), TypeFacility.getDataTypeName(getJavaDataType(pkattr.getJavaType())), entityTable); mf.addPrimaryKey("PK_"+entity.getName(), Arrays.asList(pkattr.getName()), entityTable); //$NON-NLS-1$ else if (entity.getIdType().getPersistenceType().equals(PersistenceType.EMBEDDABLE)) { SingularAttribute<?, ?> pkattr = entity.getId(entity.getIdType().getJavaType()); for (EmbeddableType<?> embeddable:model.getEmbeddables()) {
Join join; if (attribute.isCollection()) { if (!((PluralAttribute) attribute).getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) { join = new CollectionJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute); if (((SingularAttribute)attribute).getType().getPersistenceType().equals(PersistenceType.BASIC)){ return new PathImpl<Y>(this, this.metamodel, clazz, this.currentNode.get(attribute.getName()), (Bindable)attribute); }else{
private boolean isAttributeSelfReferencing(NonIdPersistentAttribute attribute) { if ( attribute.isAssociation() ) { if ( attribute.getPersistenceType().equals( PersistenceType.ENTITY ) ) { if ( getMappedClass().equals( attribute.getJavaType() ) ) { return true; else if ( attribute.getPersistenceType().equals( PersistenceType.EMBEDDABLE ) ) { final SingularPersistentAttributeEmbedded embedded = (SingularPersistentAttributeEmbedded) attribute; final EmbeddedTypeDescriptor<?> embeddedDescriptor = embedded.getEmbeddedDescriptor();
} else { TypeImpl type = ((MetamodelImpl)this.metamodel).getType(selection.getJavaType()); if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) { this.subQuery.addAttribute("", new ConstantExpression(1, ((InternalSelection)selection).getCurrentNode().getBuilder())); this.subQuery.addNonFetchJoinedAttribute(((InternalSelection)selection).getCurrentNode());
} else { TypeImpl type = ((MetamodelImpl)this.metamodel).getType(resultClass); if (type != null && type.getPersistenceType().equals(PersistenceType.ENTITY)) { return new CriteriaQueryImpl(this.metamodel, ResultType.ENTITY, resultClass, this); } else {
/** * Fetch join to the specified attribute using the given join type. * * @param assoc * target of the join * @param jt * join type * @return the resulting fetch join */ public <Y> Fetch<X, Y> fetch(SingularAttribute<? super X, Y> assoc, JoinType jt){ if (((SingularAttribute)assoc).getType().getPersistenceType().equals(PersistenceType.BASIC)){ throw new IllegalStateException(ExceptionLocalization.buildMessage("CAN_NOT_JOIN_TO_BASIC")); } Class clazz = assoc.getBindableJavaType(); Fetch<X, Y> join = null; ObjectExpression exp = ((ObjectExpression)this.currentNode).newDerivedExpressionNamed(assoc.getName()); if (jt.equals(JoinType.LEFT)){ exp.doUseOuterJoin(); }else if(jt.equals(JoinType.RIGHT)){ throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); }else{ exp.doNotUseOuterJoin(); } join = new JoinImpl<X, Y>(this, this.metamodel.managedType(clazz), this.metamodel, clazz, exp, assoc, jt); this.fetches.add(join); ((FromImpl)join).isFetch = true; return join; } /**
public MapKeyAttribute(CriteriaBuilderImpl criteriaBuilder, MapAttribute<?, K, ?> attribute) { this.attribute = attribute; this.jpaType = attribute.getKeyType(); this.jpaBinableJavaType = attribute.getKeyJavaType(); this.jpaBindableType = Type.PersistenceType .ENTITY.equals( jpaType.getPersistenceType() ) ? BindableType.ENTITY_TYPE : BindableType.SINGULAR_ATTRIBUTE; String guessedRoleName = determineRole( attribute ); SessionFactoryImplementor sfi = (SessionFactoryImplementor) criteriaBuilder.getEntityManagerFactory().getSessionFactory(); mapPersister = sfi.getCollectionPersister( guessedRoleName ); if ( mapPersister == null ) { throw new IllegalStateException( "Could not locate collection persister [" + guessedRoleName + "]" ); } mapKeyType = mapPersister.getIndexType(); if ( mapKeyType == null ) { throw new IllegalStateException( "Could not determine map-key type [" + guessedRoleName + "]" ); } this.persistentAttributeType = mapKeyType.isEntityType() ? PersistentAttributeType.MANY_TO_ONE : mapKeyType.isComponentType() ? PersistentAttributeType.EMBEDDED : PersistentAttributeType.BASIC; }
private void encodeManagedType(ManagedType<?> type, Element parent) { Document doc = parent.getOwnerDocument(); Element root = doc.createElement(type.getPersistenceType().toString().toLowerCase()); parent.appendChild(root); root.setAttribute(ATTR_NAME, type.getJavaType().getSimpleName()); List<Attribute<?,?>> attributes = MetamodelHelper.getAttributesInOrder(type); for (Attribute<?,?> a : attributes) { String tag = MetamodelHelper.getTagByAttributeType(a); Element child = doc.createElement(tag); root.appendChild(child); child.setAttribute(ATTR_TYPE, typeOf(a.getJavaType())); if (a instanceof PluralAttribute) { if (a instanceof MapAttribute) { child.setAttribute(ATTR_KEY_TYPE, typeOf(((MapAttribute)a).getKeyJavaType())); child.setAttribute(ATTR_VALUE_TYPE, typeOf(((MapAttribute)a).getBindableJavaType())); } else { child.setAttribute(ATTR_MEMBER_TYPE, typeOf(((PluralAttribute)a).getBindableJavaType())); } } child.setTextContent(a.getName()); } }
public <K, V> MapJoin<X, K, V> join(MapAttribute<? super X, K, V> map, JoinType jt) { org.eclipse.persistence.expressions.Expression node; Class clazz = map.getBindableJavaType(); MapJoin<X, K, V> join = null; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(map.getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(map.getName()); } if (map.getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { join = new BasicMapJoinImpl(this, this.metamodel, clazz, node, (Bindable) map, jt); } else { join = new MapJoinImpl(this, metamodel.managedType(clazz), this.metamodel, clazz, node, (Bindable) map, jt); } this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
public <Y> CollectionJoin<X, Y> join(CollectionAttribute<? super X, Y> collection, JoinType jt) { org.eclipse.persistence.expressions.Expression node; Class clazz = collection.getBindableJavaType(); CollectionJoin<X, Y> join = null; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(collection.getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(collection.getName()); } if (collection.getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { join = new BasicCollectionJoinImpl<X, Y>(this, this.metamodel, clazz, node, (Bindable) collection, jt); } else { join = new CollectionJoinImpl<X, Y>(this, metamodel.managedType(clazz), this.metamodel, clazz, node, (Bindable) collection, jt); } this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
protected List<EdmProperty.Builder> getProperties(String modelNamespace, ManagedType<?> et) { List<EdmProperty.Builder> properties = new ArrayList<EdmProperty.Builder>(); for (Attribute<?, ?> att : et.getAttributes()) { if (att.isCollection()) {} else { SingularAttribute<?, ?> sa = (SingularAttribute<?, ?>) att; Type<?> type = sa.getType(); // Do we have an embedded composite key here? If so, we have to flatten the @EmbeddedId since // only any set of non-nullable, immutable, <EDMSimpleType> declared properties MAY serve as the key. if (sa.isId() && type.getPersistenceType() == PersistenceType.EMBEDDABLE) { properties.addAll(getProperties(modelNamespace, (ManagedType<?>) sa.getType())); } else if (type.getPersistenceType().equals(PersistenceType.BASIC) || type.getPersistenceType().equals(PersistenceType.EMBEDDABLE)) { EdmProperty.Builder prop = toEdmProperty(modelNamespace, sa); properties.add(prop); } } } return properties; }
public <Y> ListJoin<X, Y> join(ListAttribute<? super X, Y> list, JoinType jt) { org.eclipse.persistence.expressions.Expression node; Class clazz = list.getBindableJavaType(); ListJoin<X, Y> join = null; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(list.getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(list.getName()); } if (list.getElementType().getPersistenceType().equals(PersistenceType.BASIC)) { join = new BasicListJoinImpl<X, Y>(this, this.metamodel, clazz, node, (Bindable) list, jt); } else { join = new ListJoinImpl<X, Y>(this, metamodel.managedType(clazz), this.metamodel, clazz, node, (Bindable) list, jt); } this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
public <Y> Join<X, Y> join(SingularAttribute<? super X, Y> attribute, JoinType jt) { if (((SingularAttribute)attribute).getType().getPersistenceType().equals(PersistenceType.BASIC)){ throw new IllegalStateException(ExceptionLocalization.buildMessage("CAN_NOT_JOIN_TO_BASIC")); } Class clazz = attribute.getBindableJavaType(); Join<X, Y> join = null; ObjectExpression exp = ((ObjectExpression)this.currentNode).newDerivedExpressionNamed(attribute.getName()); if (jt.equals(JoinType.LEFT)){ exp.doUseOuterJoin(); }else if(jt.equals(JoinType.RIGHT)){ throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); }else{ exp.doNotUseOuterJoin(); } join = new JoinImpl<X, Y>(this, this.metamodel.managedType(clazz), this.metamodel, clazz, exp, attribute, jt); this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }