Search in sources :

Example 1 with PersistenceWeaver

use of org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method predeployCompositeMembers.

protected void predeployCompositeMembers(Map predeployProperties, ClassLoader tempClassLoader) {
    // get all puInfos found in jar-files specified in composite's persistence.xml
    // all these puInfos are not composite because composites are recursively "taken apart", too.
    Set<SEPersistenceUnitInfo> compositeMemberPuInfos = getCompositeMemberPuInfoSet(persistenceUnitInfo, predeployProperties);
    // makes sure each member has a non-null property, overrides where required properties with composite's predeploy properties.
    updateCompositeMembersProperties(compositeMemberPuInfos, predeployProperties);
    // Don't log these properties - may contain passwords. The properties will be logged by contained persistence units.
    Map compositeMemberMapOfProperties = (Map) getConfigProperty(PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES, predeployProperties);
    this.compositeMemberEmSetupImpls = new HashSet<>(compositeMemberPuInfos.size());
    this.processor = new MetadataProcessor();
    if (enableWeaving) {
        this.weaver = new PersistenceWeaver(new HashMap<String, ClassDetails>());
    }
    // all composite members should complete a stage before any of them can move to the next one.
    for (SEPersistenceUnitInfo compositeMemberPuInfo : compositeMemberPuInfos) {
        // set composite's temporary classloader
        compositeMemberPuInfo.setNewTempClassLoader(tempClassLoader);
        String containedPuName = compositeMemberPuInfo.getPersistenceUnitName();
        EntityManagerSetupImpl containedEmSetupImpl = new EntityManagerSetupImpl(containedPuName, containedPuName);
        // set composite
        containedEmSetupImpl.setCompositeEmSetupImpl(this);
        // non-null only in case predeploy is used for static weaving
        containedEmSetupImpl.setStaticWeaveInfo(this.staticWeaveInfo);
        // the properties guaranteed to be non-null after updateCompositeMemberProperties call
        Map compositeMemberProperties = (Map) compositeMemberMapOfProperties.get(containedPuName);
        containedEmSetupImpl.predeploy(compositeMemberPuInfo, compositeMemberProperties);
        // reset temporary classloader back to the original
        compositeMemberPuInfo.setNewTempClassLoader(compositeMemberPuInfo.getClassLoader());
        this.compositeMemberEmSetupImpls.add(containedEmSetupImpl);
    }
    // mode = COMPOSITE_MEMBER_MIDDLE mode
    for (EntityManagerSetupImpl containedEmSetupImpl : this.compositeMemberEmSetupImpls) {
        // properties not used, puInfo already set
        containedEmSetupImpl.predeploy(null, null);
    }
    // mode = COMPOSITE_MEMBER_FINAL mode
    for (EntityManagerSetupImpl containedEmSetupImpl : this.compositeMemberEmSetupImpls) {
        // properties not used, puInfo already set
        PersistenceWeaver containedWeaver = (PersistenceWeaver) containedEmSetupImpl.predeploy(null, null);
        // if both composite and composite member weavings enabled copy class details from member's weaver to composite's one.
        if (enableWeaving && containedWeaver != null) {
            this.weaver.getClassDetailsMap().putAll(containedWeaver.getClassDetailsMap());
        }
    }
    if (enableWeaving && this.weaver.getClassDetailsMap().isEmpty()) {
        this.weaver = null;
    }
}
Also used : HashMap(java.util.HashMap) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) SEPersistenceUnitInfo(org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) HashMap(java.util.HashMap) MetadataProcessor(org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor) PersistenceWeaver(org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver)

Example 2 with PersistenceWeaver

use of org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver in project eclipselink by eclipse-ee4j.

the class SimpleWeaverTestSuite method buildWeaver.

public PersistenceWeaver buildWeaver(Session session, Collection entities) {
    PersistenceWeaver tw = null;
    try {
        tw = TransformerFactory.createTransformerAndModifyProject(session, entities, Thread.currentThread().getContextClassLoader(), true, false, true, true, true, false);
    } catch (Exception e) {
        fail(getName() + " failed: " + e.toString());
    }
    assertNotNull("could not build TopLinkWeaver", tw);
    return tw;
}
Also used : PersistenceWeaver(org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver) IOException(java.io.IOException)

Aggregations

PersistenceWeaver (org.eclipse.persistence.internal.jpa.weaving.PersistenceWeaver)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IdentityMap (org.eclipse.persistence.internal.identitymaps.IdentityMap)1 EntityManagerFactoryProvider.getConfigPropertyAsString (org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)1 SEPersistenceUnitInfo (org.eclipse.persistence.internal.jpa.deployment.SEPersistenceUnitInfo)1 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)1