Example usage for org.hibernate.mapping Property getName

List of usage examples for org.hibernate.mapping Property getName

Introduction

In this page you can find the example usage for org.hibernate.mapping Property getName.

Prototype

public String getName() 

Source Link

Usage

From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java

License:Open Source License

/** Recursively check the container prop in the super hierarchy */
private boolean hasEContainerProp(PersistentClass pc) {
    final Iterator<?> it = pc.getPropertyIterator();
    while (it.hasNext()) {
        final Property prop = (Property) it.next();
        if (prop.getName().equals(HbConstants.PROPERTY_ECONTAINER)) {
            return true;
        }// w ww  . j  a  v a 2 s.  c  om
    }
    if (pc.getSuperclass() == null) {
        return false;
    }
    return hasEContainerProp(pc.getSuperclass());
}

From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java

License:Open Source License

protected void addContainerMappingToPC(PersistentClass pc) {
    if (log.isDebugEnabled()) {
        log.debug("Adding eContainer and econtainerfeatureid properties to " + pc.getClassName());
    }/*from   w w  w . ja  va  2  s. co m*/
    final EContainerFeaturePersistenceStrategy featurePersistenceStrategy = getPersistenceOptions()
            .getEContainerFeaturePersistenceStrategy();

    final Property eContainer = new Property();
    eContainer.setName(HbConstants.PROPERTY_ECONTAINER);
    eContainer.setMetaAttributes(new HashMap<Object, Object>());
    eContainer.setNodeName(eContainer.getName());
    eContainer.setPropertyAccessorName(EContainerAccessor.class.getName());

    final SimpleValue sv = new SimpleValue(getMappings(), pc.getTable());
    sv.setTypeName(EContainerUserType.class.getName());

    final Column eccColumn = new Column(getPersistenceOptions().getSQLColumnNamePrefix()
            + getPersistenceOptions().getEContainerClassColumn());
    sv.addColumn(checkColumnExists(pc.getTable(), eccColumn));

    final Column ecColumn = new Column(
            getPersistenceOptions().getSQLColumnNamePrefix() + getPersistenceOptions().getEContainerColumn());
    sv.addColumn(checkColumnExists(pc.getTable(), ecColumn));

    eContainer.setValue(sv);
    pc.addProperty(eContainer);

    if (featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.FEATUREID)
            || featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.BOTH)) {
        final Property ecFID = new Property();
        ecFID.setName(HbConstants.PROPERTY_ECONTAINER_FEATURE_ID);
        ecFID.setMetaAttributes(new HashMap<Object, Object>());
        ecFID.setNodeName(ecFID.getName());
        ecFID.setPropertyAccessorName(EContainerFeatureIDAccessor.class.getName());
        final SimpleValue svfid = new SimpleValue(getMappings(), pc.getTable());
        svfid.setTypeName("integer");

        final Column ecfColumn = new Column(
                getPersistenceOptions().getSQLColumnNamePrefix() + HbConstants.COLUMN_ECONTAINER_FEATUREID);
        svfid.addColumn(checkColumnExists(pc.getTable(), ecfColumn));

        ecFID.setValue(svfid);
        pc.addProperty(ecFID);
    }
    if (featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.FEATURENAME)
            || featurePersistenceStrategy.equals(EContainerFeaturePersistenceStrategy.BOTH)) {
        final Property ecFID = new Property();
        ecFID.setName(HbConstants.PROPERTY_ECONTAINER_FEATURE_NAME);
        ecFID.setMetaAttributes(new HashMap<Object, Object>());
        ecFID.setNodeName(ecFID.getName());
        ecFID.setPropertyAccessorName(NewEContainerFeatureIDPropertyHandler.class.getName());
        final SimpleValue svfid = new SimpleValue(getMappings(), pc.getTable());
        svfid.setTypeName(EContainerFeatureIDUserType.class.getName());

        final Column ecfColumn = new Column(getPersistenceOptions().getSQLColumnNamePrefix()
                + getPersistenceOptions().getEContainerFeatureNameColumn());

        ecfColumn.setLength(getEContainerFeatureNameColumnLength());

        svfid.addColumn(checkColumnExists(pc.getTable(), ecfColumn));

        ecFID.setValue(svfid);
        pc.addProperty(ecFID);
    }
}

