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();
}
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;
}
@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);
}
}
}
/**
* 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>();
}
}
/**
* 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,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,prefix,attribute);
}
}
项目:cloud-odata-java
文件:JPAEdmComplexType.java
public JPAEdmComplexType(final JPAEdmSchemaView view,?> 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
项目: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
文件:JPAEdmTestModelView.java
项目:olingo-odata2
文件:JPAEdmModelTest.java
项目:olingo-odata2
文件:JPAEdmModelTest.java
项目:olingo-odata2
文件:JPAEdmPropertyTest.java
项目:olingo-odata2
文件:JPAEdmPropertyTest.java
项目:olingo-odata2
文件:JPAEdmPropertyTest.java
项目:olingo-odata2
文件:JPAEdmComplexTypeTest.java
项目:olingo-odata2
文件:JPAEdmComplexTypeTest.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,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,"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);
}
项目:cloud-odata-java
文件:JPAEdmComplexType.java
项目:cloud-odata-java
文件:JPAEdmComplexType.java
@Override
public void build() throws ODataJPAModelException,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
文件:JPAEdmTestModelView.java
项目:cloud-odata-java
文件:JPAEdmModelTest.java
项目:cloud-odata-java
文件:JPAEdmModelTest.java
项目:cloud-odata-java
文件:JPAEdmPropertyTest.java
项目:cloud-odata-java
文件:JPAEdmPropertyTest.java
项目:cloud-odata-java
文件:JPAEdmPropertyTest.java
项目:cloud-odata-java
文件:JPAEdmComplexTypeTest.java
项目:cloud-odata-java
文件:JPAEdmComplexTypeTest.java
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。