Example usage for org.hibernate.mapping PersistentClass hasEmbeddedIdentifier

List of usage examples for org.hibernate.mapping PersistentClass hasEmbeddedIdentifier

Introduction

In this page you can find the example usage for org.hibernate.mapping PersistentClass hasEmbeddedIdentifier.

Prototype

public abstract boolean hasEmbeddedIdentifier();

Source Link

Usage

From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil.java

License:Apache License

public static GroovyAwareJavassistProxyFactory buildProxyFactory(PersistentClass persistentClass) {
    GroovyAwareJavassistProxyFactory proxyFactory = new GroovyAwareJavassistProxyFactory();

    @SuppressWarnings("unchecked")
    Set<Class<HibernateProxy>> proxyInterfaces = CollectionUtils.newSet(HibernateProxy.class);

    final Class<?> javaClass = persistentClass.getMappedClass();
    final Property identifierProperty = persistentClass.getIdentifierProperty();
    final Getter idGetter = identifierProperty != null ? identifierProperty.getGetter(javaClass) : null;
    final Setter idSetter = identifierProperty != null ? identifierProperty.getSetter(javaClass) : null;

    if (idGetter == null || idSetter == null)
        return null;

    try {// ww w .j  a  v  a2  s . co m
        proxyFactory.postInstantiate(persistentClass.getEntityName(), javaClass, proxyInterfaces,
                idGetter.getMethod(), idSetter.getMethod(),
                persistentClass.hasEmbeddedIdentifier()
                        ? (CompositeType) persistentClass.getIdentifier().getType()
                        : null);
    } catch (HibernateException e) {
        LOG.warn("Cannot instantiate proxy factory: " + e.getMessage());
        return null;
    }

    return proxyFactory;
}

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

License:Open Source License

@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
    if (persistentClass.getClassName() == null) { // an entity, no proxy
        return null;
    }//  w  ww  .ja v  a 2s  . c o  m

    final HbDataStore ds = HbHelper.INSTANCE.getDataStore(persistentClass);
    final EClass eclass = ds.getEntityNameStrategy().toEClass(persistentClass.getEntityName());
    if (eclass == null) {
        throw new HbMapperException("No eclass found for entityname: " + persistentClass.getEntityName());
    }

    // get all the interfaces from the main class, add the real interface
    // first
    final Set<Class<?>> proxyInterfaces = new LinkedHashSet<Class<?>>();
    final Class<?> pInterface = persistentClass.getProxyInterface();
    if (pInterface != null) {
        proxyInterfaces.add(pInterface);
    }
    final Class<?> mappedClass = persistentClass.getMappedClass();
    if (mappedClass.isInterface()) {
        proxyInterfaces.add(mappedClass);
    }
    proxyInterfaces.add(HibernateProxy.class);
    proxyInterfaces.add(TeneoInternalEObject.class);

    for (Class<?> interfaces : mappedClass.getInterfaces()) {
        proxyInterfaces.add(interfaces);
    }

    // iterate over all subclasses and add them also
    final Iterator<?> iter = persistentClass.getSubclassIterator();
    while (iter.hasNext()) {
        final Subclass subclass = (Subclass) iter.next();
        final Class<?> subclassProxy = subclass.getProxyInterface();
        final Class<?> subclassClass = subclass.getMappedClass();
        if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
            proxyInterfaces.add(subclassProxy);
        }
    }

    // get the idgettters/setters
    final Method theIdGetterMethod = idGetter == null ? null : idGetter.getMethod();
    final Method theIdSetterMethod = idSetter == null ? null : idSetter.getMethod();

    final Method proxyGetIdentifierMethod = theIdGetterMethod == null || pInterface == null ? null
            : ReflectHelper.getMethod(pInterface, theIdGetterMethod);
    final Method proxySetIdentifierMethod = theIdSetterMethod == null || pInterface == null ? null
            : ReflectHelper.getMethod(pInterface, theIdSetterMethod);

    ProxyFactory pf = Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
    try {
        pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod,
                proxySetIdentifierMethod,
                persistentClass.hasEmbeddedIdentifier()
                        ? (CompositeType) persistentClass.getIdentifier().getType()
                        : null);
    } catch (HbStoreException e) {
        log.warn("could not create proxy factory for:" + getEntityName(), e);
        pf = null;
    }
    return pf;
}

From source file:org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.java

License:Open Source License