From source file:org.eclipse.emf.teneo.hibernate.HbDataStore.java

License:Open Source License

/**
 * Computes the referers, handles the lazy for containment
 *///from   w  w w  .  j  av  a 2s  .c om
protected HashMap<String, java.util.List<ReferenceTo>> computeReferers() {
    final HashMap<String, java.util.List<ReferenceTo>> result = new HashMap<String, java.util.List<ReferenceTo>>();

    final Iterator<?> it = getClassMappings();
    final ArrayList<String> fmes = new ArrayList<String>();
    while (it.hasNext()) {
        final PersistentClass pc = (PersistentClass) it.next();

        // keep track which are the feature map entries
        if (pc.getMetaAttribute(HbMapperConstants.FEATUREMAP_META) != null) {
            fmes.add(getMappedName(pc));
        }

        // everyone should have a list otherwise the copying of referers to
        // super types to
        // this type does not work
        if (result.get(getMappedName(pc)) == null) {
            result.put(getMappedName(pc), new ArrayList<ReferenceTo>());
        }

        final Iterator<?> propIt = pc.getPropertyIterator();
        while (propIt.hasNext()) {
            // handle few cases
            // OneToOne or ManyToOne, referenced class can be obtained from
            // Value and then getReferencedEntityName
            // List: in this case search for a structural feature and get
            // the EType from it
            // if no structural feature then use the type name and hope for
            // the best.

            final Property prop = (Property) propIt.next();
            EClass eClass = null;
            if (pc.getMetaAttribute(HbMapperConstants.FEATUREMAP_META) == null) {
                if (pc.getEntityName() != null) {
                    eClass = getEntityNameStrategy().toEClass(pc.getEntityName());
                } else {
                    eClass = EModelResolver.instance().getEClass(pc.getMappedClass());
                }
            }

            final EStructuralFeature ef = eClass == null ? null
                    : StoreUtil.getEStructuralFeature(eClass, prop.getName());
            try {
                String toEntity = "";
                boolean isContainer = false;
                boolean isMany = false;

                if (prop.getValue() instanceof ManyToOne) {
                    final ManyToOne mto = (ManyToOne) prop.getValue();
                    toEntity = mto.getReferencedEntityName();
                    if (ef != null) {
                        isContainer = ef instanceof EReference && ((EReference) ef).isContainment();
                    } else {
                        isContainer = prop.getCascadeStyle().hasOrphanDelete()
                                || prop.getCascade().compareTo("all") == 0; // ugly
                        // but
                    }
                    // this was
                    // the only
                    // way to
                    // get all
                    // there!
                } else if (prop.getValue() instanceof OneToOne) {
                    final OneToOne oto = (OneToOne) prop.getValue();
                    toEntity = oto.getReferencedEntityName();
                    if (ef != null) {
                        isContainer = ef instanceof EReference && ((EReference) ef).isContainment();
                    } else {
                        isContainer = prop.getCascadeStyle().hasOrphanDelete()
                                || prop.getCascadeStyle() == CascadeStyle.ALL;
                    }
                } else if (prop.getValue() instanceof Collection) {
                    isMany = true;
                    if (ef == null) { // TODO can this happen?
                        isContainer = prop.getCascadeStyle().hasOrphanDelete()
                                || prop.getCascadeStyle() == CascadeStyle.ALL;
                        if (((Collection) prop.getValue()).getElement() instanceof OneToMany) {
                            final Collection coll = (Collection) prop.getValue();
                            toEntity = ((OneToMany) coll.getElement()).getReferencedEntityName();
                        } else if (((Collection) prop.getValue()).getElement() instanceof ManyToOne) {
                            final Collection coll = (Collection) prop.getValue();
                            toEntity = ((ManyToOne) coll.getElement()).getReferencedEntityName();
                        } else {
                            continue;
                            // throw new HbMapperException("Type "
                            // + ((Collection)
                            // prop.getValue()).getElement().getClass().getName()
                            // + " not supported, property " +
                            // prop.getName());
                        }
                    } else {
                        // in case of featuremap set containment always on
                        // true because only the featuremap entries
                        // themselves know if they are containment
                        if (ef instanceof EAttribute
                                && ((EAttribute) ef).getEType().getInstanceClass() == Entry.class) {
                            isContainer = true;
                            // composite-elements are not supported.
                            if (!(((Collection) prop.getValue()).getElement() instanceof OneToMany)) {
                                continue;
                            }
                            final OneToMany otm = (OneToMany) ((Collection) prop.getValue()).getElement();
                            toEntity = otm.getReferencedEntityName();
                        } else if (ef instanceof EReference) {
                            final EReference er = (EReference) ef;
                            isContainer = er.isContainment(); // prop.getCascadeStyle().
                            // hasOrphanDelete()
                            // ||
                            // prop.getCascadeStyle()
                            // ==
                            // CascadeStyle.ALL;
                            toEntity = getEntityNameStrategy()
                                    .toEntityName(((EReference) ef).getEReferenceType());
                        } else if (ef instanceof EAttribute && ef.getEType() instanceof EClass) { // TODO
                            // can
                            // this
                            // ever
                            // happen?
                            isContainer = true; // prop.getCascadeStyle().hasOrphanDelete()
                            // || prop.getCascadeStyle()
                            // == CascadeStyle.ALL;
                            toEntity = getEntityNameStrategy().toEntityName((EClass) ef.getEType());
                        }
                        // filter out non eobjects
                        else {
                            continue;
                        }
                    }
                } else {
                    continue;
                }

                java.util.List<ReferenceTo> list = result.get(toEntity);
                if (list == null) {
                    list = new ArrayList<ReferenceTo>();
                    result.put(toEntity, list);
                }

                list.add(new ReferenceTo(getMappedName(pc), prop, isContainer, isMany, toEntity));
            } catch (StoreClassLoadException e) {
                throw new HbMapperException("Class not found using property: " + prop.getName() + " of " + prop,
                        e);
            }
        }
    }

    // at the end for each class all the refersto of superclasses and
    // interfaces are added also
    final ArrayList<EClass> classDone = new ArrayList<EClass>();
    for (String em : result.keySet()) {
        // only do this if not a fme
        if (!fmes.contains(em)) {
            setRefersToOfSupers(em, result, classDone);
        }
    }
    return result;
}

