Java Code Examples for javax.persistence.metamodel.SingularAttribute#getBindableJavaType()
The following examples show how to use
javax.persistence.metamodel.SingularAttribute#getBindableJavaType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private <Y> JoinImplementor<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, JoinType jt) { if ( Type.PersistenceType.BASIC.equals( attribute.getType().getPersistenceType() ) ) { throw new BasicPathUsageException( "Cannot join to attribute of basic type", attribute ); } // TODO : runtime check that the attribute in fact belongs to this From's model/bindable if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } final Class<Y> attributeType = attribute.getBindableJavaType(); return new SingularAttributeJoin<X, Y>( criteriaBuilder(), attributeType, this, attribute, jt ); }
Example 2
Source File: ByExampleUtil.java From javaee-lab with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public <T extends Identifiable<?>, M2O extends Identifiable<?>> List<Predicate> byExampleOnXToOne(ManagedType<T> mt, Root<T> mtPath, T mtValue, SearchParameters sp, CriteriaBuilder builder) { List<Predicate> predicates = newArrayList(); for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) { if (attr.getPersistentAttributeType() == MANY_TO_ONE || attr.getPersistentAttributeType() == ONE_TO_ONE) { M2O m2oValue = (M2O) jpaUtil.getValue(mtValue, mt.getAttribute(attr.getName())); Class<M2O> m2oType = (Class<M2O>) attr.getBindableJavaType(); Path<M2O> m2oPath = (Path<M2O>) mtPath.get(attr); ManagedType<M2O> m2oMt = em.getMetamodel().entity(m2oType); if (m2oValue != null) { if (m2oValue.isIdSet()) { // we have an id, let's restrict only on this field predicates.add(builder.equal(m2oPath.get("id"), m2oValue.getId())); } else { predicates.addAll(byExample(m2oMt, m2oPath, m2oValue, sp, builder)); } } } } return predicates; }
Example 3
Source File: JpaMetadataProviderImpl.java From rice with Educational Community License v2.0 | 6 votes |
/** * Gets a single field's relationship metadata. * * @param rd The singular attribute to process. * @return The single field's relationship metadata. */ protected DataObjectRelationship getRelationshipMetadata(SingularAttribute rd) { try { DataObjectRelationshipImpl relationship = new DataObjectRelationshipImpl(); // OJB stores the related class object name. We need to go into the repository and grab the table name. Class<?> referencedClass = rd.getBindableJavaType(); EntityType<?> referencedEntityType = entityManager.getMetamodel().entity(referencedClass); relationship.setName(rd.getName()); relationship.setRelatedType(referencedClass); populateImplementationSpecificRelationshipLevelMetadata(relationship, rd); return relationship; } catch (RuntimeException ex) { LOG.error("Unable to process Relationship metadata: " + rd); throw ex; } }
Example 4
Source File: AbstractManagedType.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings({ "SimplifiableIfStatement" }) protected <Y> boolean isPrimitiveVariant(SingularAttribute<?,?> attribute, Class<Y> javaType) { if ( attribute == null ) { return false; } Class declaredType = attribute.getBindableJavaType(); if ( declaredType.isPrimitive() ) { return ( Boolean.class.equals( javaType ) && Boolean.TYPE.equals( declaredType ) ) || ( Character.class.equals( javaType ) && Character.TYPE.equals( declaredType ) ) || ( Byte.class.equals( javaType ) && Byte.TYPE.equals( declaredType ) ) || ( Short.class.equals( javaType ) && Short.TYPE.equals( declaredType ) ) || ( Integer.class.equals( javaType ) && Integer.TYPE.equals( declaredType ) ) || ( Long.class.equals( javaType ) && Long.TYPE.equals( declaredType ) ) || ( Float.class.equals( javaType ) && Float.TYPE.equals( declaredType ) ) || ( Double.class.equals( javaType ) && Double.TYPE.equals( declaredType ) ); } if ( javaType.isPrimitive() ) { return ( Boolean.class.equals( declaredType ) && Boolean.TYPE.equals( javaType ) ) || ( Character.class.equals( declaredType ) && Character.TYPE.equals( javaType ) ) || ( Byte.class.equals( declaredType ) && Byte.TYPE.equals( javaType ) ) || ( Short.class.equals( declaredType ) && Short.TYPE.equals( javaType ) ) || ( Integer.class.equals( declaredType ) && Integer.TYPE.equals( javaType ) ) || ( Long.class.equals( declaredType ) && Long.TYPE.equals( javaType ) ) || ( Float.class.equals( declaredType ) && Float.TYPE.equals( javaType ) ) || ( Double.class.equals( declaredType ) && Double.TYPE.equals( javaType ) ); } return false; }
Example 5
Source File: AbstractRSQLMapper.java From pnc with Apache License 2.0 | 5 votes |
protected <X extends GenericEntity<?>> Path<?> mapEntity( From<?, DB> from, SingularAttribute<DB, X> entity, RSQLSelectorPath selector) { Class<X> bindableJavaType = entity.getBindableJavaType(); From<DB, X> join = from.join(entity); return mapper.toPath(bindableJavaType, join, selector); }
Example 6
Source File: AbstractRSQLMapper.java From pnc with Apache License 2.0 | 5 votes |
@Override public String toPath(RSQLSelectorPath selector) { String name = selector.getElement(); if (toAttribute(name) != null) { return toAttribute(name).getName(); } SingularAttribute<DB, ? extends GenericEntity<?>> entity = toEntity(name); if (entity != null) { Class<? extends GenericEntity<?>> bindableType = entity.getBindableJavaType(); return entity.getName() + "." + mapper.toPath(bindableType, selector.next()); } throw new RSQLException("Unknown RSQL selector " + name + " for type " + type); }
Example 7
Source File: EclipseLinkJpaMetadataProviderImpl.java From rice with Educational Community License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override protected void populateImplementationSpecificRelationshipLevelMetadata(DataObjectRelationshipImpl relationship, SingularAttribute<?, ?> rd) { // We need to go into the repository and grab the table name. Class<?> referencedClass = rd.getBindableJavaType(); EntityType<?> referencedEntityType = entityManager.getMetamodel().entity(referencedClass); if (referencedEntityType instanceof EntityTypeImpl) { relationship .setBackingObjectName(((EntityTypeImpl<?>) referencedEntityType).getDescriptor().getTableName()); } // Set to read only if store (save) operations should not be pushed through PersistentAttributeType persistentAttributeType = rd.getPersistentAttributeType(); if (rd instanceof SingularAttributeImpl) { SingularAttributeImpl<?, ?> rel = (SingularAttributeImpl<?, ?>) rd; OneToOneMapping relationshipMapping = (OneToOneMapping) rel.getMapping(); relationship.setReadOnly(relationshipMapping.isReadOnly()); relationship.setSavedWithParent(relationshipMapping.isCascadePersist()); relationship.setDeletedWithParent(relationshipMapping.isCascadeRemove()); relationship.setLoadedAtParentLoadTime(relationshipMapping.isCascadeRefresh() && !relationshipMapping.isLazy()); relationship.setLoadedDynamicallyUponUse(relationshipMapping.isCascadeRefresh() && relationshipMapping.isLazy()); List<DataObjectAttributeRelationship> attributeRelationships = new ArrayList<DataObjectAttributeRelationship>(); List<String> referencedEntityPkFields = getPrimaryKeyAttributeNames(referencedEntityType); for (String referencedEntityPkField : referencedEntityPkFields) { for (Map.Entry<DatabaseField, DatabaseField> entry : relationshipMapping.getTargetToSourceKeyFields().entrySet()) { DatabaseField childDatabaseField = entry.getKey(); String childFieldName = getPropertyNameFromDatabaseColumnName(referencedEntityType, childDatabaseField.getName()); if (referencedEntityPkField.equalsIgnoreCase(childFieldName)) { DatabaseField parentDatabaseField = entry.getValue(); String parentFieldName = getPropertyNameFromDatabaseColumnName(rd.getDeclaringType(), parentDatabaseField.getName()); if (parentFieldName != null) { attributeRelationships .add(new DataObjectAttributeRelationshipImpl(parentFieldName, childFieldName)); break; } else { LOG.warn("Unable to find parent field reference. There may be a JPA mapping problem on " + referencedEntityType.getJavaType() + ": " + relationship); } } } } relationship.setAttributeRelationships(attributeRelationships); populateInverseRelationship(relationshipMapping, relationship); } else { // get what we can based on JPA values (note that we just set some to have values here) relationship.setReadOnly(persistentAttributeType == PersistentAttributeType.MANY_TO_ONE); relationship.setSavedWithParent(persistentAttributeType == PersistentAttributeType.ONE_TO_ONE); relationship.setDeletedWithParent(persistentAttributeType == PersistentAttributeType.ONE_TO_ONE); relationship.setLoadedAtParentLoadTime(true); relationship.setLoadedDynamicallyUponUse(false); } }