@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
    if (persistentClass.getProxyInterface() == null) { // an entity, no
        // proxy//  w w w.  j  a  va 2s  .  c  om
        return null;
    }

    final HbDataStore ds = HbHelper.INSTANCE.getDataStore(persistentClass);
    final EClass eclass = ds.getEntityNameStrategy().toEClass(persistentClass.getEntityName());
    if (eclass == null && !persistentClass.getEntityName().equals(Constants.EAV_EOBJECT_ENTITY_NAME)) {
        throw new HbMapperException("No eclass found for entityname: " + persistentClass.getEntityName());
    }

    // get all the interfaces from the main class, add the real interface
    // first
    final Set<Class<?>> proxyInterfaces = new LinkedHashSet<Class<?>>();
    final Class<?> pInterface = persistentClass.getProxyInterface();
    if (pInterface != null && pInterface.isInterface()) {
        proxyInterfaces.add(pInterface);
    }
    Class<?> mappedClass = persistentClass.getMappedClass();
    if (mappedClass == null) {
        mappedClass = DynamicEObjectImpl.class;
    }
    if (mappedClass.isInterface()) {
        proxyInterfaces.add(mappedClass);
    }
    proxyInterfaces.add(HibernateProxy.class);
    proxyInterfaces.add(TeneoInternalEObject.class);

    for (Class<?> interfaces : mappedClass.getInterfaces()) {
        proxyInterfaces.add(interfaces);
    }

    // iterate over all subclasses and add them also
    final Iterator<?> iter = persistentClass.getSubclassIterator();
    while (iter.hasNext()) {
        final Subclass subclass = (Subclass) iter.next();
        final Class<?> subclassProxy = subclass.getProxyInterface();
        final Class<?> subclassClass = subclass.getMappedClass();
        if (subclassProxy != null && subclassClass != null && !subclassClass.equals(subclassProxy)) {
            proxyInterfaces.add(subclassProxy);
        }
    }

    // get the idgettters/setters
    final Method theIdGetterMethod = idGetter == null ? null : idGetter.getMethod();
    final Method theIdSetterMethod = idSetter == null ? null : idSetter.getMethod();

    final Method proxyGetIdentifierMethod = theIdGetterMethod == null || pInterface == null ? null
            : ReflectHelper.getMethod(pInterface, theIdGetterMethod);
    final Method proxySetIdentifierMethod = theIdSetterMethod == null || pInterface == null ? null
            : ReflectHelper.getMethod(pInterface, theIdSetterMethod);

    ProxyFactory pf = Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
    try {
        pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod,
                proxySetIdentifierMethod,
                persistentClass.hasEmbeddedIdentifier()
                        ? (CompositeType) persistentClass.getIdentifier().getType()
                        : null);
    } catch (HbStoreException e) {
        log.warn("could not create proxy factory for:" + getEntityName(), e);
        pf = null;
    }
    return pf;
}

From source file:org.grails.orm.hibernate.cfg.GrailsHibernateUtil.java

License:Apache License

/**
 * Constructs a proxy factory instance/*from w  ww.j av a2 s  .co m*/
 *
 * @param persistentClass The persistent class
 * @return The factory
 */
public static ProxyFactory buildProxyFactory(PersistentClass persistentClass) {
    ProxyFactory proxyFactory = ProxyFactorySupport.createProxyFactory();

    @SuppressWarnings("unchecked")
    Set<Class> proxyInterfaces = new HashSet<>();
    proxyInterfaces.add(HibernateProxy.class);

    final Class<?> javaClass = persistentClass.getMappedClass();
    final Property identifierProperty = persistentClass.getIdentifierProperty();
    final Method idGetterMethod = identifierProperty != null
            ? identifierProperty.getGetter(javaClass).getMethod()
            : null;
    final Method idSetterMethod = identifierProperty != null
            ? identifierProperty.getSetter(javaClass).getMethod()
            : null;
    final Type identifierType = persistentClass.hasEmbeddedIdentifier()
            ? persistentClass.getIdentifier().getType()
            : null;

    try {
        proxyFactory.postInstantiate(persistentClass.getEntityName(), javaClass, proxyInterfaces,
                idGetterMethod, idSetterMethod,
                identifierType instanceof CompositeType ? (CompositeType) identifierType : null);
    } catch (HibernateException e) {
        LOG.warn("Cannot instantiate proxy factory: " + e.getMessage());
        return null;
    }

    return proxyFactory;
}

From source file:org.openbravo.dal.core.OBTuplizer.java

License:Open Source License

@Override
protected ProxyFactory buildProxyFactory(PersistentClass thePersistentClass, Getter idGetter, Setter idSetter) {
    final Class<?> mappedClass = thePersistentClass.getMappedClass();
    Check.isNotNull(mappedClass, "Mapped class of entity " + thePersistentClass.getEntityName() + " is null");

    // determine the id getter and setter methods from the proxy interface
    // (if// ww w . j  ava  2 s  .  com
    // any)
    // determine all interfaces needed by the resulting proxy
    final HashSet<Object> proxyInterfaces = new HashSet<Object>();
    proxyInterfaces.add(HibernateProxy.class);

    final Class<?> proxyInterface = thePersistentClass.getProxyInterface();

    if (proxyInterface != null && !mappedClass.equals(proxyInterface)) {
        if (!proxyInterface.isInterface()) {
            throw new MappingException(
                    "proxy must be either an interface, or the class itself: " + getEntityName());
        }
        proxyInterfaces.add(proxyInterface);
    }

    if (mappedClass.isInterface()) {
        proxyInterfaces.add(mappedClass);
    }

    final Iterator<?> iter = thePersistentClass.getSubclassIterator();
    while (iter.hasNext()) {
        final Subclass subclass = (Subclass) iter.next();
        final Class<?> subclassProxy = subclass.getProxyInterface();
        final Class<?> subclassClass = subclass.getMappedClass();
        if (subclassProxy != null && !subclassClass.equals(subclassProxy)) {
            if (proxyInterface == null || !proxyInterface.isInterface()) {
                throw new MappingException(
                        "proxy must be either an interface, or the class itself: " + subclass.getEntityName());
            }
            proxyInterfaces.add(subclassProxy);
        }
    }

    final Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
    final Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();

    final Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ? null
            : ReflectHelper.getMethod(proxyInterface, idGetterMethod);
    final Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ? null
            : ReflectHelper.getMethod(proxyInterface, idSetterMethod);

    ProxyFactory pf = buildProxyFactoryInternal(thePersistentClass, idGetter, idSetter);
    try {
        pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod,
                proxySetIdentifierMethod,
                thePersistentClass.hasEmbeddedIdentifier()
                        ? (CompositeType) thePersistentClass.getIdentifier().getType()
                        : null);
    } catch (final HibernateException he) {
        log.warn("could not create proxy factory for:" + getEntityName(), he);
        pf = null;
    }
    return pf;
}