Java 类javax.persistence.metamodel.EmbeddableType 实例源码

项目:redg    文件:JpaMetamodelRedGProvider.java   
private void analyzeAttributes(ManagedType<?> managedType, String targetTableName) {
    managedType.getSingularAttributes().forEach(attribute -> {
        ManagedType<?> targetEntity = managedTypesByClass.get(attribute.getJavaType());
        if (targetEntity != null && attribute.getType() instanceof EmbeddableType) {
            analyzeAttributes((EmbeddableType) attribute.getType(), targetTableName);
        } else if (targetEntity != null && attribute.getType() instanceof IdentifiableType) { // this is a relation
            Map<String, String> referenceColumnNamesMap =
                    getReferenceColumnNamesMapForReferenceAttribute(attribute, targetEntity);
            singularAttributesByForeignKeyRelation.put(
                    new ForeignKeyRelation(targetTableName, getTableName(targetEntity.getJavaType()), referenceColumnNamesMap),
                    attribute
            );
        } else {
            String columnName = getSingularAttributeColumnName(attribute);
            singularAttributesByColumnName.put(new QualifiedColumnName(targetTableName, columnName), attribute);
        }
    });
}
项目:olingo-odata2    文件:JPAEdmComplexTypeTest.java   
@SuppressWarnings("rawtypes")
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  @SuppressWarnings("hiding")
  class JPAComplexAttribute<Long> extends JPAEmbeddableMock<Long> {

    @SuppressWarnings("unchecked")
    @Override
    public Class<Long> getJavaType() {

      return (Class<Long>) java.lang.Long.class;
    }

  }
  return new JPAComplexAttribute();
}
项目:stdlib    文件:QEntityFactory.java   
public QEntity getEmbeddable(final Class clazz, final EmbeddableType ct)
{
    if (!entities.containsKey(clazz))
    {
        if (log.isDebugEnabled())
            log.debug("Begin create QEntity " + clazz + " from EmbeddableType " + ct);

        QEntity entity = new QEntity(clazz);
        entities.put(clazz, entity);

        entity.parseEmbeddable(this, sessionFactory, null, ct);

        if (log.isDebugEnabled())
            log.debug("End create QEntity " + clazz + " from EmbeddableType " + ct);
    }

    return entities.get(clazz);
}
项目:cloud-odata-java    文件:JPAEdmComplexTypeTest.java   
@SuppressWarnings("rawtypes")
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  @SuppressWarnings("hiding")
  class JPAComplexAttribute<Long> extends JPAEmbeddableMock<Long>
  {

    @SuppressWarnings("unchecked")
    @Override
    public Class<Long> getJavaType() {

      return (Class<Long>) java.lang.Long.class;
    }

  }
  return new JPAComplexAttribute();
}
项目:crnk-framework    文件:JpaMetaProvider.java   
private static Set<Class> toTypes(EntityManagerFactory entityManagerFactory) {
    Set<Class> set = new HashSet<>();

    Set<EmbeddableType<?>> embeddables = entityManagerFactory.getMetamodel().getEmbeddables();
    for (EmbeddableType<?> embeddable : embeddables) {
        set.add(embeddable.getJavaType());
    }

    Set<EntityType<?>> entities = entityManagerFactory.getMetamodel().getEntities();
    for (EntityType<?> entity : entities) {
        set.add(entity.getJavaType());
    }
    return set;
}
项目:katharsis-framework    文件:JpaMetaProvider.java   
@Override
public void discoverElements(MetaProviderContext context) {
    if (entityManagerFactory != null) {
        Set<EmbeddableType<?>> embeddables = entityManagerFactory.getMetamodel().getEmbeddables();
        for (EmbeddableType<?> embeddable : embeddables) {
            context.getLookup().getMeta(embeddable.getJavaType(), MetaJpaDataObject.class);
        }

        Set<EntityType<?>> entities = entityManagerFactory.getMetamodel().getEntities();
        for (EntityType<?> entity : entities) {
            context.getLookup().getMeta(entity.getJavaType(), MetaJpaDataObject.class);
        }
    }
}
项目:kc-rice    文件:JpaMetadataProviderImpl.java   
/**
    * Gets the attribute names for the primary keys from the given entity type.
    *
    * @param entityType The entity type of the data object.
    * @return A list of primary key attribute names.
    */
