Example usage for org.hibernate.mapping PersistentClass getProxyInterface

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

Introduction

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

Prototype

public Class getProxyInterface() 

Source Link

Usage

From source file:com.googlecode.hibernate.audit.extension.auditable.DefaultAuditableInformationProvider.java

License:Open Source License

public String getAuditTypeClassName(Metadata metadata, String entityName) {
    if (provider != null) {
        return provider.getAuditTypeClassName(metadata, entityName);
    }/*from   w w w .j a v a  2s.  c om*/
    PersistentClass classMapping = metadata.getEntityBinding(entityName);
    Class mappedClass = classMapping.getMappedClass();

    if (mappedClass == null) {
        mappedClass = classMapping.getProxyInterface();
    }
    return mappedClass.getName();
}

From source file:com.googlecode.hibernate.audit.extension.auditable.DefaultAuditableInformationProvider.java

License:Open Source License

public String getEntityName(Metadata metadata, Session session, String auditTypeClassName) {
    if (provider != null) {
        return provider.getEntityName(metadata, session, auditTypeClassName);
    }/* w ww. j a  v a 2  s.  c  o m*/
    for (PersistentClass classMapping : metadata.getEntityBindings()) {
        Class mappedClass = classMapping.getMappedClass();
        if (mappedClass == null) {
            mappedClass = classMapping.getProxyInterface();
        }
        if (mappedClass.getName().equals(auditTypeClassName)) {
            return classMapping.getEntityName();
        }
    }
    return auditTypeClassName;
}

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;
    }/*from  www .  j a  v a2s  .  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.mapping.elist.FeatureMapEntryInstantiator.java

License:Open Source License

/** Constructor */
public FeatureMapEntryInstantiator(PersistentClass pc) {
    AssertUtil.assertTrue(pc.getEntityName() + " does not have a meta attribute",
            pc.getMetaAttribute(HbMapperConstants.FEATUREMAP_META) != null);
    if (log.isDebugEnabled()) {
        log.debug("Creating fme instantiator for " + pc.getEntityName());
    }//from   w w  w.  j  a  v a  2 s  .c  o m
    proxyInterface = pc.getProxyInterface();
    persistentClass = pc;
}

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

License:Open Source License

/** Constructor */
public EMFInstantiator(EClass eclass, PersistentClass pc) {
    if (log.isDebugEnabled()) {
        log.debug(/*from   w w  w  . ja v  a  2  s  .c o m*/
                "Creating eobject instantiator for " + pc.getEntityName() + " and eclass " + eclass.getName());
    }
    proxyInterface = pc.getProxyInterface();
    this.eclass = eclass;
    mappedClass = eclass.getInstanceClass();
}

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  ava 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.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/*from www  . j a  v a 2 s .  c  o m*/
    // 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;
}