List of usage examples for org.hibernate.proxy ProxyFactory postInstantiate
void postInstantiate(String entityName, Class persistentClass, Set<Class> interfaces, Method getIdentifierMethod, Method setIdentifierMethod, CompositeType componentIdType) throws HibernateException;
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; }/* ww w .java 2s . c om*/ 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/*from www . j a v a 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 ava 2s . 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.OBDynamicTuplizer.java
License:Open Source License
@Override protected ProxyFactory buildProxyFactory(PersistentClass thePersistentClass, Getter idGetter, Setter idSetter) { ProxyFactory pf = new MapProxyFactory(); try {//from w w w . j a v a2 s.co m pf.postInstantiate(getEntityName(), null, null, null, null, null); } catch (final HibernateException he) { log.warn("could not create proxy factory for:" + getEntityName(), he); 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/* www . j av a2 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; }