From source file:org.eclipse.emf.teneo.hibernate.HbUtil.java

License:Open Source License

/** Returns the correct accessor on the basis of the type of property */
public static PropertyAccessor getPropertyAccessor(Property mappedProperty, HbDataStore ds, String entityName,
        EClass mappedEClass) {/*  ww  w.  j av a2  s  .  c o m*/
    if (mappedProperty.getMetaAttribute(HbConstants.SYNTHETIC_PROPERTY_INDICATOR) != null) { // synthetic
        return new SyntheticPropertyHandler(mappedProperty.getName());
    } else if (mappedProperty.getMetaAttribute(HbMapperConstants.ID_META) != null) { // synthetic
        // ID
        return new IdentifierPropertyHandler();
    } else if (mappedProperty.getMetaAttribute(HbMapperConstants.VERSION_META) != null) {
        return ds.getHbContext().createVersionAccessor();
    } else if (mappedProperty.getName().compareToIgnoreCase("_identifierMapper") == 0) { // name
        // is
        // used
        // by
        // hb
        return new EmbeddedPropertyAccessor(); // new
        // DummyPropertyHandler();
    } else if (mappedProperty.getName().compareToIgnoreCase(HbConstants.PROPERTY_ECONTAINER) == 0) {
        return ds.getHbContext().createEContainerAccessor();
    } else if (mappedProperty.getName()
            .compareToIgnoreCase(HbConstants.PROPERTY_ECONTAINER_FEATURE_NAME) == 0) {
        return ds.getExtensionManager().getExtension(NewEContainerFeatureIDPropertyHandler.class);
    } else if (mappedProperty.getName().compareToIgnoreCase(HbConstants.PROPERTY_ECONTAINER_FEATURE_ID) == 0) {
        return ds.getHbContext().createEContainerFeatureIDAccessor();
    }

    EClass eClass = null;
    if (mappedEClass != null) {
        eClass = mappedEClass;
    } else {
        eClass = ds.getEntityNameStrategy().toEClass(entityName);
        if (eClass == null) {
            // for components this is the case
            eClass = ERuntime.INSTANCE.getEClass(entityName);
        }
    }
    final EStructuralFeature efeature = StoreUtil.getEStructuralFeature(eClass, mappedProperty.getName());

    if (efeature == null) {
        throw new HbMapperException("Feature not found for eclass/entity/property " + eClass.getName() + "/"
                + entityName + "/" + mappedProperty.getName());
    }

    if (log.isDebugEnabled()) {
        log.debug("Creating property accessor for " + mappedProperty.getName() + "/" + entityName + "/"
                + efeature.getName());
    }

    // check extra lazy
    final boolean extraLazy = mappedProperty.getValue() instanceof Collection
            && ((Collection) mappedProperty.getValue()).isExtraLazy();

    if (FeatureMapUtil.isFeatureMap(efeature)) {
        return ds.getHbContext().createFeatureMapPropertyAccessor(efeature);
    } else if (efeature instanceof EReference) {
        final EReference eref = (EReference) efeature;
        if (eref.isMany()) {
            return ds.getHbContext().createEListAccessor(efeature, extraLazy,
                    ds.getPersistenceOptions().isMapEMapAsTrueMap());
        } else {
            PropertyAccessor erefPropertyHandler = ds.getHbContext().createEReferenceAccessor(eref);
            if (erefPropertyHandler instanceof EReferencePropertyHandler) {
                if (mappedProperty.getPersistentClass() != null) {
                    ((EReferencePropertyHandler) erefPropertyHandler).setId(
                            mappedProperty == mappedProperty.getPersistentClass().getIdentifierProperty());
                }
            }
            return erefPropertyHandler;
        }
    } else {
        final EAttribute eattr = (EAttribute) efeature;
        if (eattr.isMany()) {
            return ds.getHbContext().createEListAccessor(efeature, extraLazy,
                    ds.getPersistenceOptions().isMapEMapAsTrueMap());
        } else {
            // note also array types are going here!
            final PropertyAccessor pa = ds.getHbContext().createEAttributeAccessor(eattr);
            // note this check is necessary because maybe somebody override
            // HBContext.createEAttributeAccessor
            // to not return a EAttributePropertyHandler
            if (pa instanceof EAttributePropertyHandler) {
                final EAttributePropertyHandler eAttributePropertyHandler = (EAttributePropertyHandler) pa;
                eAttributePropertyHandler.setPersistenceOptions(ds.getPersistenceOptions());
                if (mappedProperty.getPersistentClass() != null) {
                    eAttributePropertyHandler.setId(
                            mappedProperty == mappedProperty.getPersistentClass().getIdentifierProperty());
                }
            }
            return pa;
        }
    }
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.eav.EAVObjectTuplizer.java

License:Open Source License

@Override
protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
    if (mappedProperty.getName().equals("values")) {
        return mappedProperty.getGetter(EObjectImpl.class);
    }/* w  w w.j a v  a2  s . c om*/
    return getPropertyAccessor(mappedProperty, mappedEntity).getGetter(null, mappedProperty.getName());
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.eav.EAVObjectTuplizer.java

License:Open Source License

@Override
protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
    if (mappedProperty.getName().equals("values")) {
        return mappedProperty.getSetter(EObjectImpl.class);
    }/*  w ww . ja  va2 s.  c  o m*/
    return getPropertyAccessor(mappedProperty, mappedEntity).getSetter(null, mappedProperty.getName());
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.FeatureMapEntryComponentTuplizer.java

License:Open Source License

protected Getter buildGetter(Component component, Property prop) {
    return getPropertyAccessor(prop, component).getGetter(component.getComponentClass(), prop.getName());
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.FeatureMapEntryComponentTuplizer.java

License:Open Source License

protected Setter buildSetter(Component component, Property prop) {
    return getPropertyAccessor(prop, component).getSetter(component.getComponentClass(), prop.getName());
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.FeatureMapEntryComponentTuplizer.java

License:Open Source License

protected PropertyAccessor getPropertyAccessor(Property mappedProperty, Component component) {
    final HbDataStore hds = HbHelper.INSTANCE.getDataStore(component.getOwner());
    if (mappedProperty.getMetaAttribute(HbMapperConstants.VERSION_META) != null) {
        return hds.getHbContext().createVersionAccessor();
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_FEATURE) == 0) {
        return hds.getHbContext().createFeatureMapEntryFeatureURIAccessor();
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_CDATA) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.CDATA);
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_COMMENT) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.COMMENT);
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_TEXT) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.TEXT);
    } else if (mappedProperty.getName().endsWith(HbMapperConstants.PROPERTY_ANY_PRIMITIVE)) {
        return hds.getExtensionManager().getExtension(WildCardAttributePropertyHandler.class);
    } else if (mappedProperty.getName().endsWith(HbMapperConstants.PROPERTY_ANY_REFERENCE)) {
        return hds.getExtensionManager().getExtension(WildCardReferencePropertyHandler.class);
    }// ww w .j  a v  a2 s . c  o  m

    final MetaAttribute ma = component.getMetaAttribute(HbMapperConstants.FEATUREMAP_META);
    final String eclassUri = ma.getValue();
    final EClass eClass = hds.getEntityNameStrategy().toEClass(eclassUri);
    final EStructuralFeature efeature = StoreUtil.getEStructuralFeature(eClass, mappedProperty.getName());

    if (efeature == null) {
        throw new HbMapperException("Feature not found for property " + mappedProperty.getName());
    }

    if (log.isDebugEnabled()) {
        log.debug("Creating property accessor for " + mappedProperty.getName() + "/" + eclassUri + "/"
                + efeature.getName());
    }

    return hds.getHbContext().createFeatureMapEntryAccessor(efeature);
}