protected List<String> getPrimaryKeyAttributeNames(EntityType<?> entityType) {
    List<String> primaryKeyAttributeNames = new ArrayList<String>();
    // JHK: After examining of the metadata structures of EclipseLink, I determined that there
    // was nothing in those which preserved the order of the original annotations.
    // We *need* to know the order of PK fields for KNS/KRAD functionality.
    // So, I'm falling back to checking the annotations and fields on the referenced objects.
    // Yes, the Javadoc states that the getDeclaredFields() method does not guarantee order,
    // But, it's the best we have. And, as of Java 6, it is returning them in declaration order.

    if (entityType.getIdType() instanceof EmbeddableType) {
        for (Field pkField : entityType.getIdType().getJavaType().getDeclaredFields()) {
            primaryKeyAttributeNames.add(pkField.getName());
        }
    } else {
        // First, get the ID attributes from the metadata
        List<String> unsortedPkFields = new ArrayList<String>();
        for (SingularAttribute attr : entityType.getSingularAttributes()) {
            if (attr.isId()) {
                unsortedPkFields.add(attr.getName());
            }
        }

           getPrimaryKeyNamesInOrder(primaryKeyAttributeNames, unsortedPkFields, entityType.getJavaType().getDeclaredFields(), entityType.getJavaType());
    }
    return primaryKeyAttributeNames;
}
项目:olingo-odata2    文件:JPAEdmComplexType.java   
public JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute) {
  super(view);
  schemaView = view;
  for (EmbeddableType<?> jpaEmbeddable : schemaView.getJPAMetaModel().getEmbeddables()) {
    if (jpaEmbeddable.getJavaType().getName().equals(complexAttribute.getJavaType().getName())) {
      nestedComplexType = jpaEmbeddable;
      break;
    }
  }
  directBuild = false;
  if (nonKeyComplexList == null) {
    nonKeyComplexList = new ArrayList<String>();
  }
}
项目:rice    文件:JpaMetadataProviderImpl.java   
/**
    * Gets the attribute names for the primary keys from the given entity type.
    *
    * @param entityType The entity type of the data object.
    * @return A list of primary key attribute names.
    */
protected List<String> getPrimaryKeyAttributeNames(EntityType<?> entityType) {
    List<String> primaryKeyAttributeNames = new ArrayList<String>();
    // JHK: After examining of the metadata structures of EclipseLink, I determined that there
    // was nothing in those which preserved the order of the original annotations.
    // We *need* to know the order of PK fields for KNS/KRAD functionality.
    // So, I'm falling back to checking the annotations and fields on the referenced objects.
    // Yes, the Javadoc states that the getDeclaredFields() method does not guarantee order,
    // But, it's the best we have. And, as of Java 6, it is returning them in declaration order.

    if (entityType.getIdType() instanceof EmbeddableType) {
        for (Field pkField : entityType.getIdType().getJavaType().getDeclaredFields()) {
            primaryKeyAttributeNames.add(pkField.getName());
        }
    } else {
        // First, get the ID attributes from the metadata
        List<String> unsortedPkFields = new ArrayList<String>();
        for (SingularAttribute attr : entityType.getSingularAttributes()) {
            if (attr.isId()) {
                unsortedPkFields.add(attr.getName());
            }
        }

           getPrimaryKeyNamesInOrder(primaryKeyAttributeNames, unsortedPkFields, entityType.getJavaType().getDeclaredFields(), entityType.getJavaType());
    }
    return primaryKeyAttributeNames;
}
项目:stdlib    文件:QEntity.java   
/**
 * Parse an @Embeddable
 *
 * @param entityFactory
 * @param sessionFactory
 * @param prefix
 * @param type
 */