From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.FeatureMapEntryTuplizer.java

License:Open Source License

/** Returns the correct accessor on the basis of the type of property */
@Override/*from w  w w . j  av a2s . c o  m*/
protected PropertyAccessor getPropertyAccessor(Property mappedProperty, PersistentClass pc) {
    final HbDataStore hds = HbHelper.INSTANCE.getDataStore(pc);
    if (mappedProperty.getMetaAttribute(HbMapperConstants.VERSION_META) != null) {
        return hds.getHbContext().createVersionAccessor();
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_FEATURE) == 0) {
        return hds.getHbContext().createFeatureMapEntryFeatureURIAccessor();
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_CDATA) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.CDATA);
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_COMMENT) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.COMMENT);
    } else if (mappedProperty.getName().compareToIgnoreCase(HbMapperConstants.PROPERTY_MIXED_TEXT) == 0) {
        return hds.getHbContext().createFeatureMapEntryAccessor(Constants.TEXT);
    } else if (mappedProperty.getName().endsWith(HbMapperConstants.PROPERTY_ANY_PRIMITIVE)) {
        return hds.getExtensionManager().getExtension(WildCardAttributePropertyHandler.class);
    } else if (mappedProperty.getName().endsWith(HbMapperConstants.PROPERTY_ANY_REFERENCE)) {
        return hds.getExtensionManager().getExtension(WildCardReferencePropertyHandler.class);
    }

    final String eclassUri = HbUtil.getEClassNameFromFeatureMapMeta(pc);
    final EClass eClass = hds.getEntityNameStrategy().toEClass(eclassUri);
    final EStructuralFeature efeature = StoreUtil.getEStructuralFeature(eClass, mappedProperty.getName());

    if (efeature == null) {
        throw new HbMapperException(
                "Feature not found for entity/property " + pc.getEntityName() + "/" + mappedProperty.getName());
    }

    if (log.isDebugEnabled()) {
        log.debug("Creating property accessor for " + mappedProperty.getName() + "/" + pc.getEntityName() + "/"
                + eclassUri + "/" + efeature.getName());
    }

    return hds.getHbContext().createFeatureMapEntryAccessor(efeature);
}