public void parseEmbeddable(final QEntityFactory entityFactory,
                            final SessionFactoryImplementor sessionFactory,
                            final String prefix,
                            final EmbeddableType<?> type)
{
    this.metamodelEmbeddable = type;
    // Make sure the entity factory sees this embeddable
    entityFactory.getEmbeddable(type.getJavaType(), type);

    for (Attribute<?, ?> attribute : type.getAttributes())
    {
        parseFields(entityFactory, sessionFactory, prefix, attribute);
    }
}
项目:cloud-odata-java    文件:JPAEdmComplexType.java   
public JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute) {
  super(view);
  schemaView = view;
  for (EmbeddableType<?> jpaEmbeddable : schemaView.getJPAMetaModel().getEmbeddables())
  {
    if (jpaEmbeddable.getJavaType().getName().equals(complexAttribute.getJavaType().getName()))
    {
      nestedComplexType = jpaEmbeddable;
      break;
    }
  }
  directBuild = false;
}
项目:olingo-odata2    文件:JPAEdmComplexType.java   
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  return currentEmbeddableType;
}
项目:olingo-odata2    文件:JPAEdmComplexType.java   
@Override
public void build() throws ODataJPAModelException, ODataJPARuntimeException {
  Set<EmbeddableType<?>> embeddables = new HashSet<EmbeddableType<?>>();

  if (consistentComplextTypes == null) {
    consistentComplextTypes = new ArrayList<ComplexType>();
  }

  if (searchMap == null) {
    searchMap = new HashMap<String, ComplexType>();
  }

  if (directBuild) {
    embeddables = schemaView.getJPAMetaModel().getEmbeddables();
  } else {
    embeddables.add(nestedComplexType);
  }

  for (EmbeddableType<?> embeddableType : embeddables) {

    currentEmbeddableType = embeddableType;
    String searchKey = embeddableType.getJavaType().getName();

    if (searchMap.containsKey(searchKey)) {
      continue;
    }

    // Check for need to Exclude
    if (isExcluded(JPAEdmComplexType.this)) {
      continue;
    }

    JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView, JPAEdmComplexType.this);
    propertyView.getBuilder().build();

    currentComplexType = new ComplexType();
    currentComplexType.setProperties(propertyView.getEdmPropertyList());
    JPAEdmNameBuilder.build(JPAEdmComplexType.this);

    searchMap.put(searchKey, currentComplexType);
    consistentComplextTypes.add(currentComplexType);

  }

}
项目:olingo-odata2    文件:JPAMetaModelMock.java   
@Override
public <X> EmbeddableType<X> embeddable(final Class<X> arg0) {
  return null;
}
项目:olingo-odata2    文件:JPAMetaModelMock.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  return null;
}
项目:olingo-odata2    文件:JPAEdmTestModelView.java   
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  return null;
}
项目:olingo-odata2    文件:JPAEdmModelTest.java   
public JPAEdmMetaModel() {
  embeddableSet = new HashSet<EmbeddableType<?>>();
}
项目:olingo-odata2    文件:JPAEdmModelTest.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  embeddableSet.add(new JPAEdmEmbeddable<String>());
  return embeddableSet;
}
项目:olingo-odata2    文件:JPAEdmPropertyTest.java   
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  return new JPAEdmEmbeddable<java.lang.String>();
}
项目:olingo-odata2    文件:JPAEdmPropertyTest.java   
public JPAEdmMetaModel() {
  entities = new HashSet<EntityType<?>>();
  embeddableSet = new HashSet<EmbeddableType<?>>();
}
项目:olingo-odata2    文件:JPAEdmPropertyTest.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  embeddableSet.add(new JPAEdmEmbeddable<String>());
  return embeddableSet;
}
项目:olingo-odata2    文件:JPAEdmComplexTypeTest.java   
public JPAEdmMetaModel() {
  embeddableSet = new HashSet<EmbeddableType<?>>();
}
项目:olingo-odata2    文件:JPAEdmComplexTypeTest.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  embeddableSet.add(new JPAEdmEmbeddable<String>());
  return embeddableSet;
}
项目:breeze.server.java    文件:JPAMetadata.java   
/**
 * Adds an embeddable type definition
 * 
 * @param sattr - The embeddable type metamodel
 */
String addComponent(SingularAttribute sattr) {
    Class<?> type = sattr.getJavaType();

    // "Location:#com.breeze.model"
    String classKey = getEntityTypeName(type);
    if (_typeNames.contains(classKey)) {
        // Only add a complex type definition once.
        return classKey;
    }

    HashMap<String, Object> cmap = new LinkedHashMap<String, Object>();
    _typeList.add(0, cmap);
    _typeNames.add(classKey);

    cmap.put("shortName", type.getSimpleName());
    cmap.put("namespace", type.getPackage().getName());
    cmap.put("isComplexType", true);

    ArrayList<HashMap<String, Object>> dataArrayList = new ArrayList<HashMap<String, Object>>();
    cmap.put("dataProperties", dataArrayList);

    EmbeddableType<?> bed = _emFactory.getMetamodel().embeddable(type);

    for (Attribute<?,?> attrib : bed.getAttributes()) {
        PersistentAttributeType attrType = attrib.getPersistentAttributeType();
        if (!(attrib instanceof SingularAttribute)) {
            throw new RuntimeException("Collections not supported in complex types");
        }
        SingularAttribute cattr = (SingularAttribute) attrib; 
        if (attrType == PersistentAttributeType.EMBEDDED) {
            // nested complex type
            String complexTypeName = addComponent(cattr);
            HashMap<String, Object> compMap = new HashMap<String, Object>();
            compMap.put("nameOnServer", attrib.getName());
            compMap.put("complexTypeName", complexTypeName);
            compMap.put("isNullable", cattr.isOptional());
            dataArrayList.add(compMap);
        } else {
            // data property
            HashMap<String, Object> dmap = makeDataProperty(cattr.getName(), cattr, false, false);
            dataArrayList.add(dmap);
        }
    }

    return classKey;
}
项目:stdlib    文件:QEntity.java   
/**
 * Parse an @Entity
 *
 * @param entityFactory
 * @param metadata
 * @param sessionFactory
 */
void parse(QEntityFactory entityFactory, EntityType<?> metadata, SessionFactoryImplementor sessionFactory)
{
    this.metamodelEntity = metadata;
    this.name = metadata.getName();

    for (Attribute<?, ?> attribute : metadata.getAttributes())
    {
        parseFields(entityFactory, sessionFactory, null, attribute);
    }

    // Parse top-level properties

    // Add identifier property
    {
        if (!metadata.hasSingleIdAttribute())
            throw new IllegalArgumentException("@IdClass Entity not supported! " + metadata.getJavaType());

        Type idType = metadata.getIdType();

        switch (idType.getPersistenceType())
        {
            case BASIC:
                break; // No action necessary, will be processed like a normal field
            case EMBEDDABLE:
            {
                EmbeddableType<?> emb = (EmbeddableType<?>) idType;

                parseEmbeddable(entityFactory, sessionFactory, "id", emb);
                break;
            }
            default:
                throw new IllegalArgumentException("Cannot handle id type: " + idType.getPersistenceType() + ": " + idType);
        }
    }

    // Add links to descendants
    {
        final List<QEntity> descendants = entityFactory.getSubclasses(clazz);

        if (!descendants.isEmpty())
            this.descendants = descendants;
    }


    // Figure out the id method/field
    final String idPropertyName = getIdPropertyName();

    if (idPropertyName != null)
        this.idProperty = new PropertyWrapper(clazz, idPropertyName);
}
项目:query-utils    文件:EmbeddableUtil.java   
static <T> EmbeddableType<T> getEmbeddableType(Bindable<T> attribute, Metamodel metamodel) {
    logger.debug("getEmbeddableType({},{})", attribute, metamodel);
    EmbeddableType<T> ret = metamodel.embeddable(attribute.getBindableJavaType());
    logger.debug("getEmbeddableType -> {}", ret);
    return ret;
}
项目:cloud-odata-java    文件:JPAEdmComplexType.java   
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  return currentEmbeddableType;
}
项目:cloud-odata-java    文件:JPAEdmComplexType.java   
@Override
public void build() throws ODataJPAModelException, ODataJPARuntimeException {
  Set<EmbeddableType<?>> embeddables = new HashSet<EmbeddableType<?>>();

  if (consistentComplextTypes == null) {
    consistentComplextTypes = new ArrayList<ComplexType>();
  }

  if (searchMap == null) {
    searchMap = new HashMap<String, ComplexType>();
  }

  if (directBuild) {
    embeddables = schemaView.getJPAMetaModel().getEmbeddables();
  } else {
    embeddables.add(nestedComplexType);
  }

  for (EmbeddableType<?> embeddableType : embeddables) {

    currentEmbeddableType = embeddableType;
    String searchKey = embeddableType.getJavaType().getName();

    if (searchMap.containsKey(searchKey)) {
      continue;
    }

    // Check for need to Exclude
    if (isExcluded(JPAEdmComplexType.this)) {
      continue;
    }

    JPAEdmPropertyView propertyView = new JPAEdmProperty(
        schemaView, JPAEdmComplexType.this);
    propertyView.getBuilder().build();

    currentComplexType = new ComplexType();
    currentComplexType
        .setProperties(propertyView.getEdmPropertyList());
    JPAEdmNameBuilder.build(JPAEdmComplexType.this);

    searchMap.put(searchKey, currentComplexType);
    consistentComplextTypes.add(currentComplexType);

  }

}
项目:cloud-odata-java    文件:JPAMetaModelMock.java   
@Override
public <X> EmbeddableType<X> embeddable(final Class<X> arg0) {
  return null;
}
项目:cloud-odata-java    文件:JPAMetaModelMock.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  return null;
}
项目:cloud-odata-java    文件:JPAEdmTestModelView.java   
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  return null;
}
项目:cloud-odata-java    文件:JPAEdmModelTest.java   
public JPAEdmMetaModel() {
  embeddableSet = new HashSet<EmbeddableType<?>>();
}
项目:cloud-odata-java    文件:JPAEdmModelTest.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  embeddableSet.add(new JPAEdmEmbeddable<String>());
  return embeddableSet;
}
项目:cloud-odata-java    文件:JPAEdmPropertyTest.java   
@Override
public EmbeddableType<?> getJPAEmbeddableType() {
  return new JPAEdmEmbeddable<java.lang.String>();
}
项目:cloud-odata-java    文件:JPAEdmPropertyTest.java   
public JPAEdmMetaModel() {
  entities = new HashSet<EntityType<?>>();
  embeddableSet = new HashSet<EmbeddableType<?>>();
}
项目:cloud-odata-java    文件:JPAEdmPropertyTest.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  embeddableSet.add(new JPAEdmEmbeddable<String>());
  return embeddableSet;
}
项目:cloud-odata-java    文件:JPAEdmComplexTypeTest.java   
public JPAEdmMetaModel() {
  embeddableSet = new HashSet<EmbeddableType<?>>();
}
项目:cloud-odata-java    文件:JPAEdmComplexTypeTest.java   
@Override
public Set<EmbeddableType<?>> getEmbeddables() {
  embeddableSet.add(new JPAEdmEmbeddable<String>());
  return embeddableSet